tabCounter/tabcounter/__init__.py

80 lines
2.6 KiB
Python
Raw Normal View History

# ============================================================
# 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
2020-02-22 15:16:09 +01:00
import Falkon
from PySide2 import QtCore
from tabcounter.label import Label
from tabcounter.config import Config
from tabcounter.constants import DISPLAY_TYPE
from tabcounter.settingsDialog import SettingsDialog
2020-02-22 15:16:09 +01:00
class tabCounter(Falkon.PluginInterface, QtCore.QObject):
panelWidgets = {}
config = None
2020-02-22 15:16:09 +01:00
def init(self, state, settingsPath):
self.config = Config(
settingsFile=os.path.join(settingsPath, "tabcounter", "settings.ini"),
displayType=DISPLAY_TYPE.LOADED_AND_ALL,
enableTooltip=False
)
self.config.load()
2020-02-22 15:16:09 +01:00
plugins = Falkon.MainApplication.instance().plugins()
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
plugins.mainWindowDeleted.connect(self.mainWindowDeleted)
if state == Falkon.PluginInterface.LateInitState:
for window in Falkon.MainApplication.instance().windows():
self.onMainWindowCreated(window)
def unload(self):
for window in Falkon.MainApplication.instance().windows():
self.mainWindowDeleted(window)
def testPlugin(self):
return True
def showSettings(self, parent):
settings = SettingsDialog(self.config, parent)
settings.accepted.connect(self.config.save)
settings.exec_()
2020-02-22 15:16:09 +01:00
def onMainWindowCreated(self, window):
labelWidget = Label(window, self.config)
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
self.panelWidgets[window] = labelWidget
2020-02-22 15:16:09 +01:00
def mainWindowDeleted(self, window):
if window not in self.panelWidgets:
return
labelWidget = self.panelWidgets[window]
window.navigationBar().removeWidget(labelWidget.id())
del self.panelWidgets[window]
2020-02-22 15:16:09 +01:00
Falkon.registerPlugin(tabCounter())