def __init__(self, display): self._engine = Xkl.Engine.get_instance(display) self._configregistry = Xkl.ConfigRegistry.get_instance(self._engine) self._configregistry.load(False) self._configrec = Xkl.ConfigRec() self._configrec.get_from_server(self._engine) self._settings = Gio.Settings(_KEYBOARD_DIR)
def __init__(self, display): self._engine = Xkl.Engine.get_instance(display) self._configregistry = Xkl.ConfigRegistry.get_instance(self._engine) self._configregistry.load(False) self._configrec = Xkl.ConfigRec() self._configrec.get_from_server(self._engine) self._gconf_client = GConf.Client.get_default()
def setup(): if not _USE_XKL: return gconf_client = GConf.Client.get_default() have_config = False try: display = GdkX11.x11_get_default_xdisplay() if display is not None: engine = Xkl.Engine.get_instance(display) else: logging.debug('setup_keyboard_cb: Could not get default display.') return configrec = Xkl.ConfigRec() configrec.get_from_server(engine) # FIXME, gconf_client_get_list not introspectable #681433 layouts_from_gconf = gconf_client.get( '/desktop/sugar/peripherals/keyboard/layouts') layouts_list = [] variants_list = [] if layouts_from_gconf: for gval in layouts_from_gconf.get_list(): layout = gval.get_string() layouts_list.append(layout.split('(')[0]) variants_list.append(layout.split('(')[1][:-1]) if layouts_list and variants_list: have_config = True configrec.set_layouts(layouts_list) configrec.set_variants(variants_list) model = gconf_client.get_string(\ '/desktop/sugar/peripherals/keyboard/model') if model: have_config = True configrec.set_model(model) options = [] # FIXME, gconf_client_get_list not introspectable #681433 options_from_gconf = gconf_client.get(\ '/desktop/sugar/peripherals/keyboard/options') if options_from_gconf: for gval in options_from_gconf.get_list(): option = gval.get_string() options.append(option) if options: have_config = True configrec.set_options(options) if have_config: configrec.activate(engine) except Exception: logging.exception('Error during keyboard configuration')
def __init__(self): from gi.repository import GdkX11, Xkl self._xkl = Xkl #initialize Xkl-related stuff display = GdkX11.x11_get_default_xdisplay() self._engine = Xkl.Engine.get_instance(display) self._rec = Xkl.ConfigRec() if not self._rec.get_from_server(self._engine): raise XklWrapperError("Failed to get configuration from server") #X is probably initialized to the 'us' layout without any variant and #since we want to add layouts with variants we need the layouts and #variants lists to have the same length. Add "" padding to variants. #See docstring of the add_layout method for details. diff = len(self._rec.layouts) - len(self._rec.variants) if diff > 0 and flags.can_touch_runtime_system("activate layouts"): self._rec.set_variants(self._rec.variants + (diff * [""])) if not self._rec.activate(self._engine): # failed to activate layouts given e.g. by a kickstart (may be # invalid) lay_var_str = ",".join( map(_join_layout_variant, self._rec.layouts, self._rec.variants)) log.error( "Failed to activate layouts: '%s', " "falling back to default %s", lay_var_str, DEFAULT_KEYBOARD) self._rec.set_layouts([DEFAULT_KEYBOARD]) self._rec.set_variants([""]) if not self._rec.activate(self._engine): # failed to activate even the default layout, something is # really wrong raise XklWrapperError("Failed to initialize layouts") #needed also for Gkbd.KeyboardDrawingDialog self.configreg = Xkl.ConfigRegistry.get_instance(self._engine) self.configreg.load(False) self._layout_infos = dict() self._switch_opt_infos = dict() #this might take quite a long time self.configreg.foreach_language(self._get_language_variants, None) self.configreg.foreach_country(self._get_country_variants, None) #'grp' means that we want layout (group) switching options self.configreg.foreach_option('grp', self._get_switch_option, None)
def setup(): settings = Gio.Settings('org.sugarlabs.peripherals.keyboard') have_config = False try: display = GdkX11.x11_get_default_xdisplay() if display is not None: engine = Xkl.Engine.get_instance(display) else: logging.debug('setup_keyboard_cb: Could not get default display.') return configrec = Xkl.ConfigRec() configrec.get_from_server(engine) layouts = settings.get_strv('layouts') layouts_list = [] variants_list = [] if layouts: for layout in layouts: layouts_list.append(layout.split('(')[0]) variants_list.append(layout.split('(')[1][:-1]) if layouts_list and variants_list: have_config = True configrec.set_layouts(layouts_list) configrec.set_variants(variants_list) model = settings.get_string('model') if model: have_config = True configrec.set_model(model) options = settings.get_strv('options') if options: have_config = True configrec.set_options(options) if have_config: configrec.activate(engine) except Exception: logging.exception('Error during keyboard configuration')
def __init__(self, usermanager_loaded_cb=None, locale_selected_cb=None): self._usermanager_loaded_cb = usermanager_loaded_cb self._locale_selected_cb = locale_selected_cb self.__act_user = None self.__actusermanager_loadedid = None self._xkl_engine = Xkl.Engine.get_instance(GdkX11.x11_get_default_xdisplay()) self._xkl_registry = Xkl.ConfigRegistry.get_instance(self._xkl_engine) self._xkl_registry.load(False) self._xkl_record = Xkl.ConfigRec() self._xkl_record.get_from_server(self._xkl_engine) self._system_locales_list = _langcodes self._system_locales_dict = self.__fill_locales_dict(self._system_locales_list) self._language = 'en' self._locale = 'en_US' self._layout = 'us' self._variant = '' actusermanager = AccountsService.UserManager.get_default() self.__actusermanager_loadedid = actusermanager.connect( "notify::is-loaded", self.__on_usermanager_loaded)
# load registry registry = Xkl.ConfigRegistry.get_instance(engine) if not registry.load(False): print('Failed to load registry') sys.exit(1) print('\n== Available Layouts ==') def layout_iter(registry, item, data): print('[%s] %s, ' % (item_str(item.name), item_str(item.description))) registry.foreach_layout(layout_iter, None) print() print('\n== ConfigRec ==') rec = Xkl.ConfigRec() if not rec.get_from_server(engine): print('Failed to get configuration from server') sys.exit(1) print('Curent configuration:') print(' Model:', rec.model) print(' Layouts:', rec.layouts) print(' Variants:', rec.variants) print(' Options:', rec.options) print('Adding Danish layout...') rec.set_layouts(rec.layouts + ['dk']) rec.set_variants(rec.variants + ['']) if not rec.activate(engine): print('Failed to activate new configuration')