def onRunCode(self, parallelmode=True):
        def askcmdargs():
            return askstring('SimpleEditor', 'Commandline arguments?') or ''

        from PP4E.launchmodes import System, Start, StartArgs, Fork
        filemode = False
        thefile = str(self.getFileName())
        if os.path.exists(thefile):
            filemode = askyesno('SimpleEditor', 'Run from file?')
            self.update()
        if not filemode:  # run text string
            cmdargs = askcmdargs()
            namespace = {'__name__': '__main__'}  # run as top-level
            sys.argv = [thefile] + cmdargs.split()  # could use threads
            exec(self.getAllText() + '\n', namespace)
        elif self.text_edit_modified():
            showerror('SimpleEditor', 'Text changed: you must save before run')
        else:
            cmdargs = askcmdargs()
            mycwd = os.getcwd()  # cwd may be root
            dirname, filename = os.path.split(thefile)  # get dir, base
            os.chdir(dirname or mycwd)  # cd for filenames
            thecmd = filename + ' ' + cmdargs
            if not parallelmode:  # run as file
                System(thecmd, thecmd)()  # block editor
            else:
                if sys.platform[:3] == 'win':  # spawn in parallel
                    run = StartArgs if cmdargs else Start
                    run(thecmd, thecmd)()  # or always Spawn
                else:
                    Fork(thecmd, thecmd)()  # spawn in parallel
            os.chdir(mycwd)  # go back to my dir
Exemple #2
0
    def onRunCode(self, parallelmode=True):
        """
        run Python code being edited--not an IDE, but handy;
        tries to run in file's dir, not cwd (may be PP4E root);
        inputs and adds command-line arguments for script files;

        code's stdin/out/err = editor's start window, if any:
        run with a console window to see code's print outputs;
        but parallelmode uses start to open a DOS box for I/O;
        module search path will include '.' dir where started;
        in non-file mode, code's Tk root may be PyEdit's window;
        subprocess or multiprocessing modules may work here too;

        2.1: fixed to use base file name after chdir, not path;
        2.1: use StartArgs to allow args in file mode on Windows;
        2.1: run an update() after 1st dialog else 2nd dialog 
        sometimes does not appear in rare cases;
        """
        def askcmdargs():
            return askstring('PyEdit', 'Commandline arguments?') or ''

        from PP4E.launchmodes import System, Start, StartArgs, Fork
        filemode = False
        thefile = str(self.getFileName())
        if os.path.exists(thefile):
            filemode = askyesno('PyEdit', 'Run from file?')
            self.update()  # 2.1: run update()
        if not filemode:  # run text string
            cmdargs = askcmdargs()
            namespace = {'__name__': '__main__'}  # run as top-level
            sys.argv = [thefile] + cmdargs.split()  # could use threads
            exec(self.getAllText() + '\n', namespace)  # exceptions ignored
        elif self.text_edit_modified():  # 2.0: changed test
            showerror('PyEdit', 'Text changed: you must save before run')
        else:
            cmdargs = askcmdargs()
            mycwd = os.getcwd()  # cwd may be root
            dirname, filename = os.path.split(thefile)  # get dir, base
            os.chdir(dirname or mycwd)  # cd for filenames
            thecmd = filename + ' ' + cmdargs  # 2.1: not theFile
            if not parallelmode:  # run as file
                System(thecmd, thecmd)()  # block editor
            else:
                if sys.platform[:3] == 'win':  # spawn in parallel
                    run = StartArgs if cmdargs else Start  # 2.1: support args
                    run(thecmd, thecmd)()  # or always Spawn
                else:
                    Fork(thecmd, thecmd)()  # spawn in parallel
            os.chdir(mycwd)  # go back to my dir
Exemple #3
0
 def spawn(self, pycmdline, wait=FALSE):
     if not wait:
         PortableLauncher(pycmdline, pycmdline)()
     else:
         System(pycmdline, pycmdline)()
Exemple #4
0
 def spawn(self, pycmdline, wait=False):
     if not wait:  # start new process
         PortableLauncher(pycmdline, pycmdline)()  # run Python progam
     else:
         System(pycmdline, pycmdline)()  # wait for it to exit