Skip to content

Commit

Permalink
FIX: do not open several windows for the same plot figure (closes #265)
Browse files Browse the repository at this point in the history
  • Loading branch information
gdementen committed Oct 23, 2023
1 parent cb465fb commit 7a85833
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
5 changes: 4 additions & 1 deletion doc/source/changes/version_0_34_2.rst.inc
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ Fixes

* fixed the viewer being unusable after showing a matplotlib plot (closes :editor_issue:`261`).

* silence spurious debugger warning on Python 3.11 (closes :editor_issue:`263`).
* silence spurious debugger warning on Python 3.11 (closes :editor_issue:`263`).

* when code in the interactive console creates *and shows* a plot window, avoid showing it
a second time (closes :editor_issue:`265`).
15 changes: 13 additions & 2 deletions larray_editor/tests/test_api_larray.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def make_demo(width=20, ball_radius=5, path_radius=5, steps=30):
return la.maximum(ball_radius - la.sqrt((x - ball_center_x) ** 2 + (y - ball_center_y) ** 2), 0).transpose(x, y)


def test_matplotlib_show_interaction():
def test_edit_after_matplotlib_show():
import matplotlib.pyplot as plt

arr = la.ndtest((3, 4))
Expand All @@ -109,6 +109,17 @@ def test_matplotlib_show_interaction():
edit()


# this needs to be called in the interactive console and should open a single plot window,
# not two (see issue #265)
def test_plot_returning_ax_and_using_show():
import matplotlib.pyplot as plt

arr = la.ndtest(4)
ax = arr.plot()
plt.show()
return ax


demo = make_demo(9, 2.5, 1.5)
sphere = make_sphere(9, 4)
extreme_array = la.Array([-la.inf, -1, 0, la.nan, 1, la.inf])
Expand Down Expand Up @@ -218,4 +229,4 @@ def test_run_editor_on_exception(local_arr):

# test_run_editor_on_exception(arr2)

test_matplotlib_show_interaction()
test_edit_after_matplotlib_show()
14 changes: 10 additions & 4 deletions larray_editor/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,11 +298,17 @@ def __init__(self, canvas, parent=None):


def show_figure(parent, figure, title=None):
canvas = FigureCanvas(figure)
main = PlotDialog(canvas, parent)
if (figure.canvas is not None and figure.canvas.manager is not None and
figure.canvas.manager.window is not None):
figure.canvas.draw()
window = figure.canvas.manager.window
window.raise_()
else:
canvas = FigureCanvas(figure)
window = PlotDialog(canvas, parent)
if title is not None:
main.setWindowTitle(title)
main.show()
window.setWindowTitle(title)
window.show()


class Axis:
Expand Down

0 comments on commit 7a85833

Please sign in to comment.