diff --git a/Orange/widgets/data/owcreateclass.py b/Orange/widgets/data/owcreateclass.py index 8dfe8cf651a..c62a9cf59f9 100644 --- a/Orange/widgets/data/owcreateclass.py +++ b/Orange/widgets/data/owcreateclass.py @@ -15,6 +15,7 @@ from Orange.widgets.settings import DomainContextHandler, ContextSetting from Orange.widgets.utils.itemmodels import DomainModel from Orange.widgets.utils.widgetpreview import WidgetPreview +from Orange.widgets.utils.state_summary import format_summary_details from Orange.widgets.widget import Msg, Input, Output @@ -225,6 +226,9 @@ def __init__(self): gui.button(box, self, "Apply", autoDefault=False, width=180, callback=self.apply) + self.info.set_input_summary(self.info.NoInput) + self.info.set_output_summary(self.info.NoOutput) + # TODO: Resizing upon changing the number of rules does not work self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Maximum) @@ -250,12 +254,16 @@ def set_data(self, data): self.closeContext() self.rules = {} self.data = data + summary = len(data) if data else self.info.NoInput + details = format_summary_details(data) if data else "" + self.info.set_input_summary(summary, details) model = self.controls.attribute.model() model.set_domain(data and data.domain) self.Warning.no_nonnumeric_vars(shown=data is not None and not model) if not model: self.attribute = None self.Outputs.data.send(None) + self.info.set_output_summary(self.info.NoOutput) return self.attribute = model[0] self.openContext(data) @@ -462,6 +470,7 @@ def apply(self): self.class_name = self.class_name.strip() if not self.attribute: self.Outputs.data.send(None) + self.info.set_output_summary(self.info.NoOutput) return domain = self.data.domain if not self.class_name: @@ -470,11 +479,15 @@ def apply(self): self.Error.class_name_duplicated() if not self.class_name or self.class_name in domain: self.Outputs.data.send(None) + self.info.set_output_summary(self.info.NoOutput) return new_class = self._create_variable() new_domain = Domain( domain.attributes, new_class, domain.metas + domain.class_vars) new_data = self.data.transform(new_domain) + summary = len(new_data) if new_data is not None else self.info.NoOutput + details = format_summary_details(new_data) if new_data is not None else "" + self.info.set_output_summary(summary, details) self.Outputs.data.send(new_data) def _create_variable(self): diff --git a/Orange/widgets/data/tests/test_owcreateclass.py b/Orange/widgets/data/tests/test_owcreateclass.py index 3957a38bb7a..bb32737c1ca 100644 --- a/Orange/widgets/data/tests/test_owcreateclass.py +++ b/Orange/widgets/data/tests/test_owcreateclass.py @@ -1,5 +1,5 @@ # Test methods with long descriptive names can omit docstrings -# pylint: disable=missing-docstring +# pylint: disable=missing-docstring, protected-access import unittest from unittest.mock import patch @@ -10,6 +10,7 @@ OWCreateClass, map_by_substring, ValueFromStringSubstring, ValueFromDiscreteSubstring) from Orange.widgets.tests.base import WidgetTest +from Orange.widgets.utils.state_summary import format_summary_details class TestHelpers(unittest.TestCase): @@ -405,6 +406,36 @@ def test_same_class(self): self.get_output(widget2.Outputs.data, widget=widget2).domain.class_var ) + def test_summary(self): + """Check if status bar is updated when data is received""" + data = self.zoo + info = self.widget.info + no_input, no_output = "No data on input", "No data on output" + + self.send_signal(self.widget.Inputs.data, data) + summary, details = f"{len(data)}", format_summary_details(data) + self.assertEqual(info._StateInfo__input_summary.brief, summary) + self.assertEqual(info._StateInfo__input_summary.details, details) + output = self.get_output(self.widget.Outputs.data) + summary, details = f"{len(output)}", format_summary_details(output) + self.assertEqual(info._StateInfo__output_summary.brief, summary) + self.assertEqual(info._StateInfo__output_summary.details, details) + + self.send_signal(self.widget.Inputs.data, data) + self.widget.class_name = "" + self.widget.apply() + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, no_output) + self.widget.class_name = "type" + self.widget.apply() + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, no_output) + + self.send_signal(self.widget.Inputs.data, None) + self.assertEqual(info._StateInfo__input_summary.brief, "") + self.assertEqual(info._StateInfo__input_summary.details, no_input) + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, no_output) if __name__ == "__main__": unittest.main()