Readability/readability/Config.py
Juraj Oravec fa5930a213
WIP: Unfinished work
Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
2022-10-12 21:58:08 +02:00

200 lines
5.6 KiB
Python

# <one line to give the program's name and a brief idea of what it does.>
# Copyright (C) 2019 Juraj Oravec <jurajoravec@netc.it>
#
# 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 QObject, Signal, QSettings
class Config(QObject):
lineHeightChanged = Signal(int)
marginChanged = Signal(int)
fontSizeChanged = Signal(int)
fontChanged = Signal(str)
colorThemeChanged = Signal(str)
contextMenuChanged = Signal(_bool)
iconChanged = Signal(str)
settingsFileChanged = Signal(str)
configLoaded = Signal()
configSaved = Signal()
def __init__(self, lineHeight=None, margin=None, fontSize=None, font=None, colorTheme=None, contextMenu=None, icon=None, settingsFile=None):
QObject.__init__()
self._lineHeight = lineHeight
self._margin = margin
self._fontSize = fontSize
self._font = font
self._colorTheme = colorTheme
self._contextMenu = contextMenu
self._icon = icon
self._settingsFile = settingsFile
def load(self):
if not self.settingsFile:
return
if os.path.exists(self.settingsFile):
pass
settings = QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Readability")
self.lineHeight = int(settings.value("lineHeight", self.lineHeight))
self.margin = int(settings.value("margin", self.margin))
self.fontSize = int(settings.value("fontSize", self.fontSize))
self.font = str(settings.value("font", self.font))
self.colorTheme = str(settings.value("colorTheme", self.colorTheme))
self.contextMenu = _bool(settings.value("contextMenu", self.contextMenu))
self.icon = str(settings.value("icon", self.icon))
self.settingsFile = str(settings.value("settingsFile", self.settingsFile))
settings.endGroup()
self.configLoaded.emit()
def save(self):
if not self.settingsFile:
return
if os.path.exists(self.settingsFile):
pass
settings=QSettings(self.settingsFile, QSettings.IniFormat)
settings.beginGroup("Readability")
settings.setValue("lineHeight", self.lineHeight)
settings.setValue("margin", self.margin)
settings.setValue("fontSize", self.fontSize)
settings.setValue("font", self.font)
settings.setValue("colorTheme", self.colorTheme)
settings.setValue("contextMenu", self.contextMenu)
settings.setValue("icon", self.icon)
settings.setValue("settingsFile", self.settingsFile)
settings.endGroup()
settings.sync()
self.configSaved.emit()
@property
def lineHeight(self):
return self._lineHeight
@lineHeight.setter
def lineHeight(self, lineHeight):
if not lineHeight:
return
if self._lineHeight == lineHeight:
return
self._lineHeight = lineHeight
self.lineHeightChanged.emit(lineHeight)
@property
def margin(self):
return self._margin
@margin.setter
def margin(self, margin):
if not margin:
return
if self._margin == margin:
return
self._margin = margin
self.marginChanged.emit(margin)
@property
def fontSize(self):
return self._fontSize
@fontSize.setter
def fontSize(self, fontSize):
if not fontSize:
return
if self._fontSize == fontSize:
return
self._fontSize = fontSize
self.fontSizeChanged.emit(fontSize)
@property
def font(self):
return self._font
@font.setter
def font(self, font):
if not font:
return
if self._font == font:
return
self._font = font
self.fontChanged.emit(font)
@property
def colorTheme(self):
return self._colorTheme
@colorTheme.setter
def colorTheme(self, colorTheme):
if not colorTheme:
return
if self._colorTheme == colorTheme:
return
self._colorTheme = colorTheme
self.colorThemeChanged.emit(colorTheme)
@property
def contextMenu(self):
return self._contextMenu
@contextMenu.setter
def contextMenu(self, contextMenu):
if not contextMenu:
return
if self._contextMenu == contextMenu:
return
self._contextMenu = contextMenu
self.contextMenuChanged.emit(contextMenu)
@property
def icon(self):
return self._icon
@icon.setter
def icon(self, icon):
if not icon:
return
if self._icon == icon:
return
self._icon = icon
self.iconChanged.emit(icon)
@property
def settingsFile(self):
return self._settingsFile
@settingsFile.setter
def settingsFile(self, settingsFile):
if not settingsFile:
return
if self._settingsFile == settingsFile:
return
self._settingsFile = settingsFile
self.settingsFileChanged.emit(settingsFile)