Exemplo n.º 1
0
 def changed(self):
     ''' 
         @summary: changed() -- called whenever this value is modified.
     '''
     outstr = 'Input %s has changed to %s' % (self.key, str(self.value()))
     log.info(outstr)  # local logging
     SerialUI.println(outstr)  # remote notification
Exemplo n.º 2
0
def global_command_callback(theCommand):
    log.info("Command %s!" % theCommand.key)
    outstr ="Command '%s' [%i] triggered (global callback)" %  (
            theCommand.key, 
            theCommand.id)
    log.debug(outstr)
    SerialUI.println(outstr)
Exemplo n.º 3
0
 def command_callback(self, cmd):
     log.info("Command %s!" % cmd.key)
     outstr ="Command '%s' [%i] triggered (handler callback)" %  (
             cmd.key, 
             cmd.id)
     log.debug(outstr)
     SerialUI.println(outstr)
Exemplo n.º 4
0
def global_inputchanged_callback(theInput):
    log.info("Input %s change!" % theInput.key)
    outstr ="Input '%s' [%i] changed to '%s' (global callback)" %  (
            theInput.key, 
            theInput.id,
            str(theInput.value()))
    log.debug(outstr)
    SerialUI.println(outstr)
Exemplo n.º 5
0
 def input_changed(self, inputObj):
     log.info("Input %s change!" % inputObj.key)
     outstr ="Input '%s' [%i] changed to '%s' (handler callback)" %  (
             inputObj.key, 
             inputObj.id,
             str(inputObj.value()))
     log.debug(outstr)
     SerialUI.println(outstr)
     
     
Exemplo n.º 6
0
 def changed(self):
     ''' 
         @summary: changed() -- called whenever this input is modified.
         
     '''
     outstr = 'Input %s (which is an %s) is now "%s"' % (
         self.key,
         str(self.inputType()),
         str(self.value())
     )
     log.info(outstr) # local output
     SerialUI.println(outstr) # send to user
Exemplo n.º 7
0
 def changed(self):
     ''' 
         @summary: changed() -- called whenever this event is modified.
         
         The event item value() is a number that doesn't mean all that 
         much, at first glance.
         
         We use the wrappers.InputEvent.eventDetails() to get something
         more useful.
     '''
     
     evtDetails = self.eventDetails()
     
     outstr = 'Input %s is now scheduled for %s-%s (current: %s)' % (
         self.key,
         str(evtDetails.startTime()),
         str(evtDetails.endTime()),
         str(evtDetails.isCurrentNow())
     )
     log.info(outstr) # local output
     SerialUI.println(outstr) # send to user
Exemplo n.º 8
0
 def loaded(self):
     '''
         loaded 
         
         @summary: ready to begin, perform extra setup here
         
         Call once SerialUI is ready to start processing users.  At this stage,
         you're guaranteed to have access to the items through
             - SerialUI.tree()
             - SerialUI.top() etc
         and the tracked states (SerialUI.trackers()).
     '''
     # I don't know what your SerialUI.tree() actually contains
     # so we'll do it dynamically, by crawling the entire menu
     # tree
     log.info("Module loaded")
     log.debug("Crawling the items to setup callbacks")
     # foreachItem will call the provided function/method
     # for each menu item found (depth first)
     # return False in that function to stop going any deeper
     SerialUI.foreachItem(self.crawler_callback)
Exemplo n.º 9
0
    def __init__(self):
        '''
            SerialUIHandler init 
            @summary: called when the module is loaded (after setup, before main loop)
        '''
        print("SerialUIHandler init called!")
        # restrict access.  First create a basic validator
        self.validator = AuthValidator(AuthStorage('asecret'))
        # now set this validator as the authenticator for the system
        SerialUI.setAuthValidator(self.validator)

        # override the "NumberInput" menu item's callbacks
        if self.getMenuItem('NumberInput') is None:
            print("No 'NumberInput' menu item found here ... skipping")
        else:
            # it does exist.  All we need to do is create an instance of
            # our override class by passing it the tree item we want to affect
            # AND make sure we hold on to a reference to this object... If it
            # is garbage-collected, our override no longer applies
            self.my_number_input = MyNumberInput(
                self.getMenuItem('NumberInput'))

        # override the "ACommand" menu item
        if self.getMenuItem('ACommand') is None:
            print("No 'ACommand' menu item found here... skipping")
        else:
            # got it.  Same as for input, above.  All we do is
            # instantiate our override and hold on to the reference
            self.my_command_obj = MyCommand(self.getMenuItem('ACommand'))

        # so far, we've implemented our overrides by defining a class
        # and creating an instance.  Another method is to act on the
        # SerialUI.tree() items themselves.
        textInput = self.getMenuItem('TextInput')
        if textInput is None:
            print("Hm, can't find 'TextInput' item in tree... skipping")
        else:
            # ok, have the item in the tree...
            # let's just override its validator
            textInput.setValidator(IsThisValid)
Exemplo n.º 10
0
 def getMenuItem(self, itmName: str):
     '''
         Can't be certain this module will be run with a 
         suitably setup program, so getMenuItem() is here 
         just to safely check for, and return, items from the 
         SerialUI tree.
         
         Probably always a good idea to use such a method, but 
         you could also just do things like
         blah = MyOverride(SerialUI.tree()['An Item Im certain is there'])
         or even
         SerialUI.tree()['A Command Im certain is there'].setOnTriggered(somefunction)
         
     '''
     itemTree = SerialUI.tree()
     if itmName in itemTree:
         return itemTree[itmName]
     return None
Exemplo n.º 11
0
 def triggered(self):
     outstr = 'Command %s triggered' % self.key
     
     log.info(outstr) # local logging
     SerialUI.println(outstr) # send to user too
Exemplo n.º 12
0
 def showTree(self):
     self.printer.pprint(SerialUI.tree())
Exemplo n.º 13
0
 def triggered(self):
     reportstr = "Trigger warning! ahem.  Command triggered"
     log.debug(reportstr)
     print(reportstr)  #output here
     SerialUI.println(reportstr)  # output to client
Exemplo n.º 14
0
 def changed(self):
     reportstr = "OOOOOh number input changed to %s" % str(self.value())
     log.debug(reportstr)
     print(reportstr)  #output here
     SerialUI.println(reportstr)  # output to client
Exemplo n.º 15
0
 def triggered(self):
     outstr = 'Command %s triggered' % self.key
     print(outstr)
     log.info(outstr)  # local logging
     SerialUI.println(outstr)  # remote notification