Make keyboard shortcut configurable

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

View File

@ -17,7 +17,7 @@
# ============================================================ # ============================================================
import Falkon import Falkon
from PySide2 import QtCore from PySide2 import QtCore, QtGui
from autoZoomer.autoZoomer import AutoZoomer from autoZoomer.autoZoomer import AutoZoomer
from autoZoomer.button import AutoZoomerButton from autoZoomer.button import AutoZoomerButton
@ -29,6 +29,7 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
def init(self, state, settingsPath): def init(self, state, settingsPath):
self.manager = AutoZoomer(settingsPath) self.manager = AutoZoomer(settingsPath)
self.manager.configChanged.connect(self.onConfigChanged)
plugins = Falkon.MainApplication.instance().plugins() plugins = Falkon.MainApplication.instance().plugins()
@ -66,13 +67,14 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
self.actions[window] = a self.actions[window] = a
def mainWindowDeleted(self, window): def mainWindowDeleted(self, window):
if window not in self.buttons: if window in self.buttons:
return b = self.buttons[window]
window.statusBar().removeButton(b)
window.navigationBar().removeToolButton(b)
del self.buttons[window]
b = self.buttons[window] if window in self.actions:
window.statusBar().removeButton(b) del self.actions[window]
window.navigationBar().removeToolButton(b)
del self.buttons[window]
def onWebPageCreated(self, page): def onWebPageCreated(self, page):
def onLoadFinished(ok): def onLoadFinished(ok):
@ -83,5 +85,9 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
def populateExtensionsMenu(self, menu): def populateExtensionsMenu(self, menu):
self.manager.onPopulateExtensionsMenu(menu) self.manager.onPopulateExtensionsMenu(menu)
def onConfigChanged(self):
for window, action in self.actions.items():
action.setShortcut(QtGui.QKeySequence(self.manager.config["shortcut"]))
Falkon.registerPlugin(AutoZoomer_Plugin()) Falkon.registerPlugin(AutoZoomer_Plugin())

View File

@ -29,6 +29,8 @@ class AutoZoomer(QtCore.QObject):
remove = None remove = None
config = None config = None
configChanged = QtCore.Signal()
def __init__(self, settingsPath, parent=None): def __init__(self, settingsPath, parent=None):
super().__init__(parent) super().__init__(parent)
@ -36,7 +38,7 @@ class AutoZoomer(QtCore.QObject):
"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" "shortcut": ""
} }
self.data = {} self.data = {}
self.remove = [] self.remove = []
@ -46,6 +48,7 @@ class AutoZoomer(QtCore.QObject):
def showSettings(self, parent=None): def showSettings(self, parent=None):
settings = SettingsDialog(self.config, self.data, self.remove, parent) settings = SettingsDialog(self.config, self.data, self.remove, parent)
settings.accepted.connect(self.saveSettings) settings.accepted.connect(self.saveSettings)
settings.accepted.connect(self.configChanged)
settings.exec_() settings.exec_()
def loadSettings(self): def loadSettings(self):
@ -54,6 +57,7 @@ class AutoZoomer(QtCore.QObject):
settings.beginGroup("AutoZoomer") settings.beginGroup("AutoZoomer")
self.config["active"] = str2bool(settings.value("active", True)) self.config["active"] = str2bool(settings.value("active", True))
self.config["defaultZoom"] = str2bool(settings.value("defaultZoom", True)) self.config["defaultZoom"] = str2bool(settings.value("defaultZoom", True))
self.config["shortcut"] = str(settings.value("shortcut", ""))
settings.endGroup() settings.endGroup()
for group in settings.childGroups(): for group in settings.childGroups():
@ -73,6 +77,7 @@ class AutoZoomer(QtCore.QObject):
settings.beginGroup("AutoZoomer") settings.beginGroup("AutoZoomer")
settings.setValue("active", self.config["active"]) settings.setValue("active", self.config["active"])
settings.setValue("defaultZoom", self.config["defaultZoom"]) settings.setValue("defaultZoom", self.config["defaultZoom"])
settings.setValue("shortcut", self.config["shortcut"])
settings.endGroup() settings.endGroup()
for host in self.remove: for host in self.remove:

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>520</width> <width>520</width>
<height>358</height> <height>404</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@ -108,6 +108,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QKeySequenceEdit" name="keySequenceEditShortcut"/>
</item>
<item>
<widget class="QPushButton" name="pushButtonClear">
<property name="text">
<string>Clear</string>
</property>
</widget>
</item>
</layout>
</item>
<item> <item>
<widget class="QDialogButtonBox" name="buttonBoxConfirm"> <widget class="QDialogButtonBox" name="buttonBoxConfirm">
<property name="tabletTracking"> <property name="tabletTracking">
@ -130,5 +144,22 @@
<tabstop>checkBoxEnableAutoZoomer</tabstop> <tabstop>checkBoxEnableAutoZoomer</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>
<connections/> <connections>
<connection>
<sender>pushButtonClear</sender>
<signal>clicked()</signal>
<receiver>keySequenceEditShortcut</receiver>
<slot>clear()</slot>
<hints>
<hint type="sourcelabel">
<x>453</x>
<y>346</y>
</hint>
<hint type="destinationlabel">
<x>383</x>
<y>347</y>
</hint>
</hints>
</connection>
</connections>
</ui> </ui>

