Fix manual zoom padding, Speed up hashing

This commit is contained in:
BasioMeusPuga
2017-11-19 17:36:42 +05:30
parent bc8a533bb8
commit 6ca94924cf
4 changed files with 23 additions and 7 deletions

View File

@@ -18,6 +18,7 @@
✓ Search bar in toolbar ✓ Search bar in toolbar
✓ Shift focus to the tab that has the book open ✓ Shift focus to the tab that has the book open
✓ Tie file deletion and tab closing to model updates ✓ Tie file deletion and tab closing to model updates
✓ Create separate thread for parser - Show progress in main window
? Create emblem per filetype ? Create emblem per filetype
Look into how you might group icons Look into how you might group icons
Ignore a / the / numbers for sorting purposes Ignore a / the / numbers for sorting purposes
@@ -26,8 +27,8 @@
Mass tagging Mass tagging
Information dialog widget Information dialog widget
Context menu: Cache, Read, Edit database, delete, Mark read/unread Context menu: Cache, Read, Edit database, delete, Mark read/unread
Create separate thread for parser - Show progress in main window
Set focus to newly added file Set focus to newly added file
Better way to thread than subprocess QThread
Reading: Reading:
✓ Drop down for TOC ✓ Drop down for TOC
✓ Override the keypress event of the textedit ✓ Override the keypress event of the textedit
@@ -494,12 +495,16 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
if signal_sender == 'zoomOut': if signal_sender == 'zoomOut':
self.comic_profile['zoom_mode'] = 'manualZoom' self.comic_profile['zoom_mode'] = 'manualZoom'
self.comic_profile['padding'] += 50 self.comic_profile['padding'] += 50
# This prevents infinite zoom out
if self.comic_profile['padding'] * 2 > current_tab.contentView.viewport().width(): if self.comic_profile['padding'] * 2 > current_tab.contentView.viewport().width():
self.comic_profile['padding'] -= 50 self.comic_profile['padding'] -= 50
if signal_sender == 'zoomIn': if signal_sender == 'zoomIn':
self.comic_profile['zoom_mode'] = 'manualZoom' self.comic_profile['zoom_mode'] = 'manualZoom'
self.comic_profile['padding'] -= 50 self.comic_profile['padding'] -= 50
# This prevents infinite zoom in
if self.comic_profile['padding'] < 0: if self.comic_profile['padding'] < 0:
self.comic_profile['padding'] = 0 self.comic_profile['padding'] = 0
@@ -508,6 +513,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.comic_profile['padding'] = 0 self.comic_profile['padding'] = 0
self.bookToolBar.fitWidth.setChecked(True) self.bookToolBar.fitWidth.setChecked(True)
# Padding in the following cases is decided by
# the image pixmap loaded by the widget
if signal_sender == 'bestFit': if signal_sender == 'bestFit':
self.comic_profile['zoom_mode'] = 'bestFit' self.comic_profile['zoom_mode'] = 'bestFit'
self.bookToolBar.bestFit.setChecked(True) self.bookToolBar.bestFit.setChecked(True)
@@ -615,7 +622,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
QtWidgets.qApp.exit() QtWidgets.qApp.exit()
def main(): def main():
app = QtWidgets.QApplication(sys.argv) app = QtWidgets.QApplication(sys.argv)
app.setApplicationName('Lector') # This is needed for QStandardPaths app.setApplicationName('Lector') # This is needed for QStandardPaths

View File

@@ -46,4 +46,3 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
QtWidgets.QFileDialog.ShowDirsOnly) QtWidgets.QFileDialog.ShowDirsOnly)
# Directories will NOT be added recursively # Directories will NOT be added recursively

View File

@@ -1,7 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
# TODO # TODO
# See if tags can be generated from book content
# See if you want to include a hash of the book's name and author # See if you want to include a hash of the book's name and author
import os import os
@@ -87,10 +86,13 @@ class BookSorter:
# full path of the ebook file # full path of the ebook file
with open(filename, 'rb') as current_book: with open(filename, 'rb') as current_book:
file_md5 = hashlib.md5(current_book.read()).hexdigest() # This should speed up addition for larger files
# without compromising the integrity of the process
first_bytes = current_book.read(1024 * 32) # First 32KB of the file
salt = filename.encode()
first_bytes += salt
file_md5 = hashlib.md5(first_bytes).hexdigest()
# TODO
# Make use of this
self.statistics[0] += 1 self.statistics[0] += 1
self.progressbar.setValue(self.statistics[0]) self.progressbar.setValue(self.statistics[0])

View File

@@ -512,6 +512,12 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
elif zoom_mode == 'originalSize': elif zoom_mode == 'originalSize':
image_pixmap = self.image_pixmap image_pixmap = self.image_pixmap
new_padding = (self.viewport().width() - image_pixmap.width()) // 2
if new_padding < 0: # The image is larger than the viewport
self.main_window.comic_profile['padding'] = 0
else:
self.main_window.comic_profile['padding'] = new_padding
elif zoom_mode == 'bestFit': elif zoom_mode == 'bestFit':
available_width = self.viewport().width() available_width = self.viewport().width()
available_height = self.viewport().height() available_height = self.viewport().height()
@@ -520,6 +526,9 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
available_width, available_height, available_width, available_height,
QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation) QtCore.Qt.KeepAspectRatio, QtCore.Qt.SmoothTransformation)
self.main_window.comic_profile['padding'] = (
self.viewport().width() - image_pixmap.width()) // 2
elif zoom_mode == 'manualZoom': elif zoom_mode == 'manualZoom':
available_width = self.viewport().width() - 2 * padding available_width = self.viewport().width() - 2 * padding
image_pixmap = self.image_pixmap.scaledToWidth( image_pixmap = self.image_pixmap.scaledToWidth(