Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f543e4a

Browse filesBrowse files
committed
remove old events system
1 parent 6eb5a1a commit f543e4a
Copy full SHA for f543e4a

File tree

3 files changed

+4
-167
lines changed
Filter options

3 files changed

+4
-167
lines changed

‎fastplotlib/graphics/_base.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_base.py
-163Lines changed: 0 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -519,129 +519,6 @@ def attach_feature(self, feature: VertexPositions | VertexColors | PointsSizesFe
519519
self._sizes._shared += 1
520520
self.world_object.geometry.sizes = self._sizes.buffer
521521

522-
523-
class Interaction(ABC):
524-
"""Mixin class that makes graphics interactive"""
525-
526-
@abstractmethod
527-
def set_feature(self, feature: str, new_data: Any, indices: Any):
528-
pass
529-
530-
@abstractmethod
531-
def reset_feature(self, feature: str):
532-
pass
533-
534-
def link(
535-
self,
536-
event_type: str,
537-
target: Any,
538-
feature: str,
539-
new_data: Any,
540-
callback: callable = None,
541-
bidirectional: bool = False,
542-
):
543-
"""
544-
Link this graphic to another graphic upon an ``event_type`` to change the ``feature``
545-
of a ``target`` graphic.
546-
547-
Parameters
548-
----------
549-
event_type: str
550-
can be a pygfx event ("key_down", "key_up","pointer_down", "pointer_move", "pointer_up",
551-
"pointer_enter", "pointer_leave", "click", "double_click", "wheel", "close", "resize")
552-
or appropriate feature event (ex. colors, data, etc.) associated with the graphic (can use
553-
``graphic_instance.feature_events`` to get a tuple of the valid feature events for the
554-
graphic)
555-
556-
target: Any
557-
graphic to be linked to
558-
559-
feature: str
560-
feature (ex. colors, data, etc.) of the target graphic that will change following
561-
the event
562-
563-
new_data: Any
564-
appropriate data that will be changed in the feature of the target graphic after
565-
the event occurs
566-
567-
callback: callable, optional
568-
user-specified callable that will handle event,
569-
the callable must take the following four arguments
570-
| ''source'' - this graphic instance
571-
| ''target'' - the graphic to be changed following the event
572-
| ''event'' - the ''pygfx event'' or ''feature event'' that occurs
573-
| ''new_data'' - the appropriate data of the ''target'' that will be changed
574-
575-
bidirectional: bool, default False
576-
if True, the target graphic is also linked back to this graphic instance using the
577-
same arguments
578-
579-
For example:
580-
.. code-block::python
581-
582-
Returns
583-
-------
584-
None
585-
586-
"""
587-
if event_type in PYGFX_EVENTS:
588-
self.world_object.add_event_handler(self._event_handler, event_type)
589-
590-
# make sure event is valid
591-
elif event_type in self.feature_events:
592-
if isinstance(self, GraphicCollection):
593-
feature_instance = getattr(self[:], event_type)
594-
else:
595-
feature_instance = getattr(self, event_type)
596-
597-
feature_instance.add_event_handler(self._event_handler)
598-
599-
else:
600-
raise ValueError(
601-
f"Invalid event, valid events are: {PYGFX_EVENTS + self.feature_events}"
602-
)
603-
604-
# make sure target feature is valid
605-
if feature is not None:
606-
if feature not in target.feature_events:
607-
raise ValueError(
608-
f"Invalid feature for target, valid features are: {target.feature_events}"
609-
)
610-
611-
if event_type not in self.registered_callbacks.keys():
612-
self.registered_callbacks[event_type] = list()
613-
614-
callback_data = CallbackData(
615-
target=target,
616-
feature=feature,
617-
new_data=new_data,
618-
callback_function=callback,
619-
)
620-
621-
for existing_callback_data in self.registered_callbacks[event_type]:
622-
if existing_callback_data == callback_data:
623-
warn(
624-
"linkage already exists for given event, target, and data, skipping"
625-
)
626-
return
627-
628-
self.registered_callbacks[event_type].append(callback_data)
629-
630-
if bidirectional:
631-
if event_type in PYGFX_EVENTS:
632-
warn("cannot use bidirectional link for pygfx events")
633-
return
634-
635-
target.link(
636-
event_type=event_type,
637-
target=self,
638-
feature=feature,
639-
new_data=new_data,
640-
callback=callback,
641-
bidirectional=False, # else infinite recursion, otherwise target will call
642-
# this instance .link(), and then it will happen again etc.
643-
)
644-
645522
def _event_handler(self, event):
646523
"""Handles the event after it occurs when two graphic have been linked together."""
647524
if event.type in self.registered_callbacks.keys():
@@ -684,46 +561,6 @@ def _event_handler(self, event):
684561
)
685562

686563

687-
@dataclass
688-
class CallbackData:
689-
"""Class for keeping track of the info necessary for interactivity after event occurs."""
690-
691-
target: Any
692-
feature: str
693-
new_data: Any
694-
callback_function: callable = None
695-
696-
def __eq__(self, other):
697-
if not isinstance(other, CallbackData):
698-
raise TypeError("Can only compare against other <CallbackData> types")
699-
700-
if other.target is not self.target:
701-
return False
702-
703-
if not other.feature == self.feature:
704-
return False
705-
706-
if not other.new_data == self.new_data:
707-
return False
708-
709-
if (self.callback_function is None) and (other.callback_function is None):
710-
return True
711-
712-
if other.callback_function is self.callback_function:
713-
return True
714-
715-
else:
716-
return False
717-
718-
719-
@dataclass
720-
class PreviouslyModifiedData:
721-
"""Class for keeping track of previously modified data at indices"""
722-
723-
data: Any
724-
indices: Any
725-
726-
727564
# Dict that holds all collection graphics in one python instance
728565
COLLECTION_GRAPHICS: dict[HexStr, Graphic] = dict()
729566

‎fastplotlib/graphics/line.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/line.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
import pygfx
77

8-
from ._base import PositionsGraphic, Interaction, PreviouslyModifiedData
8+
from ._base import PositionsGraphic
99
from .selectors import LinearRegionSelector, LinearSelector
1010
from ._features import Thickness
1111

1212

13-
class LineGraphic(PositionsGraphic, Interaction):
13+
class LineGraphic(PositionsGraphic):
1414
features = {"data", "colors", "cmap", "thickness"}
1515

1616
@property

‎fastplotlib/graphics/line_collection.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/line_collection.py
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import pygfx
88

99
from ..utils import parse_cmap_values
10-
from ._base import Interaction, PreviouslyModifiedData, GraphicCollection, CollectionIndexer, CollectionFeature
10+
from ._base import GraphicCollection, CollectionIndexer, CollectionFeature
1111
from ._features import GraphicFeature
1212
from .line import LineGraphic
1313
from .selectors import LinearRegionSelector, LinearSelector
@@ -83,7 +83,7 @@ def thickness(self, values: np.ndarray | list[float]):
8383
g.thickness = v
8484

8585

86-
class LineCollection(GraphicCollection, Interaction):
86+
class LineCollection(GraphicCollection):
8787
child_type = LineGraphic
8888
_indexer = LineSelection
8989

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.