syd 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -14,14 +14,14 @@ from ..parameters import (
14
14
  FloatRangeParameter,
15
15
  UnboundedIntegerParameter,
16
16
  UnboundedFloatParameter,
17
- ButtonParameter,
17
+ ButtonAction,
18
18
  )
19
19
 
20
20
  T = TypeVar("T", bound=Parameter[Any])
21
21
  W = TypeVar("W", bound=widgets.Widget)
22
22
 
23
23
 
24
- class BaseParameterWidget(Generic[T, W], ABC):
24
+ class BaseWidget(Generic[T, W], ABC):
25
25
  """
26
26
  Abstract base class for all parameter widgets.
27
27
 
@@ -31,15 +31,16 @@ class BaseParameterWidget(Generic[T, W], ABC):
31
31
 
32
32
  _widget: W
33
33
  _callbacks: List[Dict[str, Union[Callable, Union[str, List[str]]]]]
34
+ _is_action: bool = False
34
35
 
35
- def __init__(self, parameter: T, continuous_update: bool = False):
36
- self._widget = self._create_widget(parameter, continuous_update)
36
+ def __init__(self, parameter: T, continuous: bool = False):
37
+ self._widget = self._create_widget(parameter, continuous)
37
38
  self._updating = False # Flag to prevent circular updates
38
39
  # List of callbacks to remember for quick disabling/enabling
39
40
  self._callbacks = []
40
41
 
41
42
  @abstractmethod
42
- def _create_widget(self, parameter: T, continuous_update: bool) -> W:
43
+ def _create_widget(self, parameter: T, continuous: bool) -> W:
43
44
  """Create and return the appropriate ipywidget."""
44
45
  pass
45
46
 
@@ -100,36 +101,34 @@ class BaseParameterWidget(Generic[T, W], ABC):
100
101
  self._widget.unobserve(**callback)
101
102
 
102
103
 
103
- class TextParameterWidget(BaseParameterWidget[TextParameter, widgets.Text]):
104
+ class TextWidget(BaseWidget[TextParameter, widgets.Text]):
104
105
  """Widget for text parameters."""
105
106
 
106
107
  def _create_widget(
107
- self, parameter: TextParameter, continuous_update: bool
108
+ self, parameter: TextParameter, continuous: bool
108
109
  ) -> widgets.Text:
109
110
  return widgets.Text(
110
111
  value=parameter.value,
111
112
  description=parameter.name,
112
- continuous_update=continuous_update,
113
+ continuous=continuous,
113
114
  layout=widgets.Layout(width="95%"),
114
115
  )
115
116
 
116
117
 
117
- class BooleanParameterWidget(BaseParameterWidget[BooleanParameter, widgets.Checkbox]):
118
+ class BooleanWidget(BaseWidget[BooleanParameter, widgets.Checkbox]):
118
119
  """Widget for boolean parameters."""
119
120
 
120
121
  def _create_widget(
121
- self, parameter: BooleanParameter, continuous_update: bool
122
+ self, parameter: BooleanParameter, continuous: bool
122
123
  ) -> widgets.Checkbox:
123
124
  return widgets.Checkbox(value=parameter.value, description=parameter.name)
124
125
 
125
126
 
126
- class SelectionParameterWidget(
127
- BaseParameterWidget[SelectionParameter, widgets.Dropdown]
128
- ):
127
+ class SelectionWidget(BaseWidget[SelectionParameter, widgets.Dropdown]):
129
128
  """Widget for single selection parameters."""
130
129
 
131
130
  def _create_widget(
132
- self, parameter: SelectionParameter, continuous_update: bool
131
+ self, parameter: SelectionParameter, continuous: bool
133
132
  ) -> widgets.Dropdown:
134
133
  return widgets.Dropdown(
135
134
  value=parameter.value,
@@ -153,13 +152,13 @@ class SelectionParameterWidget(
153
152
  self._widget.value = new_value
154
153
 
155
154
 
156
- class MultipleSelectionParameterWidget(
157
- BaseParameterWidget[MultipleSelectionParameter, widgets.SelectMultiple]
155
+ class MultipleSelectionWidget(
156
+ BaseWidget[MultipleSelectionParameter, widgets.SelectMultiple]
158
157
  ):
159
158
  """Widget for multiple selection parameters."""
160
159
 
161
160
  def _create_widget(
162
- self, parameter: MultipleSelectionParameter, continuous_update: bool
161
+ self, parameter: MultipleSelectionParameter, continuous: bool
163
162
  ) -> widgets.SelectMultiple:
164
163
  return widgets.SelectMultiple(
165
164
  value=parameter.value,
@@ -186,18 +185,18 @@ class MultipleSelectionParameterWidget(
186
185
  self._widget.value = new_values
187
186
 
188
187
 
189
- class IntegerParameterWidget(BaseParameterWidget[IntegerParameter, widgets.IntSlider]):
188
+ class IntegerWidget(BaseWidget[IntegerParameter, widgets.IntSlider]):
190
189
  """Widget for integer parameters."""
191
190
 
192
191
  def _create_widget(
193
- self, parameter: IntegerParameter, continuous_update: bool
192
+ self, parameter: IntegerParameter, continuous: bool
194
193
  ) -> widgets.IntSlider:
195
194
  return widgets.IntSlider(
196
195
  value=parameter.value,
197
196
  min=parameter.min_value,
198
197
  max=parameter.max_value,
199
198
  description=parameter.name,
200
- continuous_update=continuous_update,
199
+ continuous=continuous,
201
200
  layout=widgets.Layout(width="95%"),
202
201
  style={"description_width": "initial"},
203
202
  )
@@ -218,11 +217,11 @@ class IntegerParameterWidget(BaseParameterWidget[IntegerParameter, widgets.IntSl
218
217
  self.value = max(parameter.min_value, min(parameter.max_value, current_value))
219
218
 
220
219
 
221
- class FloatParameterWidget(BaseParameterWidget[FloatParameter, widgets.FloatSlider]):
220
+ class FloatWidget(BaseWidget[FloatParameter, widgets.FloatSlider]):
222
221
  """Widget for float parameters."""
223
222
 
224
223
  def _create_widget(
225
- self, parameter: FloatParameter, continuous_update: bool
224
+ self, parameter: FloatParameter, continuous: bool
226
225
  ) -> widgets.FloatSlider:
227
226
  return widgets.FloatSlider(
228
227
  value=parameter.value,
@@ -230,7 +229,7 @@ class FloatParameterWidget(BaseParameterWidget[FloatParameter, widgets.FloatSlid
230
229
  max=parameter.max_value,
231
230
  step=parameter.step,
232
231
  description=parameter.name,
233
- continuous_update=continuous_update,
232
+ continuous=continuous,
234
233
  layout=widgets.Layout(width="95%"),
235
234
  style={"description_width": "initial"},
236
235
  )
@@ -252,20 +251,18 @@ class FloatParameterWidget(BaseParameterWidget[FloatParameter, widgets.FloatSlid
252
251
  self.value = max(parameter.min_value, min(parameter.max_value, current_value))
253
252
 
254
253
 
255
- class IntegerRangeParameterWidget(
256
- BaseParameterWidget[IntegerRangeParameter, widgets.IntRangeSlider]
257
- ):
254
+ class IntegerRangeWidget(BaseWidget[IntegerRangeParameter, widgets.IntRangeSlider]):
258
255
  """Widget for integer range parameters."""
259
256
 
260
257
  def _create_widget(
261
- self, parameter: IntegerRangeParameter, continuous_update: bool
258
+ self, parameter: IntegerRangeParameter, continuous: bool
262
259
  ) -> widgets.IntRangeSlider:
263
260
  return widgets.IntRangeSlider(
264
261
  value=parameter.value,
265
262
  min=parameter.min_value,
266
263
  max=parameter.max_value,
267
264
  description=parameter.name,
268
- continuous_update=continuous_update,
265
+ continuous=continuous,
269
266
  layout=widgets.Layout(width="95%"),
270
267
  style={"description_width": "initial"},
271
268
  )
@@ -289,13 +286,11 @@ class IntegerRangeParameterWidget(
289
286
  self.value = (low, high)
290
287
 
291
288
 
292
- class FloatRangeParameterWidget(
293
- BaseParameterWidget[FloatRangeParameter, widgets.FloatRangeSlider]
294
- ):
289
+ class FloatRangeWidget(BaseWidget[FloatRangeParameter, widgets.FloatRangeSlider]):
295
290
  """Widget for float range parameters."""
296
291
 
297
292
  def _create_widget(
298
- self, parameter: FloatRangeParameter, continuous_update: bool
293
+ self, parameter: FloatRangeParameter, continuous: bool
299
294
  ) -> widgets.FloatRangeSlider:
300
295
  return widgets.FloatRangeSlider(
301
296
  value=parameter.value,
@@ -303,7 +298,7 @@ class FloatRangeParameterWidget(
303
298
  max=parameter.max_value,
304
299
  step=parameter.step,
305
300
  description=parameter.name,
306
- continuous_update=continuous_update,
301
+ continuous=continuous,
307
302
  layout=widgets.Layout(width="95%"),
308
303
  style={"description_width": "initial"},
309
304
  )
@@ -328,13 +323,13 @@ class FloatRangeParameterWidget(
328
323
  self.value = (low, high)
329
324
 
330
325
 
331
- class UnboundedIntegerParameterWidget(
332
- BaseParameterWidget[UnboundedIntegerParameter, widgets.BoundedIntText]
326
+ class UnboundedIntegerWidget(
327
+ BaseWidget[UnboundedIntegerParameter, widgets.BoundedIntText]
333
328
  ):
334
329
  """Widget for unbounded integer parameters."""
335
330
 
336
331
  def _create_widget(
337
- self, parameter: UnboundedIntegerParameter, continuous_update: bool
332
+ self, parameter: UnboundedIntegerParameter, continuous: bool
338
333
  ) -> widgets.BoundedIntText:
339
334
  return widgets.BoundedIntText(
340
335
  value=parameter.value,
@@ -359,13 +354,13 @@ class UnboundedIntegerParameterWidget(
359
354
  self._widget.max = parameter.max_value
360
355
 
361
356
 
362
- class UnboundedFloatParameterWidget(
363
- BaseParameterWidget[UnboundedFloatParameter, widgets.BoundedFloatText]
357
+ class UnboundedFloatWidget(
358
+ BaseWidget[UnboundedFloatParameter, widgets.BoundedFloatText]
364
359
  ):
365
360
  """Widget for unbounded float parameters."""
366
361
 
367
362
  def _create_widget(
368
- self, parameter: UnboundedFloatParameter, continuous_update: bool
363
+ self, parameter: UnboundedFloatParameter, continuous: bool
369
364
  ) -> widgets.BoundedFloatText:
370
365
  return widgets.BoundedFloatText(
371
366
  value=parameter.value,
@@ -390,13 +385,13 @@ class UnboundedFloatParameterWidget(
390
385
  self._widget.step = parameter.step
391
386
 
392
387
 
393
- class ButtonParameterWidget(BaseParameterWidget[ButtonParameter, widgets.Button]):
388
+ class ButtonWidget(BaseWidget[ButtonAction, widgets.Button]):
394
389
  """Widget for button parameters."""
395
390
 
396
- _is_button: bool = True
391
+ _is_action: bool = True
397
392
 
398
393
  def _create_widget(
399
- self, parameter: ButtonParameter, continuous_update: bool
394
+ self, parameter: ButtonAction, continuous: bool
400
395
  ) -> widgets.Button:
401
396
  button = widgets.Button(
402
397
  description=parameter.label,
@@ -406,11 +401,11 @@ class ButtonParameterWidget(BaseParameterWidget[ButtonParameter, widgets.Button]
406
401
  button.on_click(parameter.callback)
407
402
  return button
408
403
 
409
- def matches_parameter(self, parameter: ButtonParameter) -> bool:
404
+ def matches_parameter(self, parameter: ButtonAction) -> bool:
410
405
  """Check if the widget matches the parameter."""
411
406
  return self._widget.description == parameter.label
412
407
 
413
- def extra_updates_from_parameter(self, parameter: ButtonParameter) -> None:
408
+ def extra_updates_from_parameter(self, parameter: ButtonAction) -> None:
414
409
  """Extra updates from the parameter."""
415
410
  self._widget.description = parameter.label
416
411
  # Update click handler
@@ -438,34 +433,46 @@ class ButtonParameterWidget(BaseParameterWidget[ButtonParameter, widgets.Button]
438
433
  self._widget.on_click(None)
439
434
 
440
435
 
441
- def create_parameter_widget(
442
- parameter: Parameter[Any],
443
- continuous_update: bool = False,
444
- ) -> BaseParameterWidget[Parameter[Any], widgets.Widget]:
436
+ def create_widget(
437
+ parameter: Union[Parameter[Any], ButtonAction],
438
+ continuous: bool = False,
439
+ ) -> BaseWidget[Union[Parameter[Any], ButtonAction], widgets.Widget]:
445
440
  """Create and return the appropriate widget for the given parameter.
