mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Make loading of notes resources in HTMLDisplay opt-in
HTMLDisplay is a generic class so its not appropriate for it to try to load notes resources everywhere.
This commit is contained in:
parent
2856922aeb
commit
e6e5f0fe9f
@ -8,14 +8,16 @@ from collections import namedtuple
|
||||
from contextlib import suppress
|
||||
from functools import lru_cache, partial
|
||||
from qt.core import (
|
||||
QAction, QApplication, QClipboard, QColor, QDialog, QEasingCurve, QIcon, QPalette,
|
||||
QKeySequence, QMenu, QMimeData, QPainter, QPen, QPixmap, QPropertyAnimation, QRect,
|
||||
QSize, QSizePolicy, QSplitter, Qt, QTimer, QUrl, QWidget, pyqtProperty, pyqtSignal,
|
||||
QAction, QApplication, QClipboard, QColor, QDialog, QEasingCurve, QIcon,
|
||||
QKeySequence, QMenu, QMimeData, QPainter, QPalette, QPen, QPixmap,
|
||||
QPropertyAnimation, QRect, QSize, QSizePolicy, QSplitter, Qt, QTimer, QUrl, QWidget,
|
||||
pyqtProperty, pyqtSignal,
|
||||
)
|
||||
|
||||
from calibre import fit_image, sanitize_file_name
|
||||
from calibre.constants import config_dir, iswindows
|
||||
from calibre.db.constants import DATA_DIR_NAME, DATA_FILE_PATTERN
|
||||
from calibre.db.notes.connect import RESOURCE_URL_SCHEME
|
||||
from calibre.ebooks import BOOK_EXTENSIONS
|
||||
from calibre.ebooks.metadata.book.base import Metadata, field_metadata
|
||||
from calibre.ebooks.metadata.book.render import mi_to_html
|
||||
@ -898,6 +900,7 @@ class BookInfo(HTMLDisplay):
|
||||
edit_book = pyqtSignal(int, object)
|
||||
edit_identifiers = pyqtSignal()
|
||||
find_in_tag_browser = pyqtSignal(object, object)
|
||||
notes_resource_scheme = RESOURCE_URL_SCHEME
|
||||
|
||||
def __init__(self, vertical, parent=None):
|
||||
HTMLDisplay.__init__(self, parent)
|
||||
|
@ -2,9 +2,8 @@
|
||||
# License: GPLv3 Copyright: 2008, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
from enum import IntEnum
|
||||
import textwrap
|
||||
|
||||
from enum import IntEnum
|
||||
from qt.core import (
|
||||
QAction, QApplication, QBrush, QCheckBox, QDialog, QDialogButtonBox, QGridLayout,
|
||||
QHBoxLayout, QIcon, QKeySequence, QLabel, QListView, QModelIndex, QPalette, QPixmap,
|
||||
@ -13,6 +12,7 @@ from qt.core import (
|
||||
)
|
||||
|
||||
from calibre import fit_image
|
||||
from calibre.db.notes.connect import RESOURCE_URL_SCHEME
|
||||
from calibre.gui2 import NO_URL_FORMATTING, gprefs
|
||||
from calibre.gui2.book_details import (
|
||||
create_open_cover_with_menu, resolved_css, details_context_menu_event, render_html, set_html,
|
||||
@ -119,6 +119,8 @@ class Configure(Dialog):
|
||||
|
||||
class Details(HTMLDisplay):
|
||||
|
||||
notes_resource_scheme = RESOURCE_URL_SCHEME
|
||||
|
||||
def __init__(self, book_info, parent=None, allow_context_menu=True, is_locked=False):
|
||||
HTMLDisplay.__init__(self, parent)
|
||||
self.book_info = book_info
|
||||
|
@ -9,12 +9,11 @@ from qt.core import (
|
||||
QFontInfo, QFontMetrics, QFrame, QIcon, QKeySequence, QLabel, QLayout, QMenu,
|
||||
QMimeData, QPainter, QPalette, QPixmap, QPoint, QPushButton, QRect, QScrollArea,
|
||||
QSize, QSizePolicy, QStyle, QStyledItemDelegate, QStyleOptionToolButton,
|
||||
QStylePainter, Qt, QTabWidget, QTextBrowser, QTextDocument, QTextCursor, QTimer, QToolButton,
|
||||
QUndoCommand, QUndoStack, QUrl, QWidget, pyqtSignal,
|
||||
QStylePainter, Qt, QTabWidget, QTextBrowser, QTextCursor, QTextDocument, QTimer,
|
||||
QToolButton, QUndoCommand, QUndoStack, QUrl, QWidget, pyqtSignal,
|
||||
)
|
||||
|
||||
from calibre import prepare_string_for_xml
|
||||
from calibre.db.notes.connect import RESOURCE_URL_SCHEME
|
||||
from calibre.constants import builtin_colors_dark, builtin_colors_light
|
||||
from calibre.ebooks.metadata import rating_to_stars
|
||||
from calibre.gui2 import UNDEFINED_QDATETIME, gprefs, rating_font
|
||||
@ -519,6 +518,7 @@ class Separator(QWidget): # {{{
|
||||
class HTMLDisplay(QTextBrowser):
|
||||
|
||||
anchor_clicked = pyqtSignal(object)
|
||||
notes_resource_scheme = '' # set to scheme to use to load resources for notes from the current db
|
||||
|
||||
def __init__(self, parent=None):
|
||||
QTextBrowser.__init__(self, parent)
|
||||
@ -590,7 +590,7 @@ class HTMLDisplay(QTextBrowser):
|
||||
return QByteArray(data)
|
||||
elif qurl.scheme() == 'calibre-icon':
|
||||
return QIcon.icon_as_png(qurl.path().lstrip('/'), as_bytearray=True)
|
||||
elif qurl.scheme() == RESOURCE_URL_SCHEME and int(rtype) == int(QTextDocument.ResourceType.ImageResource):
|
||||
elif self.notes_resource_scheme and qurl.scheme() == self.notes_resource_scheme and int(rtype) == int(QTextDocument.ResourceType.ImageResource):
|
||||
from calibre.gui2.ui import get_gui
|
||||
gui = get_gui()
|
||||
if gui is not None:
|
||||
|
Loading…
x
Reference in New Issue
Block a user