Example #1
0
 def push(self, command, astMod=None):
     """Send command to the interpreter to be executed.
     
     Because this may be called recursively, we append a new list
     onto the commandBuffer list and then append commands into
     that.  If the passed in command is part of a multi-line
     command we keep appending the pieces to the last list in
     commandBuffer until we have a complete command. If not, we
     delete that last list."""
     
     # In case the command is unicode try encoding it
     if type(command) == unicode:
         try:
             command = command.encode(wx.GetDefaultPyEncoding())
         except UnicodeEncodeError:
             pass # otherwise leave it alone
             
     if not self.more:
         try: del self.commandBuffer[-1]
         except IndexError: pass
     if not self.more: self.commandBuffer.append([])
     self.commandBuffer[-1].append(command)
     source = '\n'.join(self.commandBuffer[-1])
     
     # If an ast code module is passed, pass it to runModule instead
     more=False
     if astMod != None:
         self.runModule(astMod)
         self.more=False
     else:
         more = self.more = self.runsource(source)
     dispatcher.send(signal='Interpreter.push', sender=self,
                     command=command, more=more, source=source)
     return more
Example #2
0
 def OnPageChanged(self, event):
     """Page changed event handler."""
     new = event.GetSelection()
     window = self.GetPage(new)
     dispatcher.send(signal="EditorChange", sender=self, editor=window.editor)
     window.SetFocus()
     event.Skip()
    def push(self, command):
        """Send command to the interpreter to be executed.
        
        Because this may be called recursively, we append a new list
        onto the commandBuffer list and then append commands into
        that.  If the passed in command is part of a multi-line
        command we keep appending the pieces to the last list in
        commandBuffer until we have a complete command. If not, we
        delete that last list."""

        # In case the command is unicode try encoding it
        if type(command) == unicode:
            try:
                command = command.encode(wx.GetDefaultPyEncoding())
            except UnicodeEncodeError:
                pass  # otherwise leave it alone

        if not self.more:
            try:
                del self.commandBuffer[-1]
            except IndexError:
                pass
        if not self.more: self.commandBuffer.append([])
        self.commandBuffer[-1].append(command)
        source = '\n'.join(self.commandBuffer[-1])
        more = self.more = self.runsource(source)
        dispatcher.send(signal='Interpreter.push',
                        sender=self,
                        command=command,
                        more=more,
                        source=source)
        return more
    def request_controller_status(self):
        """
        Generate a notification with the current status of the controller.
        You can check the lock in your code using something like this:

            if controllerState in network.controller.STATES_UNLOCKED:
                hide_cancel_button()
                show_command_buttons()
            else:
                show_cancel_button()
                hide_command_buttons()

        """
        dispatcher.send(
            self._network.SIGNAL_CONTROLLER_COMMAND,
            sender=self,
            network=self._network,
            controller=self,
            node=self,
            node_id=self.node_id,
            state_int=self._ctrl_last_stateint,
            state=PyControllerState[self._ctrl_last_stateint],
            state_full=PyControllerState[self._ctrl_last_stateint].doc,
            error_int=0,
            error="None",
            error_full="None",
        )
        return True
Example #5
0
 def OnPageChanged(self, event):
     """Page changed event handler."""
     new = event.GetSelection()
     window = self.GetPage(new)
     dispatcher.send(signal='EditorChange', sender=self,
                     editor=window.editor)
     window.SetFocus()
     event.Skip()
    def emit(self, signal, *args):

        signal = str(signal)

        if len(args) == 1:
            if type(args[0]) == tuple:
                args = args[0]
        dispatcher.send(signal, self, *args)
 def emit(self, signal, *args):
      
     signal = str(signal)
 
     if len(args)==1:
       if type(args[0])==tuple:
         args=args[0]
     dispatcher.send(signal, self, *args)  
Example #8
0
 def OnPageChanged(self, event):
     """Page changed event handler."""
     if DEBUG : print "EditorNotebook","OnPageChanged"  
     new = event.GetSelection()
     window = self.GetPage(new)
     dispatcher.send(signal='EditorChange', sender=self,
                     editor=window.editor)
     window.SetFocus()
     event.Skip()
Example #9
0
 def handle_read(self):
     '''
     receive data, result
     '''
     try:
         newdata = self.recv(2000)
         if newdata:
             self.RecvData += newdata
             disp.send("RESULT", ip=self.ip, string=self.RecvData)
             asyncore.dispatcher.close(self)
     except socket.error, e:
         print "read error:",e
