Font setting settings and settings saving settings
Settings
This commit is contained in:
103
__main__.py
103
__main__.py
@@ -98,17 +98,14 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
|
self.bookToolBar.fullscreenButton.triggered.connect(self.set_fullscreen)
|
||||||
|
|
||||||
self.bookToolBar.fontBox.currentFontChanged.connect(self.modify_font)
|
self.bookToolBar.fontBox.currentFontChanged.connect(self.modify_font)
|
||||||
self.bookToolBar.fontSizeUp.triggered.connect(self.modify_font)
|
self.bookToolBar.fontSizeBox.currentTextChanged.connect(self.modify_font)
|
||||||
self.bookToolBar.fontSizeDown.triggered.connect(self.modify_font)
|
|
||||||
self.bookToolBar.lineSpacingUp.triggered.connect(self.modify_font)
|
self.bookToolBar.lineSpacingUp.triggered.connect(self.modify_font)
|
||||||
self.bookToolBar.lineSpacingDown.triggered.connect(self.modify_font)
|
self.bookToolBar.lineSpacingDown.triggered.connect(self.modify_font)
|
||||||
self.bookToolBar.paddingUp.triggered.connect(self.modify_font)
|
self.bookToolBar.paddingUp.triggered.connect(self.modify_font)
|
||||||
self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
|
self.bookToolBar.paddingDown.triggered.connect(self.modify_font)
|
||||||
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)
|
||||||
self.bookToolBar.profileBox.currentIndexChanged.connect(self.change_display_profile)
|
self.bookToolBar.profileBox.currentIndexChanged.connect(self.format_contentView)
|
||||||
self.current_profile = self.bookToolBar.profileBox.itemData(
|
|
||||||
self.current_profile_index, QtCore.Qt.UserRole)
|
|
||||||
self.bookToolBar.profileBox.setCurrentIndex(self.current_profile_index)
|
self.bookToolBar.profileBox.setCurrentIndex(self.current_profile_index)
|
||||||
|
|
||||||
self.bookToolBar.colorBoxFG.clicked.connect(self.get_color)
|
self.bookToolBar.colorBoxFG.clicked.connect(self.get_color)
|
||||||
@@ -142,18 +139,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
|
self.exit_all = QtWidgets.QShortcut(QtGui.QKeySequence('Ctrl+Q'), self)
|
||||||
self.exit_all.activated.connect(self.closeEvent)
|
self.exit_all.activated.connect(self.closeEvent)
|
||||||
|
|
||||||
# Display profiles
|
|
||||||
# TODO
|
|
||||||
# Get display profiles from settings
|
|
||||||
# Current using a default
|
|
||||||
# self.bookToolBar.profileBox.setItemData(1, 'asdadasd', QtCore.Qt.UserRole)
|
|
||||||
# self.current_profile = {
|
|
||||||
# 'font': 'Noto Sans',
|
|
||||||
# 'foreground': 'grey',
|
|
||||||
# 'background': 'black',
|
|
||||||
# 'padding': 100,
|
|
||||||
# 'font_size': 22,
|
|
||||||
# 'line_spacing': 1.5}
|
|
||||||
|
|
||||||
def resizeEvent(self, event=None):
|
def resizeEvent(self, event=None):
|
||||||
if event:
|
if event:
|
||||||
@@ -339,6 +324,9 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
|
|
||||||
def get_color(self):
|
def get_color(self):
|
||||||
signal_sender = self.sender().objectName()
|
signal_sender = self.sender().objectName()
|
||||||
|
profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||||
|
current_profile = self.bookToolBar.profileBox.itemData(
|
||||||
|
profile_index, QtCore.Qt.UserRole)
|
||||||
|
|
||||||
colorDialog = QtWidgets.QColorDialog()
|
colorDialog = QtWidgets.QColorDialog()
|
||||||
new_color = colorDialog.getColor()
|
new_color = colorDialog.getColor()
|
||||||
@@ -350,54 +338,81 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
if signal_sender == 'fgColor':
|
if signal_sender == 'fgColor':
|
||||||
self.bookToolBar.colorBoxFG.setStyleSheet(
|
self.bookToolBar.colorBoxFG.setStyleSheet(
|
||||||
'background-color: %s' % color_name)
|
'background-color: %s' % color_name)
|
||||||
self.current_profile['foreground'] = color_name
|
current_profile['foreground'] = color_name
|
||||||
|
|
||||||
elif signal_sender == 'bgColor':
|
elif signal_sender == 'bgColor':
|
||||||
self.bookToolBar.colorBoxBG.setStyleSheet(
|
self.bookToolBar.colorBoxBG.setStyleSheet(
|
||||||
'background-color: %s' % color_name)
|
'background-color: %s' % color_name)
|
||||||
self.current_profile['background'] = color_name
|
current_profile['background'] = color_name
|
||||||
|
|
||||||
|
self.bookToolBar.profileBox.setItemData(
|
||||||
|
profile_index, current_profile, QtCore.Qt.UserRole)
|
||||||
self.format_contentView()
|
self.format_contentView()
|
||||||
|
|
||||||
def modify_font(self):
|
def modify_font(self):
|
||||||
signal_sender = self.sender().objectName()
|
signal_sender = self.sender().objectName()
|
||||||
|
profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||||
|
current_profile = self.bookToolBar.profileBox.itemData(
|
||||||
|
profile_index, QtCore.Qt.UserRole)
|
||||||
|
|
||||||
if signal_sender == 'fontBox':
|
if signal_sender == 'fontBox':
|
||||||
self.current_profile['font'] = self.bookToolBar.fontBox.currentFont().family()
|
current_profile['font'] = self.bookToolBar.fontBox.currentFont().family()
|
||||||
|
|
||||||
|
if signal_sender == 'fontSizeBox':
|
||||||
|
old_size = current_profile['font_size']
|
||||||
|
new_size = self.bookToolBar.fontSizeBox.currentText()
|
||||||
|
if new_size.isdigit():
|
||||||
|
current_profile['font_size'] = int(new_size)
|
||||||
|
else:
|
||||||
|
current_profile['font_size'] = old_size
|
||||||
|
|
||||||
if signal_sender == 'fontSizeUp':
|
|
||||||
self.current_profile['font_size'] += 1
|
|
||||||
if signal_sender == 'fontSizeDown':
|
|
||||||
if self.current_profile['font_size'] > 5:
|
|
||||||
self.current_profile['font_size'] -= 1
|
|
||||||
if signal_sender == 'lineSpacingUp':
|
if signal_sender == 'lineSpacingUp':
|
||||||
self.current_profile['line_spacing'] += .5
|
current_profile['line_spacing'] += .5
|
||||||
if signal_sender == 'lineSpacingDown':
|
if signal_sender == 'lineSpacingDown':
|
||||||
self.current_profile['line_spacing'] -= .5
|
current_profile['line_spacing'] -= .5
|
||||||
|
|
||||||
if signal_sender == 'paddingUp':
|
if signal_sender == 'paddingUp':
|
||||||
self.current_profile['padding'] += 5
|
current_profile['padding'] += 5
|
||||||
if signal_sender == 'paddingDown':
|
if signal_sender == 'paddingDown':
|
||||||
self.current_profile['padding'] -= 5
|
current_profile['padding'] -= 5
|
||||||
|
|
||||||
|
self.bookToolBar.profileBox.setItemData(
|
||||||
|
profile_index, current_profile, QtCore.Qt.UserRole)
|
||||||
self.format_contentView()
|
self.format_contentView()
|
||||||
|
|
||||||
def format_contentView(self):
|
def format_contentView(self):
|
||||||
# TODO
|
# TODO
|
||||||
# Implement line spacing
|
# Implement line spacing
|
||||||
# Implement font changing
|
|
||||||
# See what happens if a font isn't installed
|
# See what happens if a font isn't installed
|
||||||
|
|
||||||
# print(self.bookToolBar.profileBox.itemData(1, QtCore.Qt.UserRole))
|
profile_index = self.bookToolBar.profileBox.currentIndex()
|
||||||
# print(self.current_profile)
|
current_profile = self.bookToolBar.profileBox.itemData(
|
||||||
# current_profile = self.bookToolBar.profileBox.itemData()
|
profile_index, QtCore.Qt.UserRole)
|
||||||
|
|
||||||
|
font = current_profile['font']
|
||||||
|
foreground = current_profile['foreground']
|
||||||
|
background = current_profile['background']
|
||||||
|
padding = current_profile['padding']
|
||||||
|
font_size = current_profile['font_size']
|
||||||
|
|
||||||
font = self.current_profile['font']
|
# Change toolbar widgets to match new settings
|
||||||
foreground = self.current_profile['foreground']
|
self.bookToolBar.fontBox.blockSignals(True)
|
||||||
background = self.current_profile['background']
|
self.bookToolBar.fontSizeBox.blockSignals(True)
|
||||||
padding = self.current_profile['padding']
|
self.bookToolBar.fontBox.setCurrentText(font)
|
||||||
font_size = self.current_profile['font_size']
|
self.bookToolBar.fontSizeBox.setCurrentText(str(font_size))
|
||||||
|
self.bookToolBar.fontBox.blockSignals(False)
|
||||||
|
self.bookToolBar.fontSizeBox.blockSignals(False)
|
||||||
|
|
||||||
|
self.bookToolBar.colorBoxFG.setStyleSheet(
|
||||||
|
'background-color: %s' % foreground)
|
||||||
|
self.bookToolBar.colorBoxBG.setStyleSheet(
|
||||||
|
'background-color: %s' % background)
|
||||||
|
|
||||||
|
# Do not run when only the library tab is open
|
||||||
|
if self.tabWidget.count() == 1:
|
||||||
|
return
|
||||||
|
|
||||||
|
# Change contentView to match new settings
|
||||||
current_tab = self.tabWidget.currentIndex()
|
current_tab = self.tabWidget.currentIndex()
|
||||||
current_tab_widget = self.tabWidget.widget(current_tab)
|
current_tab_widget = self.tabWidget.widget(current_tab)
|
||||||
current_contentView = current_tab_widget.findChildren(QtWidgets.QTextBrowser)[0]
|
current_contentView = current_tab_widget.findChildren(QtWidgets.QTextBrowser)[0]
|
||||||
@@ -406,18 +421,6 @@ class MainUI(QtWidgets.QMainWindow, mainwindow.Ui_MainWindow):
|
|||||||
"QTextEdit {{font-family: {0}; font-size: {1}px; padding-left: {2}; padding-right: {2}; color: {3}; background-color: {4}}}".format(
|
"QTextEdit {{font-family: {0}; font-size: {1}px; padding-left: {2}; padding-right: {2}; color: {3}; background-color: {4}}}".format(
|
||||||
font, font_size, padding, foreground, background))
|
font, font_size, padding, foreground, background))
|
||||||
|
|
||||||
def change_display_profile(self):
|
|
||||||
profile_index = self.bookToolBar.profileBox.currentIndex()
|
|
||||||
|
|
||||||
self.bookToolBar.profileBox.setItemData()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.current_profile = self.bookToolBar.profileBox.itemData(
|
|
||||||
profile_index, QtCore.Qt.UserRole)
|
|
||||||
self.format_contentView()
|
|
||||||
|
|
||||||
|
|
||||||
def closeEvent(self, event=None):
|
def closeEvent(self, event=None):
|
||||||
# All tabs must be iterated upon here
|
# All tabs must be iterated upon here
|
||||||
for i in range(1, self.tabWidget.count()):
|
for i in range(1, self.tabWidget.count()):
|
||||||
|
@@ -171,9 +171,8 @@ class Settings:
|
|||||||
self.default_profile1,
|
self.default_profile1,
|
||||||
self.default_profile2,
|
self.default_profile2,
|
||||||
self.default_profile3])
|
self.default_profile3])
|
||||||
self.parent_window.current_profile_index = self.settings.value(
|
self.parent_window.current_profile_index = int(self.settings.value(
|
||||||
'currentProfileIndex', 0)
|
'currentProfileIndex', 0))
|
||||||
|
|
||||||
self.settings.endGroup()
|
self.settings.endGroup()
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
@@ -185,4 +184,17 @@ class Settings:
|
|||||||
self.settings.beginGroup('runtimeVariables')
|
self.settings.beginGroup('runtimeVariables')
|
||||||
self.settings.setValue('lastOpenPath', self.parent_window.last_open_path)
|
self.settings.setValue('lastOpenPath', self.parent_window.last_open_path)
|
||||||
self.settings.setValue('databasePath', self.parent_window.database_path)
|
self.settings.setValue('databasePath', self.parent_window.database_path)
|
||||||
|
|
||||||
|
current_profile1 = self.parent_window.bookToolBar.profileBox.itemData(
|
||||||
|
0, QtCore.Qt.UserRole)
|
||||||
|
current_profile2 = self.parent_window.bookToolBar.profileBox.itemData(
|
||||||
|
1, QtCore.Qt.UserRole)
|
||||||
|
current_profile3 = self.parent_window.bookToolBar.profileBox.itemData(
|
||||||
|
2, QtCore.Qt.UserRole)
|
||||||
|
current_profile_index = self.parent_window.bookToolBar.profileBox.currentIndex()
|
||||||
|
self.settings.setValue('displayProfiles', [
|
||||||
|
current_profile1,
|
||||||
|
current_profile2,
|
||||||
|
current_profile3])
|
||||||
|
self.settings.setValue('currentProfileIndex', current_profile_index)
|
||||||
self.settings.endGroup()
|
self.settings.endGroup()
|
||||||
|
34
widgets.py
34
widgets.py
@@ -35,16 +35,14 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.addAction(self.fullscreenButton)
|
self.addAction(self.fullscreenButton)
|
||||||
self.addAction(self.settingsButton)
|
self.addAction(self.settingsButton)
|
||||||
|
|
||||||
# Font modification buttons
|
# Font modification
|
||||||
# All hidden by default
|
font_sizes = [str(i) for i in range(8, 48, 2)]
|
||||||
self.fontSizeUp = QtWidgets.QAction(
|
font_sizes.extend(['56', '64', '72'])
|
||||||
QtGui.QIcon.fromTheme('format-font-size-more'),
|
self.fontSizeBox = QtWidgets.QComboBox(self)
|
||||||
'Increase font size', self)
|
self.fontSizeBox.setObjectName('fontSizeBox')
|
||||||
self.fontSizeUp.setObjectName('fontSizeUp')
|
self.fontSizeBox.setToolTip('Font size')
|
||||||
self.fontSizeDown = QtWidgets.QAction(
|
self.fontSizeBox.addItems(font_sizes)
|
||||||
QtGui.QIcon.fromTheme('format-font-size-less'),
|
self.fontSizeBox.setEditable(True)
|
||||||
'Decrease font size', self)
|
|
||||||
self.fontSizeDown.setObjectName('fontSizeDown')
|
|
||||||
|
|
||||||
self.paddingUp = QtWidgets.QAction(
|
self.paddingUp = QtWidgets.QAction(
|
||||||
QtGui.QIcon.fromTheme('format-justify-fill'),
|
QtGui.QIcon.fromTheme('format-justify-fill'),
|
||||||
@@ -75,10 +73,6 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.colorBoxBG.setToolTip('Set background color')
|
self.colorBoxBG.setToolTip('Set background color')
|
||||||
self.colorBoxBG.setObjectName('bgColor')
|
self.colorBoxBG.setObjectName('bgColor')
|
||||||
|
|
||||||
# TODO
|
|
||||||
# Get color profiles from settings
|
|
||||||
# Generate default profiles
|
|
||||||
# Maybe a default button
|
|
||||||
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
|
profiles = ['Profile 1', 'Profile 2', 'Profile 3']
|
||||||
self.profileBox = QtWidgets.QComboBox(self)
|
self.profileBox = QtWidgets.QComboBox(self)
|
||||||
self.profileBox.addItems(profiles)
|
self.profileBox.addItems(profiles)
|
||||||
@@ -86,8 +80,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.profileAction = self.addWidget(self.profileBox)
|
self.profileAction = self.addWidget(self.profileBox)
|
||||||
self.fontSeparator1 = self.addSeparator()
|
self.fontSeparator1 = self.addSeparator()
|
||||||
self.fontBoxAction = self.addWidget(self.fontBox)
|
self.fontBoxAction = self.addWidget(self.fontBox)
|
||||||
self.addAction(self.fontSizeUp)
|
self.fontSizeBoxAction = self.addWidget(self.fontSizeBox)
|
||||||
self.addAction(self.fontSizeDown)
|
|
||||||
self.fontSeparator2 = self.addSeparator()
|
self.fontSeparator2 = self.addSeparator()
|
||||||
self.fgColorAction = self.addWidget(self.colorBoxFG)
|
self.fgColorAction = self.addWidget(self.colorBoxFG)
|
||||||
self.bgColorAction = self.addWidget(self.colorBoxBG)
|
self.bgColorAction = self.addWidget(self.colorBoxBG)
|
||||||
@@ -99,8 +92,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.addAction(self.paddingDown)
|
self.addAction(self.paddingDown)
|
||||||
|
|
||||||
self.fontBoxAction.setVisible(False)
|
self.fontBoxAction.setVisible(False)
|
||||||
self.fontSizeUp.setVisible(False)
|
self.fontSizeBoxAction.setVisible(False)
|
||||||
self.fontSizeDown.setVisible(False)
|
|
||||||
self.fgColorAction.setVisible(False)
|
self.fgColorAction.setVisible(False)
|
||||||
self.bgColorAction.setVisible(False)
|
self.bgColorAction.setVisible(False)
|
||||||
self.lineSpacingUp.setVisible(False)
|
self.lineSpacingUp.setVisible(False)
|
||||||
@@ -144,8 +136,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.settingsButton.setVisible(False)
|
self.settingsButton.setVisible(False)
|
||||||
|
|
||||||
self.fontBoxAction.setVisible(True)
|
self.fontBoxAction.setVisible(True)
|
||||||
self.fontSizeUp.setVisible(True)
|
self.fontSizeBoxAction.setVisible(True)
|
||||||
self.fontSizeDown.setVisible(True)
|
|
||||||
self.fgColorAction.setVisible(True)
|
self.fgColorAction.setVisible(True)
|
||||||
self.bgColorAction.setVisible(True)
|
self.bgColorAction.setVisible(True)
|
||||||
self.lineSpacingUp.setVisible(True)
|
self.lineSpacingUp.setVisible(True)
|
||||||
@@ -167,8 +158,7 @@ class BookToolBar(QtWidgets.QToolBar):
|
|||||||
self.settingsButton.setVisible(True)
|
self.settingsButton.setVisible(True)
|
||||||
|
|
||||||
self.fontBoxAction.setVisible(False)
|
self.fontBoxAction.setVisible(False)
|
||||||
self.fontSizeUp.setVisible(False)
|
self.fontSizeBoxAction.setVisible(False)
|
||||||
self.fontSizeDown.setVisible(False)
|
|
||||||
self.fgColorAction.setVisible(False)
|
self.fgColorAction.setVisible(False)
|
||||||
self.bgColorAction.setVisible(False)
|
self.bgColorAction.setVisible(False)
|
||||||
self.lineSpacingUp.setVisible(False)
|
self.lineSpacingUp.setVisible(False)
|
||||||
|
Reference in New Issue
Block a user