From 0d8c2b664850cca636d9e3f471c4932f26e71eaa Mon Sep 17 00:00:00 2001 From: BasioMeusPuga Date: Tue, 20 Mar 2018 13:24:17 +0530 Subject: [PATCH] Multiple fixes Update translations --- TODO | 5 +-- lector/__main__.py | 11 ++--- lector/library.py | 11 ++++- lector/metadatadialog.py | 4 +- lector/models.py | 27 ++++++------ lector/settingsdialog.py | 7 +-- lector/sorter.py | 67 ++++++++++++++++------------- lector/toolbars.py | 4 ++ resources/translations/Lector_de.ts | 56 ++++++++++++++---------- resources/translations/Lector_es.ts | 56 ++++++++++++++---------- resources/translations/Lector_fr.ts | 56 ++++++++++++++---------- resources/translations/SAMPLE.ts | 56 ++++++++++++++---------- 12 files changed, 208 insertions(+), 152 deletions(-) diff --git a/TODO b/TODO index 5959405..fb039be 100644 --- a/TODO +++ b/TODO @@ -72,10 +72,7 @@ TODO Other: ✓ Define every widget in code 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 - Slider position change might be acting up too - Take metadata from the database when opening the file + Slider position change might be acting up Secondary: Annotations diff --git a/lector/__main__.py b/lector/__main__.py index 44f023e..9a6cc30 100755 --- a/lector/__main__.py +++ b/lector/__main__.py @@ -255,7 +255,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.tableView.horizontalHeader().sectionClicked.connect( self.lib_ref.table_proxy_model.sort_table_columns) self.tableView.setContextMenuPolicy(QtCore.Qt.CustomContextMenu) - self.tableView.customContextMenuRequested.connect(self.generate_library_context_menu) + self.tableView.customContextMenuRequested.connect( + self.generate_library_context_menu) # Keyboard shortcuts self.ksDistractionFree = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+D'), self) @@ -491,11 +492,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): return selected_indexes def delete_books(self, selected_indexes=None): - # TODO - # ? Mirror selection - # Ask if library files are to be excluded from further scans - # Make a checkbox for this - if not selected_indexes: # Get a list of QItemSelection objects # What we're interested in is the indexes()[0] in each of them @@ -557,7 +553,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.lib_ref.generate_library_tags() self.statusMessage.setText( - str(self.lib_ref.item_proxy_model.rowCount()) + ' books') + str(self.lib_ref.item_proxy_model.rowCount()) + + self._translate('Main_UI', ' books')) if not self.settings['perform_culling']: self.load_all_covers() diff --git a/lector/library.py b/lector/library.py index d6a1623..3bd54e9 100644 --- a/lector/library.py +++ b/lector/library.py @@ -77,6 +77,8 @@ class Library: year = i[2] path = i[4] last_accessed = i[9] + if last_accessed and not isinstance(last_accessed, QtCore.QDateTime): + last_accessed = pickle.loads(last_accessed) tags = i[7] if isinstance(tags, list): # When files are added for the first time @@ -168,7 +170,8 @@ class Library: self.parent.listView.setIconSize(s) self.parent.listView.setModel(self.item_proxy_model) - self.table_proxy_model = TableProxyModel(self.parent.temp_dir.path()) + self.table_proxy_model = TableProxyModel( + self.parent.temp_dir.path(), self.parent.tableView.horizontalHeader()) self.table_proxy_model.setSourceModel(self.view_model) self.table_proxy_model.setSortCaseSensitivity(False) self.parent.tableView.setModel(self.table_proxy_model) @@ -186,6 +189,9 @@ class Library: self.parent.libraryToolBar.searchBar.text()) # ^^^ This isn't needed, but it forces a model update every time the # text in the line edit changes. So I guess it is needed. + self.table_proxy_model.sort_table_columns( + self.parent.tableView.horizontalHeader().sortIndicatorSection()) + self.table_proxy_model.sort_table_columns() # Item proxy model self.item_proxy_model.invalidateFilter() @@ -197,7 +203,8 @@ class Library: self.parent.libraryToolBar.searchBar.text()) self.parent.statusMessage.setText( - str(self.item_proxy_model.rowCount()) + ' books') + str(self.item_proxy_model.rowCount()) + + self._translate('Library', ' books')) # TODO # Allow sorting by type diff --git a/lector/metadatadialog.py b/lector/metadatadialog.py index ad190f9..9e9ece0 100644 --- a/lector/metadatadialog.py +++ b/lector/metadatadialog.py @@ -86,7 +86,7 @@ class MetadataUI(QtWidgets.QDialog, metadata.Ui_Dialog): graphics_scene.addPixmap(image_pixmap) self.coverView.setScene(graphics_scene) - def ok_pressed(self, event): + def ok_pressed(self, event=None): book_item = self.parent.lib_ref.view_model.item(self.book_index.row()) title = self.titleLine.text() @@ -126,7 +126,7 @@ class MetadataUI(QtWidgets.QDialog, metadata.Ui_Dialog): database.DatabaseFunctions(self.database_path).modify_metadata( database_dict, book_hash) - def cancel_pressed(self, event): + def cancel_pressed(self, event=None): self.hide() def generate_display_position(self, mouse_cursor_position): diff --git a/lector/models.py b/lector/models.py index 4f80fcd..c914645 100644 --- a/lector/models.py +++ b/lector/models.py @@ -16,7 +16,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import pickle import pathlib from PyQt5 import QtCore, QtWidgets @@ -66,9 +65,9 @@ class ItemProxyModel(QtCore.QSortFilterProxyModel): class TableProxyModel(QtCore.QSortFilterProxyModel): - def __init__(self, temp_dir, parent=None): + def __init__(self, temp_dir, tableViewHeader, parent=None): super(TableProxyModel, self).__init__(parent) - + self.tableViewHeader = tableViewHeader self._translate = QtCore.QCoreApplication.translate title_string = self._translate('TableProxyModel', 'Title') @@ -98,7 +97,11 @@ class TableProxyModel(QtCore.QSortFilterProxyModel): def headerData(self, column, orientation, role): if role == QtCore.Qt.DisplayRole: - return self.header_data[column] + try: + return self.header_data[column] + except IndexError: + print('Table proxy model: Can\'t find header for column', column) + return 'IndexError' def flags(self, index): # Tag editing will take place by way of a right click menu @@ -153,11 +156,8 @@ class TableProxyModel(QtCore.QSortFilterProxyModel): return QtCore.QVariant() if index.column() == 4: - last_accessed_time = item.data(self.role_dictionary[index.column()]) - if last_accessed_time: - last_accessed = last_accessed_time - if not isinstance(last_accessed_time, QtCore.QDateTime): - last_accessed = pickle.loads(last_accessed_time) + last_accessed = item.data(self.role_dictionary[index.column()]) + if last_accessed: right_now = QtCore.QDateTime().currentDateTime() time_diff = last_accessed.msecsTo(right_now) return self.time_convert(time_diff // 1000) @@ -174,10 +174,13 @@ class TableProxyModel(QtCore.QSortFilterProxyModel): output = self.common_functions.filterAcceptsRow(row, parent) return output - def sort_table_columns(self, column): - sorting_order = self.sender().sortIndicatorOrder() + def sort_table_columns(self, column=None): + column = self.tableViewHeader.sortIndicatorSection() + sorting_order = self.tableViewHeader.sortIndicatorOrder() + self.sort(0, sorting_order) - self.setSortRole(self.role_dictionary[column]) + if column != 0: + self.setSortRole(self.role_dictionary[column]) def time_convert(self, seconds): seconds = int(seconds) diff --git a/lector/settingsdialog.py b/lector/settingsdialog.py index 4d6feab..494f114 100644 --- a/lector/settingsdialog.py +++ b/lector/settingsdialog.py @@ -21,6 +21,7 @@ import os import copy +import pathlib from PyQt5 import QtWidgets, QtCore from lector import database @@ -43,9 +44,9 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): self.move(self.parent.settings['settings_dialog_position']) self.aboutBox.setVisible(False) - application_root = os.sep.join( - os.path.realpath(__file__).rsplit('/')[:-2]) - aboutfile_path = os.path.join(application_root, 'resources', 'about.html') + install_dir = os.path.realpath(__file__) + install_dir = pathlib.Path(install_dir).parents[1] + aboutfile_path = os.path.join(install_dir, 'resources', 'about.html') with open(aboutfile_path) as about_html: self.aboutBox.setHtml(about_html.read()) diff --git a/lector/sorter.py b/lector/sorter.py index ddadfcb..db447ed 100644 --- a/lector/sorter.py +++ b/lector/sorter.py @@ -117,18 +117,22 @@ class BookSorter: def database_entry_for_book(self, file_hash): database_return = database.DatabaseFunctions( self.database_path).fetch_data( - ('Position', 'Bookmarks'), + ('Title', 'Author', 'Year', 'ISBN', 'Tags', 'Position', 'Bookmarks'), 'books', {'Hash': file_hash}, 'EQUALS')[0] book_data = [] - for i in database_return: - # All of these values are pickled and stored - if i: - book_data.append(pickle.loads(i)) + + for count, i in enumerate(database_return): + if count in (5, 6): + if i: + book_data.append(pickle.loads(i)) + else: + book_data.append(None) else: - book_data.append(None) + book_data.append(i) + return book_data def read_book(self, filename): @@ -170,37 +174,29 @@ class BookSorter: book_ref.read_book() if book_ref.book: - title = book_ref.get_title() - - author = book_ref.get_author() - if not author: - author = 'Unknown' - - try: - year = int(book_ref.get_year()) - except (TypeError, ValueError): - year = 9999 - - isbn = book_ref.get_isbn() - - tags = None - if self.auto_tags: - tags = book_ref.get_tags() this_book = {} this_book[file_md5] = { - 'title': title, - 'author': author, - 'year': year, - 'isbn': isbn, 'hash': file_md5, - 'path': filename, - 'tags': tags} + 'path': filename} # Different modes require different values if self.mode == 'addition': # Reduce the size of the incoming image # if one is found + title = book_ref.get_title() + + author = book_ref.get_author() + if not author: + author = 'Unknown' + + year = book_ref.get_year() + + isbn = book_ref.get_isbn() + + tags = None + if self.auto_tags: + tags = book_ref.get_tags() cover_image_raw = book_ref.get_cover_image() if cover_image_raw: @@ -226,14 +222,25 @@ class BookSorter: content = [('Invalid', 'Something went horribly wrong')] book_data = self.database_entry_for_book(file_md5) - position = book_data[0] - bookmarks = book_data[1] + title = book_data[0] + author = book_data[1] + year = book_data[2] + isbn = book_data[3] + tags = book_data[4] + position = book_data[5] + bookmarks = book_data[6] this_book[file_md5]['position'] = position this_book[file_md5]['bookmarks'] = bookmarks this_book[file_md5]['content'] = content this_book[file_md5]['images_only'] = images_only + this_book[file_md5]['title'] = title + this_book[file_md5]['author'] = author + this_book[file_md5]['year'] = year + this_book[file_md5]['isbn'] = isbn + this_book[file_md5]['tags'] = tags + return this_book def read_progress(self): diff --git a/lector/toolbars.py b/lector/toolbars.py index 284ee73..133c5e4 100644 --- a/lector/toolbars.py +++ b/lector/toolbars.py @@ -451,6 +451,10 @@ class FixedLineEdit(QtWidgets.QLineEdit): def sizeHint(self): return QtCore.QSize(400, 22) + def keyReleaseEvent(self, event): + if event.key() == QtCore.Qt.Key_Escape: + self.clear() + class FixedPushButton(QtWidgets.QPushButton): def __init__(self, parent=None): diff --git a/resources/translations/Lector_de.ts b/resources/translations/Lector_de.ts index ef36f2e..36ca12a 100644 --- a/resources/translations/Lector_de.ts +++ b/resources/translations/Lector_de.ts @@ -282,20 +282,25 @@ Library - + Author Autor - + Year Jahr - + manually added Manuell hinzugefügt + + + books + + LibraryToolBar @@ -371,62 +376,62 @@ Biblothek scannen - + Add books to database Bücher zur Datenbank hinzufügen - + eBooks eBooks - + Adding books... Bücher werden hinzugefügt... - + Confirm deletion Löschen bestätigen - + Save changes and start library scan Änderungen speichern & Bibliotheksscan starten - + Books Bücher - + Start reading Lesen - + Edit Bearbeiten - + Delete Löschen - + Mark read Als gelesen kennzeichnen - + Mark unread Als ungelesen kennzeichnen - + Manually Added Manuell hinzugefügt @@ -440,6 +445,11 @@ Images Bilder + + + books + + MetadataUI @@ -526,37 +536,37 @@ SettingsUI - + English Englisch - + Spanish Spanisch - + Hindi Hindi - + Save changes and start library scan Änderungen speichern & Bibliotheksscan starten - + Library scan in progress... Bibliotheksscan in Arbeit... - + Checking library folders Bibliotheksverzeichnisse werden überprüft - + Parsing files Dateien werden analysiert @@ -607,7 +617,7 @@ Zuletzt gelesen - + Tags Tags diff --git a/resources/translations/Lector_es.ts b/resources/translations/Lector_es.ts index 0b1cb98..843a2ab 100644 --- a/resources/translations/Lector_es.ts +++ b/resources/translations/Lector_es.ts @@ -282,20 +282,25 @@ Library - + Author Autor - + Year Año - + manually added añadido manualmente + + + books + + LibraryToolBar @@ -371,62 +376,62 @@ Explorar la biblioteca - + Add books to database Añadir libros a la base de datos - + eBooks Libros electrónicos - + Adding books... Añadiendo los libros… - + Confirm deletion Confirmar la eliminación - + Save changes and start library scan Guardar cambios e iniciar exploración de biblioteca - + Books Libros - + Start reading Comenzar a leer - + Edit Editar - + Delete Eliminar - + Mark read Marcar como leído - + Mark unread Marcar como no leído - + Manually Added Añadido manualmente @@ -440,6 +445,11 @@ Images Imágenes + + + books + + MetadataUI @@ -536,37 +546,37 @@ SettingsUI - + English Inglés - + Spanish Español - + Hindi Hindi - + Save changes and start library scan Guardar cambios e iniciar exploración de biblioteca - + Library scan in progress... Se está explorando la biblioteca… - + Checking library folders Comprobando las carpetas de la biblioteca - + Parsing files Procesando los archivos @@ -617,7 +627,7 @@ Última lectura - + Tags Etiquetas diff --git a/resources/translations/Lector_fr.ts b/resources/translations/Lector_fr.ts index beeeb9f..f7daa06 100644 --- a/resources/translations/Lector_fr.ts +++ b/resources/translations/Lector_fr.ts @@ -282,20 +282,25 @@ Library - + Author Auteur - + Year Année - + manually added manuellement ajouté + + + books + + LibraryToolBar @@ -371,62 +376,62 @@ Analyser la bibliothèque - + Add books to database Ajouter des livres à la base de données - + eBooks eBooks - + Adding books... Ajout des livres… - + Confirm deletion Confirmez la suppression - + Save changes and start library scan Enregistrer les modifications et démarrer l'analyse de la bibliothèque - + Books Livres - + Start reading Commencer à lire - + Edit Modifier - + Delete Supprimer - + Mark read Marquer comme lu - + Mark unread Marquer comme non-lu - + Manually Added Manuellement ajouté @@ -440,6 +445,11 @@ Images Images + + + books + + MetadataUI @@ -526,37 +536,37 @@ SettingsUI - + English Anglais - + Spanish Espagnol - + Hindi Hindi - + Save changes and start library scan Enregistrer les modifications et démarrer l'analyse de la bibliothèque - + Library scan in progress... Analyse de la bibliothèque en cours… - + Checking library folders Vérification des dossiers de la bibliothèque - + Parsing files Lecture des fichiers @@ -607,7 +617,7 @@ Lu pour la dernière fois - + Tags Étiquettes diff --git a/resources/translations/SAMPLE.ts b/resources/translations/SAMPLE.ts index 3f95dc4..f8f81d8 100644 --- a/resources/translations/SAMPLE.ts +++ b/resources/translations/SAMPLE.ts @@ -282,20 +282,25 @@ Library - + Author - + Year - + manually added + + + books + + LibraryToolBar @@ -371,62 +376,62 @@ - + Add books to database - + eBooks - + Adding books... - + Confirm deletion - + Save changes and start library scan - + Books - + Start reading - + Edit - + Delete - + Mark read - + Mark unread - + Manually Added @@ -440,6 +445,11 @@ Images + + + books + + MetadataUI @@ -526,37 +536,37 @@ SettingsUI - + English - + Spanish - + Hindi - + Save changes and start library scan - + Library scan in progress... - + Checking library folders - + Parsing files @@ -607,7 +617,7 @@ - + Tags