From 912723e7e23602816e91bd938737a5c50d4b43b1 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 27 May 2020 12:33:23 +0100 Subject: [PATCH 1/3] Fix for slowdown if a file URL refers to a missing drive. Might be a windows-only thing. --- resources/images/blank-1x1.png | Bin 0 -> 67 bytes src/calibre/gui2/comments_editor.py | 4 ++-- src/calibre/gui2/widgets2.py | 14 +++++++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) create mode 100644 resources/images/blank-1x1.png diff --git a/resources/images/blank-1x1.png b/resources/images/blank-1x1.png new file mode 100644 index 0000000000000000000000000000000000000000..91a99b94e23a00cc8133f22e3fe2a0b48a015808 GIT binary patch literal 67 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blE>9Q7kcv6UAQ@H$MqV!6EkIEQ MPgg&ebxsLQ07X&@0{{R3 literal 0 HcmV?d00001 diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index c1a2f48881..34db3b65a4 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -28,7 +28,7 @@ from calibre.gui2.widgets import LineEditECM from calibre.gui2.widgets2 import to_plain_text from calibre.utils.config import tweaks from calibre.utils.imghdr import what -from polyglot.builtins import filter, iteritems, itervalues, unicode_type +from polyglot.builtins import filter, iteritems, itervalues, unicode_type, as_bytes # Cleanup Qt markup {{{ @@ -764,7 +764,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ with lopen(path, 'rb') as f: data = f.read() except EnvironmentError: - pass + return QByteArray(I('blank-1x1.png', data=True)) else: return QByteArray(data) diff --git a/src/calibre/gui2/widgets2.py b/src/calibre/gui2/widgets2.py index 97f2d60e73..5aa6c9df59 100644 --- a/src/calibre/gui2/widgets2.py +++ b/src/calibre/gui2/widgets2.py @@ -11,7 +11,7 @@ from PyQt5.Qt import ( QDialogButtonBox, QFont, QFontInfo, QFontMetrics, QIcon, QKeySequence, QLabel, QLayout, QPalette, QPixmap, QPoint, QPushButton, QRect, QScrollArea, QSize, QSizePolicy, QStyle, QStyledItemDelegate, Qt, QTabWidget, QTextBrowser, - QToolButton, QUndoCommand, QUndoStack, QWidget, pyqtSignal + QToolButton, QUndoCommand, QUndoStack, QWidget, pyqtSignal, QByteArray ) from calibre.ebooks.metadata import rating_to_stars @@ -482,6 +482,18 @@ class HTMLDisplay(QTextBrowser): return self.anchor_clicked.emit(qurl) + def loadResource(self, rtype, qurl): + if qurl.isLocalFile(): + path = qurl.toLocalFile() + try: + with lopen(path, 'rb') as f: + data = f.read() + except EnvironmentError: + return QByteArray(I('blank-1x1.png', data=True)) + else: + return QByteArray(data) + else: + QTextBrowser.loadResource(self, rtype, qurl) class ScrollingTabWidget(QTabWidget): From 42318c46b6803fff4e545446480fbcf810bda570 Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 27 May 2020 13:16:43 +0100 Subject: [PATCH 2/3] Put the image bytes directly in code --- resources/images/blank-1x1.png | Bin 67 -> 0 bytes src/calibre/gui2/comments_editor.py | 7 ++++++- src/calibre/gui2/widgets2.py | 7 ++++++- 3 files changed, 12 insertions(+), 2 deletions(-) delete mode 100644 resources/images/blank-1x1.png diff --git a/resources/images/blank-1x1.png b/resources/images/blank-1x1.png deleted file mode 100644 index 91a99b94e23a00cc8133f22e3fe2a0b48a015808..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 67 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1|;Q0k8}blE>9Q7kcv6UAQ@H$MqV!6EkIEQ MPgg&ebxsLQ07X&@0{{R3 diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 34db3b65a4..79e9476f44 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -764,7 +764,12 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ with lopen(path, 'rb') as f: data = f.read() except EnvironmentError: - return QByteArray(I('blank-1x1.png', data=True)) + return QByteArray(bytearray.fromhex( + '89504e470d0a1a0a0000000d49484452' + '000000010000000108060000001f15c4' + '890000000a49444154789c6300010000' + '0500010d0a2db40000000049454e44ae' + '426082')) else: return QByteArray(data) diff --git a/src/calibre/gui2/widgets2.py b/src/calibre/gui2/widgets2.py index 5aa6c9df59..9a02f188c4 100644 --- a/src/calibre/gui2/widgets2.py +++ b/src/calibre/gui2/widgets2.py @@ -489,7 +489,12 @@ class HTMLDisplay(QTextBrowser): with lopen(path, 'rb') as f: data = f.read() except EnvironmentError: - return QByteArray(I('blank-1x1.png', data=True)) + return QByteArray(bytearray.fromhex( + '89504e470d0a1a0a0000000d49484452' + '000000010000000108060000001f15c4' + '890000000a49444154789c6300010000' + '0500010d0a2db40000000049454e44ae' + '426082')) else: return QByteArray(data) else: From 342036689ab9ba32eed6a8420ea2cc4d95d44d6b Mon Sep 17 00:00:00 2001 From: Charles Haley Date: Wed, 27 May 2020 13:18:40 +0100 Subject: [PATCH 3/3] Oops --- src/calibre/gui2/comments_editor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/calibre/gui2/comments_editor.py b/src/calibre/gui2/comments_editor.py index 79e9476f44..421a9a207e 100644 --- a/src/calibre/gui2/comments_editor.py +++ b/src/calibre/gui2/comments_editor.py @@ -764,7 +764,7 @@ class EditorWidget(QTextEdit, LineEditECM): # {{{ with lopen(path, 'rb') as f: data = f.read() except EnvironmentError: - return QByteArray(bytearray.fromhex( + return QByteArray(bytearray.fromhex( '89504e470d0a1a0a0000000d49484452' '000000010000000108060000001f15c4' '890000000a49444154789c6300010000'