Source code for coperniFUS.modules.module_base


[docs] class Module: """ Base class for CoperniFUS Modules """ _DEFAULT_PARAMS = {} """ Default configuration parameters used when a parameter value is not yet cached """ def __init__(self, parent_viewer, module_id, **kwargs) -> None: self.module_kwargs = kwargs self.parent_viewer = parent_viewer self._module_id = module_id @property def module_id(self): """ Holds the module identifier for reference in get_module_object_from_name """ if not isinstance(self._module_id, str): raise ValueError('Please make sure that self.module_id is defined in the __init__ of the module. module_id should be a string without any dot characters.') elif isinstance(self._module_id, str) and '.' in self._module_id: raise ValueError('Please make sure that self.module_id does not contain any dot characters.') else: return self._module_id @module_id.setter def module_id(self, value): if not isinstance(value, str): raise ValueError('Please make sure that self.module_id is defined in the __init__ of the module. module_id should be a string without any dot characters.') elif isinstance(value, str) and '.' in value: raise ValueError('Please make sure that self.module_id does not contain any dot characters.') else: self._module_id = value # --- cache wrapper for modules parameters ---
[docs] def get_user_param(self, param_name, default_value=None, additional_identifiers=[]): """ Cache wrapper for modules parameters Get parameters by their name using `param_name`. If the requested parameter is not found in the cache, default values provided in the static attribute `_DEFAULT_PARAMS` will be returned. """ if default_value is None and param_name in self._DEFAULT_PARAMS: default_value = self._DEFAULT_PARAMS[param_name] param_value = self.parent_viewer.cache.get_attr( [self.module_id, *additional_identifiers, param_name], default_value = default_value ) return param_value
[docs] def set_user_param(self, param_name, param_value, additional_identifiers=[]): self.parent_viewer.cache.set_attr( [self.module_id, *additional_identifiers, param_name], param_value )
# --- Required module attributes ---
[docs] def init_dock(self): """ Sets up a dock GUI for the module """ # Optionnal # # Resize to most comptact height # self.dock.adjustSize() # self.dock.setMinimumHeight(self.dock.sizeHint().height()) # self.dock.setMaximumHeight(self.dock.sizeHint().height()) pass
[docs] def add_rendered_object(self): """ Called when adding module-specific elements to the 3D viewer """ pass
[docs] def update_rendered_object(self): """ Called for the update of module-specific elements already present in the 3D viewer """ pass
[docs] def delete_rendered_object(self): """ Called for the removal of module-specific elements from the 3D viewer """ pass
# @propertys # def status_bar_widget_list(self): # return []