def _saveKeybindings(self, keybindings, profile, app=None): if app is not None and app != '': baseGSettings = Settings( schema_id='org.gnome.orca', path='/org/gnome/orca/profile/%s/app/%s/' % (profile, app)) appSpecific = True else: baseGSettings = Settings(schema_id='org.gnome.orca', path='/org/gnome/orca/profile/%s/' % profile) appSpecific = False keybindingList = baseGSettings.get_strv('keybindings') for keybinding in keybindings.keys(): if appSpecific == True: keybindingSettings = Settings( schema_id='org.gnome.orca.keybinding', path='/org/gnome/orca/profile/%s/app/%s/keybinding/%s/' % (profile, app, keybinding)) else: keybindingSettings = Settings( schema_id='org.gnome.orca.keybinding', path='/org/gnome/orca/profile/%s/keybinding/%s/' % (profile, keybinding)) if keybinding not in keybindingList: keybindingList.append(keybinding) keybindingVal = keybindings[keybinding][0] keybindingSettings.set_string('key', keybindingVal[0]) keybindingSettings.set_string('mod-mask', keybindingVal[1]) keybindingSettings.set_string('mod-used', keybindingVal[2]) keybindingSettings.set_string('click-count', keybindingVal[3]) # Now we remove any deleted keybindings from Gsettings. for keybinding in keybindingList: if keybinding not in keybindings.keys(): if appSpecific == True: keybindingSettings = Settings( schema_id='org.gnome.orca.keybinding', path='/org/gnome/orca/profile/%s/app/%s/keybinding/%s/' % (profile, app, keybinding)) else: keybindingSettings = Settings( schema_id='org.gnome.orca.keybinding', path='/org/gnome/orca/profile/%s/keybinding/%s/' % (profile, keybinding)) keybindingList.remove(keybinding) keybindingSettings.reset('key') keybindingSettings.reset('mod-mask') keybindingSettings.reset('mod-used') keybindingSettings.reset('click-count') if keybindingList == []: baseGSettings.reset('keybindings') else: baseGSettings.set_strv('keybindings', keybindingList)
def _savePronunciations(self, pronunciations, profile, app=None): if app is not None and app != '': baseGSettings = Settings( schema_id='org.gnome.orca', path='/org/gnome/orca/profile/%s/app/%s/' % (profile, app)) appSpecific = True else: baseGSettings = Settings(schema_id='org.gnome.orca', path='/org/gnome/orca/profile/%s/' % profile) appSpecific = False pronunciationList = baseGSettings.get_strv('pronunciations') for pronunciation in pronunciations.keys(): if appSpecific == True: pronunciationSettings = Settings( schema_id='org.gnome.orca.pronunciation', path='/org/gnome/orca/profile/%s/app/%s/pronunciation/%s/' % (profile, app, pronunciation)) else: pronunciationSettings = Settings( schema_id='org.gnome.orca.pronunciation', path='/org/gnome/orca/profile/%s/pronunciation/%s/' % (profile, pronunciation)) if pronunciation not in pronunciationList: pronunciationList.append(pronunciation) pronunciationVal = pronunciations[pronunciation] pronunciationSettings.set_string('actual', pronunciationVal[0]) pronunciationSettings.set_string('replacement', pronunciationVal[1]) # Now we remove any deleted pronunciations from GSettings. for pronunciation in pronunciationList: if pronunciation not in pronunciations.keys(): if appSpecific == True: pronunciationSettings = Settings( schema_id='org.gnome.orca.pronunciation', path= '/org/gnome/orca/profile/%s/app/%s/pronunciation/%s/' % (profile, app, pronunciation)) else: pronunciationSettings = Settings( schema_id='org.gnome.orca.pronunciation', path='/org/gnome/orca/profile/%s/pronunciation/%s/' % (profile, pronunciation)) pronunciationList.remove(pronunciation) pronunciationSettings.reset('actual') pronunciationSettings.reset('replacement') if pronunciationList == []: baseGSettings.reset('pronunciations') else: baseGSettings.set_strv('pronunciations', pronunciationList)
# Examples found here: # https://python.hotexamples.com/examples/gi.repository.Gio/Settings/-/python-settings-class-examples.html # Some Gio docs here: # https://lazka.github.io/pgi-docs/#Gio-2.0/classes/Settings.html#Gio.Settings.reset from gi.repository.Gio import Settings as GSettings import time KB_SCHEMA = 'org.gnome.Terminal.Legacy.Keybindings' KB_PATH = '/org/gnome/terminal/legacy/keybindings/' gsettings = GSettings(schema=KB_SCHEMA, path=KB_PATH) # Reset close tab combination to default "<Control><Shift>w" # https://lazka.github.io/pgi-docs/#Gio-2.0/classes/Settings.html#Gio.Settings.reset gsettings.reset('close-tab') # Send combination keyboard.send_keys('<ctrl>+w') # Alternative: # keyboard.press_key('<ctrl>') # keyboard.fake_keypress('w') # keyboard.release_key('<ctrl>') # Sleep 2 seconds for the system to process the event time.sleep(2) # Revert the close tab keyboard shortcut # https://lazka.github.io/pgi-docs/#Gio-2.0/classes/Settings.html#Gio.Settings.set_string gsettings.set_string('close-tab', '<Primary>w')