# File: tktest.py from Tkinter import * import sys from sdr1khw import * class Application(Frame): def __init__(self, master): Frame.__init__(self,master) self.grid() self.create_widgets() global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts self.dkrd() sdr = SDR1000('test', True, True, False, 0x378) sdr.PowerOn() sdr.SetFreq(x) if lna == 0: sdr.SetINAOn(False) self.lna.set(0) elif lna == 1: sdr.SetINAOn(True) self.lna.set(1) else: pass if att == 0: sdr.SetATTOn(False) self.lna.set(0) elif att == 1: sdr.SetATTOn(True) self.lna.set(1) else: pass self.freq_readout = Text(self, width=10, height = 1, wrap=NONE) self.freq_readout.grid(row=0, column=2) self.frd() self.band.set(band) self.lna.set(lna) self.att.set(att) def create_widgets(self): global v, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts self.band=IntVar() self.lna=IntVar() self.att=IntVar() self.band160 = Radiobutton(self, text="1.8 MHz", variable = self.band, value = 160, command = self.ch_band) self.band160.grid(row=0, column=0, columnspan=1, sticky="NW") self.band80 = Radiobutton(self, text="3.5 MHz", variable = self.band, value = 80, command = self.ch_band) self.band80.grid(row=1, column=0, columnspan=1, sticky="NW") self.band60 = Radiobutton(self, text="5.3 MHz", variable = self.band, value = 60, command = self.ch_band) self.band60.grid(row=2, column=0, columnspan=1, sticky="NW") self.band40 = Radiobutton(self, text=" 7 MHz", variable = self.band, value = 40, command = self.ch_band) self.band40.grid(row=3, column=0, columnspan=1, sticky="NW") self.band30 = Radiobutton(self, text=" 10 MHz", variable = self.band, value = 30, command = self.ch_band) self.band30.grid(row=0, column=1, columnspan=1, sticky="NW") self.band20 = Radiobutton(self, text=" 14 MHz", variable = self.band, value = 20, command = self.ch_band) self.band20.grid(row=1, column=1, columnspan=1, sticky="NW") self.band17 = Radiobutton(self, text=" 18 MHz", variable = self.band, value = 17, command = self.ch_band) self.band17.grid(row=2, column=1, columnspan=1, sticky="NW") self.band15 = Radiobutton(self, text=" 21 MHz", variable = self.band, value = 15, command = self.ch_band) self.band15.grid(row=3, column=1, columnspan=1, sticky="NW") self.band12 = Radiobutton(self, text=" 24 MHz", variable = self.band, value = 12, command = self.ch_band) self.band12.grid(row=2, column=2, columnspan=1, sticky="NW") self.band10 = Radiobutton(self, text=" 28 MHz", variable = self.band, value = 10, command = self.ch_band) self.band10.grid(row=3, column=2, columnspan=1, sticky="NW") self.button = Button(self, text="QUIT", fg="red", command=self.quit) self.button.grid(row=0, column=5, columnspan=1, sticky="NE") self.ch_freq_up250000 = Button(self, text="up 250 kHz", command=self.up_250000) self.ch_freq_up250000.grid(row=1, column=3, columnspan=1, sticky="NE") self.ch_freq_dn250000 = Button(self, text="dn 250 kHz", command=self.dn_250000) self.ch_freq_dn250000.grid(row=2, column=3, columnspan=1, sticky="NE") self.ch_freq_up50000 = Button(self, text="up 50 kHz", command=self.up_50000) self.ch_freq_up50000.grid(row=1, column=4, columnspan=1, sticky="NE") self.ch_freq_dn50000 = Button(self, text="dn 50 kHz", command=self.dn_50000) self.ch_freq_dn50000.grid(row=2, column=4, columnspan=1, sticky="NE") self.ch_freq_up = Button(self, text="up 5 kHz", command=self.up_5000) self.ch_freq_up.grid(row=1, column=5, columnspan=1, sticky="NE") self.ch_freq_dn = Button(self, text="dn 5 kHz", command=self.dn_5000) self.ch_freq_dn.grid(row=2, column=5, columnspan=1, sticky="NE") self.ch_freq_up50 = Button(self, text="up 50 Hz", command=self.up_50) self.ch_freq_up50.grid(row=1, column=6, columnspan=1, sticky="NE") self.ch_freq_dn50 = Button(self, text="dn 50 Hz", command=self.dn_50) self.ch_freq_dn50.grid(row=2, column=6, columnspan=1, sticky="NE") self.reset = Button(self, text="reset", command=self.reset) self.reset.grid(row=0, column=4, columnspan=1, sticky="NE") self.freq_readout_label = Label(self, width=10, height = 1, text = "Frequency") self.freq_readout_label.grid(row=1, column=2, sticky="N") self.lna_on = Radiobutton(self, text="LNA On", variable = self.lna, value = 0, command = self.lna_on) self.lna_on.grid(row=3, column=3, columnspan=1, sticky="E") self.lna_off = Radiobutton(self, text="LNA Off", variable = self.lna, value = 1, command = self.lna_off) self.lna_off.grid(row=3, column=4, columnspan=1, sticky="E") self.att_on = Radiobutton(self, text="Att On", variable = self.att, value = 1, command = self.att_on) self.att_on.grid(row=3, column=5, columnspan=1, sticky="E") self.att_off = Radiobutton(self, text="Att Off", variable = self.att, value = 0, command = self.att_off) self.att_off.grid(row=3, column=6, columnspan=1, sticky="E") self.gtfr = Checkbutton(self, text="QSY", variable = self.gtfr, command = self.gtfr) self.gtfr.grid(row=0, column=3) def gtfr(self): global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) bands=str(band) vn = v v = self.freq_readout.get(0.0,END) try: x=float(v) v=str(x) if x > 0.012 and x < 60: sdr.SetFreq(x) self.gtfr.flash() self.gtfr.deselect() self.frd() self.stv() self.dkwrt() else: v=vn x=float(vn) v=str(x) self.frd() self.stv() self.dkwrt() self.gtfr.flash() self.gtfr.deselect() except (ValueError): v=vn x=float(vn) v=str(x) self.frd() self.stv() self.dkwrt() self.gtfr.flash() self.gtfr.deselect() def lna_on(self): global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() lnas = str (lna) sdr.SetINAOn(False) bands=str(band) self.dkwrt() def lna_off(self): global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() lnas = str(lna) sdr.SetINAOn(True) bands=str(band) self.dkwrt() # print v # print "LNAS=" + lnas # print "ATTS=" + atts def att_on(self): global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts att = self.att.get() atts = str(att) sdr.SetATTOn(True) bands=str(band) self.dkwrt() # print v # print "LNAS=" + lnas # print "ATTS=" + atts def att_off(self): global v, band, bands, sdr, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts att = self.att.get() atts = str(att) sdr.SetATTOn(False) bands=str(band) f=open('sdrini','w') self.dkwrt() # print v # print "LNAS=" + lnas # print "ATTS=" + atts def ch_band(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts band = self.band.get() lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) if band == 160: v = v160 x=float(v160) sdr.SetFreq(x) elif band == 80: v = v80 x=float(v80) sdr.SetFreq(x) elif band == 60: v = v60 x=float(v60) sdr.SetFreq(x) elif band == 40: v = v40 x=float(v40) sdr.SetFreq(x) elif band == 30: v = v30 x=float(v30) sdr.SetFreq(x) elif band == 20: v = v20 x=float(v20) sdr.SetFreq(x) elif band == 17: v = v17 x=float(v17) sdr.SetFreq(x) elif band == 15: v = v15 x=float(v15) sdr.SetFreq(x) elif band == 12: v = v12 x=float(v12) sdr.SetFreq(x) elif band == 10: v = v10 x=float(v10) sdr.SetFreq(x) else: pass bands=str(band) self.dkwrt() # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() def reset(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts self.dkrd() self.frd() sdr = SDR1000('test', True, True, False, 0x378) sdr.PowerOn() sdr.SetFreq(x) def dn_250000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x - 0.25 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def up_250000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x + 0.25 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def dn_50000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x - 0.05 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def up_50000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x + 0.05 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def dn_5000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x - 0.005 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def up_5000(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x + 0.005 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def up_50(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x + 0.00005 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def dn_50(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts lna = self.lna.get() att = self.att.get() atts = str(att) lnas = str(lna) x = float(v) x = x - 0.00005 sdr.SetFreq(x) v = str(x) # print v # print "LNAS=" + lnas # print "ATTS=" + atts self.frd() self.stv() self.dkwrt() def dkrd(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts try: f=open('sdrini','r') band=int(f.readline()) x=float(f.readline()) x160=float(f.readline()) x80=float(f.readline()) x60=float(f.readline()) x40=float(f.readline()) x30=float(f.readline()) x20=float(f.readline()) x17=float(f.readline()) x15=float(f.readline()) x12=float(f.readline()) x10=float(f.readline()) lna=int(f.readline()) att=int(f.readline()) f.close() v = str(x) v160=str(x160) v80=str(x80) v60=str(x60) v40=str(x40) v30=str(x30) v20=str(x20) v17=str(x17) v15=str(x15) v12=str(x12) v10=str(x10) bands = str(band) lnas = str(lna) atts = str(att) # print v except(IOError,ValueError): band=40 bands="40" v="7.050" v160="1.800" x160=1.800 v80="3.550" x80=3.550 v60="5.3305" x60=5.3305 v40="7.050" x40=7.050 v30="10.00" x30=10.00 v20="14.050" x20=14.050 v17="18.110" x17=18.110 v15="21.05" x15=21.05 v12="24.90" x12=24.90 v10="28.05" x10=28.05 lna=0 lnas="0" att=0 atts="0" f=open('sdrini','w') x = float(v) # print v # print "LNAS=" + lnas # print "ATT=" + atts f.write(bands) f.write("\n") f.write(v) f.write("\n") f.write(v160) f.write("\n") f.write(v80) f.write("\n") f.write(v60) f.write("\n") f.write(v40) f.write("\n") f.write(v30) f.write("\n") f.write(v20) f.write("\n") f.write(v17) f.write("\n") f.write(v15) f.write("\n") f.write(v12) f.write("\n") f.write(v10) f.write("\n") f.write(lnas) f.write("\n") f.write(atts) f.write("\n") f.close return v, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10, v160, v80, v60, v40, v30, v20, v17, v15, v12, v10, lna, att, lnas, atts def dkwrt(self): global v, sdr, band, bands, x, x160, x80, x60, x40, x30, x20, x17, x15, x12, x10 global v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 global lna, att, lnas, atts f=open('sdrini','w') f.write(bands) f.write("\n") f.write(v) f.write("\n") f.write(v160) f.write("\n") f.write(v80) f.write("\n") f.write(v60) f.write("\n") f.write(v40) f.write("\n") f.write(v30) f.write("\n") f.write(v20) f.write("\n") f.write(v17) f.write("\n") f.write(v15) f.write("\n") f.write(v12) f.write("\n") f.write(v10) f.write("\n") f.write(lnas) f.write("\n") f.write(atts) f.write("\n") f.close return def frd(self): global v self.freq_readout.delete(0.0,END) self.freq_readout.insert(0.0, v) return def stv(self): global band, v, v160, v80, v60, v40, v30, v20, v17, v15, v12, v10 if band == 160: v160 = v elif band == 80: v80 = v elif band == 60: v60 = v elif band == 40: v40 = v elif band == 30: v30 = v elif band == 20: v20 = v elif band == 17: v17 = v elif band == 15: v15 = v elif band == 12: v12 = v elif band == 10: v10 = v else: pass return # main root = Tk() root.title("W3SZ SDR-1000 Control") root.geometry("570x110") app = Application(root) root.mainloop()