コード例 #1
0
    def test_layout_variant_joining(self):
        """Should correctly join keyboard layout and variant to a string spec."""

        # both layout and variant specified
        assert keyboard.join_layout_variant("cz", "qwerty") == "cz (qwerty)"

        # no variant specified
        assert keyboard.join_layout_variant("cz") == "cz"
コード例 #2
0
ファイル: keyboard_test.py プロジェクト: Jakuje/anaconda
    def layout_variant_joining_test(self):
        """Should correctly join keyboard layout and variant to a string spec."""

        # both layout and variant specified
        self.assertEqual(keyboard.join_layout_variant("cz", "qwerty"),
                         "cz (qwerty)")

        # no variant specified
        self.assertEqual(keyboard.join_layout_variant("cz"), "cz")
コード例 #3
0
ファイル: keyboard_test.py プロジェクト: LiuCan01/anaconda
    def layout_variant_joining_test(self):
        """Should correctly join keyboard layout and variant to a string spec."""

        # both layout and variant specified
        self.assertEqual(keyboard.join_layout_variant("cz", "qwerty"),
                         "cz (qwerty)")

        # no variant specified
        self.assertEqual(keyboard.join_layout_variant("cz"), "cz")
コード例 #4
0
ファイル: xkl_wrapper.py プロジェクト: sjb8100/anaconda
    def get_current_layout(self):
        """
        Get current activated X layout and variant

        :return: current activated X layout and variant (e.g. "cz (qwerty)")

        """
        # ported from the widgets/src/LayoutIndicator.c code

        self._engine.start_listen(Xkl.EngineListenModes.TRACK_KEYBOARD_STATE)
        state = self._engine.get_current_state()
        cur_group = state.group
        num_groups = self._engine.get_num_groups()

        # BUG?: if the last layout in the list is activated and removed,
        #       state.group may be equal to n_groups
        if cur_group >= num_groups:
            cur_group = num_groups - 1

        layout = self._rec.layouts[cur_group]  # pylint: disable=unsubscriptable-object
        try:
            variant = self._rec.variants[cur_group]  # pylint: disable=unsubscriptable-object
        except IndexError:
            # X server may have forgotten to add the "" variant for its default layout
            variant = ""

        self._engine.stop_listen(Xkl.EngineListenModes.TRACK_KEYBOARD_STATE)

        return join_layout_variant(layout, variant)
コード例 #5
0
    def test_layout_variant_parse_join(self):
        """Parsing and joining valid layout and variant spec should have no effect."""

        specs = ("cz", "cz (qwerty)")
        for spec in specs:
            (layout, variant) = keyboard.parse_layout_variant(spec)
            assert spec == keyboard.join_layout_variant(layout, variant)
コード例 #6
0
ファイル: keyboard_test.py プロジェクト: Jakuje/anaconda
    def layout_variant_parse_join_test(self):
        """Parsing and joining valid layout and variant spec should have no effect."""

        specs = ("cz", "cz (qwerty)")
        for spec in specs:
            (layout, variant) = keyboard.parse_layout_variant(spec)
            self.assertEqual(spec, keyboard.join_layout_variant(layout, variant))
コード例 #7
0
    def get_current_layout(self):
        """
        Get current activated X layout and variant

        :return: current activated X layout and variant (e.g. "cz (qwerty)")

        """
        # ported from the widgets/src/LayoutIndicator.c code

        self._engine.start_listen(Xkl.EngineListenModes.TRACK_KEYBOARD_STATE)
        state = self._engine.get_current_state()
        cur_group = state.group
        num_groups = self._engine.get_num_groups()

        # BUG?: if the last layout in the list is activated and removed,
        #       state.group may be equal to n_groups
        if cur_group >= num_groups:
            cur_group = num_groups - 1

        layout = self._rec.layouts[cur_group]
        try:
            variant = self._rec.variants[cur_group]
        except IndexError:
            # X server may have forgotten to add the "" variant for its default layout
            variant = ""

        self._engine.stop_listen(Xkl.EngineListenModes.TRACK_KEYBOARD_STATE)

        return join_layout_variant(layout, variant)
コード例 #8
0
    def layouts_variants(self):
        """Get current X11 layouts with variants.

        :return: a list of "layout (variant)" or "layout" layout specifications
        :rtype: list(str)
        """
        if not self._localed_proxy:
            return []

        layouts = self._localed_proxy.X11Layout
        variants = self._localed_proxy.X11Variant

        layouts = layouts.split(",") if layouts else []
        variants = variants.split(",") if variants else []

        # if there are more layouts than variants, empty strings should be appended
        diff = len(layouts) - len(variants)
        variants.extend(diff * [""])

        return [join_layout_variant(layout, variant) for layout, variant in zip(layouts, variants)]