Widget
- class Widget(**kwargs: Any)[source]
A widget class for handling simulation parameters, coordinates and settings.
- _esm
Path to the JavaScript file for the widget.
- Type:
pathlib.Path
- _css
Path to the CSS file for the widget.
- Type:
pathlib.Path
- decay_rates_input
List of decay rates as floats.
- Type:
traitlets.List
- amplitude_input
List of amplitudes as floats.
- Type:
traitlets.List
- location_input
List of locations as floats.
- Type:
traitlets.List
- width_input
List of widths as floats.
- Type:
traitlets.List
- skewness_input
List of skewness values as floats.
- Type:
traitlets.List
- timepoints_max_input
Maximum number of timepoints.
- Type:
traitlets.Int
- timepoints_stepsize_input
Step size for timepoints.
- Type:
traitlets.Float
- wavelength_min_input
Minimum wavelength value.
- Type:
traitlets.Float
- wavelength_max_input
Maximum wavelength value.
- Type:
traitlets.Float
- wavelength_stepsize_input
Step size for wavelength.
- Type:
traitlets.Float
- stdev_noise_input
Standard deviation of noise.
- Type:
traitlets.Float
- seed_input
Seed for random number generation.
- Type:
traitlets.Int
- add_gaussian_irf_input
Flag to add Gaussian IRF.
- Type:
traitlets.Bool
- irf_location_input
Location of the IRF center.
- Type:
traitlets.Float
- irf_width_input
Width of the IRF.
- Type:
traitlets.Float
- use_sequential_scheme_input
Flag to use sequential scheme.
- Type:
traitlets.Bool
- model_file_name_input
Name of the model file.
- Type:
traitlets.Unicode
- parameter_file_name_input
Name of the parameter file.
- Type:
traitlets.Unicode
- data_file_name_input
Name of the data file.
- Type:
traitlets.Unicode
- simulate
Trigger for simulation.
- Type:
traitlets.Unicode
- visualize_data
Flag to visualize data.
- Type:
traitlets.Bool
Initialize the Widget instance and set up traitlet observers.
This constructor initializes the Widget instance by calling the parent class’s initializer and sets up an observer for the ‘simulate’ traitlet. The observer triggers the _simulate function whenever the ‘simulate’ traitlet changes.
- Observers:
simulate: Calls the _simulate function when the ‘simulate’ traitlet changes.
Attributes Summary
__annotations____dict____doc____module____weakref__list of weak references to the object (if defined)
_active_widgets_all_trait_default_generators_anywidget_commands_comm_changed_control_comm_default_keys_descriptors_dom_classesCSS classes applied to widget DOM element
_holding_sync_instance_inits_log_default_model_moduleA trait for unicode strings.
_model_module_versionA trait for unicode strings.
_model_nameA trait for unicode strings.
_msg_callbacksA trait whose value must be an instance of a specified class.
_property_lockAn instance of a Python dict.
_states_to_sendAn instance of a Python set.
_static_immutable_initial_values_trait_default_generators_traits_view_countThe number of views of the model displayed in the frontend.
_view_moduleA trait for unicode strings.
_view_module_versionA trait for unicode strings.
_view_nameA trait for unicode strings.
_widget_construction_callback_widget_typesA boolean (True, False) trait.
An instance of a Python list.
commA trait which allows any value.
cross_validation_lockA contextmanager for running a block with our cross validation lock set to True.
A trait for unicode strings.
An instance of a Python list.
A float trait.
A float trait.
keysThe traits which are synced.
layoutAn instance trait which coerces a dict to an instance.
An instance of a Python list.
logA trait whose value must be an instance of a specified class.
A trait for unicode strings.
model_idGets the model id of this widget.
A trait for unicode strings.
An int trait.
A trait for unicode strings.
An instance of a Python list.
A float trait.
tabbableIs widget tabbable?
An int trait.
A float trait.
tooltipA tooltip caption.
A boolean (True, False) trait.
A boolean (True, False) trait.
A float trait.
A float trait.
A float trait.
widget_typeswidgetsAn instance of a Python list.
Methods Summary
Object disposal
Implement delattr(self, name).
Default dir() implementation.
Return self==value.
Default object formatter.
Return self>=value.
Return getattr(self, name).
Return self>value.
Return hash(self).
Initialize the Widget instance and set up traitlet observers.
Coerces _esm and _css to FileContents if they are files.
Return self<=value.
Return self<value.
Return self!=value.
Helper for pickle.
Helper for pickle.
Return repr(self).
Implement setattr(self, name, value).
Size of object in memory, in bytes.
Return str(self).
Abstract classes can override this to customize issubclass().
Static method, called when a widget is constructed.
Return default generator for a given trait
Called when a custom msg is received.
Lock a property-value pair.
Notify observers of any event
Setup a handler to be called when a trait should be cross validated.
Sends a message to the model in the front-end.
Check the property lock (property_lock)
Convert json values to objects.
Convert a trait value to json.
Adds a class to the top level element of the widget.
Dynamically add trait attributes to the Widget.
Blur the widget.
Get a dict of all event handlers defined on this class, not a parent.
Get a dict of all the traitlets defined on this class, not a parent.
Get a list of all the names of this class' traits.
Get a
dictof all the traits of this class.Close method.
Focus on the widget.
Returns the full state for a widget manager for embedding
Gets the widget state, or a piece of it.
Static method, called when a widget is constructed.
Class method, called when the comm-open message on the "jupyter.widget.control" comm channel is received
Returns True if the object has a trait with the specified name.
Hold syncing any state until the outermost context manager exits
Context manager for bundling trait change notifications and cross validation.
Called when a property has changed.
Setup a handler to be called when a trait changes.
(Un)Register a custom msg receive callback.
DEPRECATED: Setup a handler to be called when a trait changes.
Registers a callback to be called when a widget is constructed.
Open a comm to the frontend if one isn't already open.
Removes a class from the top level element of the widget.
Sends a custom msg to the widget model in the front-end.
Sends the widget state, or a piece of it, to the front-end, if it exists.
Called when a state is received from the front-end.
Forcibly sets trait attribute, including read-only attributes.
This is called before self.__init__ is called.
Return a trait's default value or a dictionary of them
Get a
dictof all the event handlers of this class.Returns True if the specified trait has a value.
Get metadata values for trait by key.
Get a list of all the names of this class' traits.
A
dictof trait names and their values.Get a
dictof all the traits of this class.Remove a trait change handler.
Remove trait change handlers of any type for the specified name.
Methods Documentation
- __delattr__(name, /)
Implement delattr(self, name).
- __dir__()
Default dir() implementation.
- __eq__(value, /)
Return self==value.
- __format__(format_spec, /)
Default object formatter.
- __ge__(value, /)
Return self>=value.
- __getattribute__(name, /)
Return getattr(self, name).
- __getstate__() dict[str, Any]
- __gt__(value, /)
Return self>value.
- __hash__()
Return hash(self).
- __init__()[source]
Initialize the Widget instance and set up traitlet observers.
This constructor initializes the Widget instance by calling the parent class’s initializer and sets up an observer for the ‘simulate’ traitlet. The observer triggers the _simulate function whenever the ‘simulate’ traitlet changes.
- Observers:
simulate: Calls the _simulate function when the ‘simulate’ traitlet changes.
- classmethod __init_subclass__(**kwargs: dict) None
Coerces _esm and _css to FileContents if they are files.
- __le__(value, /)
Return self<=value.
- __lt__(value, /)
Return self<value.
- __ne__(value, /)
Return self!=value.
- static __new__(*args: Any, **kwargs: Any) Any
- __reduce__()
Helper for pickle.
- __reduce_ex__(protocol, /)
Helper for pickle.
- __setattr__(name, value, /)
Implement setattr(self, name, value).
- __setstate__(state: dict[str, Any]) None
- __sizeof__()
Size of object in memory, in bytes.
- __str__()
Return str(self).
- __subclasshook__()
Abstract classes can override this to customize issubclass().
This is invoked early on by abc.ABCMeta.__subclasscheck__(). It should return True, False or NotImplemented. If it returns NotImplemented, the normal algorithm is used. Otherwise, it overrides the normal algorithm (and the outcome is cached).
- _add_notifiers(handler: Callable[[...], Any], name: Sentinel | str, type: str | Sentinel) None
- static _call_widget_constructed(widget)[source]
Static method, called when a widget is constructed.
- _get_trait_default_generator(name: str) Any
Return default generator for a given trait
Walk the MRO to resolve the correct default generator according to inheritance.
- _lock_property(**properties)[source]
Lock a property-value pair.
The value should be the JSON state of the property.
NOTE: This, in addition to the single lock for all state changes, is flawed. In the future we may want to look into buffering state changes back to the front-end.
- _notify_observers(event: Bunch) None
Notify observers of any event
- _notify_trait(name: str, old_value: Any, new_value: Any) None
- _register_validator(handler: Callable[[...], None], names: tuple[str | Sentinel, ...]) None
Setup a handler to be called when a trait should be cross validated.
This is used to setup dynamic notifications for cross-validation.
If a validator is already registered for any of the provided names, a TraitError is raised and no new validator is registered.
- Parameters:
handler (callable) –
A callable that is called when the given trait is cross-validated. Its signature is handler(proposal), where proposal is a Bunch (dictionary with attribute access) with the following attributes/keys:
owner: the HasTraits instancevalue: the proposed value for the modified trait attributetrait: the TraitType instance associated with the attribute
names (List of strings) – The names of the traits that should be cross-validated
- _remove_notifiers(handler: Callable[[...], Any] | None, name: Sentinel | str, type: str | Sentinel) None
- _repr_keys()
- _repr_mimebundle_(**kwargs: dict) tuple[dict, dict] | None
- add_class(className)
Adds a class to the top level element of the widget.
Doesn’t add the class if it already exists.
- blur()
Blur the widget.
- classmethod class_own_trait_events(name: str) dict[str, EventHandler]
Get a dict of all event handlers defined on this class, not a parent.
Works like
event_handlers, except for excluding traits from parents.
- classmethod class_own_traits(**metadata: Any) dict[str, TraitType[Any, Any]]
Get a dict of all the traitlets defined on this class, not a parent.
Works like class_traits, except for excluding traits from parents.
- classmethod class_trait_names(**metadata: Any) list[str]
Get a list of all the names of this class’ traits.
This method is just like the
trait_names()method, but is unbound.
- classmethod class_traits(**metadata: Any) dict[str, TraitType[Any, Any]]
Get a
dictof all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.This method is just like the
traits()method, but is unbound.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- close()[source]
Close method.
Closes the underlying comm. When the comm is closed, all of the widget views are automatically removed from the front-end.
- focus()
Focus on the widget.
- static get_manager_state(drop_defaults=False, widgets=None)[source]
Returns the full state for a widget manager for embedding
- Parameters:
drop_defaults – when True, it will not include default value
widgets – list with widgets to include in the state (or all widgets when None)
- Returns:
- get_state(key=None, drop_defaults=False)[source]
Gets the widget state, or a piece of it.
- Parameters:
key (unicode or iterable (optional)) – A single property’s name or iterable of property names to get.
- Returns:
state (dict of states)
metadata (dict) – metadata for each field: {key: metadata}
- classmethod handle_control_comm_opened(comm, msg)[source]
Class method, called when the comm-open message on the “jupyter.widget.control” comm channel is received
- has_trait(name: str) bool
Returns True if the object has a trait with the specified name.
- hold_trait_notifications() Any
Context manager for bundling trait change notifications and cross validation.
Use this when doing multiple trait assignments (init, config), to avoid race conditions in trait notifiers requesting other trait values. All trait notifications will fire after all values have been assigned.
- observe(handler: Callable[[...], Any], names: Sentinel | str | Iterable[Sentinel | str] = traitlets.All, type: Sentinel | str = 'change') None
Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
- Parameters:
handler (callable) – A callable that is called when a trait changes. Its signature should be
handler(change), wherechangeis a dictionary. The change dictionary at least holds a ‘type’ key. *type: the type of notification. Other keys may be passed depending on the value of ‘type’. In the case where type is ‘change’, we also have the following keys: *owner: the HasTraits instance *old: the old value of the modified trait attribute *new: the new value of the modified trait attribute *name: the name of the modified trait attribute.names (list, str, All) – If names is All, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
type (str, All (default: 'change')) – The type of notification to filter by. If equal to All, then all notifications are passed to the observe handler.
- on_msg(callback, remove=False)[source]
(Un)Register a custom msg receive callback.
- Parameters:
callback (callable) –
callback will be passed three arguments when a message arrives:
callback(widget, content, buffers)
remove (bool) – True if the callback should be unregistered.
- on_trait_change(handler: EventHandler | None = None, name: Sentinel | str | None = None, remove: bool = False) None
DEPRECATED: Setup a handler to be called when a trait changes.
This is used to setup dynamic notifications of trait changes.
Static handlers can be created by creating methods on a HasTraits subclass with the naming convention ‘_[traitname]_changed’. Thus, to create static handler for the trait ‘a’, create the method _a_changed(self, name, old, new) (fewer arguments can be used, see below).
If remove is True and handler is not specified, all change handlers for the specified name are uninstalled.
- Parameters:
handler (callable, None) – A callable that is called when a trait changes. Its signature can be handler(), handler(name), handler(name, new), handler(name, old, new), or handler(name, old, new, self).
name (list, str, None) – If None, the handler will apply to all traits. If a list of str, handler will apply to all names in the list. If a str, the handler will apply just to that name.
remove (bool) – If False (the default), then install the handler. If True then unintall it.
- static on_widget_constructed(callback)[source]
Registers a callback to be called when a widget is constructed.
The callback must have the following signature: callback(widget)
- remove_class(className)
Removes a class from the top level element of the widget.
Doesn’t remove the class if it doesn’t exist.
- send(content, buffers=None)[source]
Sends a custom msg to the widget model in the front-end.
- Parameters:
content (dict) – Content of the message to send.
buffers (list of binary buffers) – Binary buffers to send with message
- send_state(key=None)[source]
Sends the widget state, or a piece of it, to the front-end, if it exists.
- Parameters:
key (unicode, or iterable (optional)) – A single property’s name or iterable of property names to sync with the front-end.
- set_trait(name: str, value: Any) None
Forcibly sets trait attribute, including read-only attributes.
- setup_instance(**kwargs: Any) None
This is called before self.__init__ is called.
- trait_defaults(*names: str, **metadata: Any) dict[str, Any] | Sentinel
Return a trait’s default value or a dictionary of them
Notes
Dynamically generated default values may depend on the current state of the object.
- classmethod trait_events(name: str | None = None) dict[str, EventHandler]
Get a
dictof all the event handlers of this class.- Parameters:
name (str (default: None)) – The name of a trait of this class. If name is
Nonethen all the event handlers of this class will be returned instead.- Return type:
The event handlers associated with a trait name, or all event handlers.
- trait_has_value(name: str) bool
Returns True if the specified trait has a value.
This will return false even if
getattrwould return a dynamically generated default value. These default values will be recognized as existing only after they have been generated.Example
class MyClass(HasTraits): i = Int() mc = MyClass() assert not mc.trait_has_value("i") mc.i # generates a default value assert mc.trait_has_value("i")
- trait_metadata(traitname: str, key: str, default: Any | None = None) Any
Get metadata values for trait by key.
- trait_names(**metadata: Any) list[str]
Get a list of all the names of this class’ traits.
- trait_values(**metadata: Any) dict[str, Any]
A
dictof trait names and their values.The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- Return type:
A
dictof trait names and their values.
Notes
Trait values are retrieved via
getattr, any exceptions raised by traits or the operations they may trigger will result in the absence of a trait value in the resultdict.
- traits(**metadata: Any) dict[str, TraitType[Any, Any]]
Get a
dictof all the traits of this class. The dictionary is keyed on the name and the values are the TraitType objects.The TraitTypes returned don’t know anything about the values that the various HasTrait’s instances are holding.
The metadata kwargs allow functions to be passed in which filter traits based on metadata values. The functions should take a single value as an argument and return a boolean. If any function returns False, then the trait is not included in the output. If a metadata key doesn’t exist, None will be passed to the function.
- unobserve(handler: Callable[[...], Any], names: Sentinel | str | Iterable[Sentinel | str] = traitlets.All, type: Sentinel | str = 'change') None
Remove a trait change handler.
This is used to unregister handlers to trait change notifications.
- Parameters:
handler (callable) – The callable called when a trait attribute changes.
names (list, str, All (default: All)) – The names of the traits for which the specified handler should be uninstalled. If names is All, the specified handler is uninstalled from the list of notifiers corresponding to all changes.
type (str or All (default: 'change')) – The type of notification to filter by. If All, the specified handler is uninstalled from the list of notifiers corresponding to all types.
- unobserve_all(name: str | Any = traitlets.All) None
Remove trait change handlers of any type for the specified name. If name is not specified, removes all trait notifiers.