Move config from dictionary to Config class

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-29 00:45:16 +02:00
parent b87c793229
commit 629788068e
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 29 additions and 28 deletions

View File

@ -21,6 +21,7 @@
import Falkon import Falkon
import os import os
from PySide2 import QtCore from PySide2 import QtCore
from unloader.Config import Config
from unloader.settingsDialog import SettingsDialog from unloader.settingsDialog import SettingsDialog
@ -34,19 +35,19 @@ class UnloaderManager(QtCore.QObject):
def __init__(self, settingsPath, parent=None): def __init__(self, settingsPath, parent=None):
super().__init__(parent) super().__init__(parent)
self.config = { self.config = Config(
"settingsFile": os.path.join(settingsPath, "unloader", "settings.ini"), settingsFile=os.path.join(settingsPath, "unloader", "settings.ini"),
"threshold": 600, threshold=600,
"closeThreshold": 0, closeThreshold=0,
"updateInterval": 5 updateInterval=5
} )
self.loadSettings() self.loadSettings()
self.tabs = {} self.tabs = {}
self.timer = QtCore.QTimer(self) self.timer = QtCore.QTimer(self)
self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer) self.timer.setTimerType(QtCore.Qt.VeryCoarseTimer)
self.timer.setInterval(self.config["updateInterval"] * 1000) self.timer.setInterval(self.config.updateInterval * 1000)
self.timer.timeout.connect(self.onTimeout) self.timer.timeout.connect(self.onTimeout)
self.timer.start() self.timer.start()
@ -98,14 +99,14 @@ class UnloaderManager(QtCore.QObject):
self.tabs[tab] = time + int(self.timer.interval() / 1000) self.tabs[tab] = time + int(self.timer.interval() / 1000)
if not tab.isRestored() and self.config["closeThreshold"]: if not tab.isRestored() and self.config.closeThreshold:
if self.tabs[tab] > self.config["closeThreshold"]: if self.tabs[tab] > self.config.closeThreshold:
del self.tabs[tab] del self.tabs[tab]
tab.closeTab() tab.closeTab()
continue continue
if self.config["threshold"]: if self.config.threshold:
if self.tabs[tab] > self.config["threshold"] and tab.isRestored(): if self.tabs[tab] > self.config.threshold and tab.isRestored():
self.tabs[tab] = 0 self.tabs[tab] = 0
tab.unload() tab.unload()
@ -125,25 +126,25 @@ class UnloaderManager(QtCore.QObject):
) )
def loadSettings(self): def loadSettings(self):
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat) settings = QtCore.QSettings(self.config.settingsFile, QtCore.QSettings.IniFormat)
settings.beginGroup("Unloader") settings.beginGroup("Unloader")
self.config["threshold"] = int(settings.value("threshold", self.config["threshold"])) self.config.threshold = int(settings.value("threshold", self.config.threshold))
self.config["closeThreshold"] = int( self.config.closeThreshold = int(
settings.value("closeThreshold", self.config["closeThreshold"]) settings.value("closeThreshold", self.config.closeThreshold)
) )
self.config["updateInterval"] = int( self.config.updateInterval = int(
settings.value("defaultZoom", self.config["updateInterval"]) settings.value("defaultZoom", self.config.updateInterval)
) )
settings.endGroup() settings.endGroup()
def saveSettings(self): def saveSettings(self):
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat) settings = QtCore.QSettings(self.config.settingsFile, QtCore.QSettings.IniFormat)
settings.beginGroup("Unloader") settings.beginGroup("Unloader")
settings.setValue("threshold", self.config["threshold"]) settings.setValue("threshold", self.config.threshold)
settings.setValue("closeThreshold", self.config["closeThreshold"]) settings.setValue("closeThreshold", self.config.closeThreshold)
settings.setValue("updateInterval", self.config["updateInterval"]) settings.setValue("updateInterval", self.config.updateInterval)
settings.endGroup() settings.endGroup()
settings.sync() settings.sync()
@ -155,7 +156,7 @@ class UnloaderManager(QtCore.QObject):
settings.exec_() settings.exec_()
def onConfigChanged(self): def onConfigChanged(self):
self.timer.setInterval(self.config["updateInterval"] * 1000) self.timer.setInterval(self.config.updateInterval * 1000)
def onTabRestoredChanged(self, tab, restored): def onTabRestoredChanged(self, tab, restored):
self.tabs[tab] = 0 self.tabs[tab] = 0

View File

@ -42,9 +42,9 @@ class SettingsDialog(QtWidgets.QDialog):
self.translations() self.translations()
self.ui.updateIntervalSpinBox.setValue(self.config["updateInterval"]) self.ui.updateIntervalSpinBox.setValue(self.config.updateInterval)
self.ui.discardInactiveTabAfterSpinBox.setValue(self.config["threshold"]) self.ui.discardInactiveTabAfterSpinBox.setValue(self.config.threshold)
self.ui.closeTabForSpinBox.setValue(self.config["closeThreshold"]) self.ui.closeTabForSpinBox.setValue(self.config.closeThreshold)
self.ui.buttonBoxConfirm.accepted.connect(self.accept) self.ui.buttonBoxConfirm.accepted.connect(self.accept)
self.ui.buttonBoxConfirm.rejected.connect(self.reject) self.ui.buttonBoxConfirm.rejected.connect(self.reject)
@ -60,9 +60,9 @@ class SettingsDialog(QtWidgets.QDialog):
) )
def updateData(self): def updateData(self):
self.config["updateInterval"] = self.ui.updateIntervalSpinBox.value() self.config.updateInterval = self.ui.updateIntervalSpinBox.value()
self.config["threshold"] = self.ui.discardInactiveTabAfterSpinBox.value() self.config.threshold = self.ui.discardInactiveTabAfterSpinBox.value()
self.config["closeThreshold"] = self.ui.closeTabForSpinBox.value() self.config.closeThreshold = self.ui.closeTabForSpinBox.value()
def accept(self): def accept(self):
self.updateData() self.updateData()