View File

@ -18,7 +18,7 @@
import Falkon import Falkon
import os import os
from PySide2 import QtCore, QtWidgets, QtUiTools from PySide2 import QtCore, QtGui, QtWidgets, QtUiTools
from autoZoomer.listItem import ListItem from autoZoomer.listItem import ListItem
from autoZoomer.i18n import i18n from autoZoomer.i18n import i18n
@ -47,15 +47,20 @@ class SettingsDialog(QtWidgets.QDialog):
layout.addWidget(self.ui) layout.addWidget(self.ui)
self.setLayout(layout) self.setLayout(layout)
self.translations()
for level in Falkon.WebView.zoomLevels(): for level in Falkon.WebView.zoomLevels():
self.ui.comboBoxNew.addItem(str(level) + '%') self.ui.comboBoxNew.addItem(str(level) + '%')
self.ui.comboBoxNew.setCurrentIndex(Falkon.WebView.zoomLevels().index(100)) self.ui.comboBoxNew.setCurrentIndex(Falkon.WebView.zoomLevels().index(100))
self.translations()
self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"]) self.ui.checkBoxEnableAutoZoomer.setChecked(self.config["active"])
self.ui.checkBoxDefaultZoom.setChecked(self.config["defaultZoom"]) self.ui.checkBoxDefaultZoom.setChecked(self.config["defaultZoom"])
if self.config["shortcut"]:
self.ui.keySequenceEditShortcut.setKeySequence(
QtGui.QKeySequence(self.config["shortcut"])
)
for key, value in self.data.items(): for key, value in self.data.items():
widget = ListItem() widget = ListItem()
widget.setHost(key) widget.setHost(key)
@ -78,6 +83,7 @@ class SettingsDialog(QtWidgets.QDialog):
self.ui.pushButtonRemove.setText(i18n("Remove")) self.ui.pushButtonRemove.setText(i18n("Remove"))
self.ui.checkBoxEnableAutoZoomer.setText(i18n("Enable Auto Zoomer")) self.ui.checkBoxEnableAutoZoomer.setText(i18n("Enable Auto Zoomer"))
self.ui.checkBoxDefaultZoom.setText(i18n("On unknown host zoom to default zoom level")) self.ui.checkBoxDefaultZoom.setText(i18n("On unknown host zoom to default zoom level"))
self.ui.pushButtonClear.setText(i18n("Clear"))
def addListItem(self, host, zoom=6, active=True): def addListItem(self, host, zoom=6, active=True):
if not host: if not host:
@ -106,6 +112,7 @@ class SettingsDialog(QtWidgets.QDialog):
def updateData(self): def updateData(self):
self.config["active"] = self.ui.checkBoxEnableAutoZoomer.isChecked() self.config["active"] = self.ui.checkBoxEnableAutoZoomer.isChecked()
self.config["defaultZoom"] = self.ui.checkBoxDefaultZoom.isChecked() self.config["defaultZoom"] = self.ui.checkBoxDefaultZoom.isChecked()
self.config["shortcut"] = self.ui.keySequenceEditShortcut.keySequence().toString()
self.data.clear() self.data.clear()
@ -151,4 +158,3 @@ class SettingsDialog(QtWidgets.QDialog):
self.updateData() self.updateData()
super().accept() super().accept()
self.close()