80 lines
2.7 KiB
Python
80 lines
2.7 KiB
Python
# ============================================================
|
|
# 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
|
|
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
|
|
|
|
|
|
class tabCounter(Falkon.PluginInterface, QtCore.QObject):
|
|
panelWidgets = {}
|
|
config = None
|
|
|
|
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.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_()
|
|
|
|
|
|
def onMainWindowCreated(self, window):
|
|
labelWidget = Label(window, self.config.displayType)
|
|
self.config.displayTypeChanged.connect(labelWidget.displayTypeChanged)
|
|
|
|
window.navigationBar().addWidget(labelWidget, labelWidget.id(), labelWidget.name())
|
|
self.panelWidgets[window] = labelWidget
|
|
|
|
def mainWindowDeleted(self, window):
|
|
if window not in self.panelWidgets:
|
|
return
|
|
|
|
labelWidget = self.panelWidgets[window]
|
|
window.navigationBar().removeWidget(labelWidget.id())
|
|
del self.panelWidgets[window]
|
|
|
|
|
|
Falkon.registerPlugin(tabCounter())
|