Skip to content

Commit

Permalink
owfile: sort reader combo per source package and name
Browse files Browse the repository at this point in the history
  • Loading branch information
markotoplak committed Jan 5, 2022
1 parent 37127ed commit 0c712f8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
13 changes: 12 additions & 1 deletion Orange/widgets/data/owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,19 @@ def __init__(self):
readers = [f for f in FileFormat.formats
if getattr(f, 'read', None)
and getattr(f, "EXTENSIONS", None)]

def group_readers_per_addon_key(w):
# readers from Orange.data.io should go first
def package(w):
package = w.qualified_name().split(".")[:-1]
package = package[:2]
if ".".join(package) == "Orange.data":
return ["0"] # force "Orange" to come first
return package
return package(w), w.DESCRIPTION

self.available_readers = sorted(set(readers),
key=lambda w: (w.PRIORITY, w.DESCRIPTION))
key=group_readers_per_addon_key)

layout = QGridLayout()
layout.setSpacing(4)
Expand Down
6 changes: 5 additions & 1 deletion Orange/widgets/data/tests/test_owfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,11 @@ def test_select_reader(self):
self.assertEqual(self.widget.reader, None)

# select the tab reader
self.widget.reader_combo.activated.emit(1)
for i in range(len_with_qname):
text = self.widget.reader_combo.itemText(i)
if text.startswith("Tab-separated"):
break
self.widget.reader_combo.activated.emit(i)
self.assertEqual(len(self.widget.reader_combo), len_with_qname - 1)
self.assertTrue(self.widget.reader_combo.currentText().startswith("Tab-separated"))
self.assertIsInstance(self.widget.reader, TabReader)
Expand Down

0 comments on commit 0c712f8

Please sign in to comment.