Remove more uses of the plugins dict

This commit is contained in:
Kovid Goyal 2020-10-18 11:42:15 +05:30
parent 4d47176100
commit c41a389437
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
9 changed files with 93 additions and 94 deletions

View File

@ -5,23 +5,24 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import re, textwrap import re
import textwrap
from bisect import bisect from bisect import bisect
from functools import partial from functools import partial
from PyQt5.Qt import ( from PyQt5.Qt import (
QAbstractItemModel, QModelIndex, Qt, pyqtSignal, QApplication, QHBoxLayout, QAbstractItemModel, QAbstractListModel, QApplication, QCheckBox, QGridLayout,
QTreeView, QSize, QGridLayout, QAbstractListModel, QListView, QPen, QMenu, QHBoxLayout, QIcon, QInputMethodEvent, QLabel, QListView, QMenu, QMimeData,
QStyledItemDelegate, QSplitter, QLabel, QSizePolicy, QIcon, QMimeData, QModelIndex, QPen, QPushButton, QSize, QSizePolicy, QSplitter,
QPushButton, QToolButton, QInputMethodEvent, QCheckBox) QStyledItemDelegate, Qt, QToolButton, QTreeView, pyqtSignal
)
from calibre.constants import plugins
from calibre.gui2.widgets2 import HistoryLineEdit2
from calibre.gui2.tweak_book import tprefs from calibre.gui2.tweak_book import tprefs
from calibre.gui2.tweak_book.widgets import Dialog, BusyCursor from calibre.gui2.tweak_book.widgets import BusyCursor, Dialog
from calibre.gui2.widgets2 import HistoryLineEdit2
from calibre.utils.icu import safe_chr as codepoint_to_chr from calibre.utils.icu import safe_chr as codepoint_to_chr
from calibre.utils.unicode_names import character_name_from_code, points_for_word from calibre.utils.unicode_names import character_name_from_code, points_for_word
from polyglot.builtins import unicode_type, range, map from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.builtins import map, range, unicode_type
ROOT = QModelIndex() ROOT = QModelIndex()
@ -459,9 +460,7 @@ class CategoryView(QTreeView):
self.setAnimated(True) self.setAnimated(True)
self.activated.connect(self.item_activated) self.activated.connect(self.item_activated)
self.clicked.connect(self.item_activated) self.clicked.connect(self.item_activated)
pi = plugins['progress_indicator'][0] set_no_activate_on_click(self)
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self)
self.initialized = False self.initialized = False
self.setExpandsOnDoubleClick(False) self.setExpandsOnDoubleClick(False)
@ -600,9 +599,7 @@ class CharView(QListView):
self.setContextMenuPolicy(Qt.CustomContextMenu) self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.context_menu) self.customContextMenuRequested.connect(self.context_menu)
self.showing_favorites = False self.showing_favorites = False
pi = plugins['progress_indicator'][0] set_no_activate_on_click(self)
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self)
self.activated.connect(self.item_activated) self.activated.connect(self.item_activated)
self.clicked.connect(self.item_activated) self.clicked.connect(self.item_activated)

View File

@ -5,16 +5,11 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
from calibre.constants import plugins
def load_patience_module(): def load_patience_module():
p, err = plugins['_patiencediff_c'] from calibre_extensions import _patiencediff_c
if err: return _patiencediff_c
raise ImportError('Failed to import the PatienceDiff C module with error: %r' % err)
return p
def get_sequence_matcher(): def get_sequence_matcher():
return load_patience_module().PatienceSequenceMatcher_c return load_patience_module().PatienceSequenceMatcher_c

View File

