Fix error when installing a new editor plugin because of web engine initialization

This commit is contained in:
Kovid Goyal 2019-09-09 15:20:05 +05:30
parent 1551df845c
commit 7198248ce9
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 24 additions and 3 deletions

View File

@ -459,8 +459,11 @@ class ConfigWidget(ConfigWidgetBase, Ui_Form):
def check_for_add_to_editor_toolbar(self, plugin, previously_installed): def check_for_add_to_editor_toolbar(self, plugin, previously_installed):
if not previously_installed: if not previously_installed:
from calibre.gui2.tweak_book.plugin import install_plugin from calibre.utils.config import JSONConfig
install_plugin(plugin) prefs = JSONConfig('newly-installed-editor-plugins')
pl = set(prefs.get('newly_installed_plugins', ()))
pl.add(plugin.name)
prefs['newly_installed_plugins'] = sorted(pl)
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -17,6 +17,7 @@ from PyQt5.Qt import (
from calibre import prints from calibre import prints
from calibre.constants import __appname__, get_version, isosx, DEBUG from calibre.constants import __appname__, get_version, isosx, DEBUG
from calibre.customize.ui import find_plugin
from calibre.gui2 import elided_text, open_url from calibre.gui2 import elided_text, open_url
from calibre.gui2.dbus_export.widgets import factory from calibre.gui2.dbus_export.widgets import factory
from calibre.gui2.keyboard import Manager as KeyboardManager from calibre.gui2.keyboard import Manager as KeyboardManager
@ -29,7 +30,7 @@ from calibre.gui2.tweak_book.job import BlockingJob
from calibre.gui2.tweak_book.boss import Boss from calibre.gui2.tweak_book.boss import Boss
from calibre.gui2.tweak_book.undo import CheckpointView from calibre.gui2.tweak_book.undo import CheckpointView
from calibre.gui2.tweak_book.preview import Preview from calibre.gui2.tweak_book.preview import Preview
from calibre.gui2.tweak_book.plugin import create_plugin_actions from calibre.gui2.tweak_book.plugin import create_plugin_actions, install_plugin
from calibre.gui2.tweak_book.search import SearchPanel from calibre.gui2.tweak_book.search import SearchPanel
from calibre.gui2.tweak_book.check import Check from calibre.gui2.tweak_book.check import Check
from calibre.gui2.tweak_book.check_links import CheckExternalLinks from calibre.gui2.tweak_book.check_links import CheckExternalLinks
@ -231,6 +232,18 @@ class CursorPositionWidget(QWidget): # {{{
# }}} # }}}
def install_new_plugins():
from calibre.utils.config import JSONConfig
prefs = JSONConfig('newly-installed-editor-plugins')
pl = prefs.get('newly_installed_plugins', ())
if pl:
for name in pl:
plugin = find_plugin(name)
if plugin is not None:
install_plugin(plugin)
prefs['newly_installed_plugins'] = []
class Main(MainWindow): class Main(MainWindow):
APP_NAME = _('Edit book') APP_NAME = _('Edit book')
@ -238,6 +251,11 @@ class Main(MainWindow):
def __init__(self, opts, notify=None): def __init__(self, opts, notify=None):
MainWindow.__init__(self, opts, disable_automatic_gc=True) MainWindow.__init__(self, opts, disable_automatic_gc=True)
try:
install_new_plugins()
except Exception:
import traceback
traceback.print_exc()
self.setWindowTitle(self.APP_NAME) self.setWindowTitle(self.APP_NAME)
self.boss = Boss(self, notify=notify) self.boss = Boss(self, notify=notify)
self.setWindowIcon(QIcon(I('tweak.png'))) self.setWindowIcon(QIcon(I('tweak.png')))