pyqtconsole
===========
|Version| |Python| |License| |Tests|
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.
.. code-block:: python
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:
.. code-block:: python
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.
.. _threaded.py: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/threaded.py
.. _inuithread.py: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/inuithread.py
.. _`_gevent.py`: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/_gevent.py
.. _QtPy: https://github.com/spyder-ide/qtpy
.. Badges:
.. |Version| image:: https://img.shields.io/pypi/v/pyqtconsole.svg
:target: https://pypi.org/project/pyqtconsole
:alt: Latest Version
.. |Python| image:: https://img.shields.io/pypi/pyversions/pyqtconsole.svg
:target: https://pypi.org/project/pyqtconsole#files
:alt: Python versions
.. |License| image:: https://img.shields.io/pypi/l/pyqtconsole.svg
:target: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/LICENSE
:alt: License: MIT
.. |Tests| image:: https://github.com/pyqtconsole/pyqtconsole/workflows/Tests/badge.svg
:target: https://github.com/pyqtconsole/pyqtconsole/actions?query=Tests
:alt: Test status
Changelog
~~~~~~~~~
v1.2.3
------
Date: 19.09.2023
- fixed indentation and autocomplete conflict (#74)
- replaced ``QRegExp`` for compatibility with QT6 (#76)
v1.2.2
------
Date: 18.10.2021
- fixed PyQt warning because of explicit integer type
- fixed jedi autocomplete because of method rename
v1.2.1
------
Date: 17.03.2020
- fix accepting input with AltGr modifier on win10 (#53)
v1.2.0
------
Date: 17.03.2020
- add PySide2 compatibility
- add Ctrl-U shortcut to clear the input buffer
- use standard QtPy package to provide the compatibility layer
- hide the cursor during the execution of a python command
- mimic shell behaviour when using up and down key to go to end of history
- fix crash when closing the interpreter window of the threaded example
- disable excepthook on displaying exception
- write '\n' before syntax errors for consistency
Thanks to @roberthdevries and @irgolic for their contributions!
v1.1.5
------
Date: 25.11.2019
- fix TypeError in highlighter when called without formats
v1.1.4
------
Date: 21.11.2019
- fix 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.8
- allow user to override syntax highlighting color preferences (#29)
note that this is provisional API
- automate release process (#34)
Raw data
{
"_id": null,
"home_page": "https://github.com/marcus-oscarsson/pyqtconsole",
"name": "pyqtconsole",
"maintainer": "",
"docs_url": null,
"requires_python": ">=2.7",
"maintainer_email": "",
"keywords": "interactive interpreter console shell autocompletion jedi qt",
"author": "Marcus Oskarsson",
"author_email": "marcus.oscarsson@esrf.fr",
"download_url": "https://files.pythonhosted.org/packages/5c/1a/89cd4754be12e628e00d2517b97b4760d076d93c15811c8f2f46f4de5c1f/pyqtconsole-1.2.3.tar.gz",
"platform": null,
"description": "pyqtconsole\n===========\n\n|Version| |Python| |License| |Tests|\n\npyqtconsole is a lightweight python console for Qt applications. It's made to\nbe easy to embed in other Qt applications and comes with some examples that\nshow how this can be done. The interpreter can run in a separate thread, in\nthe UI main thread or in a gevent task.\n\nInstalling\n~~~~~~~~~~\n\nSimply type::\n\n pip install pyqtconsole\n\nOr to install a development version from local checkout, type::\n\n pip install -e .\n\nSimple usage\n~~~~~~~~~~~~\n\nThe following snippet shows how to create a console that will execute user\ninput in a separate thread. Be aware that long running tasks will still block\nthe main thread due to the GIL. See the ``examples`` directory for more\nexamples.\n\n.. code-block:: python\n\n import sys\n from threading import Thread\n from PyQt5.QtWidgets import QApplication\n\n from pyqtconsole.console import PythonConsole\n\n app = QApplication([])\n console = PythonConsole()\n console.show()\n console.eval_in_thread()\n\n sys.exit(app.exec_())\n\nEmbedding\n~~~~~~~~~\n\n* *Separate thread* - Runs the interpreter in a separate thread, see the\n example threaded.py_. Running the interpreter in a separate thread obviously\n limits the interaction with the Qt application. The parts of Qt that needs\n to be called from the main thread will not work properly, but is excellent\n way for having a 'plain' python console in your Qt app.\n\n* *main thread* - Runs the interpreter in the main thread, see the example\n inuithread.py_. Makes full interaction with Qt possible, lenghty operations\n will of course freeze the UI (as any lenghty operation that is called from\n the main thread). This is a great alternative for people who does not want\n to use the gevent based approach but still wants full interactivity with Qt.\n\n* *gevent* - Runs the interpreter in a gevent task, see the example\n `_gevent.py`_. Allows for full interactivity with Qt without special\n consideration (at least to some extent) for longer running processes. The\n best method if you want to use pyQtgraph, Matplotlib, PyMca or similar.\n\nCustomizing syntax highlighting\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\nThe coloring of the syntax highlighting can be customized by passing a\n``formats`` dictionary to the ``PythonConsole`` constructer. This dictionary\nmust be shaped as follows:\n\n.. code-block:: python\n\n import pyqtconsole.highlighter as hl\n console = PythonConsole(formats={\n 'keyword': hl.format('blue', 'bold'),\n 'operator': hl.format('red'),\n 'brace': hl.format('darkGray'),\n 'defclass': hl.format('black', 'bold'),\n 'string': hl.format('magenta'),\n 'string2': hl.format('darkMagenta'),\n 'comment': hl.format('darkGreen', 'italic'),\n 'self': hl.format('black', 'italic'),\n 'numbers': hl.format('brown'),\n 'inprompt': hl.format('darkBlue', 'bold'),\n 'outprompt': hl.format('darkRed', 'bold'),\n })\n\nAll keys are optional and default to the value shown above if left unspecified.\n\nCredits\n~~~~~~~\n\nThis module depends on QtPy which provides a compatibility layer for\nQt4 and Qt5. The console is tested under both Qt4 and Qt5.\n\n\n.. _threaded.py: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/threaded.py\n.. _inuithread.py: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/inuithread.py\n.. _`_gevent.py`: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/examples/_gevent.py\n.. _QtPy: https://github.com/spyder-ide/qtpy\n\n\n.. Badges:\n\n.. |Version| image:: https://img.shields.io/pypi/v/pyqtconsole.svg\n :target: https://pypi.org/project/pyqtconsole\n :alt: Latest Version\n\n.. |Python| image:: https://img.shields.io/pypi/pyversions/pyqtconsole.svg\n :target: https://pypi.org/project/pyqtconsole#files\n :alt: Python versions\n\n.. |License| image:: https://img.shields.io/pypi/l/pyqtconsole.svg\n :target: https://github.com/marcus-oscarsson/pyqtconsole/blob/master/LICENSE\n :alt: License: MIT\n\n.. |Tests| image:: https://github.com/pyqtconsole/pyqtconsole/workflows/Tests/badge.svg\n :target: https://github.com/pyqtconsole/pyqtconsole/actions?query=Tests\n :alt: Test status\n\nChangelog\n~~~~~~~~~\n\nv1.2.3\n------\nDate: 19.09.2023\n\n- fixed indentation and autocomplete conflict (#74)\n- replaced ``QRegExp`` for compatibility with QT6 (#76)\n\nv1.2.2\n------\nDate: 18.10.2021\n\n- fixed PyQt warning because of explicit integer type\n- fixed jedi autocomplete because of method rename\n\nv1.2.1\n------\nDate: 17.03.2020\n\n- fix accepting input with AltGr modifier on win10 (#53)\n\n\nv1.2.0\n------\nDate: 17.03.2020\n\n- add PySide2 compatibility\n- add Ctrl-U shortcut to clear the input buffer\n- use standard QtPy package to provide the compatibility layer\n- hide the cursor during the execution of a python command\n- mimic shell behaviour when using up and down key to go to end of history\n- fix crash when closing the interpreter window of the threaded example\n- disable excepthook on displaying exception\n- write '\\n' before syntax errors for consistency\n\nThanks to @roberthdevries and @irgolic for their contributions!\n\n\nv1.1.5\n------\nDate: 25.11.2019\n\n- fix TypeError in highlighter when called without formats\n\n\nv1.1.4\n------\nDate: 21.11.2019\n\n- fix AttributeError due to QueuedConnection on PyQt<5.11 (#23)\n- fix exception on import when started within spyder (#26)\n- fix gevent example to incorporate interoperability code for gevent/Qt (#28)\n- fix not waiting for empty line when entering code blocks before applying input (#30)\n- fix TypeError during compilation step on python 3.8\n- allow user to override syntax highlighting color preferences (#29)\n note that this is provisional API\n- automate release process (#34)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Light weight python interpreter, easy to embed into Qt applications",
"version": "1.2.3",
"project_urls": {
"Homepage": "https://github.com/marcus-oscarsson/pyqtconsole"
},
"split_keywords": [
"interactive",
"interpreter",
"console",
"shell",
"autocompletion",
"jedi",
"qt"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "18c79fcb0a54b42d573cded7bfe9705ea7282352f38bf8227e96fa59db24ca1f",
"md5": "96bf8431678603615b8dd344b091fbcf",
"sha256": "f491d5a5cd9b1e635eed23911236123db1b787d1d872c644c3ee58613462c72b"
},
"downloads": -1,
"filename": "pyqtconsole-1.2.3-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "96bf8431678603615b8dd344b091fbcf",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=2.7",
"size": 21466,
"upload_time": "2023-09-19T12:44:29",
"upload_time_iso_8601": "2023-09-19T12:44:29.111451Z",
"url": "https://files.pythonhosted.org/packages/18/c7/9fcb0a54b42d573cded7bfe9705ea7282352f38bf8227e96fa59db24ca1f/pyqtconsole-1.2.3-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5c1a89cd4754be12e628e00d2517b97b4760d076d93c15811c8f2f46f4de5c1f",
"md5": "ed6b67c3ddf7dded3993929dd134818c",
"sha256": "cdd2dfce0ddb69a9075debd4aada703fed39cf1ab0820ecd0ad69521826448c1"
},
"downloads": -1,
"filename": "pyqtconsole-1.2.3.tar.gz",
"has_sig": false,
"md5_digest": "ed6b67c3ddf7dded3993929dd134818c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=2.7",
"size": 23663,
"upload_time": "2023-09-19T12:44:30",
"upload_time_iso_8601": "2023-09-19T12:44:30.478127Z",
"url": "https://files.pythonhosted.org/packages/5c/1a/89cd4754be12e628e00d2517b97b4760d076d93c15811c8f2f46f4de5c1f/pyqtconsole-1.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-19 12:44:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "marcus-oscarsson",
"github_project": "pyqtconsole",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pyqtconsole"
}