Skip to content

Commit 7a85833

Browse files
committed
FIX: do not open several windows for the same plot figure (closes #265)
1 parent cb465fb commit 7a85833

File tree

3 files changed

+27
-7
lines changed

3 files changed

+27
-7
lines changed

doc/source/changes/version_0_34_2.rst.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,7 @@ Fixes
55

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

8-
* silence spurious debugger warning on Python 3.11 (closes :editor_issue:`263`).
8+
* silence spurious debugger warning on Python 3.11 (closes :editor_issue:`263`).
9+
10+
* when code in the interactive console creates *and shows* a plot window, avoid showing it
11+
a second time (closes :editor_issue:`265`).

larray_editor/tests/test_api_larray.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def make_demo(width=20, ball_radius=5, path_radius=5, steps=30):
100100
return la.maximum(ball_radius - la.sqrt((x - ball_center_x) ** 2 + (y - ball_center_y) ** 2), 0).transpose(x, y)
101101

102102

103-
def test_matplotlib_show_interaction():
103+
def test_edit_after_matplotlib_show():
104104
import matplotlib.pyplot as plt
105105

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

111111

112+
# this needs to be called in the interactive console and should open a single plot window,
113+
# not two (see issue #265)
114+
def test_plot_returning_ax_and_using_show():
115+
import matplotlib.pyplot as plt
116+
117+
arr = la.ndtest(4)
118+
ax = arr.plot()
119+
plt.show()
120+
return ax
121+
122+
112123
demo = make_demo(9, 2.5, 1.5)
113124
sphere = make_sphere(9, 4)
114125
extreme_array = la.Array([-la.inf, -1, 0, la.nan, 1, la.inf])
@@ -218,4 +229,4 @@ def test_run_editor_on_exception(local_arr):
218229

219230
# test_run_editor_on_exception(arr2)
220231

221-
test_matplotlib_show_interaction()
232+
test_edit_after_matplotlib_show()

larray_editor/utils.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,11 +298,17 @@ def __init__(self, canvas, parent=None):
298298

299299

300300
def show_figure(parent, figure, title=None):
301-
canvas = FigureCanvas(figure)
302-
main = PlotDialog(canvas, parent)
301+
if (figure.canvas is not None and figure.canvas.manager is not None and
302+
figure.canvas.manager.window is not None):
303+
figure.canvas.draw()
304+
window = figure.canvas.manager.window
305+
window.raise_()
306+
else:
307+
canvas = FigureCanvas(figure)
308+
window = PlotDialog(canvas, parent)
303309
if title is not None:
304-
main.setWindowTitle(title)
305-
main.show()
310+
window.setWindowTitle(title)
311+
window.show()
306312

307313

308314
class Axis:

0 commit comments

Comments
 (0)