Skip to main content

An interactive Python shell plugin for PyQt & PySide applications

Project description

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.

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

adeqt-0.2.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

adeqt-0.2-py2.py3-none-any.whl (7.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file adeqt-0.2.tar.gz.

File metadata

  • Download URL: adeqt-0.2.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for adeqt-0.2.tar.gz
Algorithm Hash digest
SHA256 cadfe02b31620fccd635695cbf79260875d1e6e0b79ad5434c6c36630618ec2f
MD5 db4146ca471ed930a9ba5a85fdc380ba
BLAKE2b-256 d787a924c7dda1c63e1418843c12825419dc7359a984ff2b4af462c4e9c8996a

See more details on using hashes here.

File details

Details for the file adeqt-0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: adeqt-0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for adeqt-0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 99877f1e59df16fc77af10409c749447af04a464fad699258b900fab1913757c
MD5 260726b420b82d3f150c3f246b7551cc
BLAKE2b-256 05eeac91edd910b6963edf42535f6a601c61be90a71dc89e896c2ea8715e9e14

See more details on using hashes here.

Supported by

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