class Zoomer: def __init__(self): self.incr = 0.1 self._refreshSettings() def _refreshSettings(self): self.a11yAppPrefs = Settings('org.gnome.desktop.a11y.applications') self.magPrefs = Settings('org.gnome.desktop.a11y.magnifier') def zoomIn(self): mag_factor = self.magPrefs.get_double('mag-factor') self.magPrefs.set_double('mag-factor', mag_factor + self.incr) self.zoomOn() def zoomOut(self): mag_factor = self.magPrefs.get_double('mag-factor') self.magPrefs.set_double('mag-factor', mag_factor - self.incr) self.zoomOn() def zoomOff(self): self.a11yAppPrefs.set_boolean('screen-magnifier-enabled', False) def zoomOn(self): self.a11yAppPrefs.set_boolean('screen-magnifier-enabled', True) def isActive(self): return self.a11yAppPrefs.get_boolean('screen-magnifier-enabled')
from gi.repository.Gio import Settings as GSettings # from gi.repository import cairo import cairo import pyatspi import string from tools import Tools, parseColorString MAX_BLINKS = 6 gsettings = GSettings(schema="org.a11y.Accerciser") BORDER_COLOR, BORDER_ALPHA = parseColorString(gsettings.get_string("highlight-border")) FILL_COLOR, FILL_ALPHA = parseColorString(gsettings.get_string("highlight-fill")) HL_DURATION = int(gsettings.get_double("highlight-duration") * 1000) class Bag(object): """ Bag class for converting a dicionary to an object with attributes. """ def __init__(self, **kwargs): self.__dict__.update(kwargs) def __str__(self): return ", ".join(vars(self).keys()) class Node(GObject.GObject, Tools):
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)
#from gi.repository import cairo import cairo import pyatspi import string from tools import Tools, parseColorString MAX_BLINKS = 6 gsettings = GSettings(schema='org.a11y.Accerciser') BORDER_COLOR, BORDER_ALPHA = parseColorString( gsettings.get_string('highlight-border')) FILL_COLOR, FILL_ALPHA = parseColorString( gsettings.get_string('highlight-fill')) HL_DURATION = int(gsettings.get_double('highlight-duration')*1000) class Bag(object): ''' Bag class for converting a dicionary to an object with attributes. ''' def __init__(self, **kwargs): self.__dict__.update(kwargs) def __str__(self): return ', '.join(vars(self).keys()) class Node(GObject.GObject, Tools): ''' Node class that contains convient references to accessibility information for the currently selected node. A L{Node} instance will emit an
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)
def _getVoiceSettings(self, profile, app=None): voiceSettings = {} 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)) voiceGSettingsFamily = 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)) voiceGSettingsFamily = Settings( schema_id='org.gnome.orca.voice.family', path='/org/gnome/orca/profile/%s/voice/%s/' % (profile, voice)) # Used to quickly determine whether a voice's settings have been # set and are different from the defaults voiceEstablished = voiceGSettings.get_boolean('established') voiceSetting = {} voiceSettingFamily = {} if appSpecific == False and self.voiceDefaults.__contains__(voice): voiceSetting = self.voiceDefaults[voice].copy() if voiceEstablished == True: if appSpecific == False and voiceSetting.__contains__( 'established'): voiceSetting.pop('established') for setting in ['average-pitch', 'gain', 'rate']: if voiceGSettings.get_user_value(setting) is not None: gSettingsVal = voiceGSettings.get_double(setting) debug.println( debug.LEVEL_FINEST, 'INFO: GSettings backend: Getting voice setting for voice %s with name %s = %s' % (voice, setting, gSettingsVal)) voiceSetting[setting] = gSettingsVal if voiceGSettingsFamily.get_boolean('family-set') == True: for setting in ['name', 'locale', 'dialect']: gSettingsVal = voiceGSettingsFamily.get_string(setting) debug.println( debug.LEVEL_FINEST, 'INFO: GSettings backend: Getting voice family setting for voice %s with name %s = %s' % (voice, setting, gSettingsVal)) voiceSettingFamily[setting] = gSettingsVal voiceSetting['family'] = voiceSettingFamily # The JSON backend uses acss the same way, not sure why, so will # just duplicate here to be compatible. if voiceSetting != {}: if appSpecific == True: voiceSettings[voice] = voiceSetting else: voiceSettings[voice] = acss.ACSS(voiceSetting) return voiceSettings