diff --git a/src/pypowsybl_jupyter/networkexplorer.py b/src/pypowsybl_jupyter/networkexplorer.py index e5b3664..4b7f1de 100644 --- a/src/pypowsybl_jupyter/networkexplorer.py +++ b/src/pypowsybl_jupyter/networkexplorer.py @@ -63,10 +63,13 @@ def network_explorer(network: Network, vl_id : str = None, use_name:bool = True, def go_to_vl(event: any): arrow_vl= str(event.clicked_nextvl) - sel_ctx.set_selected(arrow_vl, add_to_history=True) - update_select_widget(history, sel_ctx.get_selected(), sel_ctx.get_history_as_list(), on_selected_history) - update_select_widget(found, None, None, on_selected) - update_explorer() + if arrow_vl != sel_ctx.get_selected(): + sel_ctx.set_selected(arrow_vl, add_to_history=True) + update_select_widget(history, sel_ctx.get_selected(), sel_ctx.get_history_as_list(), on_selected_history) + update_select_widget(found, sel_ctx.get_selected() if sel_ctx.is_selected_in_filtered_vls() else None, None, on_selected) + update_explorer() + history.focus() + def toggle_switch(event: any): idswitch = event.clicked_switch.get('id') @@ -77,9 +80,12 @@ def toggle_switch(event: any): def go_to_vl_from_map(event: any): vl_from_map= str(event.selected_vl) - sel_ctx.set_selected(vl_from_map, add_to_history=True) - update_select_widget(history, sel_ctx.get_selected(), sel_ctx.get_history_as_list(), on_selected_history) - update_select_widget(found, None, None, on_selected) + if vl_from_map != sel_ctx.get_selected(): + sel_ctx.set_selected(vl_from_map, add_to_history=True) + update_select_widget(history, sel_ctx.get_selected(), sel_ctx.get_history_as_list(), on_selected_history) + update_select_widget(found, sel_ctx.get_selected() if sel_ctx.is_selected_in_filtered_vls() else None, None, on_selected) + update_explorer() + history.focus() #switch to the SLD tab tabs_diagrams.selected_index=1 @@ -185,7 +191,7 @@ def on_selected(d): def on_selected_history(d): if d['new'] != None: sel_ctx.set_selected(d['new'], add_to_history=False) - update_select_widget(found, None, None, on_selected) + update_select_widget(found, sel_ctx.get_selected() if sel_ctx.is_selected_in_filtered_vls() else None, None, on_selected) update_explorer() history.observe(on_selected_history, names='value') diff --git a/src/pypowsybl_jupyter/selectcontext.py b/src/pypowsybl_jupyter/selectcontext.py index 337f9d3..bb3a619 100644 --- a/src/pypowsybl_jupyter/selectcontext.py +++ b/src/pypowsybl_jupyter/selectcontext.py @@ -34,7 +34,8 @@ def get_vls(self): def set_selected(self, id, add_to_history=True): if id in self.vls.index: self.selected_vl = id - if add_to_history: + last_id_from_history=self.history[0]['id'] if len(self.history)>0 else None + if add_to_history and self.selected_vl != last_id_from_history: self.add_to_history(id) else: raise ValueError(f'a voltage level with id={id} does not exist in the network.')