[PATCH] Language selection should work the same as keyboard selection (#854570).

Chris Lumens clumens at redhat.com
Tue Sep 11 17:58:59 UTC 2012


That is, when you start typing in the entry box it should filter the results in
the list instead of displaying a drop down.  This also allows for typing either
the English or native names and having both work for filtering.
---
 pyanaconda/ui/gui/spokes/welcome.glade | 17 ++++----------
 pyanaconda/ui/gui/spokes/welcome.py    | 43 ++++++++++++++++++++--------------
 2 files changed, 31 insertions(+), 29 deletions(-)

diff --git a/pyanaconda/ui/gui/spokes/welcome.glade b/pyanaconda/ui/gui/spokes/welcome.glade
index e5bcc0f..5db05e6 100644
--- a/pyanaconda/ui/gui/spokes/welcome.glade
+++ b/pyanaconda/ui/gui/spokes/welcome.glade
@@ -113,12 +113,6 @@ OS you can rely on.  It's for testing purposes only.</property>
             <child>
               <placeholder/>
             </child>
-            <child>
-              <placeholder/>
-            </child>
-            <child>
-              <placeholder/>
-            </child>
           </object>
           <packing>
             <property name="expand">True</property>
@@ -133,10 +127,6 @@ OS you can rely on.  It's for testing purposes only.</property>
       <action-widget response="1">continueButton</action-widget>
     </action-widgets>
   </object>
-  <object class="GtkEntryCompletion" id="languageEntryCompletion">
-    <property name="model">languageStore</property>
-    <signal name="match-selected" handler="on_completion_matched" swapped="no"/>
-  </object>
   <object class="AnacondaSpokeWindow" id="languageSpokeWindow">
     <property name="startup_id">filler</property>
     <property name="can_focus">False</property>
@@ -199,6 +189,9 @@ OS you can rely on.  It's for testing purposes only.</property>
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkTreeModelFilter" id="languageStoreFilter">
+    <property name="child_model">languageStore</property>
+  </object>
   <object class="AnacondaStandaloneWindow" id="welcomeWindow">
     <property name="startup_id">filler</property>
     <property name="can_focus">False</property>
@@ -290,7 +283,7 @@ OS you can rely on.  It's for testing purposes only.</property>
                               <object class="GtkTreeView" id="languageView">
                                 <property name="visible">True</property>
                                 <property name="can_focus">True</property>
-                                <property name="model">languageStore</property>
+                                <property name="model">languageStoreFilter</property>
                                 <property name="headers_visible">False</property>
                                 <property name="search_column">0</property>
                                 <child internal-child="selection">
@@ -347,7 +340,7 @@ OS you can rely on.  It's for testing purposes only.</property>
                             <property name="invisible_char">●</property>
                             <property name="invisible_char_set">True</property>
                             <property name="secondary_icon_name">edit-clear-symbolic</property>
-                            <property name="completion">languageEntryCompletion</property>
+                            <signal name="changed" handler="on_entry_changed" swapped="no"/>
                             <signal name="icon-release" handler="on_clear_icon_clicked" swapped="no"/>
                           </object>
                           <packing>
diff --git a/pyanaconda/ui/gui/spokes/welcome.py b/pyanaconda/ui/gui/spokes/welcome.py
index e481e6b..dac5079 100644
--- a/pyanaconda/ui/gui/spokes/welcome.py
+++ b/pyanaconda/ui/gui/spokes/welcome.py
@@ -39,7 +39,7 @@ from pyanaconda import timezone
 __all__ = ["WelcomeLanguageSpoke", "LanguageSpoke"]
 
 class LanguageMixIn(object):
-    builderObjects = ["languageStore", "languageEntryCompletion"]
+    builderObjects = ["languageStore", "languageStoreFilter"]
 
     def __init__(self, labelName = "welcomeLabel",
                  viewName = "languageView", selectionName = "languageViewSelection"):
@@ -89,6 +89,8 @@ class LanguageMixIn(object):
 
     def initialize(self):
         store = self.builder.get_object("languageStore")
+        self._languageStoreFilter = self.builder.get_object("languageStoreFilter")
+        self._languageEntry = self.builder.get_object("languageEntry")
         self._selection = self.builder.get_object(self._selectionName)
         self._view = self.builder.get_object(self._viewName)
 
@@ -110,6 +112,7 @@ class LanguageMixIn(object):
                    self.language.preferred_translation.short_name
             self._selectLanguage(store, lang)
 
+        self._languageStoreFilter.set_visible_func(self._matchesEntry, None)
 
     def retranslate(self):
         welcomeLabel = self.builder.get_object(self._labelName)
@@ -125,11 +128,6 @@ class LanguageMixIn(object):
         store = self.builder.get_object("languageStore")
         self._selectLanguage(store, self.data.lang.lang)
 
-        # I shouldn't have to do this outside of GtkBuilder, but see:
-        # https://bugzilla.gnome.org/show_bug.cgi?id=614150
-        completion = self.builder.get_object("languageEntryCompletion")
-        completion.set_text_column(1)
-
         # Rip the label and language selection window
         # from where it is right now and add it to this
         # spoke.
@@ -144,9 +142,29 @@ class LanguageMixIn(object):
         content.pack_start(child = langLabel, fill = True, expand = False, padding = 0)
         content.pack_start(child = langAlign, fill = True, expand = True, padding = 0)
 
+        self._languageEntry.set_text("")
+        self._languageStoreFilter.refilter()
+
     def _addLanguage(self, store, native, english, setting):
         store.append([native, english, setting])
 
+    def _matchesEntry(self, model, itr, *args):
+        native = model[itr][0]
+        english = model[itr][1]
+        entry = self._languageEntry.get_text().strip()
+
+        # Nothing in the text entry?  Display everything.
+        if not entry:
+            return True
+
+        # Otherwise, filter the list showing only what is matched by the
+        # text entry.  Either the English or native names can match.
+        lowered = entry.lower()
+        if lowered in native.lower() or lowered in english.lower():
+            return True
+        else:
+            return False
+
     def _selectLanguage(self, store, language):
         itr = store.get_iter_first()
         while itr and store[itr][2] not in expand_langs(language):
@@ -174,21 +192,12 @@ class LanguageMixIn(object):
             self.language.set_system_lang(lang)
             self.retranslate()
 
-            languageEntry = self.builder.get_object("languageEntry")
-            languageEntry.set_text("")
-
     def on_clear_icon_clicked(self, entry, icon_pos, event):
         if icon_pos == Gtk.EntryIconPosition.SECONDARY:
             entry.set_text("")
 
-    def on_completion_matched(self, completion, model, itr):
-        # If the user uses the entry underneath the list of languages to pick
-        # language, make sure the list stays in sync.
-        self._selection.select_iter(itr)
-
-        # And keep the selected item in the middle of the view.
-        path = model.get_path(itr)
-        self._view.scroll_to_cell(path, None, True, 0.5, 0.5)
+    def on_entry_changed(self, *args):
+        self._languageStoreFilter.refilter()
 
 class WelcomeLanguageSpoke(LanguageMixIn, StandaloneSpoke):
     mainWidgetName = "welcomeWindow"
-- 
1.7.11.2



More information about the anaconda-patches mailing list