def __init__(self, container, lambda_factory, content, mac, handle_setThreeVal_set): # initialize parent class Tkinter.Frame.__init__(self, container) # text 1 self.textElem1 = dustGuiLib.Text(self, width=6, height=1) self.textElem1.insert(1.0, '') self.textElem1.grid(row=0, column=0) # text 2 self.textElem2 = dustGuiLib.Text(self, width=6, height=1) self.textElem2.insert(1.0, '') self.textElem2.grid(row=0, column=1) # text 3 self.textElem3 = dustGuiLib.Text(self, width=6, height=1) self.textElem3.insert(1.0, '') self.textElem3.grid(row=0, column=2) # set button self.setButton = dustGuiLib.Button( self, command=lambda_factory( handle_setThreeVal_set, (mac, self.textElem1, self.textElem2, self.textElem3, content['min2'], content['max2'], content['min3'], content['max3'], content['cb_set'])), text="set", ) self.setButton.grid(row=0, column=3)
def __init__(self, container, lambda_factory, content, mac, handle_update_set): Tkinter.Frame.__init__(self, container) # text self.textElem = dustGuiLib.Text(self, width=6, height=1) self.textElem.insert(1.0, '') self.textElem.grid(row=0, column=0) # get button self.getButton = dustGuiLib.Button( self, command=lambda_factory(content['cb_get'], (mac, )), text="get", ) self.getButton.grid(row=0, column=1) # set button self.setButton = dustGuiLib.Button( self, command=lambda_factory(handle_update_set, (mac, self.textElem, content['min'], content['max'], content['cb_set'])), text="set", ) self.setButton.grid(row=0, column=2)
def __init__(self,parentElem,guiLock,setCb,frameName="Form",row=0,column=0): # validate params assert callable(setCb) # store params self.setCb = setCb # init parent dustFrame.dustFrame.__init__(self,parentElem,guiLock,frameName,row,column) # row 0: form self.formFrame = Tkinter.Frame( self.container, borderwidth=0, bg=dustStyle.COLOR_BG, ) self.formFrame.grid(row=0,column=0,sticky=Tkinter.W) self.formText = dustGuiLib.Text( self.formFrame, font=dustStyle.FONT_BODY, width=50, height=1, returnAction=self._buttonCb, ) self.formText.insert(1.0,"") self._add(self.formText,0,0) self.formButton = dustGuiLib.Button( self.formFrame, text='set', command=self._buttonCb, ) self._add(self.formButton,0,1)
def __init__(self, parentElem, guiLock, startPressedCb, stopPressedCb, frameName="LED ping", row=0, column=0): # record params self.startPressedCb = startPressedCb self.stopPressedCb = stopPressedCb # init parent dustFrame.dustFrame.__init__(self, parentElem, guiLock, frameName, row, column) # row 0: mac self.macText = dustGuiLib.Text(self.container, font=dustStyle.FONT_BODY, width=25, height=1) self.macText.insert(1.0, "00170d000038") self._add(self.macText, 0, 0) self.startStopButton = dustGuiLib.Button( self.container, text='start', command=self._startStopButtonPressed) self.disableButton() self._add(self.startStopButton, 0, 1) # row 1: canvas self.ledCanvas = Tkinter.Canvas(self.container, width=200, height=200) self._add(self.ledCanvas, 1, 0, columnspan=2) # row 2: rtt label self.rttLabel = Tkinter.Label(self.container) self._add(self.rttLabel, 2, 0, columnspan=2)
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="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, 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,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()