Mark translatable strings

This commit is contained in:
BasioMeusPuga
2018-03-18 22:19:19 +05:30
parent fd149dcafa
commit a7df896468
8 changed files with 193 additions and 85 deletions

View File

@@ -50,6 +50,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
super(MainUI, self).__init__()
self.setupUi(self)
# Initialize translation function
self._translate = QtCore.QCoreApplication.translate
# Empty variables that will be infested soon
self.settings = {}
self.thread = None # Background Thread
@@ -103,7 +106,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Statusbar + Toolbar Visibility
self.distractionFreeToggle.setIcon(self.QImageFactory.get_image('visibility'))
self.distractionFreeToggle.setObjectName('distractionFreeToggle')
self.distractionFreeToggle.setToolTip('Toggle distraction free mode (Ctrl + D)')
self.distractionFreeToggle.setToolTip(
self._translate('Main_UI', 'Toggle distraction free mode (Ctrl + D)'))
self.distractionFreeToggle.setAutoRaise(True)
self.distractionFreeToggle.clicked.connect(self.toggle_distraction_free)
self.statusBar.addPermanentWidget(self.distractionFreeToggle)
@@ -198,7 +202,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# The library refresh button on the Library tab
self.reloadLibrary.setIcon(self.QImageFactory.get_image('reload'))
self.reloadLibrary.setObjectName('reloadLibrary')
self.reloadLibrary.setToolTip('Scan library')
self.reloadLibrary.setToolTip(self._translate('Main_UI', 'Scan library'))
self.reloadLibrary.setAutoRaise(True)
self.reloadLibrary.clicked.connect(self.settingsDialog.start_library_scan)
@@ -451,9 +455,11 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# If a file is added from here, it should not be removed
# from the libary in case of a database refresh
dialog_prompt = self._translate('Main_UI', 'Add books to database')
ebooks_string = self._translate('Main_UI', 'eBooks')
opened_files = QtWidgets.QFileDialog.getOpenFileNames(
self, 'Add books to database', self.settings['last_open_path'],
f'eBooks ({self.available_parsers})')
self, dialog_prompt, self.settings['last_open_path'],
f'{ebooks_string} ({self.available_parsers})')
if not opened_files[0]:
return
@@ -463,7 +469,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.settings['last_open_path'] = os.path.dirname(opened_files[0][0])
self.sorterProgress.setVisible(True)
self.statusMessage.setText('Adding books...')
self.statusMessage.setText(self._translate('Main_UI', 'Adding books...'))
self.thread = BackGroundBookAddition(
opened_files[0], self.database_path, False, self)
self.thread.finished.connect(self.move_on)
@@ -527,9 +533,11 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Generate a message box to confirm deletion
selected_number = len(selected_indexes)
confirm_deletion = QtWidgets.QMessageBox()
confirm_deletion.setText('Delete %d book(s)?' % selected_number)
deletion_prompt = self._translate(
'Main_UI', f'Delete {selected_number} book(s)?')
confirm_deletion.setText(deletion_prompt)
confirm_deletion.setIcon(QtWidgets.QMessageBox.Question)
confirm_deletion.setWindowTitle('Confirm deletion')
confirm_deletion.setWindowTitle(self._translate('Main_UI', 'Confirm deletion'))
confirm_deletion.setStandardButtons(
QtWidgets.QMessageBox.Yes | QtWidgets.QMessageBox.No)
confirm_deletion.buttonClicked.connect(ifcontinue)
@@ -539,7 +547,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
def move_on(self):
self.settingsDialog.okButton.setEnabled(True)
self.settingsDialog.okButton.setToolTip(
'Save changes and start library scan')
self._translate('Main_UI', 'Save changes and start library scan'))
self.reloadLibrary.setEnabled(True)
self.sorterProgress.setVisible(False)
@@ -583,7 +591,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Making the proxy model available doesn't affect
# memory utilization at all. Bleh.
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'))
else:
if self.settings['show_bars']:
@@ -1009,19 +1018,24 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
context_menu = QtWidgets.QMenu()
openAction = context_menu.addAction(
self.QImageFactory.get_image('view-readermode'), 'Start reading')
self.QImageFactory.get_image('view-readermode'),
self._translate('Main_UI', 'Start reading'))
editAction = None
if len(selected_indexes) == 1:
editAction = context_menu.addAction(
self.QImageFactory.get_image('edit-rename'), 'Edit')
self.QImageFactory.get_image('edit-rename'),
self._translate('Main_UI', 'Edit'))
deleteAction = context_menu.addAction(
self.QImageFactory.get_image('trash-empty'), 'Delete')
self.QImageFactory.get_image('trash-empty'),
self._translate('Main_UI', 'Delete'))
readAction = context_menu.addAction(
QtGui.QIcon(':/images/checkmark.svg'), 'Mark read')
QtGui.QIcon(':/images/checkmark.svg'),
self._translate('Main_UI', 'Mark read'))
unreadAction = context_menu.addAction(
QtGui.QIcon(':/images/xmark.svg'), 'Mark unread')
QtGui.QIcon(':/images/xmark.svg'),
self._translate('Main_UI', 'Mark unread'))
action = context_menu.exec_(self.sender().mapToGlobal(position))
@@ -1118,7 +1132,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
checked = [i for i in directory_list if i[3] == QtCore.Qt.Checked]
filter_list = list(map(generate_name, checked))
filter_list.sort()
filter_list.append('Manually Added')
filter_list.append(self._translate('Main_UI', 'Manually Added'))
filter_actions = [QtWidgets.QAction(i, self.libraryFilterMenu) for i in filter_list]
filter_all = QtWidgets.QAction('All', self.libraryFilterMenu)
@@ -1211,6 +1225,14 @@ def main():
app = QtWidgets.QApplication(sys.argv)
app.setApplicationName('Lector') # This is needed for QStandardPaths
# and my own hubris
# Internationalization support
translator = QtCore.QTranslator()
translation_file = f':/translations/Lector_{QtCore.QLocale.system().name()}.qm'
print(f'Localization: {QtCore.QLocale.system().name()}')
translator.load(translation_file)
app.installTranslator(translator)
form = MainUI()
form.show()
form.resizeEvent()

