From 7f4487d31896ae5e6b754b9212fdbcd8a01ad1ea Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 28 Feb 2025 16:06:42 +0530 Subject: [PATCH] Make sorting robust against tweak_fmt_order --- src/calibre/gui2/actions/tweak_epub.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/calibre/gui2/actions/tweak_epub.py b/src/calibre/gui2/actions/tweak_epub.py index 82f228c4a0..e13c6e3dc8 100644 --- a/src/calibre/gui2/actions/tweak_epub.py +++ b/src/calibre/gui2/actions/tweak_epub.py @@ -110,7 +110,12 @@ class TweakEpubAction(InterfaceActionWithLibraryDrop): tprefs.refresh() # In case they were changed in a Tweak Book process if len(tweakable_fmts) > 1: if tprefs['choose_tweak_fmt']: - d = Choose(title, sorted(tweakable_fmts, key=tprefs.defaults['tweak_fmt_order'].index), self.gui) + def index(x): + try: + return tprefs.defaults['tweak_fmt_order'].index(x) + except Exception: + return len(tprefs.defaults['tweak_fmt_order']) + d = Choose(title, sorted(tweakable_fmts, key=index), self.gui) if d.exec() != QDialog.DialogCode.Accepted: return tweakable_fmts = {d.fmt}