Skip to content

Commit

Permalink
owtable: Do not resend outputs on subset input update
Browse files Browse the repository at this point in the history
  • Loading branch information
ales-erjavec committed Apr 14, 2023
1 parent c68949c commit e379aa8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
41 changes: 29 additions & 12 deletions Orange/widgets/data/owtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,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")
Expand Down Expand Up @@ -296,6 +298,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]):
Expand All @@ -305,25 +308,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."""
Expand Down Expand Up @@ -408,7 +424,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
Expand Down
9 changes: 7 additions & 2 deletions Orange/widgets/data/tests/test_owtable.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,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()
Expand All @@ -229,7 +231,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()
Expand Down

0 comments on commit e379aa8

Please sign in to comment.