From 68a4b0910a155826e89e06cc51c104a249bb428c Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 16 Mar 2017 20:46:15 -0500 Subject: [PATCH 1/6] Adds missing parameter for format when copying in the arrayeditor. --- spyder/widgets/variableexplorer/arrayeditor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py index a937247132b..c5c3e687dc5 100644 --- a/spyder/widgets/variableexplorer/arrayeditor.py +++ b/spyder/widgets/variableexplorer/arrayeditor.py @@ -390,7 +390,6 @@ class ArrayView(QTableView): """Array view class""" def __init__(self, parent, model, dtype, shape): QTableView.__init__(self, parent) - self.setModel(model) self.setItemDelegate(ArrayDelegate(dtype, self)) total_width = 0 @@ -492,7 +491,7 @@ def _sel_to_text(self, cell_range): output = io.StringIO() try: np.savetxt(output, _data[row_min:row_max+1, col_min:col_max+1], - delimiter='\t') + delimiter='\t', fmt=self.model().get_format()) except: QMessageBox.warning(self, _("Warning"), _("It was not possible to copy values for " From 17d62a251c6dde71fa0af986d9724cbfd78521ff Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 16 Mar 2017 20:53:08 -0500 Subject: [PATCH 2/6] Restore line. --- spyder/widgets/variableexplorer/arrayeditor.py | 1 + 1 file changed, 1 insertion(+) diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py index c5c3e687dc5..4f7c30c795d 100644 --- a/spyder/widgets/variableexplorer/arrayeditor.py +++ b/spyder/widgets/variableexplorer/arrayeditor.py @@ -390,6 +390,7 @@ class ArrayView(QTableView): """Array view class""" def __init__(self, parent, model, dtype, shape): QTableView.__init__(self, parent) + self.setModel(model) self.setItemDelegate(ArrayDelegate(dtype, self)) total_width = 0 From 31a65cabcbfeb34b240e99c7a2de811f57e15d60 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Thu, 16 Mar 2017 20:59:25 -0500 Subject: [PATCH 3/6] Adds import for QKeySequence. --- spyder/widgets/variableexplorer/arrayeditor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/arrayeditor.py b/spyder/widgets/variableexplorer/arrayeditor.py index 4f7c30c795d..0e9c68bca3f 100644 --- a/spyder/widgets/variableexplorer/arrayeditor.py +++ b/spyder/widgets/variableexplorer/arrayeditor.py @@ -20,7 +20,7 @@ from qtpy.compat import from_qvariant, to_qvariant from qtpy.QtCore import (QAbstractTableModel, QItemSelection, QItemSelectionRange, QModelIndex, Qt, Slot) -from qtpy.QtGui import QColor, QCursor, QDoubleValidator +from qtpy.QtGui import QColor, QCursor, QDoubleValidator, QKeySequence from qtpy.QtWidgets import (QAbstractItemDelegate, QApplication, QCheckBox, QComboBox, QDialog, QDialogButtonBox, QGridLayout, QHBoxLayout, QInputDialog, QItemDelegate, QLabel, From 01f6aaee68b46dc9a3817f8ad0306ba2316b33de Mon Sep 17 00:00:00 2001 From: dalthviz Date: Sat, 18 Mar 2017 12:40:37 -0500 Subject: [PATCH 4/6] Initial test for arrayeditor format and key events. --- .../tests/test_arrayeditor.py | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index f0cf65dea7d..e7e27806720 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -14,9 +14,10 @@ import numpy as np from numpy.testing import assert_array_equal import pytest +from qtpy.QtCore import Qt +from qtpy.QtWidgets import QApplication # Local imports -from spyder.utils.qthelpers import qapplication from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor @@ -28,9 +29,33 @@ def launch_arrayeditor(data, title="", xlabels=None, ylabels=None): dlg.accept() # trigger slot connected to OK button return dlg.get_value() +def setup_arrayeditor(qbot, data, title="", xlabels=None, ylabels=None): + """Setups an arrayeditor.""" + dlg = ArrayEditor() + dlg.setup_and_check(data, title, xlabels=xlabels, ylabels=ylabels) + dlg.show() + qbot.addWidget(dlg) + return dlg # --- Tests # ----------------------------------------------------------------------------- +def test_arrayeditor_format(qtbot): + """Changes the format of the array and validates its selected content.""" + arr = np.array([1, 2, 3], dtype=np.float32) + dlg = setup_arrayeditor(qtbot, arr, "test array float32") + qtbot.waitForWindowShown(dlg) + qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) + qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) + contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes()) + assert contents == "1.000\n2.000\n3.000\n" + dlg.arraywidget.view.model().set_format("%.18e") + assert dlg.arraywidget.view.model().get_format() == "%.18e" + qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) + qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) + contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes()) + assert contents == "1.000000000000000000e+00\n2.000000000000000000e+00\n" + + def test_arrayeditor_with_string_array(qtbot): arr = np.array(["kjrekrjkejr"]) assert arr == launch_arrayeditor(arr, "string array") From 870818461e1e8da5d7f5ccdbb5ff99566d2a484f Mon Sep 17 00:00:00 2001 From: dalthviz Date: Sat, 18 Mar 2017 12:46:11 -0500 Subject: [PATCH 5/6] Deletes unused import. --- spyder/widgets/variableexplorer/tests/test_arrayeditor.py | 1 - 1 file changed, 1 deletion(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index e7e27806720..23cdf461090 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -15,7 +15,6 @@ from numpy.testing import assert_array_equal import pytest from qtpy.QtCore import Qt -from qtpy.QtWidgets import QApplication # Local imports from spyder.widgets.variableexplorer.arrayeditor import ArrayEditor From 653946c1d8d2ae7a49dad66165954610110fb4b5 Mon Sep 17 00:00:00 2001 From: dalthviz Date: Sat, 18 Mar 2017 13:14:37 -0500 Subject: [PATCH 6/6] Test fixes. --- spyder/widgets/variableexplorer/tests/test_arrayeditor.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py index 23cdf461090..88dd3897110 100644 --- a/spyder/widgets/variableexplorer/tests/test_arrayeditor.py +++ b/spyder/widgets/variableexplorer/tests/test_arrayeditor.py @@ -42,11 +42,10 @@ def test_arrayeditor_format(qtbot): """Changes the format of the array and validates its selected content.""" arr = np.array([1, 2, 3], dtype=np.float32) dlg = setup_arrayeditor(qtbot, arr, "test array float32") - qtbot.waitForWindowShown(dlg) qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier) contents = dlg.arraywidget.view._sel_to_text(dlg.arraywidget.view.selectedIndexes()) - assert contents == "1.000\n2.000\n3.000\n" + assert contents == "1.000\n2.000\n" dlg.arraywidget.view.model().set_format("%.18e") assert dlg.arraywidget.view.model().get_format() == "%.18e" qtbot.keyClick(dlg.arraywidget.view, Qt.Key_Down, modifier=Qt.ShiftModifier)