From 54a9b3b8487e48665f49a9c800a30f52c08f8d9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Thu, 5 Oct 2023 13:17:39 +0200 Subject: [PATCH 1/3] DOC: mention issue 263 in changelog --- doc/source/changes/version_0_34_2.rst.inc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/source/changes/version_0_34_2.rst.inc b/doc/source/changes/version_0_34_2.rst.inc index 734d050..22bc959 100644 --- a/doc/source/changes/version_0_34_2.rst.inc +++ b/doc/source/changes/version_0_34_2.rst.inc @@ -4,3 +4,5 @@ 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`). \ No newline at end of file From 331b896e6afa298ba261cb7cb0c0e76dd7363ae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Tue, 4 Oct 2022 13:29:28 +0200 Subject: [PATCH 2/3] FIX: do not open several windows for the same plot figure (closes #265) --- doc/source/changes/version_0_34_2.rst.inc | 5 ++++- larray_editor/tests/test_api_larray.py | 15 +++++++++++++-- larray_editor/utils.py | 14 ++++++++++---- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/doc/source/changes/version_0_34_2.rst.inc b/doc/source/changes/version_0_34_2.rst.inc index 22bc959..3575512 100644 --- a/doc/source/changes/version_0_34_2.rst.inc +++ b/doc/source/changes/version_0_34_2.rst.inc @@ -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`). \ No newline at end of file +* 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`). diff --git a/larray_editor/tests/test_api_larray.py b/larray_editor/tests/test_api_larray.py index 17e8ad1..a88f308 100644 --- a/larray_editor/tests/test_api_larray.py +++ b/larray_editor/tests/test_api_larray.py @@ -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)) @@ -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]) @@ -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() diff --git a/larray_editor/utils.py b/larray_editor/utils.py index 641e905..fc873b1 100644 --- a/larray_editor/utils.py +++ b/larray_editor/utils.py @@ -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: From dfc19d7f771a1560d53e296451cc70f2f666a9c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20de=20Menten?= Date: Wed, 20 Sep 2023 08:56:21 +0200 Subject: [PATCH 3/3] FIX: allow fractional digits in comparator tolerance (closes #260) --- doc/source/changes/version_0_34_2.rst.inc | 4 ++++ larray_editor/comparator.py | 20 ++++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/doc/source/changes/version_0_34_2.rst.inc b/doc/source/changes/version_0_34_2.rst.inc index 3575512..95682c1 100644 --- a/doc/source/changes/version_0_34_2.rst.inc +++ b/doc/source/changes/version_0_34_2.rst.inc @@ -9,3 +9,7 @@ Fixes * when code in the interactive console creates *and shows* a plot window, avoid showing it a second time (closes :editor_issue:`265`). + +* depending on the system regional settings, comparator tolerance sometimes did not allow simple + fractional numbers (e.g. 0.1). The only way to specify the tolerance was the scientific notation + (closes :editor_issue:`260`). diff --git a/larray_editor/comparator.py b/larray_editor/comparator.py index 665b94d..6736fc1 100644 --- a/larray_editor/comparator.py +++ b/larray_editor/comparator.py @@ -1,10 +1,7 @@ -import ast - import numpy as np import larray as la from qtpy.QtCore import Qt -from qtpy.QtGui import QDoubleValidator from qtpy.QtWidgets import (QWidget, QVBoxLayout, QListWidget, QSplitter, QHBoxLayout, QLabel, QCheckBox, QLineEdit, QComboBox, QMessageBox) @@ -53,8 +50,10 @@ def __init__(self, parent=None, bg_gradient='red-white-blue', rtol=0, atol=0, na tolerance_layout.addWidget(tolerance_combobox) self.tolerance_combobox = tolerance_combobox + # We do not use a QDoubleValidator because, by default, it uses the + # system locale (so we would need to parse the string using that + # locale too) and does not provide any feedback to users on failure tolerance_line_edit = QLineEdit() - tolerance_line_edit.setValidator(QDoubleValidator()) tolerance_line_edit.setPlaceholderText("1e-8") tolerance_line_edit.setMaximumWidth(80) tolerance_line_edit.setToolTip("Press Enter to activate the new tolerance value") @@ -118,8 +117,17 @@ def update_isequal(self): try: tol_str = self.tolerance_line_edit.text() - tol = ast.literal_eval(tol_str) if tol_str else 0 - atol, rtol = (tol, 0) if self.tolerance_combobox.currentText() == "absolute" else (0, tol) + tol = float(tol_str) if tol_str else 0 + except ValueError as e: + # this is necessary to avoid having the error message twice, because we + # first show it here, which makes the tolerance_line_edit lose focus, + # which triggers its editingFinished signal, which calls update_isequal, + # which ends up here again if tol_str did not change in-between. + self.tolerance_line_edit.setText('') + tol = 0 + QMessageBox.critical(self, "Error", str(e)) + atol, rtol = (tol, 0) if self.tolerance_combobox.currentText() == "absolute" else (0, tol) + try: self.isequal = self.array.eq(self.array0, rtol=rtol, atol=atol, nans_equal=self.nans_equal) except TypeError: self.isequal = self.array == self.array0