From 92a47c799a602c3db614f6988326519e9491370f Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Mon, 30 Mar 2020 16:44:06 +0200 Subject: [PATCH] OWSelectByDataIndex: data info displayed in the status bar --- Orange/widgets/data/owselectbydataindex.py | 24 ++++++++++ .../data/tests/test_owselectbydataindex.py | 46 +++++++++++++++++++ 2 files changed, 70 insertions(+) diff --git a/Orange/widgets/data/owselectbydataindex.py b/Orange/widgets/data/owselectbydataindex.py index 1fc97744d1c..fec3da6fe84 100644 --- a/Orange/widgets/data/owselectbydataindex.py +++ b/Orange/widgets/data/owselectbydataindex.py @@ -1,10 +1,14 @@ import numpy as np +from AnyQt.QtCore import Qt + from Orange.data import Table from Orange.widgets import widget, gui from Orange.widgets.utils import itemmodels from Orange.widgets.utils.sql import check_sql_input from Orange.widgets.utils.widgetpreview import WidgetPreview +from Orange.widgets.utils.state_summary import format_summary_details, \ + format_multiple_summaries from Orange.widgets.widget import Input, Output from Orange.widgets.utils.annotated_data import (create_annotated_table) @@ -49,6 +53,9 @@ def __init__(self): self.infoBoxExtraData = gui.label( box, self, self.data_info_text(None), box="Data Subset") + self.info.set_input_summary(self.info.NoInput) + self.info.set_output_summary(self.info.NoOutput) + @Inputs.data @check_sql_input def set_data(self, data): @@ -62,6 +69,19 @@ def set_data_subset(self, data): self.infoBoxExtraData.setText(self.data_info_text(data)) def handleNewSignals(self): + summary, details, kwargs = self.info.NoInput, "", {} + if self.data or self.data_subset: + n_data = len(self.data) if self.data else 0 + n_data_subset = len(self.data_subset) if self.data_subset else 0 + summary = f"{self.info.format_number(n_data)}, " \ + f"{self.info.format_number(n_data_subset)}" + kwargs = {"format": Qt.RichText} + details = format_multiple_summaries([ + ("Data", self.data), + ("Data subset", self.data_subset) + ]) + self.info.set_input_summary(summary, details, **kwargs) + self._invalidate() @staticmethod @@ -89,6 +109,10 @@ def commit(self): matching_output = self.data[row_sel] non_matching_output = self.data[~row_sel] annotated_output = create_annotated_table(self.data, row_sel) + + summary = self.info.NoOutput if matching_output is None else len(matching_output) + details = "" if matching_output is None else format_summary_details(matching_output) + self.info.set_output_summary(summary, details) self.Outputs.matching_data.send(matching_output) self.Outputs.non_matching_data.send(non_matching_output) self.Outputs.annotated_data.send(annotated_output) diff --git a/Orange/widgets/data/tests/test_owselectbydataindex.py b/Orange/widgets/data/tests/test_owselectbydataindex.py index 6505c8fed75..83a23a369a4 100644 --- a/Orange/widgets/data/tests/test_owselectbydataindex.py +++ b/Orange/widgets/data/tests/test_owselectbydataindex.py @@ -1,7 +1,10 @@ +# pylint: disable=protected-access from Orange.data import Table, Domain from Orange.widgets.data.owselectbydataindex import OWSelectByDataIndex from Orange.widgets.tests.base import WidgetTest from Orange.widgets.utils.annotated_data import ANNOTATED_DATA_FEATURE_NAME +from Orange.widgets.utils.state_summary import format_summary_details, \ + format_multiple_summaries class TestOWSelectSubset(WidgetTest): @@ -43,3 +46,46 @@ def test_subset_nosubset(self): self.assertTrue(self.widget.Warning.instances_not_matching.is_shown()) self.assertEqual([], list(matching)) self.assertEqual(list(data), list(non_matching)) + + def test_summary(self): + """Check if the status bar is updated when data is received""" + data = Table("iris") + info = self.widget.info + NoInput, NoOutput = "No data on input", "No data on output" + self.assertEqual(info._StateInfo__input_summary.brief, "") + self.assertEqual(info._StateInfo__input_summary.details, NoInput) + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, NoOutput) + + self.send_signal(self.widget.Inputs.data, data) + data_list = [("Data", data), ("Data subset", None)] + summary, details = f"{len(data)}, 0", format_multiple_summaries(data_list) + self.assertEqual(info._StateInfo__input_summary.brief, summary) + self.assertEqual(info._StateInfo__input_summary.details, details) + self.assertEqual(info._StateInfo__output_summary.brief, "0") + + self.send_signal(self.widget.Inputs.data_subset, data) + data_list = [("Data", data), ("Data subset", data)] + summary = f"{len(data)}, {len(data)}" + details = format_multiple_summaries(data_list) + self.assertEqual(info._StateInfo__input_summary.brief, summary) + self.assertEqual(info._StateInfo__input_summary.details, details) + output = self.get_output(self.widget.Outputs.matching_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, None) + data_list = [("Data", None), ("Data subset", data)] + summary, details = f"0, {len(data)}", format_multiple_summaries( + data_list) + self.assertEqual(info._StateInfo__input_summary.brief, summary) + self.assertEqual(info._StateInfo__input_summary.details, details) + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, NoOutput) + + self.send_signal(self.widget.Inputs.data_subset, None) + self.assertEqual(info._StateInfo__input_summary.brief, "") + self.assertEqual(info._StateInfo__input_summary.details, NoInput) + self.assertEqual(info._StateInfo__output_summary.brief, "") + self.assertEqual(info._StateInfo__output_summary.details, NoOutput)