Skip to content

Commit

Permalink
fixes found and history logic
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Biasuzzi <[email protected]>
  • Loading branch information
CBiasuzzi committed Sep 12, 2024
1 parent d5b2b7b commit 3820a5e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
22 changes: 14 additions & 8 deletions src/pypowsybl_jupyter/networkexplorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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

Expand Down Expand Up @@ -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')
Expand Down
3 changes: 2 additions & 1 deletion src/pypowsybl_jupyter/selectcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down

0 comments on commit 3820a5e

Please sign in to comment.