Add spacers
Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
parent
12d505a293
commit
0b7bf53a1c
52
toolbartools/Spacer.py
Normal file
52
toolbartools/Spacer.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
|
from PySide2 import QtWidgets
|
||||||
|
|
||||||
|
|
||||||
|
class Spacer(QtWidgets.QWidget):
|
||||||
|
number = None
|
||||||
|
|
||||||
|
def __init__(self, number=None, maxWidth=400):
|
||||||
|
super().__init__()
|
||||||
|
|
||||||
|
sizePolicy = self.sizePolicy()
|
||||||
|
sizePolicy.setHorizontalPolicy(QtWidgets.QSizePolicy.Expanding)
|
||||||
|
|
||||||
|
self.setSizePolicy(sizePolicy)
|
||||||
|
|
||||||
|
if number:
|
||||||
|
self.number = number
|
||||||
|
else:
|
||||||
|
self.number = 1
|
||||||
|
|
||||||
|
if maxWidth:
|
||||||
|
self.setMaximumWidth(maxWidth)
|
||||||
|
else:
|
||||||
|
self.setMaximumWidth(100)
|
||||||
|
|
||||||
|
def id(self):
|
||||||
|
if self.number:
|
||||||
|
return "spacer_" + str(self.number)
|
||||||
|
|
||||||
|
return "spacer_1"
|
||||||
|
|
||||||
|
def name(self):
|
||||||
|
if self.number:
|
||||||
|
return "Spacer " + str(self.number)
|
||||||
|
|
||||||
|
return "Spacer 1"
|
||||||
|
|
@ -1,9 +1,38 @@
|
|||||||
|
# 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/>.
|
||||||
|
|
||||||
import Falkon
|
import Falkon
|
||||||
|
import os
|
||||||
from PySide2 import QtCore
|
from PySide2 import QtCore
|
||||||
|
from toolbartools.Spacer import Spacer
|
||||||
|
|
||||||
|
|
||||||
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
||||||
|
spacers = None
|
||||||
|
config = None
|
||||||
|
|
||||||
def init(self, state, settingsPath):
|
def init(self, state, settingsPath):
|
||||||
|
self.spacers = {}
|
||||||
|
|
||||||
|
self.config = {
|
||||||
|
"settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"),
|
||||||
|
"spacers": 2,
|
||||||
|
"maxWidth": 150
|
||||||
|
}
|
||||||
|
|
||||||
plugins = Falkon.MainApplication.instance().plugins()
|
plugins = Falkon.MainApplication.instance().plugins()
|
||||||
|
|
||||||
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
plugins.mainWindowCreated.connect(self.onMainWindowCreated)
|
||||||
@ -21,10 +50,20 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
def onMainWindowCreated(self, window):
|
def onMainWindowCreated(self, window):
|
||||||
pass
|
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
|
||||||
|
|
||||||
def mainWindowDeleted(self, window):
|
def mainWindowDeleted(self, window):
|
||||||
pass
|
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]
|
||||||
|
|
||||||
|
|
||||||
Falkon.registerPlugin(ToolbarTools())
|
Falkon.registerPlugin(ToolbarTools())
|
||||||
|
Loading…
Reference in New Issue
Block a user