コード例 #1
0
    def __init__(self, parent, engine, world=None, panel=None):
        AccessPanel.__init__(self, parent, history=True, lock_input=True)
        self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
        self.engine = engine
        self.world = world
        self.panel = panel
        self.thread = GUIThread(self)
        session = self.panel and self.panel.session or None
        sharp_engine = session and session.sharp_engine or None
        client = sharp_engine and sharp_engine.client or None
        self.locals = {
            "engine": self.engine,
            "world": self.world,
            "panel": self.panel,
            "session": session,
            "sharp_engine": sharp_engine,
            "client": client,
        }

        # Event binding
        self.output.Bind(wx.EVT_TEXT_PASTE, self.OnPaste)

        # Launch the console
        self.thread.console.locals = self.locals
        self.thread.start()
        logger.debug("Starting the Python console thread")
コード例 #2
0
    def __init__(self, parent, session):
        AccessPanel.__init__(self, parent, history=True, lock_input=True)
        self.output.SetDefaultStyle(wx.TextAttr(wx.WHITE, wx.BLACK))
        self.session = session
        self.lines = []

        # Event binding
        self.output.Bind(wx.EVT_TEXT_PASTE, self.OnPaste)

        # Launch the console
        logger.debug("Starting the SharpScript console")
        self.Send(t("ui.dialog.sharp_script_console.banner"))
コード例 #3
0
    def __init__(self, engine, world=None, panel=None):
        wx.Dialog.__init__(self, None, title=t("ui.dialog.console.title"))
        self.engine = engine
        self.world = world

        # Build the dialog
        sizer = wx.BoxSizer(wx.VERTICAL)
        self.SetSizer(sizer)

        # Add in the panel
        logger.debug("Creating the Python console")
        self.panel = ConsolePanel(self, engine, world, panel)

        # Finish designing the window
        sizer.Add(self.panel)
        sizer.Fit(self)

        # Event binding
        self.Bind(wx.EVT_CLOSE, self.OnClose)
コード例 #4
0
    def interact(self, banner=None):
        """Interact and redirect to self.write."""
        try:
            sys.ps1
        except AttributeError:
            sys.ps1 = ">>> "
        try:
            sys.ps2
        except AttributeError:
            sys.ps2 = "... "
        cprt = 'Type "help", "copyright", "credits" or "license" for more information.'
        logger.debug("Sending the welcome prompt")
        if banner is None:
            self.write("Python %s on %s\n%s\n" %
                       (sys.version, sys.platform, cprt))
        else:
            self.write("%s\n" % str(banner))

        # Display the prompt
        self.panel.Send(">>>")

        more = 0
        while 1:
            if self.interrupt:
                break

            try:
                if more:
                    prompt = sys.ps2
                else:
                    prompt = sys.ps1
                try:
                    line = self.input()
                    if line is None:
                        time.sleep(0.2)
                        continue
                except EOFError:
                    self.write("\n")
                    break
                else:
                    stdout = sys.stdout
                    stderr = sys.stderr
                    sys.stdout = self
                    sys.stderr = self
                    logger.debug("Executing {}".format(repr(line)))
                    more = self.push(line)
                    sys.stdout = stdout
                    sys.stderr = stderr
                    logger.debug("Exec successful")

                    # Display the prompt
                    if more:
                        prompt = sys.ps2
                    else:
                        prompt = sys.ps1

                    self.panel.Send(prompt)
            except KeyboardInterrupt:
                self.write("\nKeyboardInterrupt\n")
                self.resetbuffer()
                more = 0
コード例 #5
0
 def OnInput(self, message):
     """Some text has been sent from the input."""
     # Converts the text back to 'str'
     logger.debug("Received {}".format(repr(message)))
     self.thread.console.to_exec = message
コード例 #6
0
 def run(self):
     self.panel.Send(t("ui.dialog.console.warning"))
     self.console.interact()
     logger.debug("Begin interacting with the Python console")
コード例 #7
0
 def write(self, message):
     """Write the text to the interface."""
     logger.debug("Received in answer {}".format(repr(message)))
     self.panel.Send(message)