On Tue, 25 Aug 2015 03:26:58 -0700 (PDT)
reinhard...@googlemail.com wrote:
> May be this is a stupid question:
> I'm trying to import a large Qt application into Leo. For testing, I
> created a script in a single node with the headline '@clean
> QtTest.pyw)' and the following body:
>
> @language python
> @tabwidth -4
>
> import sys
>
> from PyQt5.QtCore import QObject
> from PyQt5.QtWidgets import QApplication, QWidget
>
> class Application(QWidget):
>
> def __init__(self):
>
> QObject.__init__(self)
> self.setGeometry(100, 100, 400, 300)
> self.setWindowTitle('QtTest')
>
> if __name__ == '__main__':
> app = QApplication([])
> form = Application()
> form.show()
> sys.exit(app.exec_())
Leo executes Python code in the interpreter that runs Leo. Seeing that
interpreter has a QApplication, you can't have another. Also, if it's
executing the `if __name__ == '__main__':` block, and it seems like it
is, sys.exit() is going to bring everything to an end.
So, to execute from Leo, just do the form = Application();
form.show() part, avoid the `app =` and sys.exit() parts.
Or make a separate script button like:
import os
os.system("python /path/to/QtTest.pyw")
(or use subprocess.Popen, but if you just want the app to run to see
the impact of changes, os.system is probably sufficient)
Cheers -Terry