22
22
"""
23
23
24
24
import random
25
- from displayio_effects import WidgetType
25
+ from displayio_effects import WidgetType , WIDGET_TYPE_ATTR
26
26
27
27
__version__ = "0.0.0-auto.0"
28
28
__repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git"
@@ -44,10 +44,11 @@ def fluctuation_amplitude(self):
44
44
45
45
@fluctuation_amplitude .setter
46
46
def fluctuation_amplitude (self , amplitude ):
47
+ value_name = getattr (self , WIDGET_TYPE_ATTR )
47
48
if amplitude < 0 :
48
49
raise ValueError ("Fluctuation effect setting must be larger than 0" )
49
50
if amplitude :
50
- self ._fluctuation_hold_value = getattr (self , self . _value_name )
51
+ self ._fluctuation_hold_value = getattr (self , value_name )
51
52
self ._fluctuation_amplitude = amplitude
52
53
53
54
@@ -67,6 +68,7 @@ def fluctuation_move_rate(self, rate):
67
68
def update_fluctuation (self ):
68
69
"""Updates the widget value and propagates the fluctuation effect refresh"""
69
70
71
+ value_name = getattr (self , WIDGET_TYPE_ATTR )
70
72
if self ._fluctuation_amplitude == 0 :
71
73
self ._fluctuation_destination = None
72
74
return
@@ -78,13 +80,13 @@ def update_fluctuation(self):
78
80
+ self ._fluctuation_hold_value
79
81
)
80
82
81
- value = getattr (self , self . _value_name )
83
+ value = getattr (self , value_name )
82
84
value = (
83
85
value + self ._fluctuation_move_rate
84
86
if self ._fluctuation_destination > value
85
87
else value - self ._fluctuation_move_rate
86
88
)
87
- setattr (self , self . _value_name , value )
89
+ setattr (self , value_name , value )
88
90
89
91
threshold_check = (
90
92
value >= self ._fluctuation_destination
@@ -115,13 +117,12 @@ def hook_fluctuation_effect(widget_class, widget_type):
115
117
116
118
"""
117
119
118
- value_name = FLUCTUATION_WIDGET_VALUES .get (widget_type )
119
- if not value_name :
120
+ if not FLUCTUATION_WIDGET_VALUES .get (widget_type ):
120
121
raise ValueError (
121
122
"The given widget does not have the ability to use this effect"
122
123
)
123
124
124
- setattr (widget_class , "_value_name" , value_name )
125
+ setattr (widget_class , WIDGET_TYPE_ATTR , widget_type )
125
126
126
127
setattr (widget_class , "_fluctuation_destination" , None )
127
128
setattr (widget_class , "_fluctuation_hold_value" , 0 )
0 commit comments