diff --git a/vivarium/controllers/panel_controller.py b/vivarium/controllers/panel_controller.py index d6117f6..78aec5f 100644 --- a/vivarium/controllers/panel_controller.py +++ b/vivarium/controllers/panel_controller.py @@ -45,6 +45,8 @@ class Selected(param.Parameterized): def selection_nve_idx(self, nve_idx): return nve_idx[np.array(self.selection)].tolist() + def __len__(self): + return len(self.selection) class PanelController(SimulatorController): @@ -58,9 +60,10 @@ def __init__(self, **params): for stype, configs in self.configs.items()} self.selected_panel_configs = {EntityType.AGENT: PanelAgentConfig(), EntityType.OBJECT: PanelObjectConfig()} self.panel_simulator_config = PanelSimulatorConfig() + self.pull_selected_panel_configs() self.update_entity_list() - for etype, selected in self.selected_entities.items(): + for selected in self.selected_entities.values(): selected.param.watch(self.pull_selected_configs, ['selection'], onlychanged=True, precedence=1) selected.param.watch(self.pull_selected_panel_configs, ['selection'], onlychanged=True) diff --git a/vivarium/interface/panel_app.py b/vivarium/interface/panel_app.py index f08966f..db89e99 100644 --- a/vivarium/interface/panel_app.py +++ b/vivarium/interface/panel_app.py @@ -198,7 +198,7 @@ def plot(self, fig: figure): class WindowManager(Parameterized): controller = PanelController(client=SimulatorGRPCClient()) - config_types = [key.name for key in controller.configs.keys()] + config_types = [k.name for k, v in controller.configs.items() if v] start_toggle = pn.widgets.Toggle(**({"name": "Stop", "value": True} if controller.is_started() else {"name": "Start", "value": False}),align="center") entity_toggle = pn.widgets.ToggleGroup(name="EntityToggle", options=config_types, @@ -216,7 +216,7 @@ def __init__(self, **kwargs): panel_simulator_config=self.controller.panel_simulator_config, selected=self.controller.selected_entities[etype], etype=etype, state=self.controller.state) - for etype, manager_class in self.entity_manager_classes.items() + for etype, manager_class in self.entity_manager_classes.items() if len(self.controller.configs[etype.to_state_type()]) } self.plot = self.create_plot() @@ -233,8 +233,8 @@ def start_toggle_cb(self, event): def entity_toggle_cb(self, event): - for i, t in enumerate(self.config_types): - self.config_columns[i].visible = t in event.new + for cc in self.config_columns: + cc.visible = cc.name in event.new def update_timestep_cb(self, event): self.pcb_plot.period = event.new @@ -273,16 +273,18 @@ def create_app(self): self.config_columns = pn.Row(* [pn.Column( pn.pane.Markdown("### SIMULATOR", align="center"), - pn.panel(self.controller.panel_simulator_config, name="Visualization configurations"), - pn.panel(self.controller.simulator_config, name="Configurations"), - visible=False, sizing_mode="scale_height", scroll=True)] + + pn.panel(self.controller.panel_simulator_config, name="Visualization configuration"), + pn.panel(self.controller.simulator_config, name="Configuration"), + visible=False, sizing_mode="scale_height", scroll=True, + name="SIMULATOR")] + [pn.Column( pn.pane.Markdown(f"### {etype.name}", align="center"), self.controller.selected_entities[etype], - pn.panel(self.controller.selected_panel_configs[etype], name="Visualization configurations"), - pn.panel(self.controller.selected_configs[etype], name="State configurations"), - visible=True, sizing_mode="scale_height", scroll=True) - for etype in EntityType]) + pn.panel(self.controller.selected_panel_configs[etype], name="Visualization configuration"), + pn.panel(self.controller.selected_configs[etype], name="State configuration"), + visible=True, sizing_mode="scale_height", scroll=True, + name=etype.name) + for etype in self.entity_managers.keys()]) app = pn.Row(pn.Column(pn.Row(pn.pane.Markdown("### Start/Stop server", align="center"), self.start_toggle),