diff --git a/src/calibre/gui2/preferences/__init__.py b/src/calibre/gui2/preferences/__init__.py index ee882f2d9e..dcf38c2a43 100644 --- a/src/calibre/gui2/preferences/__init__.py +++ b/src/calibre/gui2/preferences/__init__.py @@ -59,7 +59,8 @@ class ConfigWidgetInterface(object): def initialize(self): ''' Should set all config values to their initial values (the values - stored in the config files). + stored in the config files). A "return" statement is optional. Return + False if the dialog is not to be shown. ''' raise NotImplementedError() diff --git a/src/calibre/gui2/preferences/main.py b/src/calibre/gui2/preferences/main.py index dbd74e8afa..1245f19f52 100644 --- a/src/calibre/gui2/preferences/main.py +++ b/src/calibre/gui2/preferences/main.py @@ -310,7 +310,9 @@ class Preferences(QDialog): def show_plugin(self, plugin): self.showing_widget = plugin.create_widget(self.scroll_area) self.showing_widget.genesis(self.gui) - self.showing_widget.initialize() + x = self.showing_widget.initialize() + if isinstance(x, bool) and not x: + return self.set_tooltips_for_labels() self.scroll_area.setWidget(self.showing_widget) self.stack.setCurrentIndex(1) diff --git a/src/calibre/gui2/preferences/template_functions.py b/src/calibre/gui2/preferences/template_functions.py index 0c5fcfe036..45bcbcdfe2 100644 --- a/src/calibre/gui2/preferences/template_functions.py +++ b/src/calibre/gui2/preferences/template_functions.py @@ -5,7 +5,7 @@ import copy, json, traceback from qt.core import QDialogButtonBox, QDialog -from calibre.gui2 import error_dialog, warning_dialog +from calibre.gui2 import error_dialog, warning_dialog, question_dialog from calibre.gui2.dialogs.template_dialog import TemplateDialog from calibre.gui2.preferences import ConfigWidgetBase, test_widget from calibre.gui2.preferences.template_functions_ui import Ui_Form @@ -149,9 +149,20 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form): self.builtins = formatter_functions().get_builtins_and_aliases() self.st_funcs = {} - for v in self.db.prefs.get('user_template_functions', []): - if not function_pref_is_python(v): - self.st_funcs.update({function_pref_name(v):compile_user_function(*v)}) + try: + for v in self.db.prefs.get('user_template_functions', []): + if not function_pref_is_python(v): + self.st_funcs.update({function_pref_name(v):compile_user_function(*v)}) + except: + ans = question_dialog(self, _('Template functions'), + _('The template functions saved in the library are corrupt. ' + "Do you want to delete them? Answering 'Yes' will delete all " + "the functions."), det_msg=traceback.format_exc(), + show_copy_button=True) + if ans: + print('remove the preference') + self.db.prefs['user_template_functions'] = [] + return False self.build_function_names_box() self.function_name.currentIndexChanged[native_string_type].connect(self.function_index_changed)