示例#1
0
 def apiLoaded(self,apiDef):
     
     # call the parent's apiLoaded function
     dustFrame.dustFrame.apiLoaded(self,apiDef)
     
     with self.guiLock:
         self.commandToSend = Tkinter.StringVar()
         self.commandToSend.trace_variable('w',self._handleCommandSelected)
         
         self.subcommandToSend = Tkinter.StringVar()
         self.subcommandToSend.trace_variable('w',self._handleSubCommandSelected)
     
     self.commandDropDownOptions = self.apiDef.getNames(ApiDefinition.ApiDefinition.COMMAND)
     self.commandDropDownOptions.sort()
     
     # remove command we don't want to appear in drop-down menu
     for itemToRemove in ['hello', 'hello_response','mux_hello']:
         try:
             self.commandDropDownOptions.remove(itemToRemove)
         except ValueError:
             # happens when item does not appear in list
             pass
     
     with self.guiLock:
         self.commandDropDown = dustGuiLib.OptionMenu(
             self.container,
             self.commandToSend,
             *self.commandDropDownOptions
         )
         self._add(self.commandDropDown,0,0)
示例#2
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)
示例#3
0
 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,
                 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 __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)