Move config into separate class

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-26 00:59:35 +02:00
parent 3bf1fbf129
commit 8502b8265e
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 115 additions and 11 deletions

108
toolbartools/Config.py Normal file
View File

@ -0,0 +1,108 @@
# Toolbar Tools - Falkon plugin
# 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/>.
from PySide2.QtCore import Signal, QObject
class Config(QObject):
settingsFileChanged = Signal(str)
spacerCountChanged = Signal(int)
spacerMaxWidthChanged = Signal(int)
separatorCountChanged = Signal(int)
separatorWidthChanged = Signal(int)
def __init__(self, parent=None):
super().__init__(parent)
self._settingsFile = ""
self._spacerCount = 2
self._spacerMaxWidth = 150
self._separatorCount = 2
self._separatorWidth = 5
@property
def settingsFile(self):
return self._settingsFile
@settingsFile.setter
def settingsFile(self, filePath):
if not filePath:
return
if self._settingsFile == filePath:
return
self._settingsFile = filePath
self.settingsFileChanged.emit(filePath)
@property
def spacerCount(self):
return self._spacerCount
@spacerCount.setter
def spacerCount(self, count):
if count < 0:
return
if self._spacerCount == count:
return
self._spacerCount = count
self.spacerCountChanged.emit(count)
@property
def spacerMaxWidth(self):
return self._spacerMaxWidth
@spacerMaxWidth.setter
def spacerMaxWidth(self, maxWidth):
if maxWidth < 0:
return
if self._spacerMaxWidth == maxWidth:
return
self._spacerMaxWidth = maxWidth
self.spacerMaxWidthChanged.emit(maxWidth)
@property
def separatorCount(self):
return self._separatorCount
@separatorCount.setter
def separatorCount(self, count):
if count < 0:
return
if self._separatorCount == count:
return
self._separatorCount = count
self.separatorCountChanged.emit(count)
@property
def separatorWidth(self):
return self._separatorWidth
@separatorWidth.setter
def separatorWidth(self, width):
if width < 0:
return
if self._separatorWidth == width:
return
self._separatorWidth = width
self.spacerMaxWidthChanged.emit(width)

View File

@ -17,6 +17,7 @@
import Falkon import Falkon
import os import os
from PySide2 import QtCore from PySide2 import QtCore
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
@ -30,13 +31,8 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
self.spacers = {} self.spacers = {}
self.separators = {} self.separators = {}
self.config = { self.config = Config()
"settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"), self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini")
"spacers": 2,
"spacerMaxWidth": 150,
"separators": 2,
"separatorWidth": 10
}
plugins = Falkon.MainApplication.instance().plugins() plugins = Falkon.MainApplication.instance().plugins()
@ -55,16 +51,16 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
return True return True
def onMainWindowCreated(self, window): def onMainWindowCreated(self, window):
for id in range(1, self.config["spacers"] + 1): for id in range(1, self.config.spacerCount + 1):
spacer = Spacer(id, self.config["spacerMaxWidth"]) spacer = Spacer(id, self.config.spacerMaxWidth)
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name()) window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
if window not in self.spacers: if window not in self.spacers:
self.spacers[window] = {} self.spacers[window] = {}
self.spacers[window][id] = spacer self.spacers[window][id] = spacer
for id in range(1, self.config["separators"] + 1): for id in range(1, self.config.separatorCount + 1):
separator = Separator(id, self.config["separatorWidth"]) separator = Separator(id, self.config.separatorWidth)
window.navigationBar().addWidget(separator, separator.id(), separator.name()) window.navigationBar().addWidget(separator, separator.id(), separator.name())
if window not in self.separators: if window not in self.separators: