def layout_variant_normalize_test(self): """Normalizing layout and variant strings should work as expected.""" # no effect on normalized layout and variant string self.assertEqual(keyboard.normalize_layout_variant("cz (qwerty)"), "cz (qwerty)") self.assertEqual(keyboard.normalize_layout_variant("cz"), "cz") # normalize spaces self.assertEqual(keyboard.normalize_layout_variant("cz(qwerty)"), "cz (qwerty)") self.assertEqual(keyboard.normalize_layout_variant("cz ( qwerty )"), "cz (qwerty)") self.assertEqual(keyboard.normalize_layout_variant("cz "), "cz")
def test_layout_variant_normalize(self): """Normalizing layout and variant strings should work as expected.""" # no effect on normalized layout and variant string assert keyboard.normalize_layout_variant( "cz (qwerty)") == "cz (qwerty)" assert keyboard.normalize_layout_variant("cz") == "cz" # normalize spaces assert keyboard.normalize_layout_variant("cz(qwerty)") == "cz (qwerty)" assert keyboard.normalize_layout_variant( "cz ( qwerty )") == "cz (qwerty)" assert keyboard.normalize_layout_variant("cz ") == "cz"
def _set_keyboard_defaults(self, locale): """ Set default keyboard settings (layouts, layout switching). :param locale: locale string (see localization.LANGCODE_RE) :type locale: str :return: list of preferred keyboard layouts :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ #remove all X layouts that are not valid X layouts (unsupported) #from the ksdata #XXX: could go somewhere else, but we need X running and we have # XklWrapper instance here for layout in self.data.keyboard.x_layouts: if not self._xklwrapper.is_valid_layout(layout): self.data.keyboard.x_layouts.remove(layout) if self.data.keyboard.x_layouts: #do not add layouts if there are any specified in the kickstart return layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [keyboard.normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] self.data.keyboard.x_layouts = new_layouts if flags.can_touch_runtime_system("replace runtime X layouts", touch_live=True): self._xklwrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not self.data.keyboard.switch_options: #initialize layout switching if needed self.data.keyboard.switch_options = ["grp:alt_shift_toggle"] if flags.can_touch_runtime_system("init layout switching", touch_live=True): self._xklwrapper.set_switching_options( ["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one self._xklwrapper.activate_default_layout()
def _set_keyboard_defaults(self, locale): """ Set default keyboard settings (layouts, layout switching). :param locale: locale string (see localization.LANGCODE_RE) :type locale: str :return: list of preferred keyboard layouts :rtype: list of strings :raise InvalidLocaleSpec: if an invalid locale is given (see localization.LANGCODE_RE) """ #remove all X layouts that are not valid X layouts (unsupported) #from the ksdata #XXX: could go somewhere else, but we need X running and we have # XklWrapper instance here for layout in self.data.keyboard.x_layouts: if not self._xklwrapper.is_valid_layout(layout): self.data.keyboard.x_layouts.remove(layout) if self.data.keyboard.x_layouts: #do not add layouts if there are any specified in the kickstart return layouts = localization.get_locale_keyboards(locale) if layouts: # take the first locale (with highest rank) from the list and # store it normalized new_layouts = [keyboard.normalize_layout_variant(layouts[0])] if not langtable.supports_ascii(layouts[0]): # does not support typing ASCII chars, append the default layout new_layouts.append(DEFAULT_KEYBOARD) else: log.error("Failed to get layout for chosen locale '%s'", locale) new_layouts = [DEFAULT_KEYBOARD] self.data.keyboard.x_layouts = new_layouts if flags.can_touch_runtime_system("replace runtime X layouts", touch_live=True): self._xklwrapper.replace_layouts(new_layouts) if len(new_layouts) >= 2 and not self.data.keyboard.switch_options: #initialize layout switching if needed self.data.keyboard.switch_options = ["grp:alt_shift_toggle"] if flags.can_touch_runtime_system("init layout switching", touch_live=True): self._xklwrapper.set_switching_options(["grp:alt_shift_toggle"]) # activate the language-default layout instead of the additional # one self._xklwrapper.activate_default_layout()