[PySide] using QProcess to run python function

Ryan Gonzalez rymg19 at gmail.com
Fri Jan 24 02:58:39 CET 2014


If you put an "if __name__ == '__main__'" and a main functions, you could
always import the script from the GUI frontend. Example:

myscript.py

def main(argv):
    do_cool_stuff()
    return 0

if __name__ == '__main__':
    sys.exit(main(sys.argv))

mygui.py(Python 2):

import imp

...

main = imp.load_module('myscript', *imp.find_module('myscript'))

main.main(my_argv)

mygui.py(Python 3):

import importlib.machinery

main = importlib.machinery.SourceFileLoader('myscript',
'myscript.py').load_module('myscript')

main.main(my_argv)


On Thu, Jan 23, 2014 at 7:48 PM, Frank Rueter | OHUfx <frank at ohufx.com>wrote:

> Hi all,
>
> I got a little code design question:
>
> I have a python script that does a lot of file
> processing/converting/uploading etc and I'd like to write a decent
> interface for it now.
> The main goal is to be able to show the user detailed info about the
> current step and progress as well as clean up properly in case the whole
> thing is cancelled.
>
> My existing python code needs to stay independent of QT so any
> application that supports python can use it.
> I am wondering now how to best connect the python script and the PySide
> code. Should I just run the script as an argument to the python
> interpreter like I would with any other program? E.g.:
>
> process = QtCore.QProcess(self)
> process.start(<path_to_python>, <path_to_python_script>)
>
> As simple as this seems, it feels odd to use python to call itself as an
> external program.
>
>
> I'm happy to go that way but am curious how others are doing this?!
>
> Cheers,
> frank
>
> _______________________________________________
> PySide mailing list
> PySide at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/pyside
>



-- 
Ryan
If anybody ever asks me why I prefer C++ to C, my answer will be simple:
"It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was
nul-terminated."
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/pyside/attachments/20140123/87b5ed6e/attachment.html>


More information about the PySide mailing list