Example #10
0
 def LoadHistory(self):
     if self.dataDir:
         name = os.path.join(self.dataDir, "history")
         if os.path.exists(name):
             try:
                 f = file(name, "U")
                 hist = f.read()
                 f.close()
                 self.shell.history = hist.split("\x00\n")
                 dispatcher.send(signal="Shell.loadHistory", history=self.shell.history)
             except:
                 d = wx.MessageDialog(self, "Error loading history file.", "Error", wx.ICON_EXCLAMATION)
                 d.ShowModal()
                 d.Destroy()
Example #11
0
 def LoadHistory(self):
     if self.dataDir:
         name = os.path.join(self.dataDir, 'history')
         if os.path.exists(name):
             try:
                 f = file(name, 'U')
                 hist = f.read()
                 f.close()
                 self.shell.history = hist.split('\x00\n')
                 dispatcher.send(signal="Shell.loadHistory", history=self.shell.history)
             except:
                 d = wx.MessageDialog(self, "Error loading history file.",
                                      "Error", wx.ICON_EXCLAMATION)
                 d.ShowModal()
                 d.Destroy()
    def do_poll_statistics(self):
        """
        Timer based polling system for statistics
        """
        self._timer_statistics = None
        stats = self.stats
        dispatcher.send(self.SIGNAL_CONTROLLER_STATS,
                        sender=self,
                        network=self._network,
                        controller=self,
                        stats=stats)

        self._timer_statistics = threading.Timer(self._interval_statistics,
                                                 self.do_poll_statistics)
        self._timer_statistics.start()
Example #13
0
 def handle_write(self):
     '''
     send "self.SendDta"
     '''
     try:
         data_length = len(self.SendData)
         #data_length = min(2000,_data_length)
         send_byte = self.send(self.SendData[:data_length])
         if send_byte > 0 and send_byte <= data_length:
             self.send_len += send_byte
             self.SendData = self.SendData[send_byte:]
             disp.send("STATUS", ip=self.ip, length=self.send_len)
     except Exception, e:
         print "write error:",e
         #logging.info("write error:%s"%e)
         disp.send("RESULT", ip=self.ip, string="connection failed")
 def autoCallTipShow(self, command):
     """Display argument spec and docstring in a popup window."""
     if self.window.CallTipActive():
         self.window.CallTipCancel()
     (name, argspec, tip) = self.buffer.interp.getCallTip(command)
     if tip:
         dispatcher.send(signal='Shell.calltip', sender=self, calltip=tip)
     if not self.window.autoCallTip:
         return
     startpos = self.window.GetCurrentPos()
     if argspec:
         self.window.AddText(argspec + ')')
         endpos = self.window.GetCurrentPos()
         self.window.SetSelection(startpos, endpos)
     if tip:
         tippos = startpos - (len(name) + 1)
         fallback = startpos - self.GetColumn(startpos)
         # In case there isn't enough room, only go back to the
         # fallback.
         tippos = max(tippos, fallback)
         self.CallTipShow(tippos, tip)
Example #15
0
 def autoCallTipShow(self, command):
     """Display argument spec and docstring in a popup window."""
     if self.window.CallTipActive():
         self.window.CallTipCancel()
     (name, argspec, tip) = self.buffer.interp.getCallTip(command)
     if tip:
         dispatcher.send(signal='Shell.calltip', sender=self, calltip=tip)
     if not self.window.autoCallTip:
         return
     startpos = self.window.GetCurrentPos()
     if argspec:
         self.window.AddText(argspec + ')')
         endpos = self.window.GetCurrentPos()
         self.window.SetSelection(startpos, endpos)
     if tip:
         tippos = startpos - (len(name) + 1)
         fallback = startpos - self.GetColumn(startpos)
         # In case there isn't enough room, only go back to the
         # fallback.
         tippos = max(tippos, fallback)
         self.CallTipShow(tippos, tip)
Example #16
0
    def OnKeyDown(self, event):
        """Key down event handler."""

        key = event.GetKeyCode()
        # If the auto-complete window is up let it do its thing.
        if self.window.AutoCompActive():
            event.Skip()
            return
        controlDown = event.ControlDown()
        altDown = event.AltDown()
        shiftDown = event.ShiftDown()
        # Let Ctrl-Alt-* get handled normally.
        if controlDown and altDown:
            event.Skip()
        # Increase font size.
        elif controlDown and key in (ord(']'),):
            dispatcher.send(signal='FontIncrease')
        # Decrease font size.
        elif controlDown and key in (ord('['),):
            dispatcher.send(signal='FontDecrease')
        # Default font size.
        elif controlDown and key in (ord('='),):
            dispatcher.send(signal='FontDefault')
        else:
            event.Skip()
Example #17
0
    def OnKeyDown(self, event):
        """Key down event handler."""

        key = event.GetKeyCode()
        # If the auto-complete window is up let it do its thing.
        if self.window.AutoCompActive():
            event.Skip()
            return
        controlDown = event.ControlDown()
        altDown = event.AltDown()
        shiftDown = event.ShiftDown()
        # Let Ctrl-Alt-* get handled normally.
        if controlDown and altDown:
            event.Skip()
        # Increase font size.
        elif controlDown and key in (ord(']'), ):
            dispatcher.send(signal='FontIncrease')
        # Decrease font size.
        elif controlDown and key in (ord('['), ):
            dispatcher.send(signal='FontDecrease')
        # Default font size.
        elif controlDown and key in (ord('='), ):
            dispatcher.send(signal='FontDefault')
        else:
            event.Skip()
 def _lock_controller(self):
     """Try to lock the controller and generate a notification if fails
     """
     if self._ctrl_lock.acquire(False):
         return True
     else:
         state = PyControllerState[self.INT_INPROGRESS]
         dispatcher.send(
             self._network.SIGNAL_CONTROLLER_COMMAND,
             sender=self,
             network=self._network,
             controller=self,
             node=self,
             node_id=self.node_id,
             state_int=self.INT_INPROGRESS,
             state=state,
             state_full=state.doc,
             error_int=self.STATE_ERROR,
             error='Locked',
             error_full=("Can't lock controller because a "
                         "command is already in progress"),
         )
    def hard_reset(self):
        """
        Hard Reset a PC Z-Wave Controller.
        Resets a controller and erases its network configuration settings.
        The controller becomes a primary controller ready to add devices to a
        new network.

        This command fires a lot of louie signals.
        Louie's clients must disconnect from nodes and values signals
        """
        self._network.state = self._network.STATE_RESET
        dispatcher.send(self._network.SIGNAL_NETWORK_RESET,
                        sender=self,
                        network=self._network,
                        controller=self)
        self._network.manager.resetController(self.home_id)
        try:
            self.network.network_event.wait(5.0)
        except AssertionError:
            # For gevent AssertionError: Impossible to call blocking
            # function in the event loop callback
            pass
    def _handle_controller_command(self, **kwargs):
        """
        Called when a message from controller is sent.

        :param args: data sent by the notification
        :type args: dict()

        """
        logger.debug(u'Z-Wave ControllerCommand : %s', kwargs)

        if kwargs['controllerState'] == self.STATE_WAITING:
            dispatcher.send(self._network.SIGNAL_CONTROLLER_WAITING,
                            sender=self,
                            network=self._network,
                            controller=self,
                            **kwargs)

        if kwargs['controllerState'] in self.STATES_UNLOCKED:
            try:
                self._ctrl_lock.release()
            except threading.ThreadError:
                pass
        self._ctrl_last_state = kwargs['controllerState']
        self._ctrl_last_stateint = kwargs['controllerStateInt']

        if kwargs['nodeId'] in self._network.nodes:
            node = self._network.nodes[kwargs['nodeId']]
        else:
            node = None

        dispatcher.send(self._network.SIGNAL_CONTROLLER_COMMAND,
                        sender=self,
                        network=self._network,
                        controller=self,
                        node=node,
                        node_id=kwargs.pop('nodeId'),
                        **kwargs)
Example #21
0
 def OnKeyDown(self, event):
     """Key down event handler."""
     if DEBUG : print "Editor","OnKeyDown" 
     key = event.KeyCode()
     controlDown = event.ControlDown()
     altDown = event.AltDown()
     shiftDown = event.ShiftDown()
     # Let Ctrl-Alt-* get handled normally.
     if controlDown and altDown:
         event.Skip()
     # Increase font size.
     elif controlDown and key in (ord(']'),):
         dispatcher.send(signal='FontIncrease')
     # Decrease font size.
     elif controlDown and key in (ord('['),):
         dispatcher.send(signal='FontDecrease')
     # Default font size.
     elif controlDown and key in (ord('='),):
         dispatcher.send(signal='FontDefault')
     else:
         event.Skip()
