From 5b1b9c1c922911c89e15479362169a576596fdeb Mon Sep 17 00:00:00 2001 From: BasioMeusPuga Date: Fri, 17 Nov 2017 12:13:33 +0530 Subject: [PATCH] Spacebar navigation, Settings dialog --- __main__.py | 23 +++++++- resources/raw/settings.ui | 114 ++++++++++++++++++++++++++++++++++++ resources/settingswindow.py | 85 +++++++++++++++++++++++++++ widgets.py | 47 ++++++++++----- 4 files changed, 252 insertions(+), 17 deletions(-) create mode 100644 resources/raw/settings.ui create mode 100644 resources/settingswindow.py diff --git a/__main__.py b/__main__.py index c85e2cf..85fef6f 100755 --- a/__main__.py +++ b/__main__.py @@ -68,7 +68,7 @@ from PyQt5 import QtWidgets, QtGui, QtCore import sorter import database -from resources import mainwindow +from resources import mainwindow, settingswindow from widgets import LibraryToolBar, BookToolBar, Tab from widgets import LibraryDelegate, BackGroundTabUpdate, BackGroundBookAddition from library import Library @@ -80,6 +80,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): super(MainUI, self).__init__() self.setupUi(self) + self.settings_dialog = SettingsUI() + # Empty variables that will be infested soon self.last_open_books = None self.last_open_tab = None @@ -110,6 +112,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): self.libraryToolBar = LibraryToolBar(self) self.libraryToolBar.addButton.triggered.connect(self.add_books) self.libraryToolBar.deleteButton.triggered.connect(self.delete_books) + self.libraryToolBar.settingsButton.triggered.connect(self.show_settings) self.libraryToolBar.searchBar.textChanged.connect(self.lib_ref.update_proxymodel) self.libraryToolBar.sortingBox.activated.connect(self.lib_ref.update_proxymodel) self.addToolBar(self.libraryToolBar) @@ -117,6 +120,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): # Book toolbar self.bookToolBar = BookToolBar(self) self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen) + self.bookToolBar.settingsButton.triggered.connect(self.show_settings) for count, i in enumerate(self.display_profiles): self.bookToolBar.profileBox.setItemData(count, i, QtCore.Qt.UserRole) @@ -475,10 +479,19 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): current_profile_index, current_profile_default, QtCore.Qt.UserRole) self.format_contentView() + def show_settings(self): + # TODO + # The hiding of the settings dialog should uncheck the settings show action + if not self.settings_dialog.isVisible(): + self.settings_dialog.show() + else: + self.settings_dialog.hide() + def closeEvent(self, event=None): # All tabs must be iterated upon here - self.temp_dir.remove() self.hide() + self.settings_dialog.hide() + self.temp_dir.remove() self.last_open_books = [] if self.tabWidget.count() > 1: @@ -499,6 +512,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow): QtWidgets.qApp.exit() +class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog): + def __init__(self): + super(SettingsUI, self).__init__() + self.setupUi(self) + + def main(): app = QtWidgets.QApplication(sys.argv) app.setApplicationName('Lector') # This is needed for QStandardPaths diff --git a/resources/raw/settings.ui b/resources/raw/settings.ui new file mode 100644 index 0000000..215a2f0 --- /dev/null +++ b/resources/raw/settings.ui @@ -0,0 +1,114 @@ + + + Dialog + + + + 0 + 0 + 817 + 476 + + + + Settings + + + + + + + + Library Directories: + + + Qt::AlignCenter + + + + + + + true + + + + Name + + + + + Path + + + + + Auto Tag + + + + + + + + + + Add + + + + + + + Remove + + + + + + + Refresh + + + + + + + + + Qt::Horizontal + + + + + + + + + Remember open files + + + + + + + Auto add files on start + + + + + + + OK + + + + + + + + + + + + diff --git a/resources/settingswindow.py b/resources/settingswindow.py new file mode 100644 index 0000000..cadc3e3 --- /dev/null +++ b/resources/settingswindow.py @@ -0,0 +1,85 @@ +# -*- coding: utf-8 -*- + +# Form implementation generated from reading ui file 'raw/settings.ui' +# +# Created by: PyQt5 UI code generator 5.9.1 +# +# WARNING! All changes made in this file will be lost! + +from PyQt5 import QtCore, QtGui, QtWidgets + +class Ui_Dialog(object): + def setupUi(self, Dialog): + Dialog.setObjectName("Dialog") + Dialog.resize(817, 476) + self.gridLayout = QtWidgets.QGridLayout(Dialog) + self.gridLayout.setObjectName("gridLayout") + self.verticalLayout_2 = QtWidgets.QVBoxLayout() + self.verticalLayout_2.setObjectName("verticalLayout_2") + self.label = QtWidgets.QLabel(Dialog) + self.label.setAlignment(QtCore.Qt.AlignCenter) + self.label.setObjectName("label") + self.verticalLayout_2.addWidget(self.label) + self.tableWidget = QtWidgets.QTableWidget(Dialog) + self.tableWidget.setAlternatingRowColors(True) + self.tableWidget.setObjectName("tableWidget") + self.tableWidget.setColumnCount(3) + self.tableWidget.setRowCount(0) + item = QtWidgets.QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(0, item) + item = QtWidgets.QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(1, item) + item = QtWidgets.QTableWidgetItem() + self.tableWidget.setHorizontalHeaderItem(2, item) + self.verticalLayout_2.addWidget(self.tableWidget) + self.horizontalLayout_2 = QtWidgets.QHBoxLayout() + self.horizontalLayout_2.setObjectName("horizontalLayout_2") + self.addButton = QtWidgets.QPushButton(Dialog) + self.addButton.setObjectName("addButton") + self.horizontalLayout_2.addWidget(self.addButton) + self.removeButton = QtWidgets.QPushButton(Dialog) + self.removeButton.setObjectName("removeButton") + self.horizontalLayout_2.addWidget(self.removeButton) + self.refreshButton = QtWidgets.QPushButton(Dialog) + self.refreshButton.setObjectName("refreshButton") + self.horizontalLayout_2.addWidget(self.refreshButton) + self.verticalLayout_2.addLayout(self.horizontalLayout_2) + self.line = QtWidgets.QFrame(Dialog) + self.line.setFrameShape(QtWidgets.QFrame.HLine) + self.line.setFrameShadow(QtWidgets.QFrame.Sunken) + self.line.setObjectName("line") + self.verticalLayout_2.addWidget(self.line) + self.horizontalLayout_3 = QtWidgets.QHBoxLayout() + self.horizontalLayout_3.setObjectName("horizontalLayout_3") + self.fileRemember = QtWidgets.QCheckBox(Dialog) + self.fileRemember.setObjectName("fileRemember") + self.horizontalLayout_3.addWidget(self.fileRemember) + self.checkBox = QtWidgets.QCheckBox(Dialog) + self.checkBox.setObjectName("checkBox") + self.horizontalLayout_3.addWidget(self.checkBox) + self.okButton = QtWidgets.QPushButton(Dialog) + self.okButton.setObjectName("okButton") + self.horizontalLayout_3.addWidget(self.okButton) + self.verticalLayout_2.addLayout(self.horizontalLayout_3) + self.gridLayout.addLayout(self.verticalLayout_2, 0, 0, 1, 1) + + self.retranslateUi(Dialog) + QtCore.QMetaObject.connectSlotsByName(Dialog) + + def retranslateUi(self, Dialog): + _translate = QtCore.QCoreApplication.translate + Dialog.setWindowTitle(_translate("Dialog", "Settings")) + self.label.setText(_translate("Dialog", "Library Directories:")) + item = self.tableWidget.horizontalHeaderItem(0) + item.setText(_translate("Dialog", "Name")) + item = self.tableWidget.horizontalHeaderItem(1) + item.setText(_translate("Dialog", "Path")) + item = self.tableWidget.horizontalHeaderItem(2) + item.setText(_translate("Dialog", "Auto Tag")) + self.addButton.setText(_translate("Dialog", "Add")) + self.removeButton.setText(_translate("Dialog", "Remove")) + self.refreshButton.setText(_translate("Dialog", "Refresh")) + self.fileRemember.setText(_translate("Dialog", "Remember open files")) + self.checkBox.setText(_translate("Dialog", "Auto add files on start")) + self.okButton.setText(_translate("Dialog", "OK")) + diff --git a/widgets.py b/widgets.py index 01e15a2..b451a10 100644 --- a/widgets.py +++ b/widgets.py @@ -42,6 +42,7 @@ class BookToolBar(QtWidgets.QToolBar): self.addSeparator() self.addAction(self.fullscreenButton) self.addAction(self.settingsButton) + self.settingsButton.setCheckable(True) # Font modification font_sizes = [str(i) for i in range(8, 48, 2)] @@ -213,6 +214,7 @@ class LibraryToolBar(QtWidgets.QToolBar): self.addAction(self.deleteButton) self.addSeparator() self.addAction(self.settingsButton) + self.settingsButton.setCheckable(True) # Filter sizePolicy = QtWidgets.QSizePolicy( @@ -331,6 +333,8 @@ class Tab(QtWidgets.QWidget): title = self.metadata['title'] self.parent.addTab(self, title) + self.contentView.setFocus() + def generate_position(self): total_chapters = len(self.metadata['content'].keys()) # TODO @@ -353,13 +357,6 @@ class Tab(QtWidgets.QWidget): self.prev_chapter.setObjectName('prevChapter') self.prev_chapter.activated.connect(self.sneaky_change) - # TODO - # Get this working - self.space_press = QtWidgets.QShortcut( - QtGui.QKeySequence('Spacebar'), self.contentView) - self.space_press.setObjectName('spacePress') - self.space_press.activated.connect(self.spacebar_pressed) - self.go_fs = QtWidgets.QShortcut( QtGui.QKeySequence('F11'), self.contentView) self.go_fs.activated.connect(self.window().set_fullscreen) @@ -379,14 +376,6 @@ class Tab(QtWidgets.QWidget): self.contentView.setWindowState(QtCore.Qt.WindowNoState) self.contentView.show() - def spacebar_pressed(self): - vertical = self.verticalScrollBar().value() - maximum = self.verticalScrollBar().maximum() - - if vertical == maximum: - self.contentView.common_functions.change_chapter( - 1, True) - def change_chapter_tocBox(self): chapter_name = self.window().bookToolBar.tocBox.currentText() required_content = self.metadata['content'][chapter_name] @@ -462,6 +451,21 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView): def wheelEvent(self, event): self.common_functions.wheelEvent(event, True) + def keyPressEvent(self, event): + # This function is sufficiently different to warrant + # exclusion from the common functions class + if event.key() == 32: # Spacebar press + vertical = self.verticalScrollBar().value() + maximum = self.verticalScrollBar().maximum() + + if vertical == maximum: + self.common_functions.change_chapter(1, True) + + else: + # Increment by following value + scroll_increment = int((maximum - 0) / 2) + self.verticalScrollBar().setValue(vertical + scroll_increment) + class PliantQTextBrowser(QtWidgets.QTextBrowser): def __init__(self, main_window, parent=None): @@ -475,6 +479,19 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser): def wheelEvent(self, event): self.common_functions.wheelEvent(event, False) + def keyPressEvent(self, event): + if event.key() == 32: + vertical = self.verticalScrollBar().value() + maximum = self.verticalScrollBar().maximum() + + if vertical == maximum: + self.common_functions.change_chapter(1, True) + else: + QtWidgets.QTextBrowser.keyPressEvent(self, event) + + else: + QtWidgets.QTextBrowser.keyPressEvent(self, event) + class PliantWidgetsCommonFunctions(): def __init__(self, parent_widget, main_window):