Skip to content

Commit

Permalink
Empty config list should hide corresponding config column (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsolo1 authored Apr 9, 2024
1 parent 53f2def commit 69faaa8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
5 changes: 4 additions & 1 deletion vivarium/controllers/panel_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand All @@ -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)

Expand Down
24 changes: 13 additions & 11 deletions vivarium/interface/panel_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 69faaa8

Please sign in to comment.