def _language_name(self, lang_code: str) -> str: default_locale = 'C' if lang_code in ("zhs", "zht"): custom_lang_code = lang_code lang_code = "zh" local_locale = "zh_CN" if custom_lang_code == "zhs" else "zh_TW" else: custom_lang_code = None local_locale = self.get_default_locale(lang_code) try: native_name = GnomeDesktop.get_language_from_code( lang_code, local_locale).capitalize() except AttributeError: return "" localized_name = GnomeDesktop.get_language_from_code( lang_code, default_locale).capitalize() if custom_lang_code: if custom_lang_code == "zhs": localized_name = "Chinese, simplified" else: localized_name = "Chinese, traditional" if native_name == localized_name: return native_name else: return "{native} ({localized})".format(native=native_name, localized=localized_name)
def _country_name(self, country_code) -> str: default_locale = 'C' local_locale = self.get_default_locale(country_code) native_name = GnomeDesktop.get_country_from_code( country_code, local_locale) if not native_name: return "" localized_name = GnomeDesktop.get_country_from_code( country_code, default_locale) if native_name == localized_name: return native_name else: return "{native} ({localized})".format( native=native_name, localized=localized_name)
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 personality_name(personality): # TODO: this is adapted from our installer, but we should include this information # in the releases-eos-3.json file. try: return NON_LOCALE_PERSONALITIES[personality] except KeyError: pass # Get the name of 'personality' in US English. This data actually comes from the # iso-codes package, in the iso_639 and iso_3166 gettext domains, with extra logic # to suppress the country name if the language is "unique". # # Without appending .UTF-8, these come out as (eg): # Portuguese (Brazil) [ISO-8859-1] personality_as_locale = f"{personality}.UTF-8" locale_name = GnomeDesktop.get_language_from_locale( personality_as_locale, "en_US") if locale_name: # TODO: consider using the same API to generate translations from # "Endless OS Portuguese (Brazil)" to "Endless OS Portugais (Brésil)". At # present, we do not transliterate "Endless OS" to (eg) "Ендлесс ОС" but if this # changed we would need to be a bit careful. return locale_name return personality
def _get_all_languages(self, locale): all_languages = [] for language_info in self.suggested_languages + self.additional_languages: language_info.name = GnomeDesktop.get_language_from_code( language_info.language_code, locale) all_languages.append(language_info) return all_languages
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 main(argv): factory = GnomeDesktop.DesktopThumbnailFactory() for filename in argv[1:]: if os.path.isdir(filename): thumbnail_folder(factory, filename) else: make_thumbnail(factory, filename)
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 _get_language_info(self, language_code, locale=None): if not locale: locale = self._get_default_locale(language_code) name = GnomeDesktop.get_language_from_code(language_code, locale) if not name: print('Distribution developer hint:', name, 'is not available as a locale in current system.') else: return LanguageInfo(name, language_code, locale)
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 get_current_formats(): formats = global_state.get_config('formats') if not formats: formats = global_state.get_config('locale') global_state.set_config('formats', formats) name = GnomeDesktop.get_country_from_locale(formats) if not name: # solely to prevent crashes, e.g. for Esperanto # TODO add to translatation name = 'Undefined' return (name, formats)
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 _locale_name(self, locale_code: str) -> str: lang_code = self._language_from_locale(locale_code) if lang_code in ("zhs", "zht"): custom_lang_code = lang_code lang_code = "zh" else: custom_lang_code = None country_code = country_from_locale(locale_code) language_name_locale = GnomeDesktop.get_language_from_code(lang_code) language_name_native = GnomeDesktop.get_language_from_code( lang_code, locale_code) country_name_locale = GnomeDesktop.get_country_from_code(country_code) country_name_native = GnomeDesktop.get_country_from_code( country_code, locale_code) try: if (language_name_native == language_name_locale and country_name_native == country_name_locale): return "{language} - {country}".format( language=language_name_native.capitalize(), country=country_name_native) if custom_lang_code: if custom_lang_code == "zhs": country_name_locale = "simplified, " + country_name_locale else: country_name_locale = "traditional, " + country_name_locale return "{language} - {country} " \ "({local_language} - {local_country})".format( language=language_name_native.capitalize(), country=country_name_native, local_language=language_name_locale.capitalize(), local_country=country_name_locale) except AttributeError: return locale_code
def init_remaining(self): """ Add the rest to the list """ self.scroll.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC) locales = GnomeDesktop.get_all_locales() self.moar_button.get_parent().hide() appends = list() for lc in locales: if lc in default_locales: continue item = LcLabel(lc) appends.append(item) appends.sort(key=lambda x: x.dname.lower()) for item in appends: self.listbox.add(item)
def get_formats(): formats = [] # separate name set to prevent duplicates in list # see gnome-desktop issue https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/3610 names = set() translation_locale = global_state.get_config('locale') for locale in locales: name = GnomeDesktop.get_country_from_locale(locale, translation_locale) if name and not name in names: names.add(name) formats.append((name, locale)) # return sorted (considers umlauts and such) return sorted(formats, key=lambda t: Locale.strxfrm(t[0]))
def __init__(self, lc_code): Gtk.Label.__init__(self) self.set_text(lc_code) self.set_halign(Gtk.Align.START) self.lc_code = lc_code # transl = GnomeDesktop.get_language_from_locale(lc_code, lc_code) untransl = GnomeDesktop.get_language_from_locale(lc_code, None) self.set_property("margin", 8) self.dname = untransl self.set_text(untransl) self.show()
def _locale_name(locale_code) -> str: lang_code = language_from_locale(locale_code) country_code = country_from_locale(locale_code) language_name_locale = GnomeDesktop.get_language_from_code(lang_code) language_name_native = GnomeDesktop.get_language_from_code( lang_code, locale_code) country_name_locale = GnomeDesktop.get_country_from_code(country_code) country_name_native = GnomeDesktop.get_country_from_code( country_code, locale_code) try: if (language_name_native == language_name_locale and country_name_native == country_name_locale): return "{country} - {language}".format( language=language_name_native.capitalize(), country=country_name_native) else: return "{country} - {language} " \ "({local_country} - {local_language})".format( language=language_name_native.capitalize(), country=country_name_native, local_language=language_name_locale.capitalize(), local_country=country_name_locale) except AttributeError: return locale_code
def generate_thumbnail_gnome(filename): factory = GnomeDesktop.DesktopThumbnailFactory() mtime = os.path.getmtime(filename) # Use Gio to determine the URI and mime type f = Gio.file_new_for_path(filename) uri = f.get_uri() info = f.query_info("standard::content-type", Gio.FileQueryInfoFlags.NONE, None) mime_type = info.get_content_type() if factory.lookup(uri, mtime) is not None: return False if not factory.can_thumbnail(uri, mime_type, mtime): return False thumbnail = factory.generate_thumbnail(uri, mime_type) if thumbnail is None: return False factory.save_thumbnail(thumbnail, uri, mtime) return True
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__(self): super().__init__() self.xkbinfo = GnomeDesktop.XkbInfo() self.value = 'us'
import sys from multiprocessing import Pool from pathlib import Path from typing import List, Union import click import gi from loguru import logger from tqdm import tqdm gi.require_version("GnomeDesktop", "3.0") from gi.repository import Gio, GnomeDesktop # isort:skip global factory factory = GnomeDesktop.DesktopThumbnailFactory() logger.remove() logger.add(sys.stdout, level="INFO") logger.add("/tmp/thumbgen.log", level="DEBUG", rotation="100 MB") def make_thumbnail(fpath: str) -> bool: mtime = os.path.getmtime(fpath) # Use Gio to determine the URI and mime type f = Gio.file_new_for_path(str(fpath)) uri = f.get_uri() info = f.query_info("standard::content-type", Gio.FileQueryInfoFlags.NONE, None) mime_type = info.get_content_type() if factory.lookup(uri, mtime) is not None: logger.debug("FRESH {}".format(uri))
'xh', 'yi', 'yo', 'za', 'zu' ] language_code_to_locale = {} locale_set = set() for language_code in language_codes: locales = langtable.list_locales(languageId=language_code) if len(locales) > 0: language_code_to_locale[language_code] = locales[0] for locale in locales: locale_set.add(locale) else: long_language_code = language_code + '_' + language_code.upper() locales = langtable.list_locales(languageId=long_language_code) if len(locales) > 0: language_code_to_locale[language_code] = locales[0] for locale in locales: locale_set.add(locale) else: if GnomeDesktop.language_has_translations(language_code): print("Can't convert country code '{}' to locale".format( language_code)) else: print( "Can't convert country code'{}' to locale but no translations exist anyway." .format(language_code)) print(language_code_to_locale) print('----------') print(locale_set)
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)
import os import sys from multiprocessing import Pool from pathlib import Path from typing import List, Union import click import gi from loguru import logger from tqdm import tqdm gi.require_version("GnomeDesktop", "3.0") from gi.repository import Gio, GnomeDesktop # isort:skip global factory factory = GnomeDesktop.DesktopThumbnailFactory().new( GnomeDesktop.DesktopThumbnailSize.LARGE) logger.remove() logger.add(sys.stdout, level="INFO") logger.add("/tmp/thumbgen.log", level="DEBUG", rotation="100 MB") def make_thumbnail(fpath: str) -> bool: mtime = os.path.getmtime(fpath) # Use Gio to determine the URI and mime type f = Gio.file_new_for_path(str(fpath)) uri = f.get_uri() info = f.query_info("standard::content-type", Gio.FileQueryInfoFlags.NONE, None) mime_type = info.get_content_type() if factory.lookup(uri, mtime) is not None:
def get_timezone(): timezone = GnomeDesktop.WallClock().get_timezone() return timezone.get_identifier()
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.settings_file = tailsgreeter.config.keyboard_setting_path