View File

@@ -26,8 +26,10 @@ class DefinitionsUI(QtWidgets.QDialog, definitions.Ui_Dialog):
def __init__(self, parent):
super(DefinitionsUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.previous_position = None
self.setWindowFlags(
QtCore.Qt.Popup |
@@ -109,8 +111,9 @@ class DefinitionsUI(QtWidgets.QDialog, definitions.Ui_Dialog):
html_string += f'<h2><em><strong>{word}</strong></em></h2>\n'
if nothing_found:
nope_string = self._translate('DefinitionsUI', 'No definitions found in')
language = self.parent.settings['dictionary_language'].upper()
html_string += f'<p><em>No definitions found in {language}<em></p>\n'
html_string += f'<p><em>{nope_string} {language}<em></p>\n'
else:
# Word root
html_string += f'<p><em>Word root: <em>{word_root}</p>\n'

View File

@@ -31,6 +31,7 @@ class Library:
self.view_model = None
self.item_proxy_model = None
self.table_proxy_model = None
self._translate = QtCore.QCoreApplication.translate
def generate_model(self, mode, parsed_books=None, is_database_ready=True):
if mode == 'build':
@@ -117,7 +118,9 @@ class Library:
'last_accessed': last_accessed,
'file_exists': file_exists}
tooltip_string = title + '\nAuthor: ' + author + '\nYear: ' + str(year)
author_string = self._translate('Library', 'Author')
year_string = self._translate('Library', 'Year')
tooltip_string = f'{title} \n{author_string}: {author} \n{year_string}: {str(year)}'
# Additional data can be set using an incrementing
# QtCore.Qt.UserRole
@@ -251,7 +254,8 @@ class Library:
return directory_name, directory_tags
return 'manually added', None
added_string = self._translate('Library', 'manually added')
return added_string.lower(), None
# Generate tags for the QStandardItemModel
for i in range(self.view_model.rowCount()):

View File

@@ -19,15 +19,16 @@
from PyQt5 import QtWidgets, QtCore, QtGui
from lector import database
from lector.widgets import PliantQGraphicsScene
from resources import metadata
from lector.widgets import PliantQGraphicsScene
class MetadataUI(QtWidgets.QDialog, metadata.Ui_Dialog):
def __init__(self, parent):
super(MetadataUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
self.setWindowFlags(
QtCore.Qt.Popup |
@@ -97,7 +98,9 @@ class MetadataUI(QtWidgets.QDialog, metadata.Ui_Dialog):
except ValueError:
year = self.book_year
tooltip_string = title + '\nAuthor: ' + author + '\nYear: ' + str(year)
author_string = self._translate('MetadataUI', 'Author')
year_string = self._translate('MetadataUI', 'Year')
tooltip_string = f'{title} \n{author_string}: {author} \n{year_string}: {str(year)}'
book_item.setData(title, QtCore.Qt.UserRole)
book_item.setData(author, QtCore.Qt.UserRole + 1)

View File

@@ -27,7 +27,7 @@ class BookmarkProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, parent=None):
super(BookmarkProxyModel, self).__init__(parent)
self.parent = parent
self.filter_string = None
self.filter_text = None
def setFilterParams(self, filter_text):
self.filter_text = filter_text
@@ -68,8 +68,18 @@ class ItemProxyModel(QtCore.QSortFilterProxyModel):
class TableProxyModel(QtCore.QSortFilterProxyModel):
def __init__(self, temp_dir, parent=None):
super(TableProxyModel, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
title_string = self._translate('TableProxyModel', 'Title')
author_string = self._translate('TableProxyModel', 'Author')
year_string = self._translate('TableProxyModel', 'Year')
lastread_string = self._translate('TableProxyModel', 'Last Read')
tags_string = self._translate('TableProxyModel', 'Tags')
self.header_data = [
None, 'Title', 'Author', 'Year', 'Last Read', '%', 'Tags']
None, title_string, author_string,
year_string, lastread_string, '%', tags_string]
self.temp_dir = temp_dir
self.filter_text = None
self.active_library_filters = None

View File

@@ -34,6 +34,7 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
def __init__(self, parent):
super(SettingsUI, self).__init__()
self.setupUi(self)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.database_path = self.parent.database_path
@@ -53,7 +54,11 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
self.filesystem_model = None
self.tag_data_copy = None
languages = ['English', 'Spanish', 'Hindi']
english_string = self._translate('SettingsUI', 'English')
spanish_string = self._translate('SettingsUI', 'Spanish')
hindi_string = self._translate('SettingsUI', 'Hindi')
languages = [english_string, spanish_string, hindi_string]
self.languageBox.addItems(languages)
current_language = self.parent.settings['dictionary_language']
if current_language == 'en':
@@ -64,7 +69,8 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
self.languageBox.setCurrentIndex(2)
self.languageBox.activated.connect(self.change_dictionary_language)
self.okButton.setToolTip('Save changes and start library scan')
self.okButton.setToolTip(
self._translate('SettingsUI', 'Save changes and start library scan'))
self.okButton.clicked.connect(self.start_library_scan)
self.cancelButton.clicked.connect(self.cancel_pressed)
self.aboutButton.clicked.connect(self.about_pressed)
@@ -206,10 +212,12 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
# Disallow rechecking until the first check completes
self.okButton.setEnabled(False)
self.parent.reloadLibrary.setEnabled(False)
self.okButton.setToolTip('Library scan in progress...')
self.okButton.setToolTip(
self._translate('SettingsUI', 'Library scan in progress...'))
# Traverse directories looking for files
self.parent.statusMessage.setText('Checking library folders')
self.parent.statusMessage.setText(
self._translate('SettingsUI', 'Checking library folders'))
self.thread = BackGroundBookSearch(data_pairs, self)
self.thread.finished.connect(self.finished_iterating)
self.thread.start()
@@ -222,7 +230,8 @@ class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
# Hey, messaging is important, okay?
self.parent.sorterProgress.setVisible(True)
self.parent.statusMessage.setText('Parsing files')
self.parent.statusMessage.setText(
self._translate('SettingsUI', 'Parsing files'))
# We now create a new thread to put those files into the database
self.thread = BackGroundBookAddition(

View File

@@ -17,12 +17,13 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5 import QtWidgets, QtCore
class BookToolBar(QtWidgets.QToolBar):
def __init__(self, parent=None):
super(BookToolBar, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
# Spacer
spacer = QtWidgets.QWidget()
@@ -36,27 +37,32 @@ class BookToolBar(QtWidgets.QToolBar):
self.setIconSize(QtCore.QSize(22, 22))
self.setFloatable(False)
self.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
self.setObjectName("LibraryToolBar")
self.setObjectName('LibraryToolBar')
image_factory = self.window().QImageFactory
# Buttons
self.fontButton = QtWidgets.QAction(
image_factory.get_image('gtk-select-font'),
'View settings', self)
self._translate('BookToolBar', 'View settings'),
self)
self.fullscreenButton = QtWidgets.QAction(
image_factory.get_image('view-fullscreen'),
'Fullscreen', self)
self._translate('BookToolBar', 'Fullscreen'),
self)
self.addBookmarkButton = QtWidgets.QAction(
image_factory.get_image('bookmark-new'),
'Add bookmark', self)
self._translate('BookToolBar', 'Add bookmark'),
self)
self.bookmarkButton = QtWidgets.QAction(
image_factory.get_image('bookmarks'),
'Bookmarks', self)
self._translate('BookToolBar', 'Bookmarks'),
self)
self.bookmarkButton.setObjectName('bookmarkButton')
self.resetProfile = QtWidgets.QAction(
image_factory.get_image('reload'),
'Reset profile', self)
self._translate('BookToolBar', 'Reset profile'),
self)
# Add buttons
self.addAction(self.fontButton)
@@ -74,49 +80,57 @@ class BookToolBar(QtWidgets.QToolBar):
font_sizes.extend(['56', '64', '72'])
self.fontSizeBox = QtWidgets.QComboBox(self)
self.fontSizeBox.setObjectName('fontSizeBox')
self.fontSizeBox.setToolTip('Font size')
self.fontSizeBox.setToolTip(self._translate('BookToolBar', 'Font size'))
self.fontSizeBox.addItems(font_sizes)
self.fontSizeBox.setEditable(True)
self.paddingUp = QtWidgets.QAction(
image_factory.get_image('format-indent-less'),
'Increase padding', self)
self._translate('BookToolBar', 'Increase padding'),
self)
self.paddingUp.setObjectName('paddingUp')
self.paddingDown = QtWidgets.QAction(
image_factory.get_image('format-indent-more'),
'Decrease padding', self)
self._translate('BookToolBar', 'Decrease padding'),
self)
self.paddingDown.setObjectName('paddingDown')
self.lineSpacingUp = QtWidgets.QAction(
image_factory.get_image('format-line-spacing-triple'),
'Increase line spacing', self)
self._translate('BookToolBar', 'Increase line spacing'),
self)
self.lineSpacingUp.setObjectName('lineSpacingUp')
self.lineSpacingDown = QtWidgets.QAction(
image_factory.get_image('format-line-spacing-double'),
'Decrease line spacing', self)
self._translate('BookToolBar', 'Decrease line spacing'),
self)
self.lineSpacingDown.setObjectName('lineSpacingDown')
self.alignLeft = QtWidgets.QAction(
image_factory.get_image('format-justify-left'),
'Left align text', self)
self._translate('BookToolBar', 'Left align text'),
self)
self.alignLeft.setObjectName('alignLeft')
self.alignLeft.setCheckable(True)
self.alignRight = QtWidgets.QAction(
image_factory.get_image('format-justify-right'),
'Right align text', self)
self._translate('BookToolBar', 'Right align text'),
self)
self.alignRight.setObjectName('alignRight')
self.alignRight.setCheckable(True)
self.alignCenter = QtWidgets.QAction(
image_factory.get_image('format-justify-center'),
'Center align text', self)
self._translate('BookToolBar', 'Center align text'),
self)
self.alignCenter.setObjectName('alignCenter')
self.alignCenter.setCheckable(True)
self.alignJustify = QtWidgets.QAction(
image_factory.get_image('format-justify-fill'),
'Justify text', self)
self._translate('BookToolBar', 'Justify text'),
self)
self.alignJustify.setObjectName('alignJustify')
self.alignJustify.setCheckable(True)
@@ -135,7 +149,7 @@ class BookToolBar(QtWidgets.QToolBar):
self.colorBoxFG.setObjectName('fgColor')
self.colorBoxFG.setToolTip('Text color')
self.colorBoxBG = FixedPushButton(self)
self.colorBoxBG.setToolTip('Background color')
self.colorBoxBG.setToolTip(self._translate('BookToolBar', 'Background color'))
self.colorBoxBG.setObjectName('bgColor')
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
@@ -187,31 +201,36 @@ class BookToolBar(QtWidgets.QToolBar):
# Comic view modification
self.zoomIn = QtWidgets.QAction(
image_factory.get_image('zoom-in'),
'Zoom in', self)
self._translate('BookToolBar', 'Zoom in'),
self)
self.zoomIn.setObjectName('zoomIn')
self.zoomOut = QtWidgets.QAction(
image_factory.get_image('zoom-out'),
'Zoom Out', self)
self._translate('BookToolBar', 'Zoom Out'),
self)
self.zoomOut.setObjectName('zoomOut')
self.fitWidth = QtWidgets.QAction(
image_factory.get_image('zoom-fit-width'),
'Fit Width', self)
self._translate('BookToolBar', 'Fit Width'),
self)
self.fitWidth.setObjectName('fitWidth')
self.fitWidth.setCheckable(True)
self.bestFit = QtWidgets.QAction(
image_factory.get_image('zoom-fit-best'),
'Best Fit', self)
self._translate('BookToolBar', 'Best Fit'),
self)
self.bestFit.setObjectName('bestFit')
self.bestFit.setCheckable(True)
self.originalSize = QtWidgets.QAction(
image_factory.get_image('zoom-original'),
'Original size', self)
self._translate('BookToolBar', 'Original size'),
self)
self.originalSize.setObjectName('originalSize')
self.originalSize.setCheckable(True)
self.comicBGColor = FixedPushButton(self)
self.comicBGColor.setToolTip('Background color')
self.comicBGColor.setToolTip(self._translate('BookToolBar', 'Background color'))
self.comicBGColor.setObjectName('comicBGColor')
self.comicSeparator1 = self.addSeparator()
@@ -239,7 +258,7 @@ class BookToolBar(QtWidgets.QToolBar):
# Other booktoolbar widgets
self.searchBar = FixedLineEdit(self)
self.searchBar.setPlaceholderText(
'Search...')
self._translate('BookToolBar', 'Search...'))
self.searchBar.setSizePolicy(sizePolicy)
self.searchBar.setContentsMargins(10, 0, 0, 0)
self.searchBar.setObjectName('searchBar')
@@ -247,7 +266,8 @@ class BookToolBar(QtWidgets.QToolBar):
# Sorter
self.tocBox = FixedComboBox(self)
self.tocBox.setObjectName('sortingBox')
self.tocBox.setToolTip('Table of Contents')
self.tocBox.setToolTip(
self._translate('BookToolBar', 'Table of Contents'))
# All of these will be put after the spacer
# This means that the buttons in the left side of
@@ -311,6 +331,7 @@ class BookToolBar(QtWidgets.QToolBar):
class LibraryToolBar(QtWidgets.QToolBar):
def __init__(self, parent=None):
super(LibraryToolBar, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
spacer = QtWidgets.QWidget()
spacer.setSizePolicy(
@@ -326,27 +347,41 @@ class LibraryToolBar(QtWidgets.QToolBar):
# Buttons
self.addButton = QtWidgets.QAction(
image_factory.get_image('add'), 'Add book', self)
image_factory.get_image('add'),
self._translate('LibraryToolBar', 'Add book'),
self)
self.deleteButton = QtWidgets.QAction(
image_factory.get_image('remove'), 'Delete book', self)
image_factory.get_image('remove'),
self._translate('LibraryToolBar', 'Delete book'),
self)
self.colorButton = QtWidgets.QAction(
image_factory.get_image('color-picker'), 'Library background color', self)
image_factory.get_image('color-picker'),
self._translate('LibraryToolBar', 'Library background color'),
self)
self.colorButton.setObjectName('libraryBackground')
self.settingsButton = QtWidgets.QAction(
image_factory.get_image('settings'), 'Settings', self)
image_factory.get_image('settings'),
self._translate('LibraryToolBar', 'Settings'),
self)
self.settingsButton.setCheckable(True)
self.coverViewButton = QtWidgets.QAction(
image_factory.get_image('view-grid'), 'View as covers', self)
image_factory.get_image('view-grid'),
self._translate('LibraryToolBar', 'View as covers'),
self)
self.coverViewButton.setCheckable(True)
self.tableViewButton = QtWidgets.QAction(
image_factory.get_image('table'), 'View as table', self)
image_factory.get_image('table'),
self._translate('LibraryToolBar', 'View as table'),
self)
self.tableViewButton.setCheckable(True)
self.libraryFilterButton = QtWidgets.QToolButton(self)
self.libraryFilterButton.setIcon(image_factory.get_image('view-readermode'))
self.libraryFilterButton.setText('Filter library')
self.libraryFilterButton.setToolTip('Filter library')
self.libraryFilterButton.setText(
self._translate('LibraryToolBar', 'Filter library'))
self.libraryFilterButton.setToolTip(
self._translate('LibraryToolBar', 'Filter library'))
# Auto unchecks the other QToolButton in case of clicking
self.viewButtons = QtWidgets.QActionGroup(self)
@@ -373,19 +408,26 @@ class LibraryToolBar(QtWidgets.QToolBar):
self.searchBar = FixedLineEdit(self)
self.searchBar.setClearButtonEnabled(True)
self.searchBar.setPlaceholderText(
'Search for Title, Author, Tags...')
self._translate('LibraryToolBar', 'Search for Title, Author, Tags...'))
self.searchBar.setSizePolicy(sizePolicy)
self.searchBar.setContentsMargins(10, 0, 0, 0)
self.searchBar.setObjectName('searchBar')
# Sorter
sorting_choices = ['Title', 'Author', 'Year', 'Newest', 'Last read']
title_string = self._translate('TableProxyModel', 'Title')
author_string = self._translate('TableProxyModel', 'Author')
year_string = self._translate('TableProxyModel', 'Year')
newest_string = self._translate('TableProxyModel', 'Newest')
lastread_string = self._translate('TableProxyModel', 'Last Read')
sorting_choices = [
title_string, author_string, year_string, newest_string, lastread_string]
self.sortingBox = FixedComboBox(self)
self.sortingBox.addItems(sorting_choices)
self.sortingBox.setObjectName('sortingBox')
self.sortingBox.setSizePolicy(sizePolicy)
self.sortingBox.setMinimumContentsLength(10)
self.sortingBox.setToolTip('Sort by')
self.sortingBox.setToolTip(self._translate('LibraryToolBar', 'Sort by'))
# Add widgets
self.addWidget(spacer)

