Skip to main content

Qt utilities built on PySide6

Project description

guitools

guitools is a set of utilities for PySide6-based Qt applications, including an extended MainWindow, a message/notification system, styling helpers, and a project template generator.

Installation

pip install guitools

Examples

Most features are exposed directly from the package. Example:

import sys

from PySide6.QtWidgets import (
    QApplication,
    QWidget,
    QVBoxLayout,
    QHBoxLayout,
    QLabel,
    QPushButton,
    QTabWidget,
)
from PySide6.QtCore import Qt

from guitools import MainWindow, Styles
from guitools.customWidgets.dockWidget import TabWidgetDock


class DemoWindow(MainWindow):
    def __init__(self) -> None:
        super().__init__()
        self.setWindowTitle("guitools demo")
        self.setWindowIcon(Styles.Resources.miniLogo.original())

        self._tab_counter = 0
        self._docks: list[TabWidgetDock] = []

        # Root content container
        content = QWidget()
        content_layout = QVBoxLayout(content)
        content_layout.setContentsMargins(16, 16, 16, 16)
        content_layout.setSpacing(12)

        self.tabWidget = QTabWidget()
        content_layout.addWidget(self.tabWidget, 1)

        # Fixed example with exactly 2 tabs.
        self.create_tab()
        self.create_tab(select_new=True)

        # Theme button (bottom-right)
        footer = QHBoxLayout()
        footer.setContentsMargins(0, 0, 0, 0)
        footer.addStretch(1)

        self.btn_theme = QPushButton()
        self.btn_theme.setMaximumSize(25, 25)
        self.btn_theme.setCursor(Qt.CursorShape.PointingHandCursor)
        Styles.setIconToggleTheme(self.btn_theme)
        self.btn_theme.clicked.connect(self.toggle_theme)

        footer.addWidget(self.btn_theme)
        content_layout.addLayout(footer)

        self.setCentralWidget(content)
        self.setStyleSheet(Styles.standard())

    def toggle_theme(self) -> None:
        Styles.load(Styles.oppositeTheme())
        self.setStyleSheet(Styles.standard())
        Styles.setIconToggleTheme(self.btn_theme)

    def _make_tab_content(self, tab_no: int) -> QWidget:
        widget = QWidget()
        layout = QVBoxLayout(widget)
        layout.setContentsMargins(12, 12, 12, 12)
        layout.setSpacing(0)

        title = QLabel("GUITools")
        title.setAlignment(Qt.AlignmentFlag.AlignCenter)
        title.setStyleSheet('font: 600 18pt "Segoe UI";')
        layout.addWidget(title, 1)

        layout.addStretch(1)
        return widget

    def create_tab(self, *, select_new: bool = False) -> None:
        self._tab_counter += 1
        tab_no = self._tab_counter

        icon_data = Styles.Resources.Data(
            callableIcon=Styles.Resources.miniLogo.original,
            hoverCallableIcon=Styles.Resources.miniLogo.original,
        )

        dock = TabWidgetDock(
            tabWidget=self.tabWidget,
            widgetCallable=lambda no=tab_no: self._make_tab_content(no),
            tabTitle=f"Tab {tab_no}",
            docTitle=f"Tab {tab_no}",
            iconData=icon_data,
            insertPosition=self.tabWidget.count(),
            actionEnabled=False,
            showLoading=False,
        )

        self._docks.append(dock)

        if select_new:
            self.tabWidget.setCurrentWidget(dock.tab)


if __name__ == "__main__":
    app = QApplication(sys.argv)

    Styles.init("dark")  # or "light"

    window = DemoWindow()
    window.resize(900, 600)
    window.show()
    sys.exit(app.exec())

Generate a project template (CLI)

The package registers this command:

guitools-create <destination> [--overwrite]

Examples:

guitools-create my-project
guitools-create .
guitools-create my-project --overwrite
guitools-create C:\path\to\my-project

After creation, the template prints the standard next steps shown by the CLI: install dependencies and run python main.py inside the generated directory.

License

MIT


Author

Samuel Semedo

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

guitools-2.0.2-py3-none-any.whl (1.5 MB view details)

Uploaded Python 3

File details

Details for the file guitools-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: guitools-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 1.5 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.1

File hashes

Hashes for guitools-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1c8d7432d23cead76b57301cb27fc6dbbcfd103fcf939200c47e30f3cbf96b9b
MD5 b95c78f5a491459d5c6227d448d58f50
BLAKE2b-256 647a97a2c738cbd5b5d4af979f74106ea46fe487f9126f4716ce39d68b08f524

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