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)
def _saveVoiceSettings(self, voiceSettings, profile, app=None): setEstablished = False if app is not None and app != '': appSpecific = True else: appSpecific = False for voice in ['default', 'uppercase', 'hyperlink', 'system']: if appSpecific == True: voiceGSettings = Settings( schema_id='org.gnome.orca.voice', path='/org/gnome/orca/profile/%s/app/%s/voice/%s/' % (profile, app, voice)) voiceFamilyGSettings = Settings( schema_id='org.gnome.orca.voice.family', path='/org/gnome/orca/profile/%s/app/%s/voice/%s/' % (profile, app, voice)) else: voiceGSettings = Settings( schema_id='org.gnome.orca.voice', path='/org/gnome/orca/profile/%s/voice/%s/' % (profile, voice)) voiceFamilyGSettings = Settings( schema_id='org.gnome.orca.voice.family', path='/org/gnome/orca/profile/%s/voice/%s/' % (profile, voice)) if voiceSettings.__contains__(voice): if voiceSettings[voice].get('established') is None: for setting in ['average-pitch', 'gain', 'rate']: if voiceSettings[voice].get(setting) is not None: if appSpecific == True: voiceGSettings.set_double( setting, voiceSettings[voice].get(setting)) else: if voiceSettings[voice].get( setting) is not self.voiceDefaults[ voice].get(setting): voiceGSettings.set_double( setting, voiceSettings[voice].get(setting)) setEstablished = True if appSpecific == True: voiceGSettings.set_boolean('established', True) elif appSpecific == False and setEstablished == True: voiceGSettings.set_boolean('established', True) if voiceSettings[voice].__contains__('family'): for setting in ['name', 'locale', 'dialect']: voiceFamilyGSettings.set_string( setting, voiceSettings[voice]['family'].get(setting)) voiceFamilyGSettings.set_boolean('family-set', True)
def _onComboChanged(self, model, path, iter): """ Callback for row changes. Copies the changed key combos over to gsettings. @param model: The model that emitted the signal. Should be this class instance. @type model: L{gtk.TreeModel} @param path: The path of the row that has changed. @type path: tuple @param iter: The iter of the row that has changed. @type iter: L{gtk.TreeIter} """ if not model[iter][COL_COMPONENT] or not model[iter][COL_DESC]: return gspath = self._getComboGSettingsPath(model[iter][COL_COMPONENT], model[iter][COL_DESC]) gsettings = GSettings(schema=HOTKEYS_GSCHEMA, path=gspath) combo_name = gtk.accelerator_name(model[iter][COL_KEYPRESS], gdk.ModifierType(model[iter][COL_MOD])) key = gsettings.get_string("hotkey-combo") if key != combo_name and key != "/": gsettings.set_string("hotkey-combo", combo_name)
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 _onComboChanged(self, model, path, iter): ''' Callback for row changes. Copies the changed key combos over to gsettings. @param model: The model that emitted the signal. Should be this class instance. @type model: L{gtk.TreeModel} @param path: The path of the row that has changed. @type path: tuple @param iter: The iter of the row that has changed. @type iter: L{gtk.TreeIter} ''' if not model[iter][COL_COMPONENT] or not model[iter][COL_DESC]: return gspath = self._getComboGSettingsPath(model[iter][COL_COMPONENT], model[iter][COL_DESC]) gsettings = GSettings(schema=HOTKEYS_GSCHEMA, path=gspath) combo_name = gtk.accelerator_name( model[iter][COL_KEYPRESS], gdk.ModifierType(model[iter][COL_MOD])) key = gsettings.get_string('hotkey-combo') if key != combo_name and key != '/': gsettings.set_string('hotkey-combo', combo_name)
class _HighlighterView(gtk.Alignment): ''' A container widget with the settings for the highlighter. ''' def __init__(self): gtk.Alignment.__init__(self) self.set_padding(12, 12, 18, 12) self.gsettings = GSettings(schema='org.a11y.Accerciser') self._buildUI() def _buildUI(self): ''' Programatically build the UI. ''' table = gtk.Table(3, 2) table.set_col_spacings(6) self.add(table) labels = [None, None, None] controls = [None, None, None] labels[0] = gtk.Label(_('Highlight duration:')) controls[0] = gtk.SpinButton() controls[0].set_range(0.01, 5) controls[0].set_digits(2) controls[0].set_value(self.gsettings.get_double('highlight-duration')) controls[0].set_increments(0.01, 0.1) controls[0].connect('value-changed', self._onDurationChanged) labels[1] = gtk.Label(_('Border color:')) controls[1] = self._ColorButton(node.BORDER_COLOR, node.BORDER_ALPHA) controls[1].connect('color-set', self._onColorSet, 'highlight-border') controls[1].set_tooltip_text( _('The border color of the highlight box')) labels[2] = gtk.Label(_('Fill color:')) controls[2] = self._ColorButton(node.FILL_COLOR, node.FILL_ALPHA) controls[2].connect('color-set', self._onColorSet, 'highlight-fill') controls[2].set_tooltip_text(_('The fill color of the highlight box')) for label, control, row in zip(labels, controls, range(3)): label.set_alignment(0, 0.5) table.attach(label, 0, 1, row, row + 1, gtk.AttachOptions.FILL) table.attach(control, 1, 2, row, row + 1, gtk.AttachOptions.FILL) for label, control in zip(map(lambda x: x.get_accessible(), labels), map(lambda x: x.get_accessible(), controls)): label.add_relationship(atk.RelationType.LABEL_FOR, control) control.add_relationship(atk.RelationType.LABELLED_BY, label) def _onDurationChanged(self, spin_button): ''' Callback for the duration spin button. Update key and the global variable in the L{node} module. @param spin_button: The spin button that emitted the value-changed signal. @type spin_button: gtk.SpinButton ''' node.HL_DURATION = int(spin_button.get_value() * 1000) self.gsettings.set_double('highlight-duration', spin_button.get_value()) def _onColorSet(self, color_button, key): ''' Callback for a color button. Update gsettings and the global variables in the L{node} module. @param color_button: The color button that emitted the color-set signal. @type color_button: l{_HighlighterView._ColorButton} @param key: the key name suffix for this color setting. @type key: string ''' if 'fill' in key: node.FILL_COLOR = color_button.get_rgb_string() node.FILL_ALPHA = color_button.get_alpha_float() else: node.BORDER_COLOR = color_button.get_rgb_string() node.BORDER_ALPHA = color_button.get_alpha_float() self.gsettings.set_string(key, color_button.get_rgba_string()) class _ColorButton(gtk.ColorButton): ''' ColorButton derivative with useful methods for us. ''' def __init__(self, color, alpha): color = gdk.color_parse(color) gtk.ColorButton.__init__(self) self.set_use_alpha(True) self.set_alpha(int(alpha * 0xffff)) self.set_color(color) def get_rgba_string(self): ''' Get the current color and alpha in string format. @return: String in the format of #rrggbbaa. @rtype: string. ''' color = self.get_color() color_val = 0 color_val |= color.red >> 8 << 24 color_val |= color.green >> 8 << 16 color_val |= color.blue >> 8 << 8 color_val |= self.get_alpha() >> 8 return \ '#' + hex(color_val).replace('0x', '').replace('L', '').rjust(8, '0') def get_rgb_string(self): ''' Get the current color in string format. @return: String in the format of #rrggbb. @rtype: string. ''' color = self.get_color() color_val = 0 color_val |= color.red >> 8 << 16 color_val |= color.green >> 8 << 8 color_val |= color.blue >> 8 return \ '#' + hex(color_val).replace('0x', '').replace('L', '').rjust(6, '0') def get_alpha_float(self): ''' Get the current alpha as a value from 0.0 to 1.0. ''' return self.get_alpha() / float(0xffff)
class _HighlighterView(gtk.Alignment): ''' A container widget with the settings for the highlighter. ''' def __init__(self): gtk.Alignment.__init__(self) self.set_padding(12, 12, 18, 12) self.gsettings = GSettings(schema='org.a11y.Accerciser') self._buildUI() def _buildUI(self): ''' Programatically build the UI. ''' table = gtk.Table(3, 2) table.set_col_spacings(6) self.add(table) labels = [None, None, None] controls = [None, None, None] labels[0] = gtk.Label(_('Highlight duration:')) controls[0] = gtk.SpinButton() controls[0].set_range(0.01, 5) controls[0].set_digits(2) controls[0].set_value(self.gsettings.get_double('highlight-duration')) controls[0].set_increments(0.01, 0.1) controls[0].connect('value-changed', self._onDurationChanged) labels[1] = gtk.Label(_('Border color:')) controls[1] = self._ColorButton(node.BORDER_COLOR, node.BORDER_ALPHA) controls[1].connect('color-set', self._onColorSet, 'highlight-border') controls[1].set_tooltip_text(_('The border color of the highlight box')) labels[2] = gtk.Label(_('Fill color:')) controls[2] = self._ColorButton(node.FILL_COLOR, node.FILL_ALPHA) controls[2].connect('color-set', self._onColorSet, 'highlight-fill') controls[2].set_tooltip_text(_('The fill color of the highlight box')) for label, control, row in zip(labels, controls, range(3)): label.set_alignment(0, 0.5) table.attach(label, 0, 1, row, row + 1, gtk.AttachOptions.FILL) table.attach(control, 1, 2, row, row + 1, gtk.AttachOptions.FILL) for label, control in zip([x.get_accessible() for x in labels], [x.get_accessible() for x in controls]): label.add_relationship(atk.RelationType.LABEL_FOR, control) control.add_relationship(atk.RelationType.LABELLED_BY, label) def _onDurationChanged(self, spin_button): ''' Callback for the duration spin button. Update key and the global variable in the L{node} module. @param spin_button: The spin button that emitted the value-changed signal. @type spin_button: gtk.SpinButton ''' node.HL_DURATION = int(spin_button.get_value()*1000) self.gsettings.set_double('highlight-duration', spin_button.get_value()) def _onColorSet(self, color_button, key): ''' Callback for a color button. Update gsettings and the global variables in the L{node} module. @param color_button: The color button that emitted the color-set signal. @type color_button: l{_HighlighterView._ColorButton} @param key: the key name suffix for this color setting. @type key: string ''' if 'fill' in key: node.FILL_COLOR = color_button.get_rgb_string() node.FILL_ALPHA = color_button.get_alpha_float() else: node.BORDER_COLOR = color_button.get_rgb_string() node.BORDER_ALPHA = color_button.get_alpha_float() self.gsettings.set_string(key, color_button.get_rgba_string()) class _ColorButton(gtk.ColorButton): ''' ColorButton derivative with useful methods for us. ''' def __init__(self, color, alpha): color = gdk.color_parse(color) gtk.ColorButton.__init__(self) self.set_use_alpha(True) self.set_alpha(int(alpha*0xffff)) self.set_color(color) def get_rgba_string(self): ''' Get the current color and alpha in string format. @return: String in the format of #rrggbbaa. @rtype: string. ''' color = self.get_color() color_val = 0 color_val |= color.red >> 8 << 24 color_val |= color.green >> 8 << 16 color_val |= color.blue >> 8 << 8 color_val |= self.get_alpha() >> 8 return \ '#' + hex(color_val).replace('0x', '').replace('L', '').rjust(8, '0') def get_rgb_string(self): ''' Get the current color in string format. @return: String in the format of #rrggbb. @rtype: string. ''' color = self.get_color() color_val = 0 color_val |= color.red >> 8 << 16 color_val |= color.green >> 8 << 8 color_val |= color.blue >> 8 return \ '#' + hex(color_val).replace('0x', '').replace('L', '').rjust(6, '0') def get_alpha_float(self): ''' Get the current alpha as a value from 0.0 to 1.0. ''' return self.get_alpha()/float(0xffff)
# 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')