From 0abb16004532d21fe183b8c905fc8c4f7db57243 Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Wed, 26 Feb 2020 10:49:37 +0100 Subject: [PATCH] Data info displayed in the status bar --- Orange/widgets/data/oweditdomain.py | 14 +++++++ .../widgets/data/tests/test_oweditdomain.py | 41 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/Orange/widgets/data/oweditdomain.py b/Orange/widgets/data/oweditdomain.py index 015437d081e..c13a350752c 100644 --- a/Orange/widgets/data/oweditdomain.py +++ b/Orange/widgets/data/oweditdomain.py @@ -39,6 +39,7 @@ from Orange.widgets import widget, gui, settings from Orange.widgets.utils import itemmodels from Orange.widgets.utils.widgetpreview import WidgetPreview +from Orange.widgets.utils.state_summary import format_summary_details from Orange.widgets.widget import Input, Output ndarray = np.ndarray # pylint: disable=invalid-name @@ -1606,6 +1607,9 @@ def __init__(self): mainlayout.addWidget(bbox) self.variables_view.setFocus(Qt.NoFocusReason) # initial focus + self.info.set_input_summary(self.info.NoInput) + self.info.set_output_summary(self.info.NoOutput) + @Inputs.data def set_data(self, data): """Set input dataset.""" @@ -1614,9 +1618,13 @@ def set_data(self, data): self.data = data if self.data is not None: + self.info.set_input_summary(len(data), + format_summary_details(data)) self.setup_model(data) self.openContext(self.data) self._restore() + else: + self.info.set_input_summary(self.info.NoInput) self.commit() @@ -1796,6 +1804,7 @@ def commit(self): data = self.data if data is None: self.Outputs.data.send(None) + self.info.set_output_summary(self.info.NoOutput) return model = self.variables_model @@ -1808,6 +1817,8 @@ def state(i): state = [state(i) for i in range(model.rowCount())] if all(tr is None or not tr for _, tr in state): self.Outputs.data.send(data) + self.info.set_output_summary(len(data), + format_summary_details(data)) return output_vars = [] @@ -1824,6 +1835,7 @@ def state(i): if len(output_vars) != len({v.name for v in output_vars}): self.Error.duplicate_var_name() self.Outputs.data.send(None) + self.info.set_output_summary(self.info.NoOutput) return domain = data.domain @@ -1840,6 +1852,8 @@ def state(i): domain = Orange.data.Domain(Xs, Ys, Ms) new_data = data.transform(domain) self.Outputs.data.send(new_data) + self.info.set_output_summary(len(new_data), + format_summary_details(new_data)) def sizeHint(self): sh = super().sizeHint() diff --git a/Orange/widgets/data/tests/test_oweditdomain.py b/Orange/widgets/data/tests/test_oweditdomain.py index 79c0d29f728..51ff26c2af0 100644 --- a/Orange/widgets/data/tests/test_oweditdomain.py +++ b/Orange/widgets/data/tests/test_oweditdomain.py @@ -3,6 +3,7 @@ import pickle from itertools import product from unittest import TestCase +from unittest.mock import Mock import numpy as np from numpy.testing import assert_array_equal @@ -35,6 +36,7 @@ from Orange.widgets.data.owcolor import OWColor, ColorRole from Orange.widgets.tests.base import WidgetTest, GuiTest from Orange.tests import test_filename, assert_array_nanequal +from Orange.widgets.utils.state_summary import format_summary_details MArray = np.ma.MaskedArray @@ -244,6 +246,45 @@ def restore(state): tr = model.data(model.index(4), TransformRole) self.assertEqual(tr, [AsString(), Rename("Z")]) + def test_summary(self): + """Check if status bar is updated when data is received""" + data = Table("iris") + input_sum = self.widget.info.set_input_summary = Mock() + output_sum = self.widget.info.set_output_summary = Mock() + + self.send_signal(self.widget.Inputs.data, data) + input_sum.assert_called_with(len(data), format_summary_details(data)) + output = self.get_output(self.widget.Outputs.data) + output_sum.assert_called_with(len(output), + format_summary_details(output)) + + def enter_text(widget, text): + # type: (QLineEdit, str) -> None + widget.selectAll() + QTest.keyClick(widget, Qt.Key_Delete) + QTest.keyClicks(widget, text) + QTest.keyClick(widget, Qt.Key_Return) + + editor = self.widget.findChild(ContinuousVariableEditor) + enter_text(editor.name_edit, "sepal height") + self.widget.commit() + output = self.get_output(self.widget.Outputs.data) + output_sum.assert_called_with(len(output), + format_summary_details(output)) + output_sum.reset_mock() + enter_text(editor.name_edit, "sepal width") + self.widget.commit() + output_sum.assert_called_once() + self.assertEqual(output_sum.call_args[0][0].brief, "") + + input_sum.reset_mock() + output_sum.reset_mock() + self.send_signal(self.widget.Inputs.data, None) + input_sum.assert_called_once() + self.assertEqual(input_sum.call_args[0][0].brief, "") + output_sum.assert_called_once() + self.assertEqual(output_sum.call_args[0][0].brief, "") + class TestEditors(GuiTest): def test_variable_editor(self):