Add Config class, ability to display different data
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
bca6640525
commit
3e95e04610
@ -16,16 +16,27 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
|
||||||
|
import os
|
||||||
import Falkon
|
import Falkon
|
||||||
from PySide2 import QtCore
|
from PySide2 import QtCore
|
||||||
|
|
||||||
from tabcounter.button import Button
|
from tabcounter.label import Label
|
||||||
|
from tabcounter.config import Config
|
||||||
|
from tabcounter.constants import DISPLAY_TYPE
|
||||||
|
|
||||||
|
|
||||||
class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
||||||
panelWidgets = {}
|
panelWidgets = {}
|
||||||
|
config = None
|
||||||
|
|
||||||
def init(self, state, settingsPath):
|
def init(self, state, settingsPath):
|
||||||
|
self.config = Config(
|
||||||
|
settingsFile=os.path.join(settingsPath, "tabcounter", "settings.ini"),
|
||||||
|
displayType=DISPLAY_TYPE.LOADED_AND_ALL
|
||||||
|
)
|
||||||
|
self.config.load()
|
||||||
|
|
||||||
plugins = Falkon.MainApplication.instance().plugins()
|
plugins = Falkon.MainApplication.instance().plugins()
|
||||||
|
|
||||||
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
||||||
@ -43,7 +54,9 @@ class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def onMainWindowCreated(self, window):
|
def onMainWindowCreated(self, window):
|
||||||
labelWidget = Button(window)
|
labelWidget = Label(window, self.config.displayType)
|
||||||
|
self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged)
|
||||||
|
|
||||||
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
|
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
|
||||||
self.panelWidgets[window] = labelWidget
|
self.panelWidgets[window] = labelWidget
|
||||||
|
|
||||||
|
93
tabcounter/config.py
Normal file
93
tabcounter/config.py
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Tab Counter - plugin for Falkon
|
||||||
|
# Copyright (C) 2020 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 os
|
||||||
|
from PySide2.QtCore import QObject, Signal, QSettings
|
||||||
|
|
||||||
|
|
||||||
|
class Config(QObject):
|
||||||
|
displayTypeChanged = Signal(int)
|
||||||
|
settingsFileChanged = Signal(str)
|
||||||
|
|
||||||
|
configLoaded = Signal()
|
||||||
|
configSaved = Signal()
|
||||||
|
|
||||||
|
def __init__(self, displayType=None, settingsFile=None):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
self._displayType = displayType
|
||||||
|
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("Config")
|
||||||
|
self.displayType = int(settings.value("displayType", self.displayType))
|
||||||
|
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("Config")
|
||||||
|
settings.setValue("displayType", self.displayType)
|
||||||
|
settings.endGroup()
|
||||||
|
|
||||||
|
settings.sync()
|
||||||
|
|
||||||
|
self.configSaved.emit()
|
||||||
|
|
||||||
|
@property
|
||||||
|
def displayType(self):
|
||||||
|
return self._displayType
|
||||||
|
|
||||||
|
@displayType.setter
|
||||||
|
def displayType(self, displayType):
|
||||||
|
if not displayType:
|
||||||
|
return
|
||||||
|
if self._displayType == displayType:
|
||||||
|
return
|
||||||
|
|
||||||
|
self._displayType = displayType
|
||||||
|
self.displayTypeChanged.emit(displayType)
|
||||||
|
|
||||||
|
@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)
|
27
tabcounter/constants.py
Normal file
27
tabcounter/constants.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
# ============================================================
|
||||||
|
# Tab Counter - plugin for Falkon
|
||||||
|
# Copyright (C) 2020 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/>.
|
||||||
|
# ============================================================
|
||||||
|
|
||||||
|
|
||||||
|
from enum import IntEnum
|
||||||
|
|
||||||
|
|
||||||
|
class DISPLAY_TYPE(IntEnum):
|
||||||
|
ALL = 1
|
||||||
|
LOADED = 2
|
||||||
|
UNLOADED = 3
|
||||||
|
LOADED_AND_ALL = 4
|
@ -16,18 +16,24 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
# ============================================================
|
# ============================================================
|
||||||
|
|
||||||
|
|
||||||
from PySide2 import QtWidgets
|
from PySide2 import QtWidgets
|
||||||
|
|
||||||
|
from tabcounter.constants import DISPLAY_TYPE
|
||||||
|
|
||||||
class Button(QtWidgets.QLabel):
|
|
||||||
|
class Label(QtWidgets.QLabel):
|
||||||
window = None
|
window = None
|
||||||
|
displayType = None
|
||||||
|
|
||||||
allTabs = 0
|
allTabs = 0
|
||||||
loadedTabs = 0
|
loadedTabs = 0
|
||||||
|
|
||||||
def __init__(self, window):
|
def __init__(self, window, displayType):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.window = window
|
self.window = window
|
||||||
|
self.displayType = displayType
|
||||||
|
|
||||||
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
self.setFrameStyle(QtWidgets.QFrame.StyledPanel)
|
||||||
|
|
||||||
@ -44,6 +50,15 @@ class Button(QtWidgets.QLabel):
|
|||||||
def updateText(self):
|
def updateText(self):
|
||||||
self.ubdateCounts()
|
self.ubdateCounts()
|
||||||
|
|
||||||
|
if self.displayType == DISPLAY_TYPE.ALL:
|
||||||
|
self.setText("%d" % self.allTabs)
|
||||||
|
elif self.displayType == DISPLAY_TYPE.LOADED:
|
||||||
|
self.setText("%d" % self.loadedTabs)
|
||||||
|
elif self.displayType == DISPLAY_TYPE.UNLOADED:
|
||||||
|
self.setText("%d" % self.unloadedTabs())
|
||||||
|
elif self.displayType == DISPLAY_TYPE.LOADED_AND_ALL:
|
||||||
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
||||||
|
else:
|
||||||
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
self.setText("%d/%d" % (self.loadedTabs, self.allTabs))
|
||||||
|
|
||||||
def ubdateCounts(self):
|
def ubdateCounts(self):
|
||||||
@ -55,3 +70,11 @@ class Button(QtWidgets.QLabel):
|
|||||||
for tab in tabs:
|
for tab in tabs:
|
||||||
if tab.isRestored():
|
if tab.isRestored():
|
||||||
self.loadedTabs += 1
|
self.loadedTabs += 1
|
||||||
|
|
||||||
|
def unloadedTabs(self):
|
||||||
|
return self.allTabs - self.loadedTabs
|
||||||
|
|
||||||
|
def displayTypeChanged(self, displayType):
|
||||||
|
self.displayType = displayType
|
||||||
|
|
||||||
|
self.updateText()
|
Loading…
Reference in New Issue
Block a user