Skip to content

Commit

Permalink
Data info displayed in the status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
aturanjanin committed Feb 28, 2020
1 parent 4462394 commit 0abb160
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Orange/widgets/data/oweditdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand All @@ -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()

Expand Down Expand Up @@ -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

Expand All @@ -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 = []
Expand All @@ -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
Expand All @@ -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()
Expand Down
41 changes: 41 additions & 0 deletions Orange/widgets/data/tests/test_oweditdomain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 0abb160

Please sign in to comment.