Forum

Author Topic: Export/import customized keyboard shortcuts  (Read 686 times)

Michiel_0001

  • Newbie
  • *
  • Posts: 6
    • View Profile
Export/import customized keyboard shortcuts
« on: February 13, 2023, 04:21:37 PM »
Hi,

We're using multiple machines for our processing and I'm using a lot of customized keyboard shortcuts.
Is it possible to export these keyboard shortcuts and import these on a different machine?

Kind regards

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export/import customized keyboard shortcuts
« Reply #1 on: February 13, 2023, 06:33:29 PM »
Hello Michiel,

If both machines use Windows OS, then you can transfer the shortcuts as a part of system registry - all the contents of the following registry location: "HKEY_CURRENT_USER\Software\Agisoft\Metashape Pro\main\shortcuts".

Otherwise the following functions can be used to export/import shortcuts to text file:
Code: [Select]
import Metashape
from PySide2.QtCore import QSettings
 
def export_shortcuts():

path = Metashape.app.getSaveFileName("Specify file for shortcuts export:", filter = "*.txt" )
if not path:
print("Wrong path, script aborted")
return 0

file = open(path, "wt")

settings = QSettings()
settings.beginGroup("main/shortcuts")

shortcut_keys = settings.allKeys()
shortcuts = {}
for key in shortcut_keys:
shortcuts[key] = settings.value(key)

for key in shortcuts.keys():
if shortcuts[key]:
file.write("{:s}\t{:s}\n".format(key, shortcuts[key]))
file.close()
print("Shortcuts saved to " + path)
return 1
 
def import_shortcuts():

path = Metashape.app.getOpenFileName("Specify file for shortcuts import:", filter = "*.txt" )
if not path:
print("Wrong path, script aborted")
return 0

settings = QSettings()
settings.beginGroup("main/shortcuts")

file = open(path, "rt")
lines = file.readlines()
shortcuts = {}

for line in lines:
if len(line) < 3:
continue
shortcut_key, value = line.strip().split("\t",1)
shortcuts[shortcut_key] = value
settings.setValue(shortcut_key, value)

settings.endGroup()
settings.sync()

file.close()
print("Shortcuts loaded from " + path)
return 1

Note that after import operation Metashape window should be closed and then re-opened to apply the changes.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Michiel_0001

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Export/import customized keyboard shortcuts
« Reply #2 on: February 14, 2023, 03:22:26 PM »
Hi Alexey,

Thank you for your reply and for sharing the script. I was able to find the shortcuts in the registery.

However I was wondering, perhaps as a feature request, woudn't it be better to add a simple save/open buton?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Export/import customized keyboard shortcuts
« Reply #3 on: February 14, 2023, 06:32:03 PM »
Hello Michiel,

I will add it to the feature request list, but as the task seems to be of low priority, I cannot guarantee that it will be added very soon. So meanwhile you can try to use the script for this purposes, it can be adapted in order to be included to a Custom menu option in the Main Menu for more convenient access (but would work only with Professional edition).
Best regards,
Alexey Pasumansky,
Agisoft LLC