Multiple fixes

Update translations
This commit is contained in:
BasioMeusPuga
2018-03-20 13:24:17 +05:30
parent 64a96d816d
commit 0d8c2b6648
12 changed files with 208 additions and 152 deletions

View File

@@ -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()

View File

@@ -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

View File

@@ -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):

View File

@@ -16,7 +16,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
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)

View File

@@ -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())

View File

@@ -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):

View File

@@ -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):