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:

from PyQt5.QtWidgets import QGraphicsEllipseItem
from PyQt5.QtCore import QRectF, QPointF
from PyQt5.QtGui import QBrush, QColor
from PyQtExtendedScene import ExtendedScene, AbstractComponent


# Let's describe our own component
class MyComponent(AbstractComponent):
    selected_size = 20
    normal_size = 10

    def __init__(self, x: float, y: float, descr: str = ""):
        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):
        # 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):
        return self._descr


if __name__ == '__main__':
    import sys
    from os.path import isfile
    from PyQt5.QtWidgets import QFileDialog, QApplication
    from PyQt5.QtGui import QPixmap

    app = QApplication(sys.argv)

    # Open workspace background image
    path_to_image = "workspace.png"
    if not 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"))


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


    # 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.9.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

PyQtExtendedScene-1.0.9-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: PyQtExtendedScene-1.0.9.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for PyQtExtendedScene-1.0.9.tar.gz
Algorithm Hash digest
SHA256 5842e184e2c5362110e10a6763e85280ac3ca584c0da82b2d23ebf4bd6590b35
MD5 c58e6ecc07bf9bf03d267d07f184bb1c
BLAKE2b-256 ca2a57a0b402ebc3b9bdccd061e077bd16535af8237f909e888887ab0456562a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: PyQtExtendedScene-1.0.9-py3-none-any.whl
  • Upload date:
  • Size: 6.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.6.10

File hashes

Hashes for PyQtExtendedScene-1.0.9-py3-none-any.whl
Algorithm Hash digest
SHA256 d3d0dc1bb7ce39b37fc0015c24944cbd3d0ebcf775f3d950d475a25c7a473564
MD5 8f10014308ffe73502a53c87fe1caacc
BLAKE2b-256 af0df9182f9521f8b5c27a7bd7f75641c4121d21fb31e2d63680330ad8471c6f

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