Exemplo n.º 1
0
 def processKeys(self, key):
     #print 'processKeys: ' + str(key.id) + ' ' + str(self)
     try:
         if key.id == KeyInfo.activation:
             pass
         elif key.id == KeyInfo.cancel:
             pass
         elif key.id in KeyInfo.autoComplate:
             pass
         elif key.id in KeyInfo.ignored:
             pass
         elif key.id in KeyInfo.previous:
             self.selectedIdx -= 1
         elif key.id in KeyInfo.next:
             self.selectedIdx += 1
         elif key.id in KeyInfo.back:
             if KeyInfo.hasModifiers():
                 newText = ''
             else:
                 newText = self.entry
                 newPos = len(newText) - 1
                 if newPos >= 0:
                     newText = newText[:newPos]
             self.entry = newText
         else:
             val = key.chr
             #print (val, type(val), str(val))
             #if val.isalnum() or val.isspace():
             self.entry += val
     except:
         printException()
Exemplo n.º 2
0
 def cancel(self):
     '''
     '''
     try:
         self.__state = None
         self.manager.command = None
         self.manager.lastWindowHandle = -1
         self.handler.deactivated()
     except:
         printException()
Exemplo n.º 3
0
 def __setSelection(self, selection):
     try:
         if selection != self.__selectedIdx:
             max = len(self.options)
             if selection < -1:
                 self.__selectedIdx = max - 1
             elif selection >= max:
                 self.__selectedIdx = 0
             else:
                 self.__selectedIdx = selection
         self.controller.handler.selectionChanged(self.__options,
                                                  self.__selectedIdx)
     except:
         printException()
Exemplo n.º 4
0
    def __activateOnTimer(self, *args, **kw):
        #print '__activateOnTimer'
        try:
            evt = args[1]
            self.applications.setCurrent(evt.Window)
        except:
            printException()

        state = args[0]
        assert (state)
        if self.__state:
            self.__state.deactivate()
        self.__state = state
        self.__state.activate(self.manager.command)
        self.handler.activated(self.__state)
Exemplo n.º 5
0
 def activate(self, command):
     '''
     Will be called when state is activated. Command is the current command instance Option is most likely empty
     '''
     BaseState.activate(self, command)
     assert (command)
     if hasattr(command, 'internallyUsedName'):
         name = command.internallyUsedName
     else:
         name = 'XXX'
     self.title = name + '...'
     try:
         self.options = command.options
     except:
         printException()
Exemplo n.º 6
0
    def __executeOnTimer(self, *args, **kw):
        self.__inExecution = True
        try:
            deactivate = True
            entry = args[0]
            evt = args[1]
            assert (self.__state)

            commandName = self.__commandState.complatedEntry
            optionName = self.__optionState.complatedEntry

            if self.manager.command:
                #print 'This was already in option state, so direct execution'
                assert (entry == optionName)
                self.manager.command.execute(commandName, optionName)
            else:
                #print 'This was in command state, we first need to get the command'
                if entry != '':
                    self.manager.command = entry
                    cmd = self.manager.command
                else:
                    cmd = None
                if cmd:
                    if hasattr(cmd, 'options'):
                        options = cmd.options
                    else:
                        options = None

                    if options is None:
                        #print 'No Options, we execute'
                        cmd.execute(commandName, optionName)
                    else:
                        #print 'Should switch to options state'
                        deactivate = False
                        cmd.internallyUsedName = commandName
                        self.activate(self.__optionState, evt)
        except:
            deactivate = True
            printException()

        if deactivate:
            self.__state.deactivate()
            self.__state = None
            self.manager.command = None
            self.manager.lastWindowHandle = -1
            self.handler.deactivated()

        self.__inExecution = False
Exemplo n.º 7
0
    def activate(self, command):
        '''
        Will be called when state is activated, both command and option will be empty
        Command state always start in transient mode
        
        When command state is activated it should get the command names from manager
        and update the options list
        '''
        BaseState.activate(self, command)
        assert (command == None)
        assert (self.controller.manager.command == None)

        self.onKeyDown = self.__tKeyDown
        self.onKeyUp = self.__tKeyUp

        try:
            self.options = self.controller.manager.getOptions()
        except:
            printException()
Exemplo n.º 8
0
    def __setEntry(self, entry):
        try:
            select = -1

            if len(entry) > len(self.__entry):
                oldOptions = self.options
            else:
                oldOptions = self.controller.manager.getOptions()
            self.__entry = entry

            newOptions = []
            for option in oldOptions:
                if self.findFunction(option, entry) >= 0:
                    newOptions.append(option)
            if len(newOptions) > 0:
                select = 0
            self.options = newOptions
            self.selectedIdx = select
            self.controller.handler.textChanged(self.__entry)
        except:
            printException()
Exemplo n.º 9
0
 def __setOptions(self, options):
     self.__options = options
     try:
         self.controller.handler.optionsChanged(self.__options)
     except:
         printException()
Exemplo n.º 10
0
 def cancel(self):
     try:
         self.controller.cancel()
     except:
         printException()
Exemplo n.º 11
0
 def execute(self, key):
     try:
         self.controller.execute(self.complatedEntry, key.evt)
     except:
         printException()