@ -6,21 +6,24 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
import re import re
from functools import partial
from collections import namedtuple from collections import namedtuple
from functools import partial
from PyQt5.Qt import QFont, QTextBlockUserData, QTextCharFormat from PyQt5.Qt import QFont, QTextBlockUserData, QTextCharFormat
from calibre.ebooks.oeb.polish.spell import html_spell_tags, xml_spell_tags, patterns from calibre.ebooks.oeb.polish.spell import html_spell_tags, patterns, xml_spell_tags
from calibre.spell.dictionary import parse_lang_code
from calibre.spell.break_iterator import split_into_words_and_positions
from calibre.gui2.tweak_book import dictionaries, tprefs, verify_link from calibre.gui2.tweak_book import dictionaries, tprefs, verify_link
from calibre.gui2.tweak_book.editor import ( from calibre.gui2.tweak_book.editor import (
syntax_text_char_format, SPELL_PROPERTY, SPELL_LOCALE_PROPERTY, CLASS_ATTRIBUTE_PROPERTY, LINK_PROPERTY, SPELL_LOCALE_PROPERTY, SPELL_PROPERTY,
store_locale, LINK_PROPERTY, TAG_NAME_PROPERTY, CLASS_ATTRIBUTE_PROPERTY) TAG_NAME_PROPERTY, store_locale, syntax_text_char_format
)
from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter, run_loop from calibre.gui2.tweak_book.editor.syntax.base import SyntaxHighlighter, run_loop
from calibre.gui2.tweak_book.editor.syntax.css import ( from calibre.gui2.tweak_book.editor.syntax.css import (
create_formats as create_css_formats, state_map as css_state_map, CSSState, CSSUserData) CSSState, CSSUserData, create_formats as create_css_formats,
state_map as css_state_map
)
from calibre.spell.break_iterator import split_into_words_and_positions
from calibre.spell.dictionary import parse_lang_code
from calibre_extensions import html_syntax_highlighter as _speedup
from polyglot.builtins import iteritems from polyglot.builtins import iteritems
cdata_tags = frozenset(['title', 'textarea', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes', 'noscript']) cdata_tags = frozenset(['title', 'textarea', 'style', 'script', 'xmp', 'iframe', 'noembed', 'noframes', 'noscript'])
@ -62,9 +65,6 @@ def refresh_spell_check_status():
do_spell_check = tprefs['inline_spell_check'] and hasattr(dictionaries, 'active_user_dictionaries') do_spell_check = tprefs['inline_spell_check'] and hasattr(dictionaries, 'active_user_dictionaries')
from calibre.constants import plugins
_speedup = plugins['html_syntax_highlighter'][0]
Tag = _speedup.Tag Tag = _speedup.Tag
bold_tags, italic_tags = _speedup.bold_tags, _speedup.italic_tags bold_tags, italic_tags = _speedup.bold_tags, _speedup.italic_tags
State = _speedup.State State = _speedup.State
@ -522,6 +522,7 @@ class XMLHighlighter(Highlighter):
def profile(): def profile():
import sys import sys
from PyQt5.Qt import QTextDocument from PyQt5.Qt import QTextDocument
from calibre.gui2 import Application from calibre.gui2 import Application
from calibre.gui2.tweak_book import set_book_locale from calibre.gui2.tweak_book import set_book_locale
from calibre.gui2.tweak_book.editor.themes import get_theme from calibre.gui2.tweak_book.editor.themes import get_theme

View File

@ -9,7 +9,6 @@ import sys
import textwrap import textwrap
from collections import Counter, OrderedDict, defaultdict from collections import Counter, OrderedDict, defaultdict
from functools import partial from functools import partial
from PyQt5.Qt import ( from PyQt5.Qt import (
QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout, QApplication, QCheckBox, QDialog, QDialogButtonBox, QFont, QFormLayout,
QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget, QGridLayout, QIcon, QInputDialog, QLabel, QLineEdit, QListWidget,
@ -18,7 +17,7 @@ from PyQt5.Qt import (
QVBoxLayout, QWidget, pyqtSignal QVBoxLayout, QWidget, pyqtSignal
) )
from calibre import human_readable, plugins, sanitize_file_name from calibre import human_readable, sanitize_file_name
from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES from calibre.ebooks.oeb.base import OEB_DOCS, OEB_STYLES
from calibre.ebooks.oeb.polish.container import OEB_FONTS, guess_type from calibre.ebooks.oeb.polish.container import OEB_FONTS, guess_type
from calibre.ebooks.oeb.polish.cover import ( from calibre.ebooks.oeb.polish.cover import (
@ -39,6 +38,7 @@ from calibre.gui2.tweak_book.editor import syntax_from_mime
from calibre.gui2.tweak_book.templates import template_for from calibre.gui2.tweak_book.templates import template_for
from calibre.utils.fonts.utils import get_font_names from calibre.utils.fonts.utils import get_font_names
from calibre.utils.icu import numeric_sort_key from calibre.utils.icu import numeric_sort_key
from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.binary import as_hex_unicode from polyglot.binary import as_hex_unicode
from polyglot.builtins import filter, iteritems, itervalues, map, range, unicode_type from polyglot.builtins import filter, iteritems, itervalues, map, range, unicode_type
@ -191,7 +191,7 @@ class ItemDelegate(QStyledItemDelegate): # {{{
class OpenWithHandler(object): # {{{ class OpenWithHandler(object): # {{{
def add_open_with_actions(self, menu, file_name): def add_open_with_actions(self, menu, file_name):
from calibre.gui2.open_with import populate_menu, edit_programs from calibre.gui2.open_with import edit_programs, populate_menu
fmt = file_name.rpartition('.')[-1].lower() fmt = file_name.rpartition('.')[-1].lower()
if not fmt: if not fmt:
return return
@ -242,9 +242,7 @@ class FileList(QTreeWidget, OpenWithHandler):
make_view_use_window_background(self) make_view_use_window_background(self)
self.categories = {} self.categories = {}
self.ordered_selected_indexes = False self.ordered_selected_indexes = False
pi = plugins['progress_indicator'][0] set_no_activate_on_click(self)
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self)
self.current_edited_name = None self.current_edited_name = None
self.delegate = ItemDelegate(self) self.delegate = ItemDelegate(self)
self.delegate.rename_requested.connect(self.rename_requested) self.delegate.rename_requested.connect(self.rename_requested)

View File

@ -5,38 +5,48 @@
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2014, Kovid Goyal <kovid at kovidgoyal.net>'
import os, sys import os
from collections import defaultdict, OrderedDict import sys
from itertools import chain from collections import OrderedDict, defaultdict
from threading import Thread
from functools import partial from functools import partial
from itertools import chain
from PyQt5.Qt import ( from PyQt5.Qt import (
QGridLayout, QApplication, QTreeWidget, QTreeWidgetItem, Qt, QFont, QSize, QT_VERSION_STR, QAbstractTableModel, QApplication, QCheckBox, QComboBox, QDialog,
QStackedLayout, QLabel, QVBoxLayout, QWidget, QPushButton, QIcon, QMenu, QDialogButtonBox, QFont, QFormLayout, QGridLayout, QHBoxLayout, QIcon,
QDialogButtonBox, QLineEdit, QDialog, QToolButton, QFormLayout, QHBoxLayout, QInputDialog, QKeySequence, QLabel, QLineEdit, QListWidget, QListWidgetItem,
pyqtSignal, QAbstractTableModel, QModelIndex, QTimer, QTableView, QCheckBox, QMenu, QModelIndex, QPlainTextEdit, QPushButton, QSize, QStackedLayout, Qt,
QComboBox, QListWidget, QListWidgetItem, QInputDialog, QPlainTextEdit, QKeySequence, QTableView, QTimer, QToolButton, QTreeWidget, QTreeWidgetItem, QVBoxLayout,
QT_VERSION_STR) QWidget, pyqtSignal
)
from threading import Thread
from calibre.constants import __appname__, plugins from calibre.constants import __appname__
from calibre.ebooks.oeb.polish.spell import replace_word, get_all_words, merge_locations, get_checkable_file_names, undo_replace_word from calibre.ebooks.oeb.polish.spell import (
get_all_words, get_checkable_file_names, merge_locations, replace_word,
undo_replace_word
)
from calibre.gui2 import choose_files, error_dialog from calibre.gui2 import choose_files, error_dialog
from calibre.gui2.complete2 import LineEdit from calibre.gui2.complete2 import LineEdit
from calibre.gui2.languages import LanguagesEdit from calibre.gui2.languages import LanguagesEdit
from calibre.gui2.progress_indicator import ProgressIndicator from calibre.gui2.progress_indicator import ProgressIndicator
from calibre.gui2.tweak_book import dictionaries, current_container, set_book_locale, tprefs, editors from calibre.gui2.tweak_book import (
current_container, dictionaries, editors, set_book_locale, tprefs
)
from calibre.gui2.tweak_book.widgets import Dialog from calibre.gui2.tweak_book.widgets import Dialog
from calibre.gui2.widgets2 import FlowLayout from calibre.gui2.widgets2 import FlowLayout
from calibre.spell import DictionaryLocale from calibre.spell import DictionaryLocale
from calibre.spell.dictionary import (
builtin_dictionaries, custom_dictionaries, best_locale_for_language,
get_dictionary, dprefs, remove_dictionary, rename_dictionary)
from calibre.spell.import_from import import_from_oxt
from calibre.spell.break_iterator import split_into_words from calibre.spell.break_iterator import split_into_words
from calibre.utils.localization import calibre_langcode_to_name, get_language, get_lang, canonicalize_lang from calibre.spell.dictionary import (
from calibre.utils.icu import sort_key, primary_sort_key, primary_contains, contains best_locale_for_language, builtin_dictionaries, custom_dictionaries, dprefs,
from polyglot.builtins import iteritems, unicode_type, range, filter get_dictionary, remove_dictionary, rename_dictionary
)
from calibre.spell.import_from import import_from_oxt
from calibre.utils.icu import contains, primary_contains, primary_sort_key, sort_key
from calibre.utils.localization import (
calibre_langcode_to_name, canonicalize_lang, get_lang, get_language
)
from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.builtins import filter, iteritems, range, unicode_type
LANG = 0 LANG = 0
COUNTRY = 1 COUNTRY = 1
@ -923,7 +933,6 @@ class SpellCheck(Dialog):
def setup_ui(self): def setup_ui(self):
self.state_name = 'spell-check-table-state-' + QT_VERSION_STR.partition('.')[0] self.state_name = 'spell-check-table-state-' + QT_VERSION_STR.partition('.')[0]
set_no_activate_on_click = plugins['progress_indicator'][0].set_no_activate_on_click
self.setWindowIcon(QIcon(I('spell-check.png'))) self.setWindowIcon(QIcon(I('spell-check.png')))
self.l = l = QVBoxLayout(self) self.l = l = QVBoxLayout(self)
self.setLayout(l) self.setLayout(l)

View File

@ -6,16 +6,17 @@ __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from PyQt5.Qt import ( from PyQt5.Qt import (
QDialog, pyqtSignal, QIcon, QVBoxLayout, QDialogButtonBox, QStackedWidget, QAction, QApplication, QDialog, QDialogButtonBox, QGridLayout, QIcon, QMenu,
QAction, QMenu, QTreeWidget, QTreeWidgetItem, QGridLayout, QWidget, Qt, QSize, QStackedWidget, QStyledItemDelegate, Qt, QTimer, QTreeWidget,
QSize, QStyledItemDelegate, QApplication, QTimer) QTreeWidgetItem, QVBoxLayout, QWidget, pyqtSignal
)
from calibre.constants import plugins
from calibre.ebooks.oeb.polish.toc import commit_toc, get_toc from calibre.ebooks.oeb.polish.toc import commit_toc, get_toc
from calibre.gui2 import error_dialog, make_view_use_window_background from calibre.gui2 import error_dialog, make_view_use_window_background
from calibre.gui2.toc.main import TOCView, ItemEdit from calibre.gui2.toc.main import ItemEdit, TOCView
from calibre.gui2.tweak_book import current_container, TOP, actions, tprefs from calibre.gui2.tweak_book import TOP, actions, current_container, tprefs
from polyglot.builtins import unicode_type, range from calibre_extensions.progress_indicator import set_no_activate_on_click
from polyglot.builtins import range, unicode_type
class TOCEditor(QDialog): class TOCEditor(QDialog):
@ -137,9 +138,7 @@ class TOCViewer(QWidget):
self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection) self.view.customContextMenuRequested.connect(self.show_context_menu, type=Qt.QueuedConnection)
self.view.itemActivated.connect(self.emit_navigate) self.view.itemActivated.connect(self.emit_navigate)
self.view.itemPressed.connect(self.item_pressed) self.view.itemPressed.connect(self.item_pressed)
pi = plugins['progress_indicator'][0] set_no_activate_on_click(self.view)
if hasattr(pi, 'set_no_activate_on_click'):
pi.set_no_activate_on_click(self.view)
self.view.itemDoubleClicked.connect(self.emit_navigate) self.view.itemDoubleClicked.connect(self.emit_navigate)
l.addWidget(self.view) l.addWidget(self.view)

View File

@ -17,7 +17,7 @@ from PyQt5.Qt import (
QPixmap, QRect, QPlainTextEdit, QMimeData) QPixmap, QRect, QPlainTextEdit, QMimeData)
from calibre import prepare_string_for_xml, human_readable from calibre import prepare_string_for_xml, human_readable
from calibre.constants import iswindows, plugins from calibre.constants import iswindows
from calibre.ebooks.oeb.polish.cover import get_raster_cover_name from calibre.ebooks.oeb.polish.cover import get_raster_cover_name
from calibre.ebooks.oeb.polish.utils import lead_text, guess_type from calibre.ebooks.oeb.polish.utils import lead_text, guess_type
from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images from calibre.gui2 import error_dialog, choose_files, choose_save_file, info_dialog, choose_images
@ -1230,7 +1230,7 @@ class PlainTextEdit(QPlainTextEdit): # {{{
return True return True
def windows_ignore_altgr_shortcut(self, ev): def windows_ignore_altgr_shortcut(self, ev):
winutil = plugins['winutil'][0] from calibre_extensions import winutil
s = winutil.get_async_key_state(winutil.VK_RMENU) # VK_RMENU == R_ALT s = winutil.get_async_key_state(winutil.VK_RMENU) # VK_RMENU == R_ALT
return s & 0x8000 return s & 0x8000

View File

@ -6,28 +6,27 @@ __license__ = 'GPL v3'
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import os, traceback, re import os
import re
import traceback
from contextlib import closing from contextlib import closing
from PyQt5.Qt import (
QAbstractListModel, QDir, QIcon, QItemSelection, QItemSelectionModel, Qt,
QWizard, QWizardPage, pyqtSignal
)
from PyQt5.Qt import (QWizard, QWizardPage, QIcon, Qt, QAbstractListModel,
QItemSelectionModel, pyqtSignal, QItemSelection, QDir)
from calibre import __appname__ from calibre import __appname__
from calibre.constants import (filesystem_encoding, iswindows, plugins, from calibre.constants import filesystem_encoding, isportable, iswindows
isportable) from calibre.gui2 import choose_dir, error_dialog
from calibre.gui2.wizard.send_email import smtp_prefs
from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI from calibre.gui2.wizard.device_ui import Ui_WizardPage as DeviceUI
from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
from calibre.gui2.wizard.finish_ui import Ui_WizardPage as FinishUI from calibre.gui2.wizard.finish_ui import Ui_WizardPage as FinishUI
from calibre.gui2.wizard.kindle_ui import Ui_WizardPage as KindleUI from calibre.gui2.wizard.kindle_ui import Ui_WizardPage as KindleUI
from calibre.gui2.wizard.library_ui import Ui_WizardPage as LibraryUI
from calibre.gui2.wizard.send_email import smtp_prefs
from calibre.gui2.wizard.stanza_ui import Ui_WizardPage as StanzaUI from calibre.gui2.wizard.stanza_ui import Ui_WizardPage as StanzaUI
from calibre.utils.localization import localize_user_manual_link
from calibre.utils.config import dynamic, prefs from calibre.utils.config import dynamic, prefs
from calibre.gui2 import choose_dir, error_dialog from calibre.utils.localization import localize_user_manual_link
from polyglot.builtins import iteritems, unicode_type, map from polyglot.builtins import iteritems, map, unicode_type
if iswindows:
winutil = plugins['winutil'][0]
# Devices {{{ # Devices {{{
@ -682,8 +681,9 @@ class LibraryPage(QWizardPage, LibraryUI):
def init_languages(self): def init_languages(self):
self.language.blockSignals(True) self.language.blockSignals(True)
self.language.clear() self.language.clear()
from calibre.utils.localization import (available_translations, from calibre.utils.localization import (
get_language, get_lang, get_lc_messages_path) available_translations, get_lang, get_language, get_lc_messages_path
)
lang = get_lang() lang = get_lang()
lang = get_lc_messages_path(lang) if lang else lang lang = get_lc_messages_path(lang) if lang else lang
if lang is None or lang not in available_translations(): if lang is None or lang not in available_translations():
@ -709,9 +709,9 @@ class LibraryPage(QWizardPage, LibraryUI):
prefs['language'] = unicode_type(self.language.itemData(self.language.currentIndex()) or '') prefs['language'] = unicode_type(self.language.itemData(self.language.currentIndex()) or '')
from polyglot.builtins import builtins from polyglot.builtins import builtins
builtins.__dict__['_'] = lambda x: x builtins.__dict__['_'] = lambda x: x
from calibre.utils.localization import set_translators
from calibre.gui2 import qt_app
from calibre.ebooks.metadata.book.base import reset_field_metadata from calibre.ebooks.metadata.book.base import reset_field_metadata
from calibre.gui2 import qt_app
from calibre.utils.localization import set_translators
set_translators() set_translators()
qt_app.load_translations() qt_app.load_translations()
self.retranslate.emit() self.retranslate.emit()

View File

@ -33,8 +33,8 @@ class LinuxNetworkStatus(object):
class WindowsNetworkStatus(object): class WindowsNetworkStatus(object):
def __init__(self): def __init__(self):
from calibre.constants import plugins from calibre_extensions import winutil
self.winutil = plugins['winutil'][0] self.winutil = winutil
def __call__(self): def __call__(self):
if self.winutil is None: if self.winutil is None: