diff --git a/toolbartools/Config.py b/toolbartools/Config.py new file mode 100644 index 0000000..7d685fa --- /dev/null +++ b/toolbartools/Config.py @@ -0,0 +1,108 @@ +# Toolbar Tools - Falkon plugin +# 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 . + +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) diff --git a/toolbartools/__init__.py b/toolbartools/__init__.py index b50a449..ecd6064 100644 --- a/toolbartools/__init__.py +++ b/toolbartools/__init__.py @@ -17,6 +17,7 @@ import Falkon import os from PySide2 import QtCore +from toolbartools.Config import Config from toolbartools.Spacer import Spacer from toolbartools.Separator import Separator @@ -30,13 +31,8 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): self.spacers = {} self.separators = {} - self.config = { - "settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"), - "spacers": 2, - "spacerMaxWidth": 150, - "separators": 2, - "separatorWidth": 10 - } + self.config = Config() + self.config.settingsFile = os.path.join(settingsPath, "ToolbarTools", "settings.ini") plugins = Falkon.MainApplication.instance().plugins() @@ -55,16 +51,16 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): return True def onMainWindowCreated(self, window): - for id in range(1, self.config["spacers"] + 1): - spacer = Spacer(id, self.config["spacerMaxWidth"]) + for id in range(1, self.config.spacerCount + 1): + spacer = Spacer(id, self.config.spacerMaxWidth) window.navigationBar().addWidget(spacer, spacer.id(), spacer.name()) if window not in self.spacers: self.spacers[window] = {} self.spacers[window][id] = spacer - for id in range(1, self.config["separators"] + 1): - separator = Separator(id, self.config["separatorWidth"]) + for id in range(1, self.config.separatorCount + 1): + separator = Separator(id, self.config.separatorWidth) window.navigationBar().addWidget(separator, separator.id(), separator.name()) if window not in self.separators: