Skip to main content

Console plugin for Python Qt applications

Adeqt gives you a Python shell inside your Qt applications using PyQt or PySide. You can use this for simple debugging or as a 'power user' feature.

How to use

Install the adeqt package: pip install adeqt.

If you don't want to add any dependencies, you can copy adeqt.py into your own project instead. You might also want to change the imports to use your chosen Python Qt package directly (it normally uses the QtPy compatibility layer).

Connect up a menu entry or a keyboard shortcut to open the Adeqt window like this:

from PyQt5.QtCore import Qt
from PyQt5.QtGui import QKeySequence
from PyQt5.QtWidgets import QAction, QMainWindow, QShortcut


class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)

        # ... Other application setup ...

        # Menu entry
        adeqt_action = QAction("Python console", self)
        adeqt_action.triggered.connect(self.show_adeqt)
        some_menu.addAction(adeqt_action)

        # Keyboard shortcut (here F12)
        adeqt_shortcut = QShortcut(QKeySequence(Qt.Key_F12), self)
        adeqt_shortcut.activated.connect(self.show_adeqt)

    adeqt_window = None

    def show_adeqt(self):
        # Change to 'from .adeqt ...' if you copy adeqt into your application
        from adeqt import AdeqtWindow
        if self.adeqt_window is None:
            self.adeqt_window = AdeqtWindow({'window': self}, parent=self)
        self.adeqt_window.show()

The dictionary you pass to AdeqtWindow defines variables that will be available in the console. This will normally have at least the main window/application object, and any other objects you want convenient access to.

When using the console window:

  • Ctrl-Enter executes the existing code
  • Tab shows available completions
  • Ctrl-W closes the console window

Design & limitations

  • Adeqt is deliberately simple, providing a basic console experience. It's meant to be easy to copy into your project and easy to modify as required.

  • It doesn't protect anything from malicious users. Users running a Python application can probably do anything anyway, but Adeqt makes it very easy. If you need to restrict what users can do, think about security at other levels.

  • User code runs in the main thread. This makes it easy to safely call Qt methods, but if you run something slow from the console, the GUI locks up until it finishes.

Alternatives

The Jupyter Qt Console can be embedded in an application. This is a much more featureful console - with rich output, syntax highlighting, better tab completions, etc. - but it's designed to run code in a separate 'kernel' process. Running the code in the same process as the console ('inprocess') is possible, but not well supported. It also needs quite a few dependencies.

Debuggers can pause your code during execution and give you a place to run commands and explore the stack. Some modern debuggers can also 'attach' to a process which wasn't started in a debugger. A good debugger is strictly more powerful than Adeqt, but that power also makes it trickier to use.

Metadata

Release files for adeqt 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adeqt 0.2
File Size Uploaded
adeqt-0.2.tar.gz 7.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adeqt 0.2
File Interpreter ABI Platform
adeqt-0.2-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 15.0 kB

Release files / adeqt-0.2.tar.gz

Download URL adeqt-0.2.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
cadfe02b31620fccd635695cbf79260875d1e6e0b79ad5434c6c36630618ec2f
BLAKE2b-256 checksum
How to use checksums
d787a924c7dda1c63e1418843c12825419dc7359a984ff2b4af462c4e9c8996a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release files / adeqt-0.2-py2.py3-none-any.whl

Download URL adeqt-0.2-py2.py3-none-any.whl
Size 7.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
99877f1e59df16fc77af10409c749447af04a464fad699258b900fab1913757c
BLAKE2b-256 checksum
How to use checksums
05eeac91edd910b6963edf42535f6a601c61be90a71dc89e896c2ea8715e9e14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.6

Release history Release notifications | RSS feed

This release

0.2 This release

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page