Readability/readability/settingsDialog.py
Juraj Oravec 49089e7e45
Add reader`s options to settings dialog
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
2019-06-20 22:48:43 +02:00

102 lines
3.9 KiB
Python

# ============================================================
# Readability - plugin for Falkon
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# 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 Falkon
import os
from PySide2 import QtCore, QtWidgets, QtUiTools
from readability.i18n import i18n
class SettingsDialog(QtWidgets.QDialog):
ui = None
config = None
def __init__(self, config, parent=None):
super().__init__(parent)
self.config = config
file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settingsDialog.ui"))
file.open(QtCore.QFile.ReadOnly)
self.ui = QtUiTools.QUiLoader().load(file, self)
file.close()
layout = QtWidgets.QVBoxLayout(self)
layout.addWidget(self.ui)
self.setLayout(layout)
self.translations()
self.applyConfig()
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
def applyConfig(self):
self.ui.radioButtonLight.setChecked(self.config["icon"] == "light")
self.ui.radioButtonDark.setChecked(self.config["icon"] == "dark")
self.ui.radioButtonSchemeLight.setChecked(self.config["colorTheme"] == "light")
self.ui.radioButtonSchemeSepia.setChecked(self.config["colorTheme"] == "sepia")
self.ui.radioButtonSchemeDark.setChecked(self.config["colorTheme"] == "dark")
self.ui.radioButtonFontSansSerif.setChecked(self.config["font"] == "sans-serif")
self.ui.radioButtonFontSerif.setChecked(self.config["font"] == "serif")
self.ui.comboBoxFontSize.setCurrentIndex(self.config["fontSize"] - 1)
self.ui.checkBoxContextMenu.setChecked(self.config["contextMenu"])
def translations(self):
self.setWindowTitle(i18n("Readability Settings"))
self.ui.groupBoxIcon.setTitle(i18n("Menu icon"))
self.ui.radioButtonLight.setText(i18n("Light"))
self.ui.radioButtonDark.setText(i18n("Dark"))
self.ui.groupBoxColorScheme.setTitle(i18n("Color scheme"))
self.ui.radioButtonSchemeLight.setText(i18n("Light"))
self.ui.radioButtonSchemeSepia.setText(i18n("Sepia"))
self.ui.radioButtonSchemeDark.setText(i18n("Dark"))
self.ui.groupBoxFont.setTitle(i18n("Font"))
self.ui.radioButtonFontSansSerif.setText(i18n("Sans-Serif"))
self.ui.radioButtonFontSerif.setText(i18n("Serif"))
self.ui.labelFontSize.setText(i18n("Font size:"))
self.ui.checkBoxContextMenu.setText(i18n("Show in context menu"))
def updateData(self):
self.config["icon"] = "light" if self.ui.radioButtonLight.isChecked() else "dark"
if self.ui.radioButtonSchemeLight.isChecked():
self.config["colorTheme"] = "light"
elif self.ui.radioButtonSchemeSepia.isChecked():
self.config["colorTheme"] = "sepia"
else:
self.config["colorTheme"] = "dark"
self.config["font"] = "sans-serif" if self.ui.radioButtonFontSansSerif.isChecked() else "serif"
self.config["fontSize"] = self.ui.comboBoxFontSize.currentIndex() + 1
self.config["contextMenu"] = self.ui.checkBoxContextMenu.isChecked()
def accept(self):
self.updateData()
super().accept()