def __init__(self): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=3) self._option_objects = [] self._sg = Gtk.SizeGroup(mode=Gtk.SizeGroupMode.HORIZONTAL) ok = False try: self._kbdsettings = GSettingsSetting(self.XKB_GSETTINGS_SCHEMA) self._kbdsettings.connect("changed::" + self.XKB_GSETTINGS_NAME, self._on_changed) self._xkb_info = GnomeDesktop.XkbInfo() ok = True self.loaded = True except GSettingsMissingError: logging.info("Typing missing schema %s" % self.XKB_GSETTINGS_SCHEMA) self.loaded = False except AttributeError: logging.warning("Typing missing GnomeDesktop.gir with Xkb support") self.loaded = False finally: if ok: for opt in set(self._xkb_info.get_all_option_groups() ) - self.XKB_OPTIONS_BLACKLIST: obj = _XkbOption(opt, self._kbdsettings, self._xkb_info) self._sg.add_widget(obj._combo) self._option_objects.append(obj) self.pack_start(obj, False, False, 0) TweakGroup.__init__(self, _("Typing"), *self._option_objects)
def __init__(self): Gtk.Box.__init__(self, orientation=Gtk.Orientation.VERTICAL, spacing=3) self._option_objects = [] ok = False try: self._kbdsettings = GSettingsSetting(self.XKB_GSETTINGS_SCHEMA) self._kdb_settings_id = self._kbdsettings.connect("changed::"+self.XKB_GSETTINGS_NAME, self._on_changed) self._xkb_info = GnomeDesktop.XkbInfo() ok = True self.loaded = True except GSettingsMissingError: logging.info("Typing missing schema %s" % self.XKB_GSETTINGS_SCHEMA) self.loaded = False except AttributeError: logging.warning("Typing missing GnomeDesktop.gir with Xkb support") self.loaded = False finally: if ok: for opt in set(self._xkb_info.get_all_option_groups()) - self.XKB_OPTIONS_BLACKLIST: obj = _XkbOption(opt, self._kbdsettings, self._xkb_info) self._option_objects.append(obj) self._option_objects.sort(key=lambda item_desc: item_desc.name) for item in self._option_objects: self.pack_start(item, False, False, 0) TweakGroup.__init__(self, _("Typing"), *self._option_objects) self.connect("destroy", self._on_destroy)
def load_xkb_mappings(): xkb = GnomeDesktop.XkbInfo() layouts = xkb.get_all_layouts() name_to_xkb = {} for layout in layouts: name = xkb.get_layout_info(layout).display_name name_to_xkb[name] = layout return name_to_xkb
def on_row_click_keyboard(self, list_box_keyboard, current_row_keyboard_clicked=None) -> None: if not current_row_keyboard_clicked: self._config_general['language_live_page']['keyboard'] = None self._config_general['language_live_page']['keyboard_sz'] = None self._config_general['language_live_page']['keyboard_next'] = False self._win_parent.set_button_action_visibility( MainWindowButton.NEXT, False) return row_elem = current_row_keyboard_clicked.get_child() if row_elem != self._components.get_component( 'keyboard_window_more_btn'): self._config_general['language_live_page'][ 'keyboard'] = row_elem.keyboard_id self._config_general['language_live_page'][ 'keyboard_sz'] = row_elem.keyboard_name self.set_keyboard() self._config_general['language_live_page']['keyboard_next'] = True if self._config_general['language_live_page']['language_next'] and \ self._config_general['language_live_page']['keyboard_next']: self._win_parent.set_button_action_visibility( MainWindowButton.NEXT, True) self._components.get_component('keyboard_window_input').set_text( '') return self._components.get_component( 'keyboard_window_more_btn').get_parent().hide() keyboard_info = GnomeDesktop.XkbInfo() all_keyboard_code_info = keyboard_info.get_all_layouts() all_expand_languages = list() for current in self.country_depending_keyboard: if not current.keyboard_id in self.keyboard_already_showed: self.keyboard_already_showed.add(current.keyboard_id) all_expand_languages.append(current) for current in all_keyboard_code_info: if not current in self.keyboard_already_showed: info = keyboard_info.get_layout_info(current) if info[0]: all_expand_languages.append( KeyboardLabel(current, info.display_name)) all_expand_languages.sort(key=lambda sort: sort.keyboard_name.lower()) for current in all_expand_languages: if not current.keyboard_id in self.keyboard_already_showed: self._components.get_component('keyboard_window_listbox').add( current) self.set_selected_keyboard_row()
def init_view_keyboard(self) -> None: keyboard_info = GnomeDesktop.XkbInfo() country = self._locale_general.get_detailed_locale_country( self._config_general['language_live_page']['locale']) country_lower = country.lower() input_locale = GnomeDesktop.get_input_source_from_locale( self._locale_general.get_detailed_locale( self._config_general['language_live_page']['locale'])) keyboard_depending_language = list([input_locale.id]) keyboard_depending_language_after = list() all_keyboard_and_extra = list() all_keyboard = keyboard_info.get_all_layouts() for current in all_keyboard: info = keyboard_info.get_layout_info(current) if not info[0]: continue if info[3].lower() == country_lower: keyboard_depending_language_after.append(current) keyboard_depending_language_after.remove(input_locale.id) keyboard_depending_language_after = sorted( keyboard_depending_language_after) keyboard_depending_language.extend(keyboard_depending_language_after) for current in keyboard_depending_language: info = keyboard_info.get_layout_info(current) if info[0]: all_keyboard_and_extra.append( KeyboardLabel(current, info.display_name)) for current in all_keyboard_and_extra: if current.keyboard_id in self.keyboard_already_showed: continue if len(self.keyboard_already_showed) >= self.nb_default_keyboard: self.country_depending_keyboard.append(current) continue self.keyboard_already_showed.add(current.keyboard_id) self._components.get_component('keyboard_window_listbox').add( current) self._components.get_component('keyboard_window_more_btn').show_all() self._components.get_component('keyboard_window_listbox').add( self._components.get_component('keyboard_window_more_btn')) self.set_selected_keyboard_row()
def refresh_ui_language(self) -> None: self._components.get_component('language_window_label').set_markup( u'<span font-size="medium">{}</span>'.format( self._locale_general.translate_msg('language_live_page', 'desc_language'))) self._components.get_component('keyboard_window_label').set_markup( u'<span font-size="medium">{}</span>'.format( self._locale_general.translate_msg('language_live_page', 'desc_keyboard'))) self._components.get_component( 'keyboard_window_input').set_placeholder_text( self._locale_general.translate_msg('language_live_page', 'input_keyboard')) self.set_system_language() languages = self._locale_general.available_languages keyboard_info = GnomeDesktop.XkbInfo() for current_row in self._components.get_component( 'language_window_listbox').get_children(): label = current_row.get_child() if label != self._components.get_component( 'language_window_more_btn'): label.language_name = self._locale_general.translate_msg( 'language_live_page', languages[label.language_code]) label.set_text(label.language_name) for current_row in self._components.get_component( 'keyboard_window_listbox').get_children(): label = current_row.get_child() if label != self._components.get_component( 'keyboard_window_more_btn'): info = keyboard_info.get_layout_info(label.keyboard_id) label.keyboard_name = info.display_name label.set_text(label.keyboard_name)
def init_view(self): """ Initialise ourself from GNOME XKB """ if self.had_init: return self.had_init = True self.xkb = GnomeDesktop.XkbInfo() items = GnomeDesktop.parse_locale(self.info.locale) if items[0]: lang = items[1] country = items[2] else: # Shouldn't ever happen, but ya never know. lang = "en" country = "US" if self.info.cached_location: country = self.info.cached_location.upper() l = self.info.locale success, type_, id_ = GnomeDesktop.get_input_source_from_locale(l) kbset = set() kbset.update(self.xkb.get_layouts_for_country(country)) kbset.update(self.xkb.get_layouts_for_language(lang)) major_layouts = self.xkb.get_all_layouts() for item in major_layouts: xkbinf = self.xkb.get_layout_info(item) if not xkbinf[0]: continue if xkbinf[3].lower() == country.lower(): kbset.add(item) layouts = list() for x in kbset: info = self.xkb.get_layout_info(x) if not info[0]: continue widget = KbLabel(x, info) layouts.append(widget) c = country.lower() native = filter(lambda x: x.country.lower() == c, layouts) primary = None if not native: native = layouts for item in native: if item.layout[:2].lower() == lang.lower() and not item.extras: primary = item else: for item in native: if not item.extras: primary = item break self.added = 0 self.extras = list() def append_inner(layout, item): if layout in self.shown_layouts: return if self.added >= 5: self.extras.append(item) return self.shown_layouts.add(layout) self.layouts.add(item) self.added += 1 self.shown_layouts = set() if primary: append_inner(primary.kb, primary) for item in native: append_inner(item.kb, item) for item in layouts: append_inner(item.kb, item) self.moar_button.show_all() kids = self.layouts.get_children() if kids: s = self.layouts.get_children()[0] self.layouts.select_row(s) self.layouts.add(self.moar_button)
def __init__(self): super().__init__() self.xkbinfo = GnomeDesktop.XkbInfo() self.value = 'us'
def __init__(self): super().__init__() self.xkbinfo = GnomeDesktop.XkbInfo() self.settings_file = tailsgreeter.config.keyboard_setting_path