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

View File

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