Add settings dialog
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
b663e7b753
commit
6abddde8e3
|
@ -46,7 +46,7 @@ class UnloaderPlugin(Falkon.PluginInterface, QtCore.QObject):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def showSettings(self, parent):
|
def showSettings(self, parent):
|
||||||
pass
|
self.manager.showSettings(parent)
|
||||||
|
|
||||||
|
|
||||||
Falkon.registerPlugin(UnloaderPlugin())
|
Falkon.registerPlugin(UnloaderPlugin())
|
||||||
|
|
|
@ -19,34 +19,37 @@
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import Falkon
|
import Falkon
|
||||||
|
import os
|
||||||
from PySide2 import QtCore
|
from PySide2 import QtCore
|
||||||
|
from unloader.settingsDialog import SettingsDialog
|
||||||
|
|
||||||
|
|
||||||
class UnloaderManager(QtCore.QObject):
|
class UnloaderManager(QtCore.QObject):
|
||||||
tabs = None
|
tabs = None
|
||||||
timer = None
|
timer = None
|
||||||
threshold = None
|
|
||||||
config = None
|
config = None
|
||||||
|
|
||||||
|
configChanged = QtCore.Signal()
|
||||||
|
|
||||||
def __init__(self, settingsPath, parent=None):
|
def __init__(self, settingsPath, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.config = {
|
self.config = {
|
||||||
"settingsPath": settingsPath,
|
"settingsFile": os.path.join(settingsPath, "unloader", "settings.ini"),
|
||||||
"threshold": 600,
|
"threshold": 600,
|
||||||
"updateInterval": 5
|
"updateInterval": 5
|
||||||
}
|
}
|
||||||
|
|
||||||
self.threshold = self.config["threshold"]
|
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(5000)
|
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()
|
||||||
|
|
||||||
|
self.configChanged.connect(self.onConfigChanged)
|
||||||
|
|
||||||
def onMainWindowCreated(self, window):
|
def onMainWindowCreated(self, window):
|
||||||
tabs = window.tabWidget().allTabs()
|
tabs = window.tabWidget().allTabs()
|
||||||
|
|
||||||
|
@ -84,8 +87,8 @@ class UnloaderManager(QtCore.QObject):
|
||||||
|
|
||||||
self.tabs[tab] = time + int(self.timer.interval() / 1000)
|
self.tabs[tab] = time + int(self.timer.interval() / 1000)
|
||||||
|
|
||||||
if self.threshold:
|
if self.config["threshold"]:
|
||||||
if self.tabs[tab] > self.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()
|
||||||
|
|
||||||
|
@ -98,3 +101,32 @@ class UnloaderManager(QtCore.QObject):
|
||||||
|
|
||||||
for tab in winTabs:
|
for tab in winTabs:
|
||||||
self.tabs[tab] = oldTabs.get(tab, 0)
|
self.tabs[tab] = oldTabs.get(tab, 0)
|
||||||
|
|
||||||
|
def loadSettings(self):
|
||||||
|
settings = QtCore.QSettings(self.config["settingsFile"], QtCore.QSettings.IniFormat)
|
||||||
|
|
||||||
|
settings.beginGroup("Unloader")
|
||||||
|
self.config["threshold"] = int(settings.value("active", self.config["threshold"]))
|
||||||
|
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.beginGroup("Unloader")
|
||||||
|
settings.setValue("threshold", self.config["threshold"])
|
||||||
|
settings.setValue("updateInterval", self.config["updateInterval"])
|
||||||
|
settings.endGroup()
|
||||||
|
|
||||||
|
settings.sync()
|
||||||
|
|
||||||
|
def showSettings(self, parent=None):
|
||||||
|
settings = SettingsDialog(self.config, parent)
|
||||||
|
settings.accepted.connect(self.saveSettings)
|
||||||
|
settings.accepted.connect(self.configChanged)
|
||||||
|
settings.exec_()
|
||||||
|
|
||||||
|
def onConfigChanged(self):
|
||||||
|
self.timer.setInterval(self.config["updateInterval"] * 1000)
|
||||||
|
|
88
unloader/settings.ui
Normal file
88
unloader/settings.ui
Normal file
|
@ -0,0 +1,88 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>SettingsDialog</class>
|
||||||
|
<widget class="QWidget" name="SettingsDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>412</width>
|
||||||
|
<height>118</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Unloader Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QFormLayout" name="formLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="updateIntervalLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Update interval (in seconds):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QSpinBox" name="updateIntervalSpinBox">
|
||||||
|
<property name="buttonSymbols">
|
||||||
|
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>60</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>5</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="discardInactiveTabAfterLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>Discard inactive tab after (in seconds):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QSpinBox" name="discardInactiveTabAfterSpinBox">
|
||||||
|
<property name="buttonSymbols">
|
||||||
|
<enum>QAbstractSpinBox::PlusMinus</enum>
|
||||||
|
</property>
|
||||||
|
<property name="minimum">
|
||||||
|
<number>60</number>
|
||||||
|
</property>
|
||||||
|
<property name="maximum">
|
||||||
|
<number>86400</number>
|
||||||
|
</property>
|
||||||
|
<property name="singleStep">
|
||||||
|
<number>10</number>
|
||||||
|
</property>
|
||||||
|
<property name="value">
|
||||||
|
<number>600</number>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
65
unloader/settingsDialog.py
Normal file
65
unloader/settingsDialog.py
Normal file
|
@ -0,0 +1,65 @@
|
||||||
|
# ============================================================
|
||||||
|
# Unloader - plugin for Falkon
|
||||||
|
# Copyright (C) 2019 Juraj Oravec <sgd.orava@gmail.com>
|
||||||
|
#
|
||||||
|
# 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/>.
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
import Falkon
|
||||||
|
import os
|
||||||
|
from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools
|
||||||
|
from unloader.i18n import i18n
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsDialog(QtWidgets.QDialog):
|
||||||
|
ui = None
|
||||||
|
config = None
|
||||||
|
|
||||||
|
def __init__(self, config, remove, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self.config = config
|
||||||
|
|
||||||
|
file = QtCore.QFile(os.path.join(os.path.dirname(__file__), "settings.ui"))
|
||||||
|
file.open(QtCore.QFile.ReadOnly)
|
||||||
|
self.ui = QtUiTools.QUiLoader().load(file, self)
|
||||||
|
file.close()
|
||||||
|
|
||||||
|
layout = QtWidgets.QVBoxLayout(self)
|
||||||
|
layout.addWidget(self.ui)
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
self.translations()
|
||||||
|
|
||||||
|
self.ui.updateIntervalSpinBox.setValue(self.config["updateInterval"])
|
||||||
|
self.ui.discardInactiveTabAfterSpinBox.setValue(self.config["threshold"])
|
||||||
|
|
||||||
|
self.ui.buttonBoxConfirm.accepted.connect(self.accept)
|
||||||
|
self.ui.buttonBoxConfirm.rejected.connect(self.reject)
|
||||||
|
|
||||||
|
def translations(self):
|
||||||
|
self.setWindowTitle(i18n("Unloader Settings"))
|
||||||
|
self.ui.updateIntervalLabel.setText(i18n("Update interval (in seconds):"))
|
||||||
|
self.ui.discardInactiveTabAfterLabel.setText(
|
||||||
|
i18n("Discard inactive tab after (in seconds):")
|
||||||
|
)
|
||||||
|
|
||||||
|
def updateData(self):
|
||||||
|
self.config["updateInterval"] = self.ui.updateIntervalSpinBox.value()
|
||||||
|
self.config["threshold"] = self.ui.discardInactiveTabAfterSpinBox.value()
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self.updateData()
|
||||||
|
|
||||||
|
super().accept()
|
Loading…
Reference in New Issue
Block a user