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()
|