예제 #1
0
    def on_run(self):
        """Runs selected code in a new window."""

        # Create a test frame and hook into the caller.
        # Allows this frame to be destroyed by the main window on close.
        reactor = wx.GetApp().this_reactor

#       run_editor = SimpleFrame(wx.GetApp().TopWindow, title="")
#       run_panel = wx.richtext.RichTextCtrl(run_editor, style=wx.TE_READONLY)
#       run_editor.sizer.Add(run_panel, 1, wx.EXPAND)
#       run_editor.Layout()

        run_panel = self.console

        # If the console is closed or minimized, it should be made viewable
        # and maximized to run the file
        run_headered_panel = run_panel.GetParent().GetParent()
        run_headered_panel.Show(True)
        if run_headered_panel._minimized:
            run_headered_panel.restore_state()

        active_editor = self.editor_tab_get_editor()

        if active_editor.filepath:
            if active_editor.GetModify():
                active_editor.SaveFile(active_editor.filepath)
            filename = os.path.split(active_editor.filepath)[1]
            run_panel.WriteText("Running %s" % filename)
            run_panel.Newline()
            reactor.spawnProcess(PythonProcessProtocol(run_panel),
                                 get_python_exe(),
                                 ["python", str(active_editor.filepath)])

        else: # If the current file is not saved, run unsaved script
            run_panel.WriteText("Running unsaved script.")
            run_panel.Newline()
            script = StringIO()
            script.write(active_editor.GetText())
            script.seek(0)
            scr = script.read().replace("\r", '')

            reactor.spawnProcess(PythonProcessProtocol(run_panel),
                                 get_python_exe(),
                                 ["python", "-c", scr])

        return run_panel
예제 #2
0
    def on_run(self):
        """Runs selected code in a new window."""

        # Create a test frame and hook into the caller.
        # Allows this frame to be destroyed by the main window on close.
        reactor = wx.GetApp().this_reactor

        #       run_editor = SimpleFrame(wx.GetApp().TopWindow, title="")
        #       run_panel = wx.richtext.RichTextCtrl(run_editor, style=wx.TE_READONLY)
        #       run_editor.sizer.Add(run_panel, 1, wx.EXPAND)
        #       run_editor.Layout()

        run_panel = self.console

        # If the console is closed or minimized, it should be made viewable
        # and maximized to run the file
        run_headered_panel = run_panel.GetParent().GetParent()
        run_headered_panel.Show(True)
        if run_headered_panel._minimized:
            run_headered_panel.restore_state()

        active_editor = self.editor_tab_get_editor()

        if active_editor.filepath:
            if active_editor.GetModify():
                active_editor.SaveFile(active_editor.filepath)
            filename = os.path.split(active_editor.filepath)[1]
            run_panel.WriteText("Running %s" % filename)
            run_panel.Newline()
            reactor.spawnProcess(
                PythonProcessProtocol(run_panel), get_python_exe(),
                ["python", str(active_editor.filepath)])

        else:  # If the current file is not saved, run unsaved script
            run_panel.WriteText("Running unsaved script.")
            run_panel.Newline()
            script = StringIO()
            script.write(active_editor.GetText())
            script.seek(0)
            scr = script.read().replace("\r", '')

            reactor.spawnProcess(PythonProcessProtocol(run_panel),
                                 get_python_exe(), ["python", "-c", scr])

        return run_panel
예제 #3
0
def spawn_python():
    return [PythonProcessProtocol(None), get_python_exe(), ["python"]]