Skip to main content

Light weight python interpreter, easy to embed into Qt applications

Project description

Latest Version Python versions License: MIT Test status

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.

Installing

Simply type:

pip install pyqtconsole

Or to install a development version from local checkout, type:

pip install -e .

Simple usage

The 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 the examples directory for more examples.

import sys
from threading import Thread
from PyQt5.QtWidgets import QApplication

from pyqtconsole.console import PythonConsole

app = QApplication([])
console = PythonConsole()
console.show()
console.eval_in_thread()

sys.exit(app.exec_())

Embedding

  • Separate thread - Runs the interpreter in a separate thread, see the example threaded.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 example inuithread.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 highlighting

The coloring of the syntax highlighting can be customized by passing a formats dictionary to the PythonConsole constructer. This dictionary must be shaped as follows:

import pyqtconsole.highlighter as hl
console = 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.

Credits

This module depends on QtPy which provides a compatibility layer for Qt4 and Qt5. The console is tested under both Qt4 and Qt5.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyqtconsole-1.2.2.tar.gz (21.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyqtconsole-1.2.2-py2.py3-none-any.whl (20.8 kB view details)

Uploaded Python 2Python 3

File details

Details for the file pyqtconsole-1.2.2.tar.gz.

File metadata

  • Download URL: pyqtconsole-1.2.2.tar.gz
  • Upload date:
  • Size: 21.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyqtconsole-1.2.2.tar.gz
Algorithm Hash digest
SHA256 074870f8e678b86ec383b506d1bae7859ff0d70d6280183e52de2ae4898f8b1b
MD5 a19e5353cbfeab7fcb94be3a82560730
BLAKE2b-256 e9828a3578e9efe686c9896a7cf7774f77e742d18f8e1cb0b34c9c6ff8784aea

See more details on using hashes here.

File details

Details for the file pyqtconsole-1.2.2-py2.py3-none-any.whl.

File metadata

  • Download URL: pyqtconsole-1.2.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for pyqtconsole-1.2.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6288772ff445a29b1d1bb853743118e38669807e68fd19d8b7aae899713be7b6
MD5 4ada89135fff770acf89317595de0e41
BLAKE2b-256 81e877a203d04effb5c4ddaf61e08e4b92c2d70cc922b199e4edf9c0cbeb7572

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page