def __init__(self, root): """ Create a DSP interface instance. :param root: is the Tk() interface where the DPS will be drawedstring with the prot name i.e. /dev/ttyUSB0 or COM5 for Windows :returns: a new instance of DPS graphical interface """ self.root = root root.title("DPS power supplier interface") root.protocol("WM_DELETE_WINDOW", self.wnwcmdclose) self.dps = None self.poller = None self.waver = None self.strtme = time() self.dpsfwave = None self.maxoutv = 5 self.maxoutc = 5 menubar = Menu(root) filemenu = Menu(menubar, tearoff=0) filemenu.add_command(label="Exit", command=self.wnwcmdclose) menubar.add_cascade(label="File", menu=filemenu) scopemenu = Menu(menubar, tearoff=0) scopemenu.add_command(label="Load sampled points...", command=self.mnucmdloadsmppts) scopemenu.add_command(label="Save sampled points as...", command=self.mnucmdsavesmppts) menubar.add_cascade(label="Scope", menu=scopemenu) wavemenu = Menu(menubar, tearoff=0) wavemenu.add_command(label="New wave", command=self.mnucmdnewwve) wavemenu.add_command(label="Load wave...", command=self.mnucmdloadwve) wavemenu.add_command(label="Edit wave...", command=self.mnucmdedtwve) wavemenu.add_command(label="Save wave as...", command=self.mnucmdsavewve) menubar.add_cascade(label="Wave", menu=wavemenu) memmenu = Menu(menubar, tearoff=0) memmenu.add_command(label="Edit memories...", command=self.mnucmdedtmem) menubar.add_cascade(label="Memory", menu=memmenu) helpmenu = Menu(menubar, tearoff=0) helpmenu.add_command(label="Help...", command=self.mnucmdhelp) helpmenu.add_command(label="About...", command=self.mnucmdabout) menubar.add_cascade(label="Help", menu=helpmenu) root.config(menu=menubar) row = 0 col = 0 rowspan = 1 colspan = 1 insertlabelrow(root, row, col, ("Serial: ", None, "Addr,Baud: "), E) col += colspan self.svardpsport = StringVar() self.svardpsport.set('/dev/ttyUSB0') self.entryserport = Entry(root, textvariable=self.svardpsport, width=ENTRYWIDTH, justify='right') self.entryserport.grid(row=row, column=col, sticky=W) col += colspan col += colspan self.svardpsaddbrt = StringVar() self.svardpsaddbrt.set('1, 9600') self.entrydpsadd = Entry(root, textvariable=self.svardpsaddbrt, width=ENTRYWIDTH, justify='right') self.entrydpsadd.grid(row=row, column=col, sticky=W) col += colspan colspan = 2 self.ivarconctd = IntVar() self.ivarconctd.set(0) Checkbutton(root, variable=self.ivarconctd, text='Connect', command=self.butcmdconnect).grid(row=row, column=col, columnspan=colspan, sticky=E + W) row += rowspan col = 0 colspan = 1 Separator(root, orient='horizontal').grid(row=row, columnspan=8, sticky=E + W, pady=8) row += rowspan rowspan = 1 colspan = 2 col = 0 self.ivarbrghtnes = IntVar() s = Scale(root, label='Brightness', variable=self.ivarbrghtnes, from_=0, to=5, resolution=1, orient="horizontal") s.bind("<ButtonRelease-1>", self.sclbndbrghtnss) s.grid(row=row, column=col, columnspan=colspan, sticky=E + W) col += colspan colspan = 1 Label(root, text="Model: ").grid(row=row, column=col, sticky=E) col += colspan self.ivarmodel = IntVar() Entry(root, textvariable=self.ivarmodel, state="readonly", width=ENTRYWIDTH, justify='right').grid(row=row, column=col, sticky=W) col += colspan colspan = 2 self.ivarsetmem = IntVar() s = Scale(root, label='Mem Recall', variable=self.ivarsetmem, from_=1, to=9, resolution=1, orient="horizontal") s.bind("<ButtonRelease-1>", self.sclbndmemory) s.grid(row=row, column=col, columnspan=colspan, sticky=E + W) row += rowspan colspan = 1 col = 0 insertlabelrow( root, row, col, (("Vinp [V]: ", VCOL), None, "Out Mode: ", None, "Protection: "), E) self.dvarvinp = DoubleVar() self.svarwrmde = StringVar() self.setworkmode(0) self.svarprot = StringVar() self.setprotection(0) insertentryrow( root, row, col, (None, self.dvarvinp, None, self.svarwrmde, None, self.svarprot), 'right', W, 'readonly') colspan = 1 row += rowspan col = 0 insertlabelrow(root, row, col, (("Vmax [V]: ", VCOL), None, ("Cmax [A]: ", CCOL), None, ("Pmax [W]: ", PCOL)), E) self.dvarvmaxm0 = DoubleVar() self.dvarcmaxm0 = DoubleVar() self.dvarpmaxm0 = DoubleVar() entries = insertentryrow(root, row, col, (None, self.dvarvmaxm0, None, self.dvarcmaxm0, None, self.dvarpmaxm0), 'right', W) for e, f in zip(entries, (self.entbndvmax, self.entbndcmax, self.entbndpmax)): e.bind('<FocusOut>', f) e.bind('<Return>', f) row += rowspan col = 0 insertlabelrow(root, row, col, (("Vout [V]: ", VCOL), None, ("Cout [A]: ", CCOL), None, ("Pout [W]: ", PCOL)), E) self.dvarvout = DoubleVar() self.dvarcout = DoubleVar() self.dvarpout = DoubleVar() insertentryrow( root, row, col, (None, self.dvarvout, None, self.dvarcout, None, self.dvarpout), 'right', W, 'readonly') row += rowspan col = 0 self.scope = Scope(root, [], row, col) row += 9 col = 4 Label(root, text="Rte[s/Sa]: ").grid(row=row, column=col, sticky=E) col += colspan self.dvarsecsmp = DoubleVar() self.dvarsecsmp.set(self.scope.sampletime()) e = Entry(root, textvariable=self.dvarsecsmp, width=ENTRYWIDTH, justify='right').grid(row=row, column=col, sticky=W) row += rowspan col = 0 colspan = 2 self.ivaracquire = IntVar() self.ivaracquire.set(0) Checkbutton(root, variable=self.ivaracquire, text='Run Acquisition', command=self.butcmdacquire).grid(row=row, column=col, columnspan=2, sticky=E + W) col += colspan self.ivarkeylock = IntVar() self.ivarkeylock.set(0) Checkbutton(root, variable=self.ivarkeylock, text="Key Lock", command=self.butcmdkeylock).grid(row=row, column=col, sticky=E + W, columnspan=colspan) col += colspan self.ivaroutenab = IntVar() self.ivaroutenab.set(0) Checkbutton(root, variable=self.ivaroutenab, text="Output Enable", command=self.butcmdoutenable).grid(row=row, column=col, sticky=E + W, columnspan=colspan) row += rowspan col = 0 rowspan = 1 colspan = 3 self.dvarvscale = DoubleVar() self.voltscale = Scale(root, label='Vset [V]', foreground=VCOL, variable=self.dvarvscale, from_=0, to=self.maxoutv, resolution=1, orient="horizontal") #, label='Vset[V]' self.voltscale.bind("<ButtonRelease-1>", self.sclbndvolt) self.voltscale.grid(row=row, column=col, columnspan=colspan, sticky=E + W) col += colspan self.dvarcscale = DoubleVar() self.curntscale = Scale(root, label='Cset[A]', foreground=CCOL, variable=self.dvarcscale, from_=0, to=self.maxoutc, resolution=1, orient="horizontal") #,label='Cset[A]' self.curntscale.bind("<ButtonRelease-1>", self.sclbndcrnt) self.curntscale.grid(row=row, column=col, columnspan=colspan, sticky=E + W) row += rowspan col = 0 self.dvarvscalef = DoubleVar() sc = Scale(root, foreground=VCOL, variable=self.dvarvscalef, from_=0, to=0.99, resolution=0.01, orient="horizontal") sc.bind("<ButtonRelease-1>", self.sclbndvolt) sc.grid(row=row, column=col, columnspan=colspan, sticky=E + W) col += colspan self.dvarcscalef = DoubleVar() sc = Scale(root, foreground=CCOL, variable=self.dvarcscalef, from_=0, to=0.99, resolution=0.01, orient="horizontal") sc.bind("<ButtonRelease-1>", self.sclbndcrnt) sc.grid(row=row, column=col, columnspan=colspan, sticky=E + W) row += rowspan col = 0 colspan = 1 Separator(root, orient='horizontal').grid(row=row, columnspan=6, sticky=E + W, pady=8) row += rowspan colspan = 1 col = 0 Label(root, text="Waveform: ").grid(row=row, column=col, sticky=E) col += colspan colspan = 2 self.svarwave = StringVar() Entry(root, textvariable=self.svarwave, width=ENTRYWIDTH, justify='right', state='readonly').grid(row=row, column=col, columnspan=colspan, sticky=E + W) col += colspan colspan = 1 self.ivarplaywv = IntVar() self.ivarplaywv.set(0) Checkbutton(root, variable=self.ivarplaywv, text='Play', command=self.butcmdplaywave).grid(row=row, column=col, sticky=E + W) col += colspan self.ivarpausewv = IntVar() self.ivarpausewv.set(0) Checkbutton(root, variable=self.ivarpausewv, text='Pause', command=self.butcmdpausewave).grid(row=row, column=col, sticky=E + W) col += colspan self.ivarloopwv = IntVar() self.ivarloopwv.set(0) Checkbutton(root, variable=self.ivarloopwv, text='Loop').grid(row=row, column=col, sticky=E + W) self.scope.update() self.scope.redraw()
def __init__(self, root, datawve, updateview, row0, col0): """ Create a Clipboard. :param root: is the top level Tkinterface where the clipboard sits. :param datawve: is the list of poins from which the data is copied and pasted :param updateview: is the function called when the main data is changed (paste/cut action) :param row0: is th first row of the grid where the clipborad sits :param col0: is th first column of the grid where the clipborad sits """ self.root = root self.datawve = datawve self.updateview = updateview self.dataclpbrd = [] self.clipboardtime = 0 row = row0 col = col0 rowspan = 1 colspan = 1 self.tableclipboard = Table(root, self.dataclpbrd, ('step', 'dt [s]', ('voltage [V]', VCOL), ('current [A]', CCOL)), row, col, CLIPROW, TABLECOL) row += CLIPROW+1 col = col0 colspan = 1 insertlabelrow(root, row, col, ('beg step', None, 'end step')) self.ivarstepbeg = IntVar() self.ivarstepend = IntVar() insertentryrow(root, row, col, (None, self.ivarstepbeg, None, self.ivarstepend)) col = col0+TABLECOL Button(root, text="Copy", command=self.butcmdcopy).grid(row=row, column=col, sticky=E+W, padx=8) col += colspan Button(root, text="Cut", command=self.butcmdcut).grid(row=row, column=col, sticky=E+W, padx=8) row += rowspan col = col0 insertlabelrow(root, row, col, ('paste step', None, 'paste times')) self.ivarpastestep = IntVar() self.ivarpastetimes = IntVar() self.ivarpastetimes.set(1) insertentryrow(root, row, col, (None, self.ivarpastestep, None, self.ivarpastetimes)) col = col0+TABLECOL Button(root, text="Paste Ins", command=self.butcmdpasteins).grid(row=row, column=col, sticky=E+W, padx=8) col += colspan Button(root, text="Paste Ovw", command=self.butcmdpasteovw).grid(row=row, column=col, sticky=E+W, padx=8) row += rowspan col = col0 insertlabelrow(root, row, col, ('coef (t,v,c)', )) self.dvartcoeff = DoubleVar() self.dvarvcoeff = DoubleVar() self.dvarccoeff = DoubleVar() insertentryrow(root, row, col, (None, self.dvartcoeff, self.dvarvcoeff, self.dvarccoeff)) col = col0+TABLECOL Button(root, text="Amp Clipb", command=self.butcmdampliclip).grid(row=row, column=col, sticky=E+W, padx=8) col += colspan Button(root, text="Trn Clipb", command=self.butcmdtransclip).grid(row=row, column=col, sticky=E+W, padx=8) row += rowspan col = col0 insertlabelrow(root, row, col, ('rmp steps', )) self.ivarrampsteps = IntVar() self.ivarrampsteps.set(10) insertentryrow(root, row, col, (None, self.ivarrampsteps, None, None)) col = col0+TABLECOL Button(root, text="Rmp Clipb", command=self.butcmdramp).grid(row=row, column=col, sticky=E+W, padx=8)
def __init__(self, prevroot, datawve): """ Create a waveinterface instance. :param prevroot: is the main window :param datawve: is the datapoints to play with :returns: a new instance of wave interface """ self.root = maketoplevel(prevroot, True) self.root.title("Wave editor") self.datawve = datawve self.dataclpbrd = [] self.clipboardtime = 0 row = 0 col = 0 self.tablewve = Table(self.root, self.datawve, ('step', 'time [s]', ('voltage [V]', VCOL), ('current [A]', CCOL)), row, col, TABLEROW, TABLECOL) SCOPEROWSPAN = 15 self.scope = Scope(self.root, self.datawve, TABLEROW + 1 + 1, 0, rowspan=SCOPEROWSPAN, showpower=False, horizontaljoin=True, buttoncallback=self.buttoncallback) row = 1 rowspan = 1 colspan = 1 col = TABLECOL + colspan Button(self.root, text="Pick beg", command=self.btncmdpckbeg).grid(row=row, column=col, sticky=E + W, padx=8) col = TABLECOL + colspan row += rowspan Button(self.root, text="Pick end", command=self.btncmdpckend).grid(row=row, column=col, sticky=E + W, padx=8) Separator(self.root, orient='horizontal').grid(row=TABLEROW + 1, column=0, columnspan=TABLECOL + 2 + 1 + 6, sticky=E + W, pady=8) Separator(self.root, orient='vertical').grid(row=0, column=6, rowspan=1 + TABLEROW + 1 + SCOPEROWSPAN, sticky=N + S, padx=8) row = 0 COL1 = TABLECOL + 2 + 1 col = COL1 colspan = 1 insertlabelrow(self.root, row, col, (None, None, ('voltage [V]', VCOL), ('current [A]', CCOL))) row += rowspan insertlabelrow(self.root, row, col, ('time [s]:', )) self.dvartime = DoubleVar() self.dvarvoltage = DoubleVar() self.dvarcurrent = DoubleVar() insertentryrow( self.root, row, col, (None, self.dvartime, self.dvarvoltage, self.dvarcurrent)) col += TABLECOL Button(self.root, text="Insert", command=self.butcmdinsert).grid(row=row, column=col, sticky=E + W, padx=8) row += rowspan col = COL1 insertlabelrow(self.root, row, col, ('step :', )) self.ivarstep = IntVar() insertentryrow( self.root, row, col, (None, self.ivarstep, self.dvarvoltage, self.dvarcurrent)) col += TABLECOL Button(self.root, text="Modify", command=self.butcmdmodify).grid(row=row, column=col, sticky=E + W, padx=8) col += colspan Button(self.root, text="Delete", command=self.butcmddelete).grid(row=row, column=col, sticky=E + W, padx=8) row += rowspan col = COL1 insertlabelrow(self.root, row, col, ('pause [s]:', )) self.dvarpause = DoubleVar() insertentryrow( self.root, row, col, (None, self.dvarpause, self.dvarvoltage, self.dvarcurrent)) col += TABLECOL Button(self.root, text="Append", command=self.butcmdappend).grid(row=row, column=col, sticky=E + W, padx=8) self.clipboard = Clipboard(self.root, self.datawve, self.updateview, TABLEROW + 2, COL1) col = COL1 + TABLECOL colspan = 1 row = TABLEROW + 1 + SCOPEROWSPAN Button(self.root, text="Help", command=self.btncmdhelp).grid(row=row, column=col, sticky=E + W, padx=8) col += 1 Button(self.root, text="Done", command=self.butcmddone).grid(row=row, column=col, sticky=E + W, padx=8) self.scope.update() self.scope.redraw()
def __init__(self, root, data, row0, col0, rowspan=10, colspan=6, showpower=True, horizontaljoin=False, buttoncallback=None): """ Create a scope interface. :param root: is the main window :param data: is the data to display (update if enabled) :param row0: is the beginning row as whitch the scope should be placed on the grid layout :param col0: is the beginning column as whitch the scope should be placed on the grid layout :param rowspan: is how many rows should be used to draw the whole scope :param colspan: is how many columns should be used to draw the whole scope :param showpower: is a boolean field used to show the power (not required in wave editor) :param horizontaljoin: if true the points are joined through horizontal segments then vertica (for waveditor) if it is false they are just joined as useful in the scope view :param buttoncallback: it is the function to provide if the user can manage the graphs changing point (for wave editor) :returns: a new instance of scope """ self.root = root row = row0 rowspan -= 4 #those lines are used for inputs self.scopetube = Scopetube(root, data, horizontaljoin, self.newratios, buttoncallback) self.scopetube.grid(row=row, column=col0, columnspan=colspan, rowspan=rowspan, sticky=E + W) row += rowspan rowspan = 1 colspan = 1 insertlabelrow(root, row, col0, (("Y [V/div]: ", VCOL), None, ("Y [A/div]: ", CCOL)), E) self.dvarvdiv = DoubleVar() self.dvarvdiv.set(1.) self.dvarcdiv = DoubleVar() self.dvarcdiv.set(1.) entries = insertentryrow(root, row, col0, (None, self.dvarvdiv, None, self.dvarcdiv), 'right', W) self.dvarpdiv = DoubleVar() self.dvarpdiv.set(1.) if showpower: insertlabelrow(root, row, col0, (None, None, None, None, ("Y [W/div]: ", PCOL)), E) entries += insertentryrow( root, row, col0, (None, None, None, None, None, self.dvarpdiv), 'right', W) row += rowspan insertlabelrow(root, row, col0, (("Y0 [V]: ", VCOL), None, ("Y0 [A]: ", CCOL)), E) self.dvarv0 = DoubleVar() self.dvarv0.set(0.) self.dvarc0 = DoubleVar() self.dvarc0.set(0.) entries += insertentryrow(root, row, col0, (None, self.dvarv0, None, self.dvarc0), 'right', W) self.dvarp0 = DoubleVar() self.dvarp0.set(0.) if showpower: insertlabelrow(root, row, col0, (None, None, None, None, ("Y0 [W]: ", PCOL)), E) entries += insertentryrow( root, row, col0, (None, None, None, None, None, self.dvarp0), 'right', W) row += rowspan rowspan = 1 colspan = 2 col = col0 self.ivarvena = IntVar() self.ivarvena.set(1) Checkbutton(root, variable=self.ivarvena, text='Voltage show', foreground=VCOL, command=self.entbndcmdbutscpupdt).grid(row=row, column=col, columnspan=colspan, sticky=E + W) col += colspan self.ivarcena = IntVar() self.ivarcena.set(1) Checkbutton(root, variable=self.ivarcena, text='Current show', foreground=CCOL, command=self.entbndcmdbutscpupdt).grid(row=row, column=col, columnspan=colspan, sticky=E + W) self.ivarpena = IntVar() self.ivarpena.set(0) if showpower: col += colspan self.ivarpena.set(1) Checkbutton(root, variable=self.ivarpena, text='Power show', foreground=PCOL, command=self.entbndcmdbutscpupdt).grid( row=row, column=col, columnspan=colspan, sticky=E + W) row += rowspan col = col0 insertlabelrow(root, row, col0, ("X [s/div]: ", None, "X0 [s]: "), E) self.dvartdiv = DoubleVar() self.dvartdiv.set(60.) self.dvart0 = DoubleVar() self.dvart0.set(0.) entries += insertentryrow(root, row, col0, (None, self.dvartdiv, None, self.dvart0), 'right', W) for e in entries: e.bind('<FocusOut>', self.entbndcmdbutscpupdt) e.bind('<Return>', self.entbndcmdbutscpupdt) self.varlist = (self.ivarvena, self.ivarcena, self.ivarpena, self.dvarvdiv, self.dvarcdiv, self.dvarpdiv, self.dvarv0, self.dvarc0, self.dvarp0, self.dvartdiv, self.dvart0) self.update()
def __init__(self, prevroot, dps, updatefields): """ Create a memory interface. :param prevroot: is the main window :param dps: is the dps class instance used to read/write the memory :param updatefields: is used to update the fields showed by the main interface if something changed :returns: a new instance of memory interface """ self.root = maketoplevel(prevroot, True) self.root.title("Memory editor") self.dps = dps self.updatefields = updatefields row = 0 col = 0 colspan = 2 rowspan = 1 self.ivarmem = IntVar() Scale(self.root, label='Memory', variable=self.ivarmem, from_=0, to=9, resolution=1, orient="horizontal").grid(row=row, column=col, sticky=W + E, columnspan=colspan) col += colspan Button(self.root, text="Recall", command=self.butcmdrecall).grid(row=row, column=col, columnspan=colspan, sticky=E + W, padx=8) col += colspan Button(self.root, text='Store', command=self.butcmdstore).grid(row=row, column=col, columnspan=colspan, sticky=E + W, padx=8) colspan = 1 row += rowspan col = 0 insertlabelrow(self.root, row, col, (("Vset [V]: ", VCOL), None, ("Cset [A]: ", CCOL)), E) self.dvarvset = DoubleVar() self.dvarcset = DoubleVar() insertentryrow(self.root, row, col, (None, self.dvarvset, None, self.dvarcset), 'right', W) colspan = 1 row += rowspan col = 0 insertlabelrow(self.root, row, col, (("Vmax [V]: ", VCOL), None, ("Cmax [A]: ", CCOL), None, ("Pmax [W]: ", PCOL)), E) self.dvarvmax = DoubleVar() self.dvarcmax = DoubleVar() self.dvarpmax = DoubleVar() insertentryrow( self.root, row, col, (None, self.dvarvmax, None, self.dvarcmax, None, self.dvarpmax), 'right', W) row += rowspan colspan = 1 col = 0 Label(self.root, text='Bright:').grid(row=row, column=col, columnspan=colspan) col += colspan self.ivarbrght = IntVar() Scale(self.root, variable=self.ivarbrght, from_=0, to=5, resolution=1, orient="horizontal").grid( row=row, column=col, columnspan=colspan) #, label='Brightness' col += colspan colspan = 2 self.ivaroutmset = IntVar() self.ivaroutmset.set(0) Checkbutton(self.root, variable=self.ivaroutmset, text="Out same/off@MSet").grid(row=row, column=col, sticky=E + W, columnspan=colspan) col += colspan self.ivaroutpwron = IntVar() self.ivaroutpwron.set(0) Checkbutton(self.root, variable=self.ivaroutpwron, text="Out on/off@PwOn").grid(row=row, column=col, sticky=E + W, columnspan=colspan) row += rowspan colspan = 2 col = 2 Button(self.root, text="Help", command=self.btncmdhelp).grid(row=row, column=col, sticky=E + W, columnspan=colspan, padx=8) col += colspan Button(self.root, text="Done", command=self.btncmddone).grid(row=row, column=col, sticky=E + W, columnspan=colspan, padx=8)