View File

@@ -43,6 +43,8 @@ from lector.sorter import resize_image
class Tab(QtWidgets.QWidget):
def __init__(self, metadata, parent=None):
super(Tab, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.metadata = metadata # Save progress data into this dictionary
self.are_we_doing_images_only = self.metadata['images_only']
@@ -118,7 +120,7 @@ class Tab(QtWidgets.QWidget):
# Create the dock widget for context specific display
self.dockWidget = PliantDockWidget(self)
self.dockWidget.setWindowTitle('Bookmarks')
self.dockWidget.setWindowTitle(self._translate('Tab', 'Bookmarks'))
self.dockWidget.setFeatures(QtWidgets.QDockWidget.DockWidgetClosable)
self.dockWidget.setFloating(False)
self.dockWidget.hide()
@@ -373,7 +375,7 @@ class Tab(QtWidgets.QWidget):
# Start dockListView.edit(index) when something new is added
identifier = uuid.uuid4().hex[:10]
description = 'New bookmark'
description = self._translate('Tab', 'New bookmark')
if self.are_we_doing_images_only:
chapter = self.metadata['position']['current_chapter']
@@ -446,9 +448,11 @@ class Tab(QtWidgets.QWidget):
bookmark_menu = QtWidgets.QMenu()
editAction = bookmark_menu.addAction(
self.main_window.QImageFactory.get_image('edit-rename'), 'Edit')
self.main_window.QImageFactory.get_image('edit-rename'),
self._translate('Tab', 'Edit'))
deleteAction = bookmark_menu.addAction(
self.main_window.QImageFactory.get_image('trash-empty'), 'Delete')
self.main_window.QImageFactory.get_image('trash-empty'),
self._translate('Tab', 'Delete'))
action = bookmark_menu.exec_(
self.dockListView.mapToGlobal(position))
@@ -482,6 +486,7 @@ class Tab(QtWidgets.QWidget):
class PliantQGraphicsView(QtWidgets.QGraphicsView):
def __init__(self, filepath, main_window, parent=None):
super(PliantQGraphicsView, self).__init__(parent)
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.main_window = main_window
@@ -677,31 +682,31 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
saveAction = contextMenu.addAction(
self.main_window.QImageFactory.get_image('filesaveas'),
'Save page as...')
self._translate('PliantQGraphicsView', 'Save page as...'))
zoominAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('zoom-in'),
'Zoom in (+)')
self._translate('PliantQGraphicsView', 'Zoom in (+)'))
zoomoutAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('zoom-out'),
'Zoom out (-)')
self._translate('PliantQGraphicsView', 'Zoom out (-)'))
fitWidthAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('zoom-fit-width'),
'Fit width (W)')
self._translate('PliantQGraphicsView', 'Fit width (W)'))
bestFitAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('zoom-fit-best'),
'Best fit (B)')
self._translate('PliantQGraphicsView', 'Best fit (B)'))
originalSizeAction = viewSubMenu.addAction(
self.main_window.QImageFactory.get_image('zoom-original'),
'Original size (O)')
self._translate('PliantQGraphicsView', 'Original size (O)'))
toggleAction = contextMenu.addAction(
self.main_window.QImageFactory.get_image('visibility'),
'Toggle distraction free mode')
self._translate('PliantQGraphicsView', 'Toggle distraction free mode'))
action = contextMenu.exec_(self.sender().mapToGlobal(position))
@@ -730,18 +735,23 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
class PliantQTextBrowser(QtWidgets.QTextBrowser):
def __init__(self, main_window, parent=None):
super(PliantQTextBrowser, self).__init__(parent)
self.main_window = main_window
self._translate = QtCore.QCoreApplication.translate
self.parent = parent
self.ignore_wheel_event = False
self.ignore_wheel_event_number = 0
self.main_window = main_window
self.common_functions = PliantWidgetsCommonFunctions(
self, self.main_window)
self.verticalScrollBar().sliderMoved.connect(self.record_scroll_position)
self.setMouseTracking(True)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(
self.generate_textbrowser_context_menu)
self.setMouseTracking(True)
self.viewport().setCursor(QtCore.Qt.IBeamCursor)
self.verticalScrollBar().sliderMoved.connect(self.record_scroll_position)
self.ignore_wheel_event = False
self.ignore_wheel_event_number = 0
def wheelEvent(self, event):
self.record_scroll_position()
@@ -794,17 +804,18 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
defineAction = 'Caesar si viveret, ad remum dareris'
if selected_word and selected_word != '':
selected_word = selected_word.split()[0]
define_string = self._translate('PliantQTextBrowser', 'Define')
defineAction = context_menu.addAction(
self.main_window.QImageFactory.get_image('view-readermode'),
f'Define "{selected_word}"')
f'{define_string} "{selected_word}"')
searchAction = context_menu.addAction(
self.main_window.QImageFactory.get_image('search'),
'Search')
self._translate('PliantQTextBrowser', 'Search'))
toggleAction = context_menu.addAction(
self.main_window.QImageFactory.get_image('visibility'),
'Toggle distraction free mode')
self._translate('PliantQTextBrowser', 'Toggle distraction free mode'))
action = context_menu.exec_(self.sender().mapToGlobal(position))
@@ -877,7 +888,8 @@ class PliantWidgetsCommonFunctions():
if (current_toc_index < max_toc_index and direction == 1) or (
current_toc_index > 0 and direction == -1):
self.main_window.bookToolBar.tocBox.setCurrentIndex(current_toc_index + direction)
self.main_window.bookToolBar.tocBox.setCurrentIndex(
current_toc_index + direction)
# Set page position depending on if the chapter number is increasing or decreasing
if direction == 1 or was_button_pressed:
@@ -906,14 +918,17 @@ class PliantQGraphicsScene(QtWidgets.QGraphicsScene):
def __init__(self, parent=None):
super(PliantQGraphicsScene, self).__init__(parent)
self.parent = parent
self._translate = QtCore.QCoreApplication.translate
def mouseReleaseEvent(self, event):
self.parent.previous_position = self.parent.pos()
image_files = '*.jpg *.png'
dialog_prompt = self._translate('PliantQGraphicsScene', 'Select new cover')
images_string = self._translate('PliantQGraphicsScene', 'Images')
new_cover = QtWidgets.QFileDialog.getOpenFileName(
None, 'Select new cover', self.parent.parent.settings['last_open_path'],
f'Images ({image_files})')[0]
None, dialog_prompt, self.parent.parent.settings['last_open_path'],
f'{images_string} ({image_files})')[0]
if not new_cover:
self.parent.show()