@@ -401,22 +401,45 @@ def _click_handler(self, _):
401
401
# Flip back the checkbox if the click resulted in an error
402
402
self .input .setChecked (not (self .input .isChecked ()))
403
403
raise e
404
-
404
+
405
+
406
+ class _PartialAccessor :
407
+ def __init__ (self , param ):
408
+ self .param = param
409
+
410
+ def __setitem__ (self , key , value ):
411
+ self .param ._value .__setitem__ (key , value )
412
+ self .param .set_value ()
405
413
406
414
class ParamArray (BaseParam ):
407
415
"""
408
416
A param that stores a numpy array. There is no GUI input, the Param simply displays the
409
417
dimensions of the array, and indicates when the data has been updated.
410
418
411
- The array can be modified programmatically by providing setters or getters, or using
412
- :func:`~puzzlepiece.param.BaseParam.set_value`.
419
+ The array can be modified through programmatic interaction with setter or getter functions
420
+ (for example the array can be obtained from a hardware spectrometer), or treated as a variable
421
+ and set using :func:`~puzzlepiece.param.BaseParam.set_value`.
413
422
"""
414
423
_type = np .asarray
415
424
416
425
def __init__ (self , name , value , setter = None , getter = None , visible = True , format = '{}' , _type = None , * args , ** kwargs ):
417
426
self ._indicator_state = True
427
+ self ._partial_accessor = _PartialAccessor (self )
418
428
super ().__init__ (name , value , setter , getter , visible , format , _type , * args , ** kwargs )
419
429
430
+ @property
431
+ def set_partial (self ):
432
+ """
433
+ Use this property to set values to slices of the stored numpy array, using
434
+ any slicing methods that a numpy array accepts::
435
+
436
+ puzzle['piece'].params['image'].set_partial[100:200, :] = 128
437
+
438
+ This will call the param's setter if there's one, and in general
439
+ acts like :func:`~puzzlepiece.param.BaseParam.set_value`.
440
+ """
441
+ return self ._partial_accessor
442
+
420
443
def _make_input (self , value = None , connect = None ):
421
444
"""
422
445
:meta private:
@@ -430,7 +453,27 @@ def _input_set_value(self, value):
430
453
"""
431
454
:meta private:
432
455
"""
433
- self .input .setText (self ._format_array (value ))
456
+ self .input .setText (self ._format_array (value ))
457
+
458
+ def _input_get_value (self ):
459
+ """
460
+ :meta private:
461
+ """
462
+ return self ._value
463
+
464
+ def set_value (self , value = None ):
465
+ """
466
+ This method overrides :func:`puzzlepiece.param.BaseParam.set_value`.
467
+ See there for documentation.
468
+
469
+ :meta private:
470
+ """
471
+ # Small check to account for the label being set twice
472
+ # in super().set_value(value) when the
473
+ # value argument is None
474
+ if value is not None :
475
+ self ._indicator_state = not self ._indicator_state
476
+ return super ().set_value (value )
434
477
435
478
def _format_array (self , value ):
436
479
self ._indicator_state = not self ._indicator_state
0 commit comments