Example #22
0
    def OnKeyDown(self, event):
        """Key down event handler."""

        key = event.KeyCode()
        # If the auto-complete window is up let it do its thing.
        if self.AutoCompActive():
            event.Skip()
            return
        # Prevent modification of previously submitted
        # commands/responses.
        controlDown = event.ControlDown()
        altDown = event.AltDown()
        shiftDown = event.ShiftDown()
        currpos = self.GetCurrentPos()
        endpos = self.GetTextLength()
        selecting = self.GetSelectionStart() != self.GetSelectionEnd()
        # Return (Enter) is used to submit a command to the
        # interpreter.
        if not controlDown and key == wx.WXK_RETURN:
            if self.CallTipActive():
                self.CallTipCancel()
            self.processLine()
        # Ctrl+Return (Cntrl+Enter) is used to insert a line break.
        elif controlDown and key == wx.WXK_RETURN:
            if self.CallTipActive():
                self.CallTipCancel()
            if currpos == endpos:
                self.processLine()
            else:
                self.insertLineBreak()
        # Let Ctrl-Alt-* get handled normally.
        elif controlDown and altDown:
            event.Skip()
        # Clear the current, unexecuted command.
        elif key == wx.WXK_ESCAPE:
            if self.CallTipActive():
                event.Skip()
            else:
                self.clearCommand()
        # Increase font size.
        elif controlDown and key in (ord(']'),):
            dispatcher.send(signal='FontIncrease')
        # Decrease font size.
        elif controlDown and key in (ord('['),):
            dispatcher.send(signal='FontDecrease')
        # Default font size.
        elif controlDown and key in (ord('='),):
            dispatcher.send(signal='FontDefault')
        # Cut to the clipboard.
        elif (controlDown and key in (ord('X'), ord('x'))) \
        or (shiftDown and key == wx.WXK_DELETE):
            self.Cut()
        # Copy to the clipboard.
        elif controlDown and not shiftDown \
            and key in (ord('C'), ord('c'), wx.WXK_INSERT):
            self.Copy()
        # Copy to the clipboard, including prompts.
        elif controlDown and shiftDown \
            and key in (ord('C'), ord('c'), wx.WXK_INSERT):
            self.CopyWithPrompts()
        # Copy to the clipboard, including prefixed prompts.
        elif altDown and not controlDown \
            and key in (ord('C'), ord('c'), wx.WXK_INSERT):
            self.CopyWithPromptsPrefixed()
        # Home needs to be aware of the prompt.
        elif key == wx.WXK_HOME:
            home = self.promptPosEnd
            if currpos > home:
                self.SetCurrentPos(home)
                if not selecting and not shiftDown:
                    self.SetAnchor(home)
                    self.EnsureCaretVisible()
            else:
                event.Skip()
        #
        # The following handlers modify text, so we need to see if
        # there is a selection that includes text prior to the prompt.
        #
        # Don't modify a selection with text prior to the prompt.
        elif selecting and key not in NAVKEYS and not self.CanEdit():
            pass
        # Paste from the clipboard.
        elif (controlDown and not shiftDown and key in (ord('V'), ord('v'))) \
                 or (shiftDown and not controlDown and key == wx.WXK_INSERT):
            self.Paste()
        # Paste from the clipboard, run commands.
        elif controlDown and shiftDown and key in (ord('V'), ord('v')):
            self.PasteAndRun()
        # Replace with the previous command from the history buffer.
        elif (controlDown and key == wx.WXK_UP) \
                 or (altDown and key in (ord('P'), ord('p'))):
            self.OnHistoryReplace(step=+1)
        # Replace with the next command from the history buffer.
        elif (controlDown and key == wx.WXK_DOWN) \
                 or (altDown and key in (ord('N'), ord('n'))):
            self.OnHistoryReplace(step=-1)
        # Insert the previous command from the history buffer.
        elif (shiftDown and key == wx.WXK_UP) and self.CanEdit():
            self.OnHistoryInsert(step=+1)
        # Insert the next command from the history buffer.
        elif (shiftDown and key == wx.WXK_DOWN) and self.CanEdit():
            self.OnHistoryInsert(step=-1)
        # Search up the history for the text in front of the cursor.
        elif key == wx.WXK_F8:
            self.OnHistorySearch()
        # Don't backspace over the latest non-continuation prompt.
        elif key == wx.WXK_BACK:
            if selecting and self.CanEdit():
                event.Skip()
            elif currpos > self.promptPosEnd:
                event.Skip()
        # Only allow these keys after the latest prompt.
        elif key in (wx.WXK_TAB, wx.WXK_DELETE):
            if self.CanEdit():
                event.Skip()
        # Don't toggle between insert mode and overwrite mode.
        elif key == wx.WXK_INSERT:
            pass
        # Don't allow line deletion.
        elif controlDown and key in (ord('L'), ord('l')):
            pass
        # Don't allow line transposition.
        elif controlDown and key in (ord('T'), ord('t')):
            pass
        # Basic navigation keys should work anywhere.
        elif key in NAVKEYS:
            event.Skip()
        # Protect the readonly portion of the shell.
        elif not self.CanEdit():
            pass
        else:
            event.Skip()