From 301e2079e571c652cab2f28dabd735386e27ff31 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Wed, 26 Jun 2019 09:53:43 +0200 Subject: [PATCH] Add Settings Dialog Signed-off-by: Juraj Oravec --- toolbartools/__init__.py | 5 ++ toolbartools/metadata.desktop | 2 +- toolbartools/settingsDialog.py | 78 +++++++++++++++++++++++ toolbartools/settingsDialog.ui | 111 +++++++++++++++++++++++++++++++++ 4 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 toolbartools/settingsDialog.py create mode 100644 toolbartools/settingsDialog.ui diff --git a/toolbartools/__init__.py b/toolbartools/__init__.py index 1d57034..df11e47 100644 --- a/toolbartools/__init__.py +++ b/toolbartools/__init__.py @@ -20,6 +20,7 @@ from PySide2 import QtCore from toolbartools.Config import Config from toolbartools.Spacer import Spacer from toolbartools.Separator import Separator +from toolbartools.settingsDialog import SettingsDialog class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): @@ -53,6 +54,10 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): def testPlugin(self): return True + def showSettings(self, parent): + settings = SettingsDialog(self.config, parent) + settings.exec_() + def onMainWindowCreated(self, window): for id in range(1, self.config.spacerCount + 1): spacer = Spacer(id, self.config.spacerMaxWidth) diff --git a/toolbartools/metadata.desktop b/toolbartools/metadata.desktop index b54ae82..c14f595 100644 --- a/toolbartools/metadata.desktop +++ b/toolbartools/metadata.desktop @@ -8,4 +8,4 @@ X-Falkon-Type=Extension/Python X-Falkon-Author=Juraj Oravec X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Version=1.0.0 -X-Falkon-Settings=false +X-Falkon-Settings=true diff --git a/toolbartools/settingsDialog.py b/toolbartools/settingsDialog.py new file mode 100644 index 0000000..48996e6 --- /dev/null +++ b/toolbartools/settingsDialog.py @@ -0,0 +1,78 @@ +# ============================================================ +# Toolbar Tools - plugin for Falkon +# Copyright (C) 2019 Juraj Oravec +# +# 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 . +# ============================================================ + +import Falkon +import os +from PySide2 import QtCore, QtWidgets, QtUiTools +from toolbartools.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.numberOfSpacersSpinBox.setValue(self.config.spacerCount) + self.ui.spacerWidthSpinBox.setValue(self.config.spacerMaxWidth) + + self.ui.numberOfSeparatorsSpinBox.setValue(self.config.separatorCount) + self.ui.separatorWidthSpinBox.setValue(self.config.separatorWidth) + + def translations(self): + self.setWindowTitle(i18n("Toolbar Tools Settings")) + + self.ui.tabWidget.setTabText(0, "Spacer") + self.ui.numberOfSpacersLabel.setText(i18n("Number of spacers:")) + self.ui.maximumWidthLabel.setText(i18n("Maximum width:")) + + self.ui.tabWidget.setTabText(1, "Separator") + self.ui.numberOfSeparatorsLabel.setText(i18n("Number of separators")) + self.ui.separatorWidthLabel.setText(i18n("Width")) + + def updateConfig(self): + self.config.spacerCount = self.ui.numberOfSpacersSpinBox.value() + self.config.spacerMaxWidth = self.ui.spacerWidthSpinBox.value() + + self.config.separatorCount = self.ui.numberOfSeparatorsSpinBox.value() + self.config.separatorWidth = self.ui.separatorWidthSpinBox.value() + + def accept(self): + self.updateConfig() + self.config.save() + + super().accept() diff --git a/toolbartools/settingsDialog.ui b/toolbartools/settingsDialog.ui new file mode 100644 index 0000000..eb4e996 --- /dev/null +++ b/toolbartools/settingsDialog.ui @@ -0,0 +1,111 @@ + + + Form + + + + 0 + 0 + 350 + 165 + + + + Toolbar Tools Settings + + + + + + 0 + + + + Spacer + + + + + + + + Number of spacers: + + + + + + + + + + Maximum width: + + + + + + + 1 + + + 999999 + + + + + + + + + + Separator + + + + + + + + Number of separators + + + + + + + + + + Width: + + + + + + + 1 + + + 999999 + + + + + + + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + +