Skip to content

Commit

Permalink
ListView - empty variable when all values unselected
Browse files Browse the repository at this point in the history
  • Loading branch information
PrimozGodec committed May 8, 2023
1 parent e35d172 commit 0a6165d
Showing 2 changed files with 17 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Orange/widgets/gui.py
Original file line number Diff line number Diff line change
@@ -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:
9 changes: 9 additions & 0 deletions Orange/widgets/tests/test_gui.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 0a6165d

Please sign in to comment.