ToolbarTools/toolbartools/__init__.py

70 lines
2.4 KiB
Python
Raw Normal View History

# Toolbar Tools - Falkon plugin
# 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/>.
2019-06-24 20:57:25 +02:00
import Falkon
import os
2019-06-24 20:57:25 +02:00
from PySide2 import QtCore
from toolbartools.Spacer import Spacer
2019-06-24 20:57:25 +02:00
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
spacers = None
config = None
2019-06-24 20:57:25 +02:00
def init(self, state, settingsPath):
self.spacers = {}
self.config = {
"settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"),
"spacers": 2,
"maxWidth": 150
}
2019-06-24 20:57:25 +02: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 onMainWindowCreated(self, window):
for id in range(1, self.config["spacers"] + 1):
spacer = Spacer(id, self.config["maxWidth"])
window.navigationBar().addWidget(spacer, spacer.id(), spacer.name())
if window not in self.spacers:
self.spacers[window] = {}
self.spacers[window][id] = spacer
2019-06-24 20:57:25 +02:00
def mainWindowDeleted(self, window):
if window in self.spacers:
for id, spacer in list(self.spacers[window].items()):
window.navigationBar().removeWidget(spacer.id())
del self.spacers[window][id]
del self.spacers[window]
2019-06-24 20:57:25 +02:00
Falkon.registerPlugin(ToolbarTools())