From 25c0b827c4e7332663f06ba9d2454ca4ed04ae6f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sun, 9 Oct 2022 20:23:07 +0530 Subject: [PATCH] E-book viewer: Fix a regression that broke adding of new lookup sources. Fixes #1992278 [Could not add extra lookup sources](https://bugs.launchpad.net/calibre/+bug/1992278) --- src/calibre/gui2/viewer/lookup.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/calibre/gui2/viewer/lookup.py b/src/calibre/gui2/viewer/lookup.py index e1f54f6e86..51d4f7ee33 100644 --- a/src/calibre/gui2/viewer/lookup.py +++ b/src/calibre/gui2/viewer/lookup.py @@ -32,6 +32,15 @@ def lookup_lang(): return ans +special_processors = {} + + +def special_processor(func): + special_processors[func.__name__] = func + return func + + +@special_processor def google_dictionary(word): ans = f'https://www.google.com/search?q=define:{word}' lang = lookup_lang() @@ -44,7 +53,7 @@ vprefs.defaults['lookup_locations'] = [ { 'name': 'Google dictionary', 'url': 'https://www.google.com/search?q=define:{word}', - 'special_processor': google_dictionary, + 'special_processor': 'google_dictionary', 'langs': [], }, @@ -393,7 +402,7 @@ class Lookup(QWidget): def special_processor(self): idx = self.source_box.currentIndex() if idx > -1: - return self.source_box.itemData(idx).get('special_processor') + return special_processors.get(self.source_box.itemData(idx).get('special_processor')) @property def query_is_up_to_date(self):