From 1c239080494c7c5b5e1f38eade470844c70cdb28 Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Mon, 6 May 2019 22:08:24 -0400 Subject: [PATCH] preferences: fix sort order when moving an action out of the toolbar The sort() call is operating on objects that have no comparison functions and span multiple types, so they were always compared by their hash(). This resulted in adding an action, then removing it, causing the entire "Available Actions" box to be sorted seemingly at random. This was uncovered during python3 porting, as the objects cannot be compared at all and therefore return errors. The default sort order (before anything is done) is to sort based on pretty names, and therefore use this as the sort key when re-sorting. --- src/calibre/gui2/preferences/toolbar.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/preferences/toolbar.py b/src/calibre/gui2/preferences/toolbar.py index 43d3a62492..15108c321e 100644 --- a/src/calibre/gui2/preferences/toolbar.py +++ b/src/calibre/gui2/preferences/toolbar.py @@ -121,7 +121,7 @@ class AllModel(BaseModel): actions.append(self.name_to_action(name, self.gui)) self.beginResetModel() self._data.extend(actions) - self._data.sort() + self._data.sort(key=lambda x: x.action_spec[0] if hasattr(x, 'action_spec') else x.name) self.endResetModel() def remove(self, indices, allowed):