2222"""
2323
2424import random
25- from displayio_effects import WidgetType
25+ from displayio_effects import WidgetType , WIDGET_TYPE_ATTR
2626
2727__version__ = "0.0.0-auto.0"
2828__repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git"
@@ -44,10 +44,11 @@ def fluctuation_amplitude(self):
4444
4545@fluctuation_amplitude .setter
4646def fluctuation_amplitude (self , amplitude ):
47+ value_name = getattr (self , WIDGET_TYPE_ATTR )
4748 if amplitude < 0 :
4849 raise ValueError ("Fluctuation effect setting must be larger than 0" )
4950 if amplitude :
50- self ._fluctuation_hold_value = getattr (self , self . _value_name )
51+ self ._fluctuation_hold_value = getattr (self , value_name )
5152 self ._fluctuation_amplitude = amplitude
5253
5354
@@ -67,6 +68,7 @@ def fluctuation_move_rate(self, rate):
6768def update_fluctuation (self ):
6869 """Updates the widget value and propagates the fluctuation effect refresh"""
6970
71+ value_name = getattr (self , WIDGET_TYPE_ATTR )
7072 if self ._fluctuation_amplitude == 0 :
7173 self ._fluctuation_destination = None
7274 return
@@ -78,13 +80,13 @@ def update_fluctuation(self):
7880 + self ._fluctuation_hold_value
7981 )
8082
81- value = getattr (self , self . _value_name )
83+ value = getattr (self , value_name )
8284 value = (
8385 value + self ._fluctuation_move_rate
8486 if self ._fluctuation_destination > value
8587 else value - self ._fluctuation_move_rate
8688 )
87- setattr (self , self . _value_name , value )
89+ setattr (self , value_name , value )
8890
8991 threshold_check = (
9092 value >= self ._fluctuation_destination
@@ -115,13 +117,12 @@ def hook_fluctuation_effect(widget_class, widget_type):
115117
116118 """
117119
118- value_name = FLUCTUATION_WIDGET_VALUES .get (widget_type )
119- if not value_name :
120+ if not FLUCTUATION_WIDGET_VALUES .get (widget_type ):
120121 raise ValueError (
121122 "The given widget does not have the ability to use this effect"
122123 )
123124
124- setattr (widget_class , "_value_name" , value_name )
125+ setattr (widget_class , WIDGET_TYPE_ATTR , widget_type )
125126
126127 setattr (widget_class , "_fluctuation_destination" , None )
127128 setattr (widget_class , "_fluctuation_hold_value" , 0 )
0 commit comments