Even though we have the keyboard layouts's descriptions translated it may be easier to filter them using English especially when using ASCII-based layout and a non-ascii language (e.g. Japanesse).
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com --- pyanaconda/keyboard.py | 20 +++++++++++++++----- pyanaconda/ui/gui/spokes/keyboard.py | 36 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 20 deletions(-)
diff --git a/pyanaconda/keyboard.py b/pyanaconda/keyboard.py index e86771a..5124db4 100644 --- a/pyanaconda/keyboard.py +++ b/pyanaconda/keyboard.py @@ -530,7 +530,7 @@ class XklWrapper(object):
return self._switch_opt_infos.iterkeys()
- def get_layout_variant_description(self, layout_variant, with_lang=True): + def get_layout_variant_description(self, layout_variant, with_lang=True, xlated=True): """ Get description of the given layout-variant.
@@ -539,20 +539,30 @@ class XklWrapper(object): :param with_lang: whether to include language of the layout-variant (if defined) in the description or not :type with_lang: bool + :param xlated: whethe to return translated or english version of the description + :type xlated: bool :return: description of the layout-variant specification (e.g. 'Czech (qwerty)') :rtype: str
"""
layout_info = self._layout_infos[layout_variant] + if xlated: + description = Xkb_(layout_info.desc).decode("utf-8") + else: + description = layout_info.desc + if with_lang and layout_info.lang: # translate language and upcase its first letter, translate the # layout-variant description - xlated_lang = iso_(layout_info.lang) - return "%s (%s)" % (iutil.upcase_first_letter(xlated_lang.decode("utf-8")), - Xkb_(layout_info.desc).decode("utf-8")) + if xlated: + lang = iso_(layout_info.lang).decode("utf-8") + else: + lang = layout_info.lang + + return "%s (%s)" % (iutil.upcase_first_letter(lang), description) else: - return layout_info.desc + return description
def get_switch_opt_description(self, switch_opt): """ diff --git a/pyanaconda/ui/gui/spokes/keyboard.py b/pyanaconda/ui/gui/spokes/keyboard.py index 7c575d8..2d2c904 100644 --- a/pyanaconda/ui/gui/spokes/keyboard.py +++ b/pyanaconda/ui/gui/spokes/keyboard.py @@ -61,23 +61,29 @@ class AddLayoutDialog(GUIObject): self._chosen_layouts = []
def matches_entry(self, model, itr, user_data=None): + def have_word_match(str1, str2): + """Tells if all words from str1 exist in str2 or not.""" + + if str1 is None or str2 is None: + return False + + str1 = str1.lower() + str1_words = str1.split() + + try: + str2 = str2.lower() + for word in str1_words: + str2.index(word) + return True + except ValueError: + return False + value = model[itr][0] - value = self._xkl_wrapper.get_layout_variant_description(value) + eng_value = self._xkl_wrapper.get_layout_variant_description(value, xlated=False) + xlated_value = self._xkl_wrapper.get_layout_variant_description(value) entry_text = self._entry.get_text() - if entry_text is not None: - entry_text = entry_text.lower() - entry_text_words = entry_text.split() - else: - return False - try: - if value: - value = value.lower() - for word in entry_text_words: - value.index(word) - return True - return False - except ValueError: - return False + + return have_word_match(entry_text, eng_value) or have_word_match(entry_text, xlated_value)
def compare_layouts(self, model, itr1, itr2, user_data=None): """
On Mon, Sep 23, 2013 at 03:53:43PM -0400, Vratislav Podzimek wrote:
Even though we have the keyboard layouts's descriptions translated it may be easier to filter them using English especially when using ASCII-based layout and a non-ascii language (e.g. Japanesse).
Signed-off-by: Vratislav Podzimek vpodzime@redhat.com
pyanaconda/keyboard.py | 20 +++++++++++++++----- pyanaconda/ui/gui/spokes/keyboard.py | 36 +++++++++++++++++++++--------------- 2 files changed, 36 insertions(+), 20 deletions(-)
Ack
anaconda-patches@lists.fedorahosted.org