Skip to content

Commit

Permalink
Check that graphs opened from the Jupyter notebook interface always h…
Browse files Browse the repository at this point in the history
…ave the MultiGraph backend.
  • Loading branch information
jvdwetering committed Jan 23, 2025
1 parent 5280470 commit 942cd5f
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions zxlive/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,14 +494,19 @@ def new_graph(self, graph: Optional[GraphT] = None, name: Optional[str] = None)
self._new_panel(panel, name)

def open_graph_from_notebook(self, graph: GraphT, name: str) -> None:
"""Opens a ZXLive window from within a notebook to edit a graph.
"""Opens a ZXLive window from within a Jupyter notebook to edit a graph.
Replaces the graph in an existing tab if it has the same name."""

if not isinstance(graph, GraphT): # The graph we are given is not a MultiGraph
graph = graph.copy(backend='multigraph')
graph.set_auto_simplify(False)

# TODO: handle multiple tabs with the same name somehow
for i in range(self.tab_widget.count()):
if self.tab_widget.tabText(i) == name or self.tab_widget.tabText(i) == name + "*":
self.tab_widget.setCurrentIndex(i)
assert self.active_panel
assert self.active_panel is not None
self.active_panel.replace_graph(graph)
return
self.new_graph(copy.deepcopy(graph), name)
Expand Down

0 comments on commit 942cd5f

Please sign in to comment.