File: scene.py

package info (click to toggle)
orange3 3.40.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,908 kB
  • sloc: python: 162,745; ansic: 622; makefile: 322; sh: 93; cpp: 77
file content (26 lines) | stat: -rw-r--r-- 880 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
"""Common QGraphicsScene components that can be composed when needed."""

from AnyQt.QtWidgets import QGraphicsScene

class UpdateItemsOnSelectGraphicsScene(QGraphicsScene):
    """Calls the selection_changed method on items.

    Whenever the scene selection changes, this view will call the
    ˙selection_changed˙ method on any item on the scene.

    Notes
    -----
    .. note:: I suspect this is completely unnecessary, but have not been able
        to find a reasonable way to keep the selection logic inside the actual
        `QGraphicsItem` objects

    """

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.selectionChanged.connect(self.__handle_selection)

    def __handle_selection(self):
        for item in self.items():
            if hasattr(item, 'selection_changed'):
                item.selection_changed()