446
441
 
447
442
  Args:
448
443
  parameter: The parameter to create a widget for
449
- continuous_update: Whether to update the widget value continuously during user interaction
444
+ continuous: Whether to update the widget value continuously during user interaction
450
445
  """
451
446
  widget_map = {
452
- TextParameter: TextParameterWidget,
453
- SelectionParameter: SelectionParameterWidget,
454
- MultipleSelectionParameter: MultipleSelectionParameterWidget,
455
- BooleanParameter: BooleanParameterWidget,
456
- IntegerParameter: IntegerParameterWidget,
457
- FloatParameter: FloatParameterWidget,
458
- IntegerRangeParameter: IntegerRangeParameterWidget,
459
- FloatRangeParameter: FloatRangeParameterWidget,
460
- UnboundedIntegerParameter: UnboundedIntegerParameterWidget,
461
- UnboundedFloatParameter: UnboundedFloatParameterWidget,
462
- ButtonParameter: ButtonParameterWidget,
447
+ TextParameter: TextWidget,
448
+ SelectionParameter: SelectionWidget,
449
+ MultipleSelectionParameter: MultipleSelectionWidget,
450
+ BooleanParameter: BooleanWidget,
451
+ IntegerParameter: IntegerWidget,
452
+ FloatParameter: FloatWidget,
453
+ IntegerRangeParameter: IntegerRangeWidget,
454
+ FloatRangeParameter: FloatRangeWidget,
455
+ UnboundedIntegerParameter: UnboundedIntegerWidget,
456
+ UnboundedFloatParameter: UnboundedFloatWidget,
457
+ ButtonAction: ButtonWidget,
463
458
  }
464
459
 
460
+ # Try direct type lookup first
465
461
  widget_class = widget_map.get(type(parameter))
462
+
463
+ # If that fails, try matching by class name
464
+ if widget_class is None:
465
+ param_type_name = type(parameter).__name__
466
+ for key_class, value_class in widget_map.items():
467
+ if key_class.__name__ == param_type_name:
468
+ widget_class = value_class
469
+ break
470
+
466
471
  if widget_class is None:
467
472
  raise ValueError(
468
- f"No widget implementation for parameter type: {type(parameter)}"
473
+ f"No widget implementation for parameter type: {type(parameter)}\n"
474
+ f"Parameter type name: {type(parameter).__name__}\n"
475
+ f"Available types: {[k.__name__ for k in widget_map.keys()]}"
469
476
  )
470
477
 
471
- return widget_class(parameter, continuous_update)
478
+ return widget_class(parameter, continuous)