|
22 | 22 | """
|
23 | 23 |
|
24 | 24 | import random
|
| 25 | +from displayio_effects import WidgetType |
25 | 26 |
|
26 | 27 | __version__ = "0.0.0-auto.0"
|
27 | 28 | __repo__ = "https://github.com/tekktrik/CircuitPython_Org_DisplayIO_Effects.git"
|
28 | 29 |
|
29 | 30 |
|
| 31 | +FLUCTUATION_WIDGET_VALUES = { |
| 32 | + WidgetType.DIAL: "value", |
| 33 | + WidgetType.GAUGE: "level", |
| 34 | +} |
| 35 | + |
| 36 | + |
30 | 37 | @property
|
31 | 38 | def fluctuation_amplitude(self):
|
32 | 39 | """The furtherest the fluctuation effect can randomly set the widget value relative
|
@@ -88,26 +95,31 @@ def update_fluctuation(self):
|
88 | 95 | self._fluctuation_destination = self._fluctuation_hold_value
|
89 | 96 |
|
90 | 97 |
|
91 |
| -def hook_fluctuation_effect(widget_class, value_name): |
| 98 | +def hook_fluctuation_effect(widget_class, widget_type): |
92 | 99 | """Adds the fluctuation effect for the given class
|
93 | 100 |
|
94 |
| - :param widget_classes: The widgets that should have this effect hooked |
| 101 | + :param widget_class: The widget that should have this effect hooked |
95 | 102 | into them.
|
96 |
| - :param str value_name: The name of the attribute that sets the "value" |
97 |
| - for this widget |
| 103 | + :param int widget_type: The enum value of this widget type, must be a |
| 104 | + valid ~WidgetType |
98 | 105 |
|
99 | 106 | For example, to hook this into the ``Dial`` widget, you would use the
|
100 | 107 | following code:
|
101 | 108 |
|
102 | 109 | .. code-block:: python
|
103 | 110 |
|
104 | 111 | from displayio_dial import Dial
|
105 |
| - from displayio_effects import fluctuation_effect |
| 112 | + from |
| 113 | + from displayio_effects import WidgetType, fluctuation_effect |
106 | 114 |
|
107 |
| - fluctuation_effect.hook_fluctuation_effect(Dial, "value") |
| 115 | + fluctuation_effect.hook_fluctuation_effect(Dial, WidgetType.DIAL) |
108 | 116 |
|
109 | 117 | """
|
110 | 118 |
|
| 119 | + value_name = FLUCTUATION_WIDGET_VALUES.get(widget_type) |
| 120 | + if not value_name: |
| 121 | + raise ValueError("The given widget does not have the ability to use this effect") |
| 122 | + |
111 | 123 | setattr(widget_class, "_value_name", value_name)
|
112 | 124 |
|
113 | 125 | setattr(widget_class, "_fluctuation_destination", None)
|
|
0 commit comments