On Tue, 25 Aug 2015 03:26:58 -0700 (PDT)
[email protected] 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

> From the command line, this script runs without problems (using
> 'python QtTest.pyw').
> But if I try to execute the script in the node (using Ctrl-B), Leo 
> disappears, the Qt window is opened and immediately closed. I want
> Leo stay visibly in the background and the Qt window in the
> foreground until it is closed explicitly.
> 
> What do I miss?
> 

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to