Image caching mostly functional

This commit is contained in:
BasioMeusPuga
2018-03-07 21:51:21 +05:30
parent 3919fe530e
commit a9dff278b9
3 changed files with 63 additions and 8 deletions

5
TODO
View File

@@ -25,7 +25,6 @@ TODO
✓ Information dialog widget
✓ Allow editing of database data through the UI + for Bookmarks
Set focus to newly added file
Change focus rectangle dimensions
Reading:
✓ Drop down for TOC
✓ Override the keypress event of the textedit
@@ -54,10 +53,10 @@ TODO
Comic view modes
Continuous paging
Double pages
Cache next and previous images
Filetypes:
✓ cbz, cbr support
✓ Keep font settings enabled but only for background color
Cache next and previous images
epub support
mobi, azw support
Other:
@@ -65,10 +64,12 @@ TODO
Bugs:
If there are files open and the database is deleted, TypeErrors result
Cover culling does not occur if some other tab has initial focus
Exiting with Ctrl + Q does not save the cursor position INITIALLY
Secondary:
Annotations
Graphical themes
Change focus rectangle dimensions
Tab reordering
Allow tabs to detach and form their own windows
Goodreads API: Ratings, Read, Recommendations

View File

@@ -229,7 +229,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# TODO
# Maybe use this for readjusting the border of the focus rectangle
# in the listView
# in the listView. Maybe this is a job for QML?
# self.listView.setStyleSheet(
# "QListView::item:selected { border-color:blue; border-style:outset;"
@@ -1165,7 +1165,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.settings['last_open_books'].append(tab_metadata['path'])
Settings(self).save_settings()
self.thread = BackGroundTabUpdate(self.database_path, all_metadata)
self.thread = BackGroundTabUpdate(
self.database_path, all_metadata)
self.thread.finished.connect(self.database_care)
self.thread.start()

View File

@@ -225,7 +225,7 @@ class Tab(QtWidgets.QWidget):
self.exit_fs.activated.connect(self.exit_fullscreen)
# TODO
# See why Ctrl + Q stop working on a non fullscreened contentView
# See why Ctrl + Q won't work on a non fullscreened contentView
# widget in case the following is in code
# self.exit_all = QtWidgets.QShortcut(
@@ -437,16 +437,69 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
self.common_functions = PliantWidgetsCommonFunctions(
self, self.main_window)
self.setMouseTracking(True)
self.image_cache = [None for _ in range(4)]
def loadImage(self, image_path):
def loadImage(self, current_image):
# TODO
# Cache 4 images
# For single page view: 1 before, 2 after
# For double page view: 1 before, 1 after
# Move caching to new thread
# Account for IndexErrors
# Image panning with mouse
self.image_pixmap = QtGui.QPixmap()
self.image_pixmap.load(image_path)
content = self.parent.metadata['content']
image_paths = [i[1] for i in content.items()]
def generate_image_cache(current_image):
print('Generator hit', self.image_cache, '\n')
current_image_index = image_paths.index(current_image)
for i in (-1, 0, 1, 2):
try:
this_path = image_paths[current_image_index + i]
this_pixmap = QtGui.QPixmap()
this_pixmap.load(this_path)
self.image_cache[i + 1] = (this_path, this_pixmap)
except IndexError:
self.image_cache[i + 1] = None
def refill_cache(remove_value):
remove_index = self.image_cache.index(remove_value)
refill_pixmap = QtGui.QPixmap()
if remove_index == 0:
self.image_cache.pop(3)
first_path = self.image_cache[0][0]
previous_path = image_paths[image_paths.index(first_path) - 1]
refill_pixmap.load(previous_path)
self.image_cache.insert(0, (previous_path, refill_pixmap))
else:
self.image_cache.remove(remove_value)
try:
last_path = self.image_cache[2][0]
next_path = image_paths[image_paths.index(last_path) + 1]
refill_pixmap.load(next_path)
self.image_cache.append((next_path, refill_pixmap))
except (IndexError, TypeError):
self.image_cache.append(None)
def check_cache(current_image):
for i in self.image_cache:
if i:
if i[0] == current_image:
return_pixmap = i[1]
refill_cache(i)
return return_pixmap
# No return happened so the image isn't in the cache
generate_image_cache(current_image)
return_pixmap = None
while not return_pixmap:
return_pixmap = check_cache(current_image)
self.image_pixmap = return_pixmap
self.resizeEvent()
def resizeEvent(self, *args):