Spacebar navigation, Settings dialog

This commit is contained in:
BasioMeusPuga
2017-11-17 12:13:33 +05:30
parent bf8ddf4346
commit 5b1b9c1c92
4 changed files with 252 additions and 17 deletions

View File

@@ -68,7 +68,7 @@ from PyQt5 import QtWidgets, QtGui, QtCore
import sorter import sorter
import database import database
from resources import mainwindow from resources import mainwindow, settingswindow
from widgets import LibraryToolBar, BookToolBar, Tab from widgets import LibraryToolBar, BookToolBar, Tab
from widgets import LibraryDelegate, BackGroundTabUpdate, BackGroundBookAddition from widgets import LibraryDelegate, BackGroundTabUpdate, BackGroundBookAddition
from library import Library from library import Library
@@ -80,6 +80,8 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
super(MainUI, self).__init__() super(MainUI, self).__init__()
self.setupUi(self) self.setupUi(self)
self.settings_dialog = SettingsUI()
# Empty variables that will be infested soon # Empty variables that will be infested soon
self.last_open_books = None self.last_open_books = None
self.last_open_tab = None self.last_open_tab = None
@@ -110,6 +112,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
self.libraryToolBar = LibraryToolBar(self) self.libraryToolBar = LibraryToolBar(self)
self.libraryToolBar.addButton.triggered.connect(self.add_books) self.libraryToolBar.addButton.triggered.connect(self.add_books)
self.libraryToolBar.deleteButton.triggered.connect(self.delete_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.searchBar.textChanged.connect(self.lib_ref.update_proxymodel)
self.libraryToolBar.sortingBox.activated.connect(self.lib_ref.update_proxymodel) self.libraryToolBar.sortingBox.activated.connect(self.lib_ref.update_proxymodel)
self.addToolBar(self.libraryToolBar) self.addToolBar(self.libraryToolBar)
@@ -117,6 +120,7 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
# Book toolbar # Book toolbar
self.bookToolBar = BookToolBar(self) self.bookToolBar = BookToolBar(self)
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen) self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
self.bookToolBar.settingsButton.triggered.connect(self.show_settings)
for count, i in enumerate(self.display_profiles): for count, i in enumerate(self.display_profiles):
self.bookToolBar.profileBox.setItemData(count, i, QtCore.Qt.UserRole) 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) current_profile_index, current_profile_default, QtCore.Qt.UserRole)
self.format_contentView() 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): def closeEvent(self, event=None):
# All tabs must be iterated upon here # All tabs must be iterated upon here
self.temp_dir.remove()
self.hide() self.hide()
self.settings_dialog.hide()
self.temp_dir.remove()
self.last_open_books = [] self.last_open_books = []
if self.tabWidget.count() > 1: if self.tabWidget.count() > 1:
@@ -499,6 +512,12 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
QtWidgets.qApp.exit() QtWidgets.qApp.exit()
class SettingsUI(QtWidgets.QDialog, settingswindow.Ui_Dialog):
def __init__(self):
super(SettingsUI, self).__init__()
self.setupUi(self)
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

114
resources/raw/settings.ui Normal file
View File

@@ -0,0 +1,114 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog</class>
<widget class="QDialog" name="Dialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>817</width>
<height>476</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Library Directories:</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QTableWidget" name="tableWidget">
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
<column>
<property name="text">
<string>Auto Tag</string>
</property>
</column>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="addButton">
<property name="text">
<string>Add</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="text">
<string>Remove</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="refreshButton">
<property name="text">
<string>Refresh</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QCheckBox" name="fileRemember">
<property name="text">
<string>Remember open files</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="text">
<string>Auto add files on start</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="okButton">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

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

View File

@@ -42,6 +42,7 @@ class BookToolBar(QtWidgets.QToolBar):
self.addSeparator() self.addSeparator()
self.addAction(self.fullscreenButton) self.addAction(self.fullscreenButton)
self.addAction(self.settingsButton) self.addAction(self.settingsButton)
self.settingsButton.setCheckable(True)
# Font modification # Font modification
font_sizes = [str(i) for i in range(8, 48, 2)] font_sizes = [str(i) for i in range(8, 48, 2)]
@@ -213,6 +214,7 @@ class LibraryToolBar(QtWidgets.QToolBar):
self.addAction(self.deleteButton) self.addAction(self.deleteButton)
self.addSeparator() self.addSeparator()
self.addAction(self.settingsButton) self.addAction(self.settingsButton)
self.settingsButton.setCheckable(True)
# Filter # Filter
sizePolicy = QtWidgets.QSizePolicy( sizePolicy = QtWidgets.QSizePolicy(
@@ -331,6 +333,8 @@ class Tab(QtWidgets.QWidget):
title = self.metadata['title'] title = self.metadata['title']
self.parent.addTab(self, title) self.parent.addTab(self, title)
self.contentView.setFocus()
def generate_position(self): def generate_position(self):
total_chapters = len(self.metadata['content'].keys()) total_chapters = len(self.metadata['content'].keys())
# TODO # TODO
@@ -353,13 +357,6 @@ class Tab(QtWidgets.QWidget):
self.prev_chapter.setObjectName('prevChapter') self.prev_chapter.setObjectName('prevChapter')
self.prev_chapter.activated.connect(self.sneaky_change) 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( self.go_fs = QtWidgets.QShortcut(
QtGui.QKeySequence('F11'), self.contentView) QtGui.QKeySequence('F11'), self.contentView)
self.go_fs.activated.connect(self.window().set_fullscreen) 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.setWindowState(QtCore.Qt.WindowNoState)
self.contentView.show() 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): def change_chapter_tocBox(self):
chapter_name = self.window().bookToolBar.tocBox.currentText() chapter_name = self.window().bookToolBar.tocBox.currentText()
required_content = self.metadata['content'][chapter_name] required_content = self.metadata['content'][chapter_name]
@@ -462,6 +451,21 @@ class PliantQGraphicsView(QtWidgets.QGraphicsView):
def wheelEvent(self, event): def wheelEvent(self, event):
self.common_functions.wheelEvent(event, True) 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): class PliantQTextBrowser(QtWidgets.QTextBrowser):
def __init__(self, main_window, parent=None): def __init__(self, main_window, parent=None):
@@ -475,6 +479,19 @@ class PliantQTextBrowser(QtWidgets.QTextBrowser):
def wheelEvent(self, event): def wheelEvent(self, event):
self.common_functions.wheelEvent(event, False) 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(): class PliantWidgetsCommonFunctions():
def __init__(self, parent_widget, main_window): def __init__(self, parent_widget, main_window):