From 629788068e45efda18d5eed2daf7dfbec2e1ddb6 Mon Sep 17 00:00:00 2001 From: Juraj Oravec Date: Sat, 29 Jun 2019 00:45:16 +0200 Subject: [PATCH] Move config from dictionary to Config class Signed-off-by: Juraj Oravec --- unloader/manager.py | 45 +++++++++++++++++++------------------- unloader/settingsDialog.py | 12 +++++----- 2 files changed, 29 insertions(+), 28 deletions(-) diff --git a/unloader/manager.py b/unloader/manager.py index f1e2671..5dcd923 100644 --- a/unloader/manager.py +++ b/unloader/manager.py @@ -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 diff --git a/unloader/settingsDialog.py b/unloader/settingsDialog.py index 4dda068..b84b64b 100644 --- a/unloader/settingsDialog.py +++ b/unloader/settingsDialog.py @@ -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()