diff --git a/Orange/widgets/gui.py b/Orange/widgets/gui.py index 75b45896586..ebae96e3acf 100644 --- a/Orange/widgets/gui.py +++ b/Orange/widgets/gui.py @@ -503,14 +503,14 @@ def __call__(self, *_): if isinstance(self.view.model(), QSortFilterProxyModel): selection = self.view.model().mapSelectionToSource(selection) values = [i.row() for i in selection.indexes()] - if values: - # FIXME: irrespective of PyListModel check, this might/should always - # callback with values! - if isinstance(self.model, PyListModel): - values = [self.model[i] for i in values] - if self.view.selectionMode() == self.view.SingleSelection: - values = values[0] - self.acyclic_setattr(values) + + # set attribute's values + if isinstance(self.model, PyListModel): + values = [self.model[i] for i in values] + if self.view.selectionMode() == self.view.SingleSelection: + assert len(values) <= 1 + values = values[0] if values else None + self.acyclic_setattr(values) class CallBackListBox: diff --git a/Orange/widgets/tests/test_gui.py b/Orange/widgets/tests/test_gui.py index 1d7d46b7325..6c385b7e975 100644 --- a/Orange/widgets/tests/test_gui.py +++ b/Orange/widgets/tests/test_gui.py @@ -1,3 +1,4 @@ +import unittest from unittest.mock import patch import numpy as np @@ -55,6 +56,10 @@ def test_select_callback(self): view.setCurrentIndex(self.attrs.index(1, 0)) self.assertEqual(widget.foo, [b]) + # unselect all + sel_model.clear() + self.assertEqual(widget.foo, []) + def test_select_callfront(self): widget = self.widget view = self.view @@ -129,3 +134,7 @@ def test_argsort(): test_array = np.array(["Bertha", "daniela", "ann", "Cecilia"]) assert_equal(func(test_array, Qt.AscendingOrder), [2, 0, 3, 1]) assert_equal(func(test_array, Qt.DescendingOrder), [1, 3, 0, 2]) + + +if __name__ == "__main__": + unittest.main()