Skip to content

Commit

Permalink
v 0.7.4: Set the keyboard shortcut to Ctrl+F5 by default and make it …
Browse files Browse the repository at this point in the history
…properly configurable
  • Loading branch information
borysiasty committed Jul 13, 2018
1 parent 974c40b commit 4025d80
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
0.7.4
Set the keyboard shortcut to Ctrl+F5 by default and make it properly configurable

0.7.3
Update to recent API changes. Thanks to Francisco Raga, olivierh65 and Heikki Vesanto.
Improve GUI strings.
Expand Down
2 changes: 1 addition & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ name=Plugin Reloader
qgisMinimumVersion=3.0
description=Reloads a chosen plugin in one click
about=This tool is only useful for Python Plugin Developers!
version=0.7.3
version=0.7.4

# Optional items:

Expand Down
41 changes: 40 additions & 1 deletion reloader_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,58 @@ def __init__(self, iface):
self.toolButton.setPopupMode(QToolButton.MenuButtonPopup)
self.toolBtnAction = self.iface.addToolBarWidget(self.toolButton)

def theBestShortcutForPluginReload(self):
''' Try to find the best saved setting.
Note **the action name is variable**, so the "Keyboard Shortcuts" window
tends to save concurrent shortcuts:
.../shortcuts/Reload plugin: plugin Foo=F5
.../shortcuts/Reload plugin: plugin Bar=Ctrl+F5
.../shortcuts/Reload plugin: plugin HelloWorld=Ctrl+Alt+Del
so we should find the recent one (not always possible) and remove the rest.
'''
DEFAULT = "Ctrl+F5"
settings = QSettings()
settings.beginGroup('shortcuts')
# Find all saved shortcuts:
keys = [key for key in settings.childKeys() if key.startswith('Reload plugin: ')]
if settings.contains('Reload chosen plugin'):
keys.append('Reload chosen plugin')
if not len(keys):
# Nothing found in settings - fallback to default:
key = None
shortcut = DEFAULT
elif len(keys) == 1:
# Just one setting found, take that!
shortcut = settings.value(keys[0])
else:
# More then one old setting found. Take the best one and remove the rest.
if self.actionRun.text() in keys:
# The current action text found - let's hope it's the recent one...
key = self.actionRun.text()
shortcut = settings.value(key)
else:
# Otherwise take the first one
key = keys[0]
shortcut = settings.value(key)
# Remove redundant settings
for i in keys:
if i != key:
settings.remove(i)
return shortcut

def initGui(self):
self.actionRun = QAction(
QIcon(os.path.join(os.path.dirname(__file__), "reload.png")),
u"Reload chosen plugin",
self.iface.mainWindow()
)
self.iface.registerMainWindowAction(self.actionRun, "F5")
self.actionRun.setWhatsThis(u"Reload chosen plugin")
plugin = currentPlugin()
if plugin:
self.actionRun.setWhatsThis(u"Reload plugin: %s" % plugin)
self.actionRun.setText(u"Reload plugin: %s" % plugin)
self.iface.addPluginToMenu("&Plugin Reloader", self.actionRun)
self.iface.registerMainWindowAction(self.actionRun, self.theBestShortcutForPluginReload())
m = self.toolButton.menu()
m.addAction(self.actionRun)
self.toolButton.setDefaultAction(self.actionRun)
Expand Down

0 comments on commit 4025d80

Please sign in to comment.