mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Bug #1928548: Error opening template functions preference. Part of a fix, ensuring that the exception doesn't leave the ghost dialog.
This commit is contained in:
parent
ed62171495
commit
54ea660722
@ -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()
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user