Skip to main content

Extended scene library

Project description

PyQtExtendedScene

PyQtExtendedScene is a little library for creating workspaces.

Having described the method of drawing your components, with this library you get (draggable) workspace (scene) where the components you described can be selected, moved, deleted, etc. The scene itself can be increased, reduced, the work area may be moved.

In short, with this library you can create minimalistic (very minimalistic) similarities of such programs as AutoCAD, Labview, yEd, etc.

Repository: https://github.com/EPC-MSU/PyQtExtendedScene

Installation

Installation is very simple:

pip install PyQtExtendedScene

Working example

import os
import sys
from PyQt5.QtCore import QPointF, QRectF
from PyQt5.QtGui import QBrush, QColor, QPixmap
from PyQt5.QtWidgets import QApplication, QFileDialog, QGraphicsEllipseItem
from PyQtExtendedScene import AbstractComponent, ExtendedScene


# Let's describe our own component
class MyComponent(AbstractComponent):

    selected_size = 20
    normal_size = 10

    def __init__(self, x: float, y: float, descr: str = "") -> None:
        super().__init__(draggable=True, selectable=True, unique_selection=True)
        self._r = self.normal_size

        self.setPos(QPointF(x, y))

        # We must describe how to draw our own component. Our own component will be just a circle
        self._item = QGraphicsEllipseItem(-self._r, -self._r, self._r * 2, self._r * 2, self)
        # ... yellow circle
        self._item.setBrush(QBrush(QColor(0xFFFF00)))

        # Add description to our object - it will be used in "click" callback function
        self._descr = descr

    # We must override parent method "select" because our component changes shape when selected
    def select(self, selected: bool = True) -> None:
        # Radius of our circle changes when selected
        self._r = self.selected_size if selected else self.normal_size
        # redraw our object with new radius
        self._item.setRect(QRectF(-self._r, -self._r, self._r * 2, self._r * 2))

    @property
    # That is our own property
    def description(self) -> str:
        return self._descr


def left_click(component) -> None:
    if isinstance(component, MyComponent):
        print(f"Left click on '{component.description}'")


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

    # Open workspace background image
    path_to_image = "workspace.png"
    if not os.path.isfile(path_to_image):
        path_to_image = QFileDialog().getOpenFileName(caption="Open workspace image",
                                                      filter="Image Files (*.png *.jpg *.bmp *.tiff)")[0]

    image = QPixmap(path_to_image)
    image = image.scaled(800, 600)
    # Create workspace!
    widget = ExtendedScene(image)

    # Let's add some components to our workspace
    widget.add_component(MyComponent(10, 10, "My component 1"))
    widget.add_component(MyComponent(100, 200, "My component 2"))

    # Handle left click
    widget.on_component_left_click.connect(left_click)
    widget.show()

    sys.exit(app.exec_())

Workspace example:

Workspace example

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

PyQtExtendedScene-1.0.13.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

PyQtExtendedScene-1.0.13-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file PyQtExtendedScene-1.0.13.tar.gz.

File metadata

  • Download URL: PyQtExtendedScene-1.0.13.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

File hashes

Hashes for PyQtExtendedScene-1.0.13.tar.gz
Algorithm Hash digest
SHA256 2cecee7bbadd607e8192372bf00134598beea3b31576582f579eca14d84dbcd6
MD5 0967c4e8da6a9dcb3fec58ce7a089210
BLAKE2b-256 3de10cf52fab66389d2e16628e5fbe16068f42204f8848befcbf11f2d3674bb5

See more details on using hashes here.

File details

Details for the file PyQtExtendedScene-1.0.13-py3-none-any.whl.

File metadata

  • Download URL: PyQtExtendedScene-1.0.13-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.8.3 keyring/23.4.1 rfc3986/1.5.0 colorama/0.4.4 CPython/3.6.8

File hashes

Hashes for PyQtExtendedScene-1.0.13-py3-none-any.whl
Algorithm Hash digest
SHA256 b912a76a87a69b10b449022dbda293a9f77eac69becdf0cec9b41850a77c2ede
MD5 d2679e678ca90c528f0ce54f59d3402b
BLAKE2b-256 1d22bba63a648c2f3cb36b6982a022f57b3514eb4d332fa8e95db232bd45ea2b

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