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
from PySide2 import QtCore
from PySide2 import QtCore, QtGui
from autoZoomer.autoZoomer import AutoZoomer
from autoZoomer.button import AutoZoomerButton
@ -29,6 +29,7 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
def init(self, state, settingsPath):
self.manager = AutoZoomer(settingsPath)
self.manager.configChanged.connect(self.onConfigChanged)
plugins = Falkon.MainApplication.instance().plugins()
@ -66,13 +67,14 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
self.actions[window] = a
def mainWindowDeleted(self, window):
if window not in self.buttons:
return
if window in self.buttons:
b = self.buttons[window]
window.statusBar().removeButton(b)
window.navigationBar().removeToolButton(b)
del self.buttons[window]
b = self.buttons[window]
window.statusBar().removeButton(b)
window.navigationBar().removeToolButton(b)
del self.buttons[window]
if window in self.actions:
del self.actions[window]
def onWebPageCreated(self, page):
def onLoadFinished(ok):
@ -83,5 +85,9 @@ class AutoZoomer_Plugin(Falkon.PluginInterface, QtCore.QObject):
def populateExtensionsMenu(self, 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())

View File

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

View File

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>520</width>
<height>358</height>
<height>404</height>
</rect>
</property>
<property name="windowTitle">
@ -108,6 +108,20 @@
</property>
</widget>
</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>
<widget class="QDialogButtonBox" name="buttonBoxConfirm">
<property name="tabletTracking">
@ -130,5 +144,22 @@
<tabstop>checkBoxEnableAutoZoomer</tabstop>
</tabstops>
<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>

View File

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