Add separator

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-06-25 12:31:08 +02:00
parent 6c5e3b8c96
commit 3e726eb7b8
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 73 additions and 1 deletions

54
toolbartools/Separator.py Normal file
View File

@ -0,0 +1,54 @@
# 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 QtCore, QtGui, QtWidgets
class Separator(QtWidgets.QWidget):
number = None
def __init__(self, number=None, width=None):
super().__init__()
if width:
self.setMinimumWidth(width)
else:
self.setMinimumWidth(10)
if number:
self.number = number
else:
self.number = 1
def id(self):
if self.number:
return "separator_" + str(self.number)
return "separator_1"
def name(self):
if self.number:
return "Separator " + str(self.number)
return "Separator 1"
def paintEvent(self, paintEvent):
painter = QtGui.QPainter(self)
painter.drawLine(
self.width() / 2, 0,
self.width() / 2, self.height()
)

View File

@ -18,19 +18,23 @@ import Falkon
import os import os
from PySide2 import QtCore from PySide2 import QtCore
from toolbartools.Spacer import Spacer from toolbartools.Spacer import Spacer
from toolbartools.Separator import Separator
class ToolbarTools(Falkon.PluginInterface, QtCore.QObject): class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
spacers = None spacers = None
separators = None
config = None config = None
def init(self, state, settingsPath): def init(self, state, settingsPath):
self.spacers = {} self.spacers = {}
self.separators = {}
self.config = { self.config = {
"settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"), "settingsFile": os.path.join(settingsPath, "ToolbarTools", "settings.ini"),
"spacers": 2, "spacers": 2,
"maxWidth": 150 "maxWidth": 150,
"separators": 2
} }
plugins = Falkon.MainApplication.instance().plugins() plugins = Falkon.MainApplication.instance().plugins()
@ -58,6 +62,14 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
self.spacers[window] = {} self.spacers[window] = {}
self.spacers[window][id] = spacer self.spacers[window][id] = spacer
for id in range(1, self.config["separators"] + 1):
separator = Separator(id)
window.navigationBar().addWidget(separator, separator.id(), separator.name())
if window not in self.separators:
self.separators[window] = {}
self.separators[window][id] = separator
def mainWindowDeleted(self, window): def mainWindowDeleted(self, window):
if window in self.spacers: if window in self.spacers:
for id, spacer in list(self.spacers[window].items()): for id, spacer in list(self.spacers[window].items()):
@ -65,5 +77,11 @@ class ToolbarTools(Falkon.PluginInterface, QtCore.QObject):
del self.spacers[window][id] del self.spacers[window][id]
del self.spacers[window] del self.spacers[window]
if window in self.separators:
for id, separator in list(self.separators[window].items()):
window.navigationBar().removeWidget(separator.id())
del self.separators[window][id]
del self.separators[window]
Falkon.registerPlugin(ToolbarTools()) Falkon.registerPlugin(ToolbarTools())