Add Settings Dialog

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-26 09:53:43 +02:00
parent 983572eb43
commit 301e2079e5
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
4 changed files with 195 additions and 1 deletions

View File

@ -20,6 +20,7 @@ from PySide2 import QtCore
from toolbartools.Config import Config from toolbartools.Config import Config
from toolbartools.Spacer import Spacer from toolbartools.Spacer import Spacer
from toolbartools.Separator import Separator from toolbartools.Separator import Separator
from toolbartools.settingsDialog import SettingsDialog
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
@ -53,6 +54,10 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
def testPlugin(self): def testPlugin(self):
return True return True
def showSettings(self, parent):
settings = SettingsDialog(self.config, parent)
settings.exec_()
def onMainWindowCreated(self, window): def onMainWindowCreated(self, window):
for id in range(1, self.config.spacerCount + 1): for id in range(1, self.config.spacerCount + 1):
spacer = Spacer(id, self.config.spacerMaxWidth) spacer = Spacer(id, self.config.spacerMaxWidth)

View File

@ -8,4 +8,4 @@ X-Falkon-Type=Extension/Python
X-Falkon-Author=Juraj Oravec X-Falkon-Author=Juraj Oravec
X-Falkon-Email=sgd.orava@gmail.com X-Falkon-Email=sgd.orava@gmail.com
X-Falkon-Version=1.0.0 X-Falkon-Version=1.0.0
X-Falkon-Settings=false X-Falkon-Settings=true

View File

@ -0,0 +1,78 @@
# ============================================================
# Toolbar Tools - 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 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()

View File

@ -0,0 +1,111 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>350</width>
<height>165</height>
</rect>
</property>
<property name="windowTitle">
<string>Toolbar Tools Settings</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="spacer">
<attribute name="title">
<string>Spacer</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QFormLayout" name="formLayout">
<item row="0" column="0">
<widget class="QLabel" name="numberOfSpacersLabel">
<property name="text">
<string>Number of spacers:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="numberOfSpacersSpinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="maximumWidthLabel">
<property name="text">
<string>Maximum width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="spacerWidthSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<widget class="QWidget" name="separator">
<attribute name="title">
<string>Separator</string>
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QFormLayout" name="formLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="numberOfSeparatorsLabel">
<property name="text">
<string>Number of separators</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QSpinBox" name="numberOfSeparatorsSpinBox"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="separatorWidthLabel">
<property name="text">
<string>Width:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="separatorWidthSpinBox">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999999</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>