Package: pyqtconsole
pyqtconsole is a lightweight python console for Qt applications. It’s made to
be easy to embed in other Qt applications and comes with some examples that
show how this can be done. The interpreter can run in a separate thread, in
the UI main thread or in a gevent task.InstallingSimply type:pip install pyqtconsoleOr to install a development version from local checkout, type:pip install -e .Simple usageThe following snippet shows how to create a console that will execute user
input in a separate thread. Be aware that long running tasks will still block
the main thread due to the GIL. See theexamplesdirectory for more
examples.importsysfromthreadingimportThreadfromPyQt5.QtWidgetsimportQApplicationfrompyqtconsole.consoleimportPythonConsoleapp=QApplication([])console=PythonConsole()console.show()console.eval_in_thread()sys.exit(app.exec_())EmbeddingSeparate thread- Runs the interpreter in a separate thread, see the
examplethreaded.py. Running the interpreter in a separate thread obviously
limits the interaction with the Qt application. The parts of Qt that needs
to be called from the main thread will not work properly, but is excellent
way for having a ‘plain’ python console in your Qt app.main thread- Runs the interpreter in the main thread, see the exampleinuithread.py. Makes full interaction with Qt possible, lenghty operations
will of course freeze the UI (as any lenghty operation that is called from
the main thread). This is a great alternative for people who does not want
to use the gevent based approach but still wants full interactivity with Qt.gevent- Runs the interpreter in a gevent task, see the example_gevent.py. Allows for full interactivity with Qt without special
consideration (at least to some extent) for longer running processes. The
best method if you want to use pyQtgraph, Matplotlib, PyMca or similar.Customizing syntax highlightingThe coloring of the syntax highlighting can be customized by passing aformatsdictionary to thePythonConsoleconstructer. This dictionary
must be shaped as follows:importpyqtconsole.highlighterashlconsole=PythonConsole(formats={'keyword':hl.format('blue','bold'),'operator':hl.format('red'),'brace':hl.format('darkGray'),'defclass':hl.format('black','bold'),'string':hl.format('magenta'),'string2':hl.format('darkMagenta'),'comment':hl.format('darkGreen','italic'),'self':hl.format('black','italic'),'numbers':hl.format('brown'),'inprompt':hl.format('darkBlue','bold'),'outprompt':hl.format('darkRed','bold'),})All keys are optional and default to the value shown above if left unspecified.CreditsThis module depends on QtPy which provides a compatibility layer for
Qt4 and Qt5. The console is tested under both Qt4 and Qt5.Changelogv1.2.3Date: 19.09.2023fixed indentation and autocomplete conflict (#74)replacedQRegExpfor compatibility with QT6 (#76)v1.2.2Date: 18.10.2021fixed PyQt warning because of explicit integer typefixed jedi autocomplete because of method renamev1.2.1Date: 17.03.2020fix accepting input with AltGr modifier on win10 (#53)v1.2.0Date: 17.03.2020add PySide2 compatibilityadd Ctrl-U shortcut to clear the input bufferuse standard QtPy package to provide the compatibility layerhide the cursor during the execution of a python commandmimic shell behaviour when using up and down key to go to end of historyfix crash when closing the interpreter window of the threaded exampledisable excepthook on displaying exceptionwrite ‘n’ before syntax errors for consistencyThanks to @roberthdevries and @irgolic for their contributions!v1.1.5Date: 25.11.2019fix TypeError in highlighter when called without formatsv1.1.4Date: 21.11.2019fix AttributeError due to QueuedConnection on PyQt<5.11 (#23)fix exception on import when started within spyder (#26)fix gevent example to incorporate interoperability code for gevent/Qt (#28)fix not waiting for empty line when entering code blocks before applying input (#30)fix TypeError during compilation step on python 3.8allow user to override syntax highlighting color preferences (#29)
note that this is provisional APIautomate release process (#34)