From 1ca1db53594b04d013e46b6a44a62b385f549258 Mon Sep 17 00:00:00 2001 From: Aleksandra Date: Wed, 26 Feb 2020 10:22:14 +0100 Subject: [PATCH] Data info displayed in the status bar --- Orange/widgets/data/owcorrelations.py | 15 ++++++++++-- .../widgets/data/tests/test_owcorrelations.py | 23 ++++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/Orange/widgets/data/owcorrelations.py b/Orange/widgets/data/owcorrelations.py index cb8940a481f..2564b68664d 100644 --- a/Orange/widgets/data/owcorrelations.py +++ b/Orange/widgets/data/owcorrelations.py @@ -25,6 +25,7 @@ from Orange.widgets.utils.itemmodels import DomainModel from Orange.widgets.utils.signals import Input, Output from Orange.widgets.utils.widgetpreview import WidgetPreview +from Orange.widgets.utils.state_summary import format_summary_details from Orange.widgets.visualize.utils import VizRankDialogAttrPair from Orange.widgets.widget import OWWidget, AttributeList, Msg @@ -292,6 +293,9 @@ def __init__(self): button_box = gui.hBox(self.mainArea) button_box.layout().addWidget(self.vizrank.button) + self.info.set_input_summary(self.info.NoInput) + self.info.set_output_summary(self.info.NoOutput) + @staticmethod def sizeHint(): return QSize(350, 400) @@ -358,6 +362,10 @@ def set_data(self, data): self.Warning.not_enough_vars() else: self.cont_data = SklImpute()(cont_data) + self.info.set_input_summary(len(data), + format_summary_details(data)) + else: + self.info.set_input_summary(self.info.NoInput) self.set_feature_model() self.openContext(self.cont_data) self.apply() @@ -380,8 +388,12 @@ def apply(self): self.commit() def commit(self): + self.Outputs.data.send(self.data) + summary = len(self.data) if self.data else self.info.NoOutput + details = format_summary_details(self.data) if self.data else "" + self.info.set_output_summary(summary, details) + if self.data is None or self.cont_data is None: - self.Outputs.data.send(self.data) self.Outputs.features.send(None) self.Outputs.correlations.send(None) return @@ -401,7 +413,6 @@ def commit(self): corr_table = Table(domain, x, metas=m) corr_table.name = "Correlations" - self.Outputs.data.send(self.data) # data has been imputed; send original attributes self.Outputs.features.send(AttributeList( [self.data.domain[name] for name, _ in self.selection])) diff --git a/Orange/widgets/data/tests/test_owcorrelations.py b/Orange/widgets/data/tests/test_owcorrelations.py index c7350a49bcb..9ca33cfdcce 100644 --- a/Orange/widgets/data/tests/test_owcorrelations.py +++ b/Orange/widgets/data/tests/test_owcorrelations.py @@ -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 time import unittest from unittest.mock import patch, Mock @@ -19,6 +19,7 @@ from Orange.widgets.tests.utils import simulate from Orange.widgets.visualize.owscatterplot import OWScatterPlot from Orange.widgets.widget import AttributeList +from Orange.widgets.utils.state_summary import format_summary_details class TestOWCorrelations(WidgetTest): @@ -301,6 +302,26 @@ def test_send_report(self): self.send_signal(self.widget.Inputs.data, None) self.widget.report_button.click() + 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)) + + 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 TestCorrelationRank(WidgetTest): @classmethod