Example #1
0
    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()
Example #2
0
    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)
Example #3
0
    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)