Add extension menu action and keyboard shortcut

Signed-off-by: Juraj Oravec <sgd.orava@gmail.com>
This commit is contained in:
Juraj Oravec 2019-05-18 12:10:02 +02:00
parent a84e306764
commit e31b96fa64
No known key found for this signature in database
GPG Key ID: 63ACB65056BC8D07
2 changed files with 37 additions and 1 deletions

View File

@ -25,6 +25,7 @@ from autoZoomer.button import AutoZoomerButton
class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject): class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
manager = None manager = None
buttons = {} buttons = {}
actions = {}
def init(self, state, settingsPath): def init(self, state, settingsPath):
self.manager = AutoZoomer(settingsPath) self.manager = AutoZoomer(settingsPath)
@ -60,6 +61,10 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
window.navigationBar().addToolButton(b) window.navigationBar().addToolButton(b)
self.buttons[window] = b self.buttons[window] = b
a = self.manager.createMenuAction(shortcut=True)
window.addAction(a)
self.actions[window] = a
def mainWindowDeleted(self, window): def mainWindowDeleted(self, window):
if window not in self.buttons: if window not in self.buttons:
return return
@ -75,5 +80,8 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
page.loadFinished.connect(onLoadFinished) page.loadFinished.connect(onLoadFinished)
def populateExtensionsMenu(self, menu):
self.manager.onPopulateExtensionsMenu(menu)
Falkon.registerPlugin(AutoZoomer_Plugin()) Falkon.registerPlugin(AutoZoomer_Plugin())

View File

@ -21,8 +21,10 @@ import os
from PySide2 import QtCore, QtGui, QtWidgets from PySide2 import QtCore, QtGui, QtWidgets
from autoZoomer.settingsDialog import SettingsDialog from autoZoomer.settingsDialog import SettingsDialog
from autoZoomer.str2bool import str2bool from autoZoomer.str2bool import str2bool
from autoZoomer.i18n import i18n
class AutoZoomer(QtCore.QObject): class AutoZoomer(QtCore.QObject):
menuAction = None
data = None data = None
remove = None remove = None
config = None config = None
@ -33,7 +35,8 @@ class AutoZoomer(QtCore.QObject):
self.config = { self.config = {
"settingsFile": os.path.join(settingsPath, "autoZoomer", "settings.ini"), "settingsFile": os.path.join(settingsPath, "autoZoomer", "settings.ini"),
"active": True, "active": True,
"defaultZoom": True "defaultZoom": True,
"shortcut": "Ctrl+Shift+L"
} }
self.data = {} self.data = {}
self.remove = [] self.remove = []
@ -101,6 +104,31 @@ class AutoZoomer(QtCore.QObject):
if view.zoomLevel() != defaultZoom: if view.zoomLevel() != defaultZoom:
view.setZoomLevel(defaultZoom) view.setZoomLevel(defaultZoom)
def createMenuAction(self, parent=None, shortcut=False):
menuAction = Falkon.Action(
QtGui.QIcon(os.path.join(os.path.dirname(__file__), "icon.svg")),
i18n("Save current zoom level"),
parent
)
if self.config["shortcut"] and shortcut:
menuAction.setShortcut(QtGui.QKeySequence(self.config["shortcut"]))
menuAction.triggered.connect(self.onMenuActionTriggered)
return menuAction
def onMenuActionTriggered(self):
view = Falkon.MainApplication.instance().getWindow().weView()
host = view.page().url().host()
zoom = view.zoomLevel()
print(host, zoom)
self.addItem(host=host, zoom=zoom)
def onPopulateExtensionsMenu(self, menu):
menuAction = self.createMenuAction(menu)
menu.addAction(menuAction)
def addItem(self, host, zoom=6, active=True): def addItem(self, host, zoom=6, active=True):
if not host: if not host:
return return