load and run another .py file in wxpython GUI -


have written script gui using wx python. need load python file , run option of providing inputs(values) variables of python file using gui. , display python file results. able load file need run....

here code gooeypi application. gui front-end pyinstaller. runs pyinstaller.py code flags , sends output textctrl widget. uses wx.yield avoid locking interface, although moving code own thread option.

class gooeypi(wx.frame):     def __init__(self, *args, **kwargs):         super(gooeypi, self).__init__(*args, **kwargs)         ...         # results go in here. read style people can't write in it.         self.txtresults = wx.textctrl(self.panel, size=(420,200),                                       style=wx.te_multiline|wx.te_readonly)       def onsubmit(self, e):         ...         # getflags returns ['python.exe', 'pyinstaller.py' '--someflag' '--someotherflag']         flags = util.getflags(self.fbb.getvalue())         logging.debug('calling subprocess {}'.format(flags))         line in self.callinstaller(flags):             self.txtresults.appendtext(line)                     def callinstaller(self, flags):         ' generator function, yields on every line in output of command          p = subprocess.popen(flags, stdout=subprocess.pipe, stderr=subprocess.stdout)         while(true):             retcode = p.poll()             line = p.stdout.readline()             wx.yield() # prevent gui freezing             yield line             if(retcode not none):                 yield ("pyinstaller returned return code: {}".format(retcode))                 break 

and getflags function reference. uses sys.executable find path python binary file , os.path.join find path python script run. appends number of flags based on config file. resulting list returned.

def getflags(fname):     flags=[]     flags.append(sys.executable) # python executable run pyinstaller     flags.append(os.path.join(config['pyidir'], 'pyinstaller.py'))     if config['noconfirm']:         flags.append('--noconfirm')     if config['singlefile']:         flags.append('--onefile')     if config['ascii']:         flags.append('--ascii')     if config['windowed']:         flags.append('--noconsole')     if config['upxdir'] != '':         flags.append('--upx-dir=' + config['upxdir'])     if pyversion(config['pyidir']) == 2.1:         flags.append('--distpath=' + os.path.dirname(fname))     else:         flags.append('--out=' + os.path.dirname(fname))     flags.append(fname)     return(flags) 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -