@@ -519,129 +519,6 @@ def attach_feature(self, feature: VertexPositions | VertexColors | PointsSizesFe
519
519
self ._sizes ._shared += 1
520
520
self .world_object .geometry .sizes = self ._sizes .buffer
521
521
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
-
645
522
def _event_handler (self , event ):
646
523
"""Handles the event after it occurs when two graphic have been linked together."""
647
524
if event .type in self .registered_callbacks .keys ():
@@ -684,46 +561,6 @@ def _event_handler(self, event):
684
561
)
685
562
686
563
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
-
727
564
# Dict that holds all collection graphics in one python instance
728
565
COLLECTION_GRAPHICS : dict [HexStr , Graphic ] = dict ()
729
566
0 commit comments