From d096f176cf29e2b642aa1f5fc379365b6235ddec Mon Sep 17 00:00:00 2001 From: Ales Erjavec Date: Fri, 14 Apr 2023 14:27:20 +0200 Subject: [PATCH] owtable: Do not resend outputs on subset input update --- Orange/widgets/data/owtable.py | 41 ++++++++++++++++------- Orange/widgets/data/tests/test_owtable.py | 9 +++-- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Orange/widgets/data/owtable.py b/Orange/widgets/data/owtable.py index a5719c9b5e4..ec9bc9f5037 100644 --- a/Orange/widgets/data/owtable.py +++ b/Orange/widgets/data/owtable.py @@ -220,6 +220,8 @@ def __init__(self): self._subset_ids: Optional[set] = None self.__pending_selection: Optional[_Selection] = self.stored_selection self.__pending_sort: Optional[_Sorting] = self.stored_sort + self.__have_new_data = False + self.__have_new_subset = False self.dist_color = QColor(220, 220, 220, 255) info_box = gui.vBox(self.controlArea, "Info") @@ -297,6 +299,7 @@ def update(_): summary.len.add_done_callback(update) else: self.input = None + self.__have_new_data = True @Inputs.data_subset def set_subset_dataset(self, subset: Optional[Table]): @@ -306,25 +309,38 @@ def set_subset_dataset(self, subset: Optional[Table]): else: ids = None self._subset_ids = ids + self.__have_new_subset = True def handleNewSignals(self): super().handleNewSignals() self.Warning.non_sortable_input.clear() self.Warning.missing_sort_columns.clear() data: Optional[Table] = self.input.table if self.input else None - self._setup_table_view() - self._update_input_summary() + model = self.input.model if self.input else None + + if self.__have_new_data: + self._setup_table_view() + self._update_input_summary() + + if data is not None and self.__pending_sort is not None: + self.__restore_sort() - if data is not None and self.__pending_sort is not None: - self.__restore_sort() + if data is not None and self.__pending_selection is not None: + selection = self.__pending_selection + self.__pending_selection = None + rows = selection["rows"] + columns = selection["columns"] + self.set_selection(rows, columns) - if data is not None and self.__pending_selection is not None: - selection = self.__pending_selection - self.__pending_selection = None - rows = selection["rows"] - columns = selection["columns"] - self.set_selection(rows, columns) - self.commit.now() + if self.__have_new_subset and model is not None: + model.setSubsetRowIds(self._subset_ids or set()) + self.__have_new_subset = False + + self._setup_view_delegate() + + if self.__have_new_data: + self.commit.now() + self.__have_new_data = False def _setup_table_view(self): """Setup the view with current input data.""" @@ -409,7 +425,8 @@ def _on_distribution_color_changed(self): self._setup_view_delegate() def _setup_view_delegate(self): - assert self.input is not None + if self.input is None: + return model = self.input.model data = model.source class_var = data.domain.class_var diff --git a/Orange/widgets/data/tests/test_owtable.py b/Orange/widgets/data/tests/test_owtable.py index 9f9829354d7..251a0f2e5e9 100644 --- a/Orange/widgets/data/tests/test_owtable.py +++ b/Orange/widgets/data/tests/test_owtable.py @@ -202,7 +202,9 @@ def test_show_attribute_labels(self): def test_subset_input(self): w = self.widget self.send_signal(w.Inputs.data, self.data) - self.send_signal(w.Inputs.data_subset, self.data[[0, 1, 5]]) + with patch.object(w.signalManager, "send") as m: + self.send_signal(w.Inputs.data_subset, self.data[[0, 1, 5]]) + m.assert_not_called() w.view.grab() # cover delegate painting methods model = w.view.model() @@ -211,7 +213,10 @@ def test_subset_input(self): self.assertTrue(model.headerData(0, Qt.Vertical, model.SubsetRole)) self.assertFalse(model.headerData(2, Qt.Vertical, model.SubsetRole)) - self.send_signal(w.Inputs.data_subset, None) + with patch.object(w.signalManager, "send") as m: + self.send_signal(w.Inputs.data_subset, None) + m.assert_not_called() + w.view.grab() model = w.view.model()