Rather than reloading Leo each time I want to experiment with Qt, I would
like to just run a script within Leo:
*@file c:/test/qt_prototype.py*
import sys
from PyQt5 import QtWidgets # Qt, QtCore, QtGui
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
sys.exit(app.exec_())
*@button run-prototype @key=ctrl-1*
# Run the prototype in a separate process (without waiting) so Leo doesn't
hang.
import subprocess
subprocess.Popen(r'python c:\test\qt_prototype.py', shell=True)
This works, as far as it goes, but see the summary.
We can also use g.app.gui.qtApp to create a stand-alone prototype. Just
put this in a node and hit Ctrl-B:
import sys
from PyQt5 import QtWidgets # Qt, QtCore, QtGui
app = g.app.gui.qtApp # Use the running Leo Qt app.
g.app.permanentScriptDict ['prototype']=w
# Keep a reference, so the window remains visible
w = QtWidgets.QWidget()
w.resize(250, 150)
w.move(300, 300)
w.setWindowTitle('Simple')
w.show()
*Summary*
It's easy to create quick prototypes of gui code that don't hang Leo.
Alas, they aren't going to be very useful unless the prototypes duplicate
much of Leo's gui code. What we really want is something akin to
Smalltalk's hot swapping of code. That can't be done in Python.
Edward
--
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 https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.