Skip to main content

qtility

Overview

PySide (a python wrapper around the Qt framework) is a brilliant libary which allows for the development of rich user interfaces.

However, there are a lot of common pieces of functionality that is needed reqularly which takes a fair amount of code to achieve. qtility exposes a series of functions which minimises code replication between qt projects.

Examples of these are being able to blinding resolve widgets from values and values from widgets (a mechanism which is great for building dynamic ui's to represent data). Other examples are fast paths to user interaction, emptying layouts and loading in ui files.

Installation

You can either clone or download this github repo, or alternatively you can install this via pip:

pip install qtility

Development Status

This is currently in development but is actively used. It will reach 1.x status within the next couple of months after further testing.

Getting Started Quick

Here is an example of a small application which makes use of the qtility library to remove some complexity from our code.

import qtility
from PySide6 import QtWidgets


# -- Memorable Window is a QMainWindow which stores its geometry data
# -- whenever its moved or resized and will re-open at the same location
# -- on screen
class Window(qtility.windows.MemorableWindow):

    def __init__(self, parent=None, ):
        super(Window, self).__init__(parent=parent, storage_identifier="foobar")
        self._widget = Widget(self)
        self.setCentralWidget(self._widget)


class Widget(QtWidgets.QWidget):

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

        # -- When adding a layout, quite often we want it with no
        # -- margins. The slimify function does that for us
        self.setLayout(
            qtility.layouts.slimify(
                QtWidgets.QVBoxLayout(),
            ),
        )

        self.some_arbitrary_values = {
            "An Int Value": int(1),
            "A Float Value": 12.0,
            "A String Value": "Hello",
            "A list of strings": ["A", "B", "C"],
            "A Checkbox": True,
        }
        self.dynamic_widgets = []

        for label, value in self.some_arbitrary_values.items():

            # -- Dynamically resolve the right widget based on the value
            widget = qtility.derive.qwidget(value)

            # -- Add a callback to trigger whenever that widget changes
            # -- without knowing what the widget is
            qtility.derive.connect(widget, self._react_to_change)

            self.layout().addWidget(widget)

        # -- Here we show how we can load a ui file as a child widget without
        # -- any overhead
        self.ui = qtility.designer.load(r"c:/path/to/ui_file.ui")
        self.layout().addWidget(self.ui)

    def _react_to_change(self, *args, **kwargs):
        print("Reacting to a widget change!")


if __name__ == "__main__":
    # -- Get the QApplication instance. This will create one for us
    # -- if there is not one available, but will return the running
    # -- instance if there is one. This is useful when working within
    # -- embedded environments.
    app = qtility.app.get()

    # -- Instance the window, but set the parent to the main window
    # -- of the running application. This is particularly useful if
    # -- running within embedded environments
    window = Window(parent=qtility.windows.application())
    window.show()

    app.exec_()

In this example we're using qtility which is a dynamic property which will automatically resolve based on whether PySide6 or PySide2 is available.

This ensures that qtility supports being used in qapplications which are designed to be used between different environments. However, if you explicitely want to use qtility for PySide2 or specifically for PySide6 then you can use the following code:

import qtility.six as qtility6

app = qtility6.app.get()
import qtility.two as qtuils2

app = qtuils2.app.get()

But generally it is better to allow qtility to resolve this for you using the example below as your code is then more likely to work between Qt versions.

import qtility

qtility.app.get()

Metadata

Release files for qtility 1.0.9

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

Source distribution (sdist)

Source distribution for qtility 1.0.9
File Size Uploaded Provenance Actions
qtility-1.0.9.tar.gz 25.4 kB Without provenance Details for qtility-1.0.9.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for qtility 1.0.9
File Interpreter ABI Platform Actions
qtility-1.0.9-py3-none-any.whl Python 3 none any Details for qtility-1.0.9-py3-none-any.whl

Total release size: 56.9 kB

Release files / qtility-1.0.9.tar.gz

Download URL qtility-1.0.9.tar.gz
Size 25.4 kB
Tags Source
SHA-256 checksum
How to use checksums
388b83d788581293175a36efa0785be8e97a92e81e0a2c49fdeec30c9784adfa
BLAKE2b-256 checksum
How to use checksums
f0a19b4967192e70801c3dcc733ab7e02486456b418fffefd06f80d85978d685
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / qtility-1.0.9-py3-none-any.whl

Download URL qtility-1.0.9-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2f40d2469c6664fb0af20059670d47793d351a057337ac938a421e2d876a14a8
BLAKE2b-256 checksum
How to use checksums
3067ded7c54b12b6ce94f9d39df851183ca6d58db74521afbf9695a40855e054
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Security for qtility 1.0.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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