Loading src/nova/trame/_internal/utils.py +4 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ from trame_server.core import State from nova.mvvm._internal.utils import rgetdictvalue, rsetdictvalue # Reads a state parameter from Trame. For internal use only, if you're using this in your application you're violating # the MVVM framework. :) def get_state_param(state: State, value: Union[Any, Tuple]) -> Any: if isinstance(value, tuple): return rgetdictvalue(state, value[0]) Loading @@ -14,6 +16,8 @@ def get_state_param(state: State, value: Union[Any, Tuple]) -> Any: return value # Writes a state parameter to Trame. For internal use only, if you're using this in your application you're violating # the MVVM framework. :) def set_state_param(state: State, value: Union[Any, Tuple], new_value: Any = None) -> Any: with state: if isinstance(value, tuple): Loading src/nova/trame/view/components/data_selector.py +9 −1 Original line number Diff line number Diff line Loading @@ -244,19 +244,27 @@ class DataSelector(datagrid.VGrid): "`nova.trame.view.components.ornl`." ) # This method sets up Trame state change listeners for each binding parameter that can be changed directly by this # component. This allows us to communicate the changes to the developer's bindings without requiring our own. We # don't want bindings in the internal implementation as our callbacks could compete with the developer's. def setup_bindings(self) -> None: # If the bindings were given initial values, write these to the state. set_state_param(self.state, self._directory) set_state_param(self.state, self._extensions) set_state_param(self.state, self._subdirectory) self._vm.set_binding_parameters( directory=get_state_param(self.state, self._directory), extensions=get_state_param(self.state, self._extensions), subdirectory=get_state_param(self.state, self._subdirectory), ) # The component used by this parameter will attempt to set the initial value itself, which will trigger the # below change listeners causing unpredictable behavior. if isinstance(self._subdirectory, tuple): self._subdirectory = (self._subdirectory[0],) # Now we set up the change listeners for all bound parameters. These are responsible for updating the component # when other portions of the application manipulate these parameters. if isinstance(self._directory, tuple): @self.state.change(self._directory[0].split(".")[0]) Loading src/nova/trame/view/components/ornl/neutron_data_selector.py +10 −5 Original line number Diff line number Diff line Loading @@ -165,16 +165,18 @@ class NeutronDataSelector(DataSelector): allow_custom_directories=get_state_param(self.state, self._allow_custom_directories), ) # This method sets up Trame state change listeners for each binding parameter that can be changed directly by this # component. This allows us to communicate the changes to the developer's bindings without requiring our own. We # don't want bindings in the internal implementation as our callbacks could compete with the developer's. def setup_bindings(self) -> None: # If the bindings were given initial values, write these to the state. set_state_param(self.state, self._facility) set_state_param(self.state, self._instrument) set_state_param(self.state, self._experiment) set_state_param(self.state, self._allow_custom_directories) self._last_facility = get_state_param(self.state, self._facility) self._last_instrument = get_state_param(self.state, self._instrument) self._last_experiment = get_state_param(self.state, self._experiment) self._vm.set_binding_parameters( facility=get_state_param(self.state, self._facility), instrument=get_state_param(self.state, self._instrument), Loading @@ -182,6 +184,8 @@ class NeutronDataSelector(DataSelector): allow_custom_directories=get_state_param(self.state, self._allow_custom_directories), ) # Now we set up the change listeners for all bound parameters. These are responsible for updating the component # when other portions of the application manipulate these parameters. if isinstance(self._facility, tuple): @self.state.change(self._facility[0].split(".")[0]) Loading Loading @@ -231,18 +235,19 @@ class NeutronDataSelector(DataSelector): ) ) # These update methods notify the rest of the application when the component changes bound parameters. def update_facility(self, facility: str) -> None: self._vm.set_binding_parameters( facility=set_state_param(self.state, (self._selected_facility_name,), facility), instrument=set_state_param(self.state, (self._selected_instrument_name,), ""), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), instrument=set_state_param(self.state, (self._selected_instrument_name,), ""), # Reset the instrument experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), # Reset the experiment ) self._vm.reset() def update_instrument(self, instrument: str) -> None: self._vm.set_binding_parameters( instrument=set_state_param(self.state, (self._selected_instrument_name,), instrument), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), # Reset the experiment ) self._vm.reset() Loading Loading
src/nova/trame/_internal/utils.py +4 −0 Original line number Diff line number Diff line Loading @@ -7,6 +7,8 @@ from trame_server.core import State from nova.mvvm._internal.utils import rgetdictvalue, rsetdictvalue # Reads a state parameter from Trame. For internal use only, if you're using this in your application you're violating # the MVVM framework. :) def get_state_param(state: State, value: Union[Any, Tuple]) -> Any: if isinstance(value, tuple): return rgetdictvalue(state, value[0]) Loading @@ -14,6 +16,8 @@ def get_state_param(state: State, value: Union[Any, Tuple]) -> Any: return value # Writes a state parameter to Trame. For internal use only, if you're using this in your application you're violating # the MVVM framework. :) def set_state_param(state: State, value: Union[Any, Tuple], new_value: Any = None) -> Any: with state: if isinstance(value, tuple): Loading
src/nova/trame/view/components/data_selector.py +9 −1 Original line number Diff line number Diff line Loading @@ -244,19 +244,27 @@ class DataSelector(datagrid.VGrid): "`nova.trame.view.components.ornl`." ) # This method sets up Trame state change listeners for each binding parameter that can be changed directly by this # component. This allows us to communicate the changes to the developer's bindings without requiring our own. We # don't want bindings in the internal implementation as our callbacks could compete with the developer's. def setup_bindings(self) -> None: # If the bindings were given initial values, write these to the state. set_state_param(self.state, self._directory) set_state_param(self.state, self._extensions) set_state_param(self.state, self._subdirectory) self._vm.set_binding_parameters( directory=get_state_param(self.state, self._directory), extensions=get_state_param(self.state, self._extensions), subdirectory=get_state_param(self.state, self._subdirectory), ) # The component used by this parameter will attempt to set the initial value itself, which will trigger the # below change listeners causing unpredictable behavior. if isinstance(self._subdirectory, tuple): self._subdirectory = (self._subdirectory[0],) # Now we set up the change listeners for all bound parameters. These are responsible for updating the component # when other portions of the application manipulate these parameters. if isinstance(self._directory, tuple): @self.state.change(self._directory[0].split(".")[0]) Loading
src/nova/trame/view/components/ornl/neutron_data_selector.py +10 −5 Original line number Diff line number Diff line Loading @@ -165,16 +165,18 @@ class NeutronDataSelector(DataSelector): allow_custom_directories=get_state_param(self.state, self._allow_custom_directories), ) # This method sets up Trame state change listeners for each binding parameter that can be changed directly by this # component. This allows us to communicate the changes to the developer's bindings without requiring our own. We # don't want bindings in the internal implementation as our callbacks could compete with the developer's. def setup_bindings(self) -> None: # If the bindings were given initial values, write these to the state. set_state_param(self.state, self._facility) set_state_param(self.state, self._instrument) set_state_param(self.state, self._experiment) set_state_param(self.state, self._allow_custom_directories) self._last_facility = get_state_param(self.state, self._facility) self._last_instrument = get_state_param(self.state, self._instrument) self._last_experiment = get_state_param(self.state, self._experiment) self._vm.set_binding_parameters( facility=get_state_param(self.state, self._facility), instrument=get_state_param(self.state, self._instrument), Loading @@ -182,6 +184,8 @@ class NeutronDataSelector(DataSelector): allow_custom_directories=get_state_param(self.state, self._allow_custom_directories), ) # Now we set up the change listeners for all bound parameters. These are responsible for updating the component # when other portions of the application manipulate these parameters. if isinstance(self._facility, tuple): @self.state.change(self._facility[0].split(".")[0]) Loading Loading @@ -231,18 +235,19 @@ class NeutronDataSelector(DataSelector): ) ) # These update methods notify the rest of the application when the component changes bound parameters. def update_facility(self, facility: str) -> None: self._vm.set_binding_parameters( facility=set_state_param(self.state, (self._selected_facility_name,), facility), instrument=set_state_param(self.state, (self._selected_instrument_name,), ""), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), instrument=set_state_param(self.state, (self._selected_instrument_name,), ""), # Reset the instrument experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), # Reset the experiment ) self._vm.reset() def update_instrument(self, instrument: str) -> None: self._vm.set_binding_parameters( instrument=set_state_param(self.state, (self._selected_instrument_name,), instrument), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), experiment=set_state_param(self.state, (self._selected_experiment_name,), ""), # Reset the experiment ) self._vm.reset() Loading