From 89a32bfedab300c2d7d9d196b43ef40f79e690de Mon Sep 17 00:00:00 2001 From: BasioMeusPuga Date: Sat, 17 Mar 2018 10:44:02 +0530 Subject: [PATCH] Add toggle for image caching Remove PyQt5 reference from setup.py --- lector/settings.py | 4 ++++ lector/settingsdialog.py | 8 ++++---- lector/widgets.py | 17 +++++++++++------ resources/raw/settings.ui | 7 +++++-- resources/settingswindow.py | 9 +++++---- setup.py | 3 +-- 6 files changed, 30 insertions(+), 18 deletions(-) diff --git a/lector/settings.py b/lector/settings.py index 6d2baf2..0be9abc 100644 --- a/lector/settings.py +++ b/lector/settings.py @@ -99,6 +99,9 @@ class Settings: 'performCulling', 'True').capitalize()) self.parent.settings['dictionary_language'] = self.settings.value( 'dictionaryLanguage', 'en') + self.parent.settings['caching_enabled'] = literal_eval(self.settings.value( + 'cachingEnabled', 'True').capitalize()) + self.settings.endGroup() self.settings.beginGroup('dialogSettings') @@ -167,6 +170,7 @@ class Settings: self.settings.setValue('scanLibraryAtStart', current_settings['scan_library']) self.settings.setValue('performCulling', current_settings['perform_culling']) self.settings.setValue('dictionaryLanguage', current_settings['dictionary_language']) + self.settings.setValue('cachingEnabled', current_settings['caching_enabled']) self.settings.endGroup() self.settings.beginGroup('dialogSettings') diff --git a/lector/settingsdialog.py b/lector/settingsdialog.py index 3e8c853..510409b 100644 --- a/lector/settingsdialog.py +++ b/lector/settingsdialog.py @@ -83,15 +83,14 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): self.refreshLibrary.setChecked(self.parent.settings['scan_library']) self.fileRemember.setChecked(self.parent.settings['remember_files']) self.performCulling.setChecked(self.parent.settings['perform_culling']) + self.cachingEnabled.setChecked(self.parent.settings['caching_enabled']) self.autoTags.clicked.connect(self.manage_checkboxes) self.coverShadows.clicked.connect(self.manage_checkboxes) self.refreshLibrary.clicked.connect(self.manage_checkboxes) self.fileRemember.clicked.connect(self.manage_checkboxes) self.performCulling.clicked.connect(self.manage_checkboxes) - - self.comicsRemain.setEnabled(False) - self.comicsRemain.setToolTip('Not implemented yet') + self.cachingEnabled.clicked.connect(self.manage_checkboxes) # Generate the filesystem treeView self.generate_tree() @@ -278,7 +277,8 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): 'autoTags': 'auto_tags', 'refreshLibrary': 'scan_library', 'fileRemember': 'remember_files', - 'performCulling': 'perform_culling'} + 'performCulling': 'perform_culling', + 'cachingEnabled': 'caching_enabled',} self.parent.settings[sender_dict[sender]] = not self.parent.settings[sender_dict[sender]] diff --git a/lector/widgets.py b/lector/widgets.py index 5dc967e..f36ad84 100644 --- a/lector/widgets.py +++ b/lector/widgets.py @@ -27,7 +27,11 @@ import uuid import zipfile from PyQt5 import QtWidgets, QtGui, QtCore -import popplerqt5 +try: + import popplerqt5 +except ImportError: + pass + from rarfile import rarfile from lector.models import BookmarkProxyModel @@ -513,8 +517,6 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): def loadImage(self, current_page): # TODO - # Threaded caching will still work here - # Look at a commit where it's not been deleted # For double page view: 1 before, 1 after all_pages = [i[1] for i in self.parent.metadata['content']] @@ -565,9 +567,12 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): # No return happened so the image isn't in the cache generate_image_cache(current_page) - return_pixmap = None - while not return_pixmap: - return_pixmap = check_cache(current_page) + if self.window().settings['caching_enabled']: + return_pixmap = None + while not return_pixmap: + return_pixmap = check_cache(current_page) + else: + return_pixmap = load_page(current_page) self.image_pixmap = return_pixmap self.resizeEvent() diff --git a/resources/raw/settings.ui b/resources/raw/settings.ui index 766ec59..0b05ed6 100644 --- a/resources/raw/settings.ui +++ b/resources/raw/settings.ui @@ -116,9 +116,12 @@ - + + + Greatly reduces page transition time at the cost of more memory + - Leave comics on disc + Cache comic / pdf pages diff --git a/resources/settingswindow.py b/resources/settingswindow.py index 7366278..9830ac3 100644 --- a/resources/settingswindow.py +++ b/resources/settingswindow.py @@ -71,9 +71,9 @@ class Ui_Dialog(object): self.performCulling = QtWidgets.QCheckBox(self.groupBox) self.performCulling.setObjectName("performCulling") self.horizontalLayout.addWidget(self.performCulling) - self.comicsRemain = QtWidgets.QCheckBox(self.groupBox) - self.comicsRemain.setObjectName("comicsRemain") - self.horizontalLayout.addWidget(self.comicsRemain) + self.cachingEnabled = QtWidgets.QCheckBox(self.groupBox) + self.cachingEnabled.setObjectName("cachingEnabled") + self.horizontalLayout.addWidget(self.cachingEnabled) self.horizontalLayout_5 = QtWidgets.QHBoxLayout() self.horizontalLayout_5.setObjectName("horizontalLayout_5") self.label = QtWidgets.QLabel(self.groupBox) @@ -118,7 +118,8 @@ class Ui_Dialog(object): self.coverShadows.setText(_translate("Dialog", "Cover shadows")) self.performCulling.setToolTip(_translate("Dialog", "Enabling reduces startup time and memory usage")) self.performCulling.setText(_translate("Dialog", "Load covers only when needed")) - self.comicsRemain.setText(_translate("Dialog", "Leave comics on disc")) + self.cachingEnabled.setToolTip(_translate("Dialog", "Greatly reduces page transition time at the cost of more memory")) + self.cachingEnabled.setText(_translate("Dialog", "Cache comic / pdf pages")) self.label.setToolTip(_translate("Dialog", "Restart to see changes")) self.label.setText(_translate("Dialog", "Icon theme: ")) self.darkIconsRadio.setToolTip(_translate("Dialog", "Restart to see changes")) diff --git a/setup.py b/setup.py index a68a369..899d19a 100644 --- a/setup.py +++ b/setup.py @@ -13,8 +13,7 @@ VERSION = "{}.{}.{}".format(MAJOR_VERSION, MINOR_VERSION, MICRO_VERSION) with codecs.open(path.join(HERE, 'README.md'), encoding='utf-8') as f: LONG_DESC = f.read() -INSTALL_DEPS = ['PyQt5', - 'requests', +INSTALL_DEPS = ['requests', 'beautifulsoup4'] TEST_DEPS = ['pytest', 'unittest2']