Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] OWColor: Data info displayed in the status bar #4501

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Orange/widgets/data/owcolor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from Orange.widgets.gui import HorizontalGridDelegate
from Orange.widgets.utils import itemmodels, colorpalettes
from Orange.widgets.utils.widgetpreview import WidgetPreview
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.widget import Input, Output
from orangewidget.settings import IncompatibleContext

Expand Down Expand Up @@ -458,6 +459,9 @@ def __init__(self):
box.button.setFixedWidth(180)
box.layout().insertStretch(0)

self.info.set_input_summary(self.info.NoInput)
self.info.set_output_summary(self.info.NoOutput)

@staticmethod
def sizeHint(): # pragma: no cover
return QSize(500, 570)
Expand All @@ -469,8 +473,10 @@ def set_data(self, data):
self.cont_descs = []
if data is None:
self.data = self.domain = None
self.info.set_input_summary(self.info.NoInput)
else:
self.data = data
self.info.set_input_summary(len(data), format_summary_details(data))
for var in chain(data.domain.variables, data.domain.metas):
if var.is_discrete:
self.disc_descs.append(DiscAttrDesc(var))
Expand Down Expand Up @@ -498,6 +504,7 @@ def make(variables):

if self.data is None:
self.Outputs.data.send(None)
self.info.set_output_summary(self.info.NoOutput)
return

disc_dict = {desc.var.name: desc for desc in self.disc_descs}
Expand All @@ -507,6 +514,8 @@ def make(variables):
new_domain = Orange.data.Domain(
make(dom.attributes), make(dom.class_vars), make(dom.metas))
new_data = self.data.transform(new_domain)
self.info.set_output_summary(len(new_data),
format_summary_details(new_data))
self.Outputs.data.send(new_data)

def send_report(self):
Expand Down
22 changes: 21 additions & 1 deletion Orange/widgets/data/tests/test_owcolor.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Test methods with long descriptive names can omit docstrings
# pylint: disable=missing-docstring, protected-access
# pylint: disable=missing-docstring, protected-access,unsubscriptable-object
import unittest
from unittest.mock import patch, Mock

Expand All @@ -10,6 +10,7 @@
from Orange.data import Table, ContinuousVariable, DiscreteVariable, Domain
from Orange.util import color_to_hex
from Orange.widgets.utils import colorpalettes
from Orange.widgets.utils.state_summary import format_summary_details
from Orange.widgets.data import owcolor
from Orange.widgets.data.owcolor import ColorRole
from Orange.widgets.tests.base import WidgetTest
Expand Down Expand Up @@ -483,6 +484,25 @@ def test_report(self):
def test_string_variables(self):
self.send_signal(self.widget.Inputs.data, Table("zoo"))

def test_summary(self):
"""Check if the status bar is updated when data is received"""
data = self.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))
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, "")


if __name__ == "__main__":
unittest.main()