def __init__(self, parentElem, guiLock, getTemperatureCb, getEnergySourceCb, getAdcValueCb, frameName='Last Report', row=0, column=1): # record params self.getTemperatureCb = getTemperatureCb self.getEnergySourceCb = getEnergySourceCb self.getAdcValueCb = getAdcValueCb # local variables self.blinker = None # initialize parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) # temperature self.temperature = dustGuiLib.Label(self.container, fg='green', relief=Tkinter.GROOVE, borderwidth=2, text='--.--' + SYMBOL_DEGREE) self._add(self.temperature, 0, 0) self.temperature.configure( font=('System', 40, 'bold'), bg='black', ) self.blinker = dustFrameDC2126AReportBlinker(self.temperature) # energysource temp = dustGuiLib.Label(self.container, text='Mote powered by') self._add(temp, 1, 0) temp.configure(font=("Helvetica", 12, "bold"), anchor=Tkinter.CENTER) self.energysource = dustGuiLib.Label( self.container, text='-', ) self._add(self.energysource, 2, 0) self.energysource.configure( font=("Helvetica", 16, "bold"), anchor=Tkinter.CENTER, ) # adcValue self.adcValue = dustGuiLib.Label( self.container, text='', ) self._add(self.adcValue, 3, 0) self.adcValue.configure(anchor=Tkinter.CENTER, ) # schedule first GUI update self.after(self.GUI_UPDATE_PERIOD, self.updateGui)
def _createAndFillLabels(self, data, displayOptions): # clear old elems for line in self.guiElems: for elem in line: elem.removeGui() self.guiElems = [] # create and fill labels for row in range(len(data)): self.guiElems.append([]) for column in range(len(data[row])): temp = dustGuiLib.Label(self.container, text=str(data[row][column]), border=1, bg=dustStyle.COLOR_BG, relief=Tkinter.RIDGE, borderwidth=1, padx=3, pady=3) self._add(temp, row, column, sticky=Tkinter.W + Tkinter.E) self.guiElems[-1].append(temp) # apply display options self._applyDisplayOptions(displayOptions)
def __init__(self, parentElem, guiLock, type, frameName="fields", row=0, column=0): # record variables self.type = type # init parent dustFrame.dustFrame.__init__( self, parentElem=parentElem, guiLock=guiLock, frameName=frameName, row=row, column=column, scrollable=True, ) # row 0: headerLabel self.headerLabel = dustGuiLib.Label( self.container, text='', ) self._add(self.headerLabel, 0, 0) # row 1: fieldsFrame self.fieldsFrame = Tkinter.Frame(self.container) self._add(self.fieldsFrame, 1, 0)
def __init__(self, parentElem, guiLock, cbApiLoaded, frameName="api", row=0, column=0, deviceType=None): # store params self.cbApiLoaded = cbApiLoaded self.deviceType = deviceType # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) temp = dustGuiLib.Label(self.container, text="network type:") self._add(temp, 0, 0) self.networkTypeString = Tkinter.StringVar(self.container) self.networkTypeString.set(self.WHART) self.networkTypeMenu = dustGuiLib.OptionMenu(self.container, self.networkTypeString, self.WHART, self.IP) self._add(self.networkTypeMenu, 0, 1) temp = dustGuiLib.Label(self.container, text="device type:") self._add(temp, 0, 2) self.deviceTypeString = Tkinter.StringVar(self) if deviceType: self.deviceTypeString.set(deviceType) else: self.deviceTypeString.set(self.MANAGER) self.deviceTypeMenu = dustGuiLib.OptionMenu(self.container, self.deviceTypeString, self.MANAGER, self.MOTE) self._add(self.deviceTypeMenu, 0, 3) if self.deviceType: self.deviceTypeMenu.config(state=Tkinter.DISABLED) self.loadButton = dustGuiLib.Button(self.container, text="load", command=self._loadApi) self._add(self.loadButton, 0, 4)
def _addRowInternal(self, contents, coltypes, mac=None): assert (len(contents) == len(coltypes)) self.guiElems.append([]) for (content, type) in zip(contents, coltypes): if type == self.LABEL: temp = dustGuiLib.Label(self.container, text=str(content), border=1, bg=dustStyle.COLOR_BG, relief=Tkinter.RIDGE, borderwidth=1, padx=3, pady=3) elif type == self.ACTION: temp = dustGuiLib.Button(self.container) temp.configure(text=content['text']) temp.configure( command=self._lambda_factory(content['callback'], (mac, temp))) elif type == self.SETONEVAL: if 'defaultVal' in content: defaultVal = content['defaultVal'] else: defaultVal = '' temp = SetOneValFrame(self.container, self._lambda_factory, content, mac, self._handle_setOneVal_set, defaultVal) elif type == self.GETSETONEVAL: temp = GetSetOneValFrame(self.container, self._lambda_factory, content, mac, self._handle_getSetOneVal_set) elif type == self.SETTHREEVAL: temp = SetThreeValFrame(self.container, self._lambda_factory, content, mac, self._handle_setThreeVal_set) else: raise SystemError("column type {0} unsupported".format(type)) self._add(temp, len(self.guiElems) - 1, len(self.guiElems[-1]), sticky=Tkinter.W + Tkinter.E) self.guiElems[-1].append(temp)
def __init__(self,parentElem,guiLock,frameName="text",row=0,column=0): # record variables # init parent dustFrame.dustFrame.__init__(self,parentElem,guiLock,frameName,row,column) #row 0: text field self.toolTipLabel = dustGuiLib.Label(self.container, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, wraplength=600, justify=Tkinter.LEFT, text="") self._add(self.toolTipLabel,0,0)
def __init__(self, parentElem, guiLock, frameName="sensor data", row=0, column=0): # record variables # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) #row 0: slide self.slide = Tkinter.Scale(self.container, from_=0, to=0xffff, state=Tkinter.DISABLED, orient=Tkinter.HORIZONTAL) self._add(self.slide, 0, 0, columnspan=2) #row 1: sourceMac temp = dustGuiLib.Label(self.container, text='source MAC:') self._add(temp, 1, 0) self.sourceMac = dustGuiLib.Label(self.container) self._add(self.sourceMac, 1, 1) #row 2: sourcePort temp = dustGuiLib.Label(self.container, text='source port:') self._add(temp, 2, 0) self.sourcePort = dustGuiLib.Label(self.container) self._add(self.sourcePort, 2, 1) #row 3: destPort temp = dustGuiLib.Label(self.container, text='destination port:') self._add(temp, 3, 0) self.destPort = dustGuiLib.Label(self.container) self._add(self.destPort, 3, 1)
def _handleCommand(self,level): ''' \brief Generic handler when item is selected from drop-down list of (sub)commands. \param level 0 indicates a command was selected. 1 indicates a subcommand was selected. ''' # clear the old guiElems self._clearGuiElems(level) if self.fieldsFrame: self.fieldsFrame.grid_forget() self.fieldsFrame = None c = { 'commandName' : None, 'fieldNames' : [], 'fieldNamesGui' : [], 'fieldFormats' : [], 'fieldFormatsGui' : [], 'fieldLengths' : [], 'fieldOptions' : [], 'fieldValuesGui' : [], 'fieldValuesString' : [], 'fieldValuesRaw' : [], 'fieldValues' : [], 'commandORbuttonGui' : None, } # read the command name just selected with self.guiLock: if level==0: c['commandName'] = self.commandToSend.get() elif level==1: c['commandName'] = self.subcommandToSend.get() fullCmd = [elem['commandName'] for elem in self.guiElems] fullCmd.append(c['commandName']) # call the selected callback self.selectedCb(fullCmd) # add elements for fields try: c['fieldNames'] = self.apiDef.getRequestFieldNames(fullCmd) c['fieldFormats'] = [ self.apiDef.getRequestFieldFormat(fullCmd,fieldName) for fieldName in c['fieldNames'] ] c['fieldLengths'] = [ self.apiDef.getRequestFieldLength(fullCmd,fieldName) for fieldName in c['fieldNames'] ] c['fieldOptions'] = [ self.apiDef.getRequestFieldOptions(fullCmd,fieldName) for fieldName in c['fieldNames'] ] except CommandError as err: traceback.print_exc() return # create a frame for all fields and add GUI elements with self.guiLock: self.fieldsFrame = Tkinter.Frame( self.container, borderwidth=10, bg=dustStyle.COLOR_BG, ) self._add( self.fieldsFrame, level*2+2, column=0, ) headerColor = self._getHeaderColor() with self.guiLock: for i in range(len(c['fieldNames'])): if c['fieldNames'][i] in ApiDefinition.ApiDefinition.RESERVED: continue # calculate width of text entry if c['fieldLengths'][i]: if c['fieldFormats'][i] in [ApiDefinition.FieldFormats.STRING]: textEntryWidth = c['fieldLengths'][i]+2 elif c['fieldFormats'][i] in [ApiDefinition.FieldFormats.HEXDATA]: textEntryWidth = c['fieldLengths'][i]*2+2 else: textEntryWidth = dustStyle.TEXTFIELD_ENTRY_LENGTH_DEFAULT autoResize = False else: textEntryWidth = dustStyle.TEXTFIELD_ENTRY_LENGTH_DEFAULT autoResize = True if textEntryWidth>dustStyle.TEXTFIELD_ENTRY_LENGTH_MAX: textEntryWidth = dustStyle.TEXTFIELD_ENTRY_LENGTH_MAX # display row 0: name c['fieldNamesGui'] += [ dustGuiLib.Label( self.fieldsFrame, text = c['fieldNames'][i], bg = dustStyle.COLOR_BG, relief = Tkinter.RIDGE, borderwidth = 1, background = headerColor, padx = 3, pady = 3, ) ] c['fieldNamesGui'][-1].grid( row = 0, column = i, sticky = Tkinter.W+Tkinter.E, ) # display row 1: value if c['fieldOptions'][i].optionDescs or c['fieldFormats'][i]=='bool': if c['fieldOptions'][i].optionDescs: optionValues = c['fieldOptions'][i].optionDescs else: optionValues = ['True','False'] c['fieldValuesString'] += [Tkinter.StringVar()] c['fieldValuesGui'] += [ dustGuiLib.OptionMenu( self.fieldsFrame, c['fieldValuesString'][-1], *optionValues ) ] else: c['fieldValuesString'] += [None] c['fieldValuesGui'] += [ dustGuiLib.Text( self.fieldsFrame, font = dustStyle.FONT_BODY, width = textEntryWidth, height = 1, padx = 3, pady = 3, autoResize = autoResize, ) ] c['fieldValuesGui'][-1].grid( row = 1, column = i, sticky = Tkinter.W+Tkinter.E, ) # display row 2: format and length fieldFormatsString = ApiDefinition.ApiDefinition.fieldFormatToString( c['fieldLengths'][i], c['fieldFormats'][i] ) c['fieldFormatsGui'] += [ dustGuiLib.Label( self.fieldsFrame, text = fieldFormatsString, bg = dustStyle.COLOR_BG, relief = Tkinter.RIDGE, borderwidth = 1, padx = 3, pady = 3, ) ] c['fieldFormatsGui'][-1].grid( row = 2, column = i, sticky = Tkinter.W+Tkinter.E, ) # subcommands with self.guiLock: tempOptions = None if self.apiDef.hasSubcommands(ApiDefinition.ApiDefinition.COMMAND, fullCmd)==True: tempOptions = self.apiDef.getNames(ApiDefinition.ApiDefinition.COMMAND, fullCmd) tempOptions.sort() c['commandORbuttonGui'] = dustGuiLib.OptionMenu(self.container, self.subcommandToSend, *tempOptions) else: c['commandORbuttonGui'] = dustGuiLib.Button(self.container, command=self._handleSend, text="send",) self._add(c['commandORbuttonGui'],level*2+2+1,0) # add to guiElems self.guiElems.append(c) # display the first alphabetical subcommand in subcommand option menu if tempOptions: self.subcommandToSend.set(tempOptions[0])
def __init__(self, parentElem, guiLock, frameName, row=0, column=0, scrollable=False, columnspan=1): # record variables self.guiLock = guiLock self.row = row self.column = column self.scrollable = scrollable self.columnspan = columnspan # init parent Tkinter.Frame.__init__(self, parentElem, relief=Tkinter.SUNKEN, borderwidth=1, bg=dustStyle.COLOR_BG) #=== # label temp = dustGuiLib.Label(self, font=dustStyle.FONT_HEADER, text=frameName, bg=dustStyle.COLOR_BG) temp.grid(row=0, column=0, columnspan=2, sticky=Tkinter.W) #=== # pad frame temp = Tkinter.Frame(self, bg=dustStyle.COLOR_BG, relief=Tkinter.FLAT) temp.grid(row=1, column=0, padx=10, pady=10) # container if self.scrollable: # the container is a frame with scrollbars which appear when # it gets higher/wider than MAX_HEIGHT/MAX_WIDTH. self.containerFrame = Tkinter.Frame(self, bg=dustStyle.COLOR_BG, relief=Tkinter.FLAT) self.containerFrame.grid(row=1, column=1, padx=5, pady=5) vscrollbar = AutoHideScrollbar(self.containerFrame, orient=Tkinter.VERTICAL) vscrollbar.grid(row=0, column=1, sticky=Tkinter.N + Tkinter.S) hscrollbar = AutoHideScrollbar(self.containerFrame, orient=Tkinter.HORIZONTAL) hscrollbar.grid(row=1, column=0, sticky=Tkinter.E + Tkinter.W) self.containerCanvas = Tkinter.Canvas( self.containerFrame, width=100, height=100, borderwidth=0, highlightthickness=0, yscrollcommand=vscrollbar.set, xscrollcommand=hscrollbar.set) self.containerCanvas.grid(row=0, column=0, sticky=Tkinter.N + Tkinter.S + Tkinter.E + Tkinter.W) vscrollbar.config(command=self.containerCanvas.yview) hscrollbar.config(command=self.containerCanvas.xview) # make the canvas expandable self.containerFrame.grid_rowconfigure(0, weight=1) self.containerFrame.grid_columnconfigure(0, weight=1) # create canvas contents self.container = Tkinter.Frame(self.containerCanvas, bg=dustStyle.COLOR_BG, padx=0, pady=0, border=0, relief=Tkinter.FLAT) self.containerCanvas.create_window(0, 0, anchor=Tkinter.NW, window=self.container) self.container.update_idletasks() self._adjustCanvasSize() else: self.container = Tkinter.Frame(self, bg=dustStyle.COLOR_BG, relief=Tkinter.FLAT) self.container.grid(row=1, column=1, padx=5, pady=5) # local vars self.apiDef = None self.connector = None self.rowCtr = 0 self.colCtr = 0 self.guiElems = [] self.headerColor = dustStyle.COLOR_PRIMARY2_LIGHT
def __init__(self, parentElem, guiLock, frameName="sensor", row=0, column=0): # record params # local variables self.connector = None self.payloadCounter = 0 # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) #row 0: slide self.slide = Tkinter.Scale(self.container, from_=0, to=0xffff, orient=Tkinter.HORIZONTAL) self._add(self.slide, 0, 0, columnspan=3) #row 1: label temp = dustGuiLib.Label(self.container, text='destination IPv6 address') self._add(temp, 1, 0) temp.configure(font=dustStyle.FONT_HEADER) temp = dustGuiLib.Label(self.container, text='dest. UDP port') self._add(temp, 1, 1) temp.configure(font=dustStyle.FONT_HEADER) #row 2: send to manager temp = dustGuiLib.Label(self.container, text=WELL_KNOWN_ADDR_MANAGER) self._add(temp, 2, 0) self.mgrPortText = dustGuiLib.Text(self.container, width=6, height=1) self.mgrPortText.insert(1.0, DEFAULT_DEST_PORT) self._add(self.mgrPortText, 2, 1) self.mgrButton = dustGuiLib.Button(self.container, text='send to manager', state=Tkinter.DISABLED, command=self._sendMgr) self._add(self.mgrButton, 2, 2) #row 3: send to host self.hostAddrText = dustGuiLib.Text(self.container, width=35, height=1) self.hostAddrText.insert(1.0, DEFAULT_HOST_ADDR) self._add(self.hostAddrText, 3, 0) self.hostPortText = dustGuiLib.Text(self.container, width=6, height=1) self.hostPortText.insert(1.0, DEFAULT_DEST_PORT) self._add(self.hostPortText, 3, 1) self.hostButton = dustGuiLib.Button(self.container, text='send to host', state=Tkinter.DISABLED, command=self._sendHost) self._add(self.hostButton, 3, 2) #row 4: status self.statusLabel = dustGuiLib.Label(self.container) self._add(self.statusLabel, 4, 0, columnspan=3)
def __init__(self, parentElem, guiLock, frameName="Conversion", topName='top', toBottomCb=None, bottomName='bottom', toTopCb=None, row=0, column=0): if toBottomCb: assert callable(toBottomCb) if toTopCb: assert callable(toTopCb) # record variables self.topName = topName self.toBottomCb = toBottomCb self.bottomName = bottomName self.toTopCb = toTopCb # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) #===== row 0: topName temp = dustGuiLib.Label( self.container, text=self.topName, ) self._add(temp, 0, 0, columnspan=2) temp.configure(font=dustStyle.FONT_HEADER) #===== row 1: topField topscrollbar = Tkinter.Scrollbar(self.container) topscrollbar.grid(row=1, column=2, sticky=Tkinter.N + Tkinter.S) self.topField = Tkinter.Text( self.container, bg=dustStyle.COLOR_BG, width=100, height=10, yscrollcommand=topscrollbar.set, ) topscrollbar.config(command=self.topField.yview) self._add(self.topField, 1, 0, columnspan=2) self.topField.configure(font=self.FONT_MONOSPACE) #===== row 2: buttons temp = dustGuiLib.Button(self.container, text='to {0}'.format(self.bottomName), command=self._toBottomButtonPressed) self._add(temp, 2, 0) temp = dustGuiLib.Button(self.container, text='to {0}'.format(self.topName), command=self._toTopButtonPressed) self._add(temp, 2, 1) #===== row 3: bottomName temp = dustGuiLib.Label( self.container, text=self.bottomName, ) self._add(temp, 3, 0, columnspan=2) temp.configure(font=dustStyle.FONT_HEADER) #===== row 4: bottomField bottomscrollbar = Tkinter.Scrollbar(self.container) bottomscrollbar.grid(row=4, column=2, sticky=Tkinter.N + Tkinter.S) self.bottomField = Tkinter.Text( self.container, bg=dustStyle.COLOR_BG, width=100, height=10, yscrollcommand=bottomscrollbar.set, ) bottomscrollbar.config(command=self.bottomField.yview) self._add(self.bottomField, 4, 0, columnspan=2) self.bottomField.configure(font=self.FONT_MONOSPACE)
def __init__(self, parentElem, guiLock, selectedMoteChangedCB, displayMoteButtonCB, refreshButtonCB, clearMotesButtonCB, frameName="Configuration", row=0, column=1): # record params self.selectedMoteChangedCB = selectedMoteChangedCB self.displayMoteButtonCB = displayMoteButtonCB self.refreshButtonCB = refreshButtonCB self.clearMotesButtonCB = clearMotesButtonCB # local variables self.selectedMote = Tkinter.StringVar() self.selectedMote.trace("w", self._selectedMoteChangedCB_internal) # initialize parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) # motes temp = dustGuiLib.Label(self.container, anchor=Tkinter.NW, justify=Tkinter.LEFT, text='Select mote:') self._add(temp, 0, 0) self.motes = dustGuiLib.OptionMenu(self.container, self.selectedMote, *['']) self._add(self.motes, 0, 1) # display mote button self.displayMoteButton = dustGuiLib.Button( self.container, text='Display Mote', command=self.displayMoteButtonCB, ) self._add(self.displayMoteButton, 0, 2) # refresh button self.refreshButton = dustGuiLib.Button(self.container, text='Update Mote List', command=self.refreshButtonCB) self._add(self.refreshButton, 1, 2) #clear mote buttons self.clearMotesButton = dustGuiLib.Button( self.container, text='Clear Motes', command=self.clearMotesButtonCB, ) self._add(self.clearMotesButton, 2, 2) # action label self.actionLabel = dustGuiLib.Label( self.container, anchor=Tkinter.CENTER, justify=Tkinter.LEFT, text='', ) self._add(self.actionLabel, 1, 1)
def _displayFieldsRow(self,rowNumber,firstRow,lastRow,type,nameArray,fields): c = { 'commandName' : None, 'fieldNames' : [], 'fieldNamesGui' : [], 'fieldFormats' : [], 'fieldFormatsGui' : [], 'fieldLengths' : [], 'fieldOptions' : [], 'fieldValuesGui' : [], 'fieldValuesString' : [], 'fieldValuesRaw' : [], 'fieldValues' : [], 'commandORbuttonGui' : None, } # add elements for fields for i in range(len(nameArray)): tempName = nameArray[:i+1] try: temp_fieldNames = self.apiDef.getResponseFieldNames( type, tempName ) temp_fieldFormats = [self.apiDef.getResponseFieldFormat( type, tempName, fieldName ) for fieldName in temp_fieldNames] temp_fieldLengths = [self.apiDef.getResponseFieldLength( type, tempName, fieldName) for fieldName in temp_fieldNames] temp_fieldOptions = [self.apiDef.getResponseFieldOptions( type, tempName, fieldName) for fieldName in temp_fieldNames] c['fieldNames'] += temp_fieldNames c['fieldFormats'] += temp_fieldFormats c['fieldLengths'] += temp_fieldLengths c['fieldOptions'] += temp_fieldOptions except CommandError as err: print str(err) return # add values for i in range(len(c['fieldNames'])): fieldName = c['fieldNames'][i] try: fieldValue = fields[fieldName] except KeyError: fieldValue = "N.A." if c['fieldFormats'][i]=='hex': fieldString = self._hexdata2string(fieldValue,0,len(fieldValue)) elif fieldValue==None: fieldString = 'missing' else: fieldString = str(fieldValue) try: description = self.apiDef.fieldValueToDesc(type, nameArray, fieldName, fieldValue) fieldString = fieldString+" ("+description+")" except CommandError as err: if err.errorCode!=CommandError.VALUE_NOT_IN_OPTIONS: raise c['fieldValues'].append(fieldString) headercolor = self._getHeaderColor() self.guiLock.acquire() for i in range(len(c['fieldNames'])): if c['fieldNames'][i] in ApiDefinition.ApiDefinition.RESERVED: continue # row: name (iff first row) if firstRow: c['fieldNamesGui'].append(dustGuiLib.Label( self.fieldsFrame, text=c['fieldNames'][i], bg=dustStyle.COLOR_BG, relief=Tkinter.RIDGE, borderwidth=1, background=headercolor, padx=3, pady=3)) c['fieldNamesGui'][-1].grid(row=0,column=i, sticky=Tkinter.W+Tkinter.E) # row: value c['fieldValuesString'].append(None) c['fieldValuesGui'].append( dustGuiLib.Label( self.fieldsFrame, text=c['fieldValues'][i], bg=dustStyle.COLOR_BG, relief=Tkinter.RIDGE, borderwidth=1, padx=3, pady=3 ) ) c['fieldValuesGui'][-1].grid( row=rowNumber+1, column=i, sticky=Tkinter.W+Tkinter.E ) # row: format and length (iff last row) if lastRow: fieldFormatsString = ApiDefinition.ApiDefinition.fieldFormatToString( c['fieldLengths'][i], c['fieldFormats'][i] ) c['fieldFormatsGui'].append(dustGuiLib.Label( self.fieldsFrame, text=fieldFormatsString, bg=dustStyle.COLOR_BG, relief=Tkinter.RIDGE, borderwidth=1, padx=3, pady=3)) c['fieldFormatsGui'][-1].grid(row=rowNumber+2,column=i, sticky=Tkinter.W+Tkinter.E) self.guiLock.release() # add to the guiElems self.guiElems.append(c)
def __init__(self, parentElem, guiLock, getCurrentCb, getChargeCb, frameName='Last Report', row=0, column=0, NUM_CURRENT_VALUES=10, SCALE_CURRENT=1): # record params self.getCurrentCb = getCurrentCb self.getChargeCb = getChargeCb self.maxcurrentvalues = NUM_CURRENT_VALUES self.currentxData = [] self.currentyData = [] self.numcurrentvalues = 0 self.line = None # initialize parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, 'DC2369A Mote Report', row, column, False, columnspan=2) #configure the dustFrame self.columnconfigure(0, weight=1) self.columnconfigure(1, weight=1) self.columnconfigure(2, weight=1) #add the MAC address at the top of the frame temp = dustGuiLib.Label(self.container, text=frameName) self._add(temp, 0, 0) temp.grid(columnspan=3) temp.configure(font=("Helvetica", 12, "bold"), anchor=Tkinter.CENTER) #Current label temp = dustGuiLib.Label(self.container, text='Measured Current (A)') self._add(temp, 1, 0) temp.configure(font=("Helvetica", 12, "bold"), anchor=Tkinter.CENTER) #Current Display self.current = dustGuiLib.Label( self.container, fg='green', relief=Tkinter.GROOVE, borderwidth=2, width=6, ) self._add(self.current, 2, 0) self.current.configure( font=('System', 40, 'bold'), bg='black', ) # Charge label temp = dustGuiLib.Label(self.container, text='Used Battery Life') self._add(temp, 3, 0) temp.configure(font=("Helvetica", 12, "bold"), anchor=Tkinter.CENTER) #Charge Display self.charge = dustGuiLib.Label( self.container, fg='green', relief=Tkinter.GROOVE, borderwidth=2, ) self._add(self.charge, 4, 0) self.charge.configure( font=('System', 40, 'bold'), bg='black', ) #Graph #setup figure and subplots fig = plt.Figure(figsize=(4.5, 3)) ax = fig.add_subplot(111) #adjust to be able to view axes titles fig.subplots_adjust(bottom=.2, left=.2, top=.85) #set axis and graph titles ax.set_title("Recent Current Values") ax.set_xlabel("Time (s)") ax.set_ylabel("Current (A)") #set axis dimensions ax.axis([ 0, self.maxcurrentvalues - 1, -SCALE_CURRENT - 0.2, SCALE_CURRENT + 0.2 ]) #set graph visibility options - turn off x axis labels ax.get_xaxis().set_ticklabels([]) ax.yaxis.grid() ax.xaxis.grid() #plot data self.line, = ax.plot(self.currentxData, self.currentyData, 'b-') plt.show() #set up animation canvas = FigureCanvasTkAgg(fig, master=self.container) canvas.get_tk_widget().grid(column=2, row=1, rowspan=4) canvas._tkcanvas.config(highlightthickness=0) self.ani = animation.FuncAnimation(fig, self.animate, arange(1, 200), init_func=self.clear_animation, interval=30, blit=True) # schedule first GUI update, and call a update to set the valuies for Current and Charge self.updateGui() self.after(self.GUI_UPDATE_PERIOD, self.updateGui)
def __init__(self,parentElem,guiLock, selectedMoteChangedCB, refreshButtonCB, getConfigurationCB, setConfigurationCB, frameName="Configuration",row=0,column=1): # record params self.selectedMoteChangedCB = selectedMoteChangedCB self.refreshButtonCB = refreshButtonCB self.getConfigurationCB = getConfigurationCB self.setConfigurationCB = setConfigurationCB # local variables self.selectedMote = Tkinter.StringVar() self.selectedMote.trace("w",self._selectedMoteChangedCB_internal) # initialize parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row,column ) # report period temp = dustGuiLib.Label(self.container, anchor = Tkinter.NW, justify = Tkinter.LEFT, text = 'Report Period (ms):', ) self._add(temp,0,0) self.reportPeriod = dustGuiLib.Text(self.container, font = dustStyle.FONT_BODY, width = 25, height = 1, ) self._add(self.reportPeriod,0,1) # bridge settling time temp = dustGuiLib.Label(self.container, anchor = Tkinter.NW, justify = Tkinter.LEFT, text = 'Bridge Settling Time (ms):', ) self._add(temp,1,0) self.bridgeSettlingTime = dustGuiLib.Text(self.container, font = dustStyle.FONT_BODY, width = 25, height = 1, ) self._add(self.bridgeSettlingTime,1,1) # LDO on time temp = dustGuiLib.Label(self.container, anchor = Tkinter.NW, justify = Tkinter.LEFT, text = 'LDO on time (ms):', ) self._add(temp,2,0) self.ldoOnTime = dustGuiLib.Text( self.container, font = dustStyle.FONT_BODY, width = 25, height = 1, ) self._add(self.ldoOnTime,2,1) # motes temp = dustGuiLib.Label(self.container, anchor = Tkinter.NW, justify = Tkinter.LEFT, text = 'Select mote:') self._add(temp,3,0) self.motes = dustGuiLib.OptionMenu( self.container, self.selectedMote, *[''] ) self._add(self.motes,3,1) # refresh button self.refreshButton = dustGuiLib.Button(self.container, text = 'refresh', command = self.refreshButtonCB ) self._add(self.refreshButton,3,2) # action label self.actionLabel = dustGuiLib.Label(self.container, anchor = Tkinter.CENTER, justify = Tkinter.LEFT, text = '', ) self._add(self.actionLabel,4,1) # get configuration button self.getConfigurationButton = dustGuiLib.Button(self.container, text = 'get configuration', command = self.getConfigurationCB, ) self._add(self.getConfigurationButton,4,2) # set configuration button self.setConfigurationButton = dustGuiLib.Button(self.container, text = 'set configuration', command = self._setConfigurationCB_internal, ) self._add(self.setConfigurationButton,5,2)
def __init__(self, parentElem, guiLock, connectedCb, frameName="br connection", row=0, column=0): # record variables self.connectedCb = connectedCb # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) #==== # connect button self.connectButton = dustGuiLib.Button(self.container, text='connect', command=self._connect) self._add(self.connectButton, 0, 0) #==== self.connectionErrorLabel = dustGuiLib.Label(self.container, text='') self._add(self.connectionErrorLabel, 1, 0, columnspan=2) #==== # connection temp = dustGuiLib.Label(self.container, text="connection:") self._add(temp, 2, 0) self.connectionLabel = dustGuiLib.Label(self.container, text='') self._add(self.connectionLabel, 2, 1) # status temp = dustGuiLib.Label(self.container, text="status:") self._add(temp, 3, 0) self.statusLabel = dustGuiLib.Label(self.container, text='') self._add(self.statusLabel, 3, 1) # prefix temp = dustGuiLib.Label(self.container, text="prefix:") self._add(temp, 4, 0) self.prefixLabel = dustGuiLib.Label(self.container, text='') self._add(self.prefixLabel, 4, 1) # statsTx temp = dustGuiLib.Label(self.container, text="transmitted to LBR:") self._add(temp, 5, 0) self.statsTxLabel = dustGuiLib.Label(self.container, text='') self._add(self.statsTxLabel, 5, 1) # statsRx temp = dustGuiLib.Label(self.container, text="received from LBR:") self._add(temp, 6, 0) self.statsRxLabel = dustGuiLib.Label(self.container, text='') self._add(self.statsRxLabel, 6, 1) # have GUI update self.after(UPDATEPERIOD, self._updateGui)
def __init__(self,parentElem,guiLock,connectCb,frameName="connection",row=0,column=0): # record variables self.connectCb = connectCb # init parent dustFrame.dustFrame.__init__(self,parentElem,guiLock,frameName,row,column) # row 0: serial port self.serialFrame = Tkinter.Frame(self.container, borderwidth=0, bg=dustStyle.COLOR_BG) temp = dustGuiLib.Label(self.serialFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="through serial port:") self._add(temp,0,0,columnspan=3) temp = dustGuiLib.Label(self.serialFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="port name:") self._add(temp,1,0) self.serialPortText = dustGuiLib.Text(self.serialFrame, font=dustStyle.FONT_BODY, width=25, height=1, returnAction=self._connectSerial) self.serialPortText.insert(1.0,"") self._add(self.serialPortText,1,1) self.serialButton = dustGuiLib.Button(self.serialFrame, text='connect', command=self._connectSerial) self._add(self.serialButton,1,2) # row 2: serialMux self.serialMuxFrame = Tkinter.Frame(self.container, borderwidth=0, bg=dustStyle.COLOR_BG) temp = dustGuiLib.Label(self.serialMuxFrame, font=dustStyle.FONT_BODY, text="through serialMux:", bg=dustStyle.COLOR_BG) self._add(temp,0,0,columnspan=5) temp = dustGuiLib.Label(self.serialMuxFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="host:") self._add(temp,1,0) self.serialMuxHostText = dustGuiLib.Text(self.serialMuxFrame, font=dustStyle.FONT_BODY, width=15, height=1, returnAction=self._connectSerialMux) self.serialMuxHostText.insert(1.0,"127.0.0.1") self._add(self.serialMuxHostText,1,1) temp = dustGuiLib.Label(self.serialMuxFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="port:") self._add(temp,1,2) self.serialMuxPortText = dustGuiLib.Text(self.serialMuxFrame, font=dustStyle.FONT_BODY, width=5, height=1, returnAction=self._connectSerialMux) self.serialMuxPortText.insert(1.0,"9900") self._add(self.serialMuxPortText,1,3) self.serialMuxButton = dustGuiLib.Button(self.serialMuxFrame, text='connect', command=self._connectSerialMux) self._add(self.serialMuxButton,1,4) # row 3: xml self.xmlFrame = Tkinter.Frame(self.container,borderwidth=0,bg=dustStyle.COLOR_BG) temp = dustGuiLib.Label(self.xmlFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="through XML-RPC:") self._add(temp,0,0,columnspan=5) temp = dustGuiLib.Label(self.xmlFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="host:") self._add(temp,1,0) self.xmlHostText = dustGuiLib.Text(self.xmlFrame, font=dustStyle.FONT_BODY, width=15, height=1, returnAction=self._connectXml) self.xmlHostText.insert(1.0,"") self._add(self.xmlHostText,1,1) temp = dustGuiLib.Label(self.xmlFrame, font=dustStyle.FONT_BODY, bg=dustStyle.COLOR_BG, text="port:") self._add(temp,1,2) self.xmlPortText = dustGuiLib.Text(self.xmlFrame, font=dustStyle.FONT_BODY, width=5, height=1, returnAction=self._connectXml) self.xmlPortText.insert(1.0,"4445") self._add(self.xmlPortText,1,3) self.xmlButton = dustGuiLib.Button(self.xmlFrame, text='connect', command=self._connectXml) self._add(self.xmlButton,1,4) # row 4: text self.tipLabel = dustGuiLib.Label(self.container,borderwidth=0,bg=dustStyle.COLOR_BG) self.guiLock.acquire() self.tipLabel.grid(row=4,column=0,sticky=Tkinter.W) self.guiLock.release()