[master] timezone: allow the user to type it in.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



GTK currently does not suppoort search-as-you-type comboboxes, so this is
an alternative functionality, where we try to guess (using difflib) what
the user meant.

Cons: if he types 'Brno' which s-c-date doesn't know about, then 'Prague'
is not suggested automatically.

Pros: if you know your 'timezone city' you can just type it in quickly
(I'd argue most people in Europe know what their 'timezone city' is).

Related: rhbz#520631
---
 pyanaconda/iw/timezone_gui.py |   37 +++++++++++++++++++++++++++++++++++++
 1 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/pyanaconda/iw/timezone_gui.py b/pyanaconda/iw/timezone_gui.py
index ca237bc..4a8798b 100644
--- a/pyanaconda/iw/timezone_gui.py
+++ b/pyanaconda/iw/timezone_gui.py
@@ -18,6 +18,7 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+import difflib
 import string
 import gtk
 import gtk.glade
@@ -41,6 +42,11 @@ try:
 except ImportError:
     import gnome.canvas as gnomecanvas
 
+class SearchCache:
+    def __init__(self):
+        self.iterators = []
+        self.timezone_names = []
+
 class TimezoneWindow(InstallWindow):
     def __init__(self, ics):
         InstallWindow.__init__(self, ics)
@@ -114,6 +120,17 @@ class AnacondaTZMap(TimezoneMap):
     def __init__(self, zonetab, default, map="", viewportWidth=480):
         TimezoneMap.__init__(self, zonetab, default, map=map, viewportWidth=viewportWidth)
         self.columns = Enum("TRANSLATED", "TZ", "ENTRY")
+        self.search_cache = self._generate_search_cache()
+        
+    def _generate_search_cache(self):
+        search_cache = SearchCache()
+        iter = self.tzSorted.get_iter_first()
+        while iter:
+            search_cache.iterators.append(iter)
+            translated = self.tzSorted.get_value(iter, self.columns.TRANSLATED)
+            search_cache.timezone_names.append(translated.lower())
+            iter = self.tzSorted.iter_next(iter)
+        return search_cache
 
     def status_bar_init(self):
         self.status = None
@@ -136,6 +153,16 @@ class AnacondaTZMap(TimezoneMap):
                     self.fallbackEntry = entry
 
             iter = self.tzStore.insert_after(iter, [entry.translated_tz, entry.tz, entry])
+            
+    def search_changed(self, search_bar):
+        term_string = search_bar.get_text().lower()
+        close_matches = difflib.get_close_matches(
+            term_string, self.search_cache.timezone_names, n=1, cutoff=0.45)
+        if len(close_matches) > 0:
+            match = close_matches[0]
+            index = self.search_cache.timezone_names.index(match)
+            iter = self.search_cache.iterators[index]
+            self.tzCombo.set_active_iter(iter)
 
     def timezone_list_init (self, default):
         self.hbox = gtk.HBox()
@@ -146,6 +173,15 @@ class AnacondaTZMap(TimezoneMap):
 
         self.load_entries(root)
 
+        # Add a searchbar
+        search_hbox = gtk.HBox()
+        label = gtk.Label(_("Type the name of a big city near you:"))
+        self.tz_search_bar = gtk.Entry()
+        self.tz_search_bar.set_width_chars(30)
+        self.tz_search_bar.connect("changed", self.search_changed)
+        search_hbox.pack_start(label, False, False)
+        search_hbox.pack_start(self.tz_search_bar, False, False)
+
         # Add the ListStore to the sorted model after the list has been
         # populated, since otherwise we end up resorting on every addition.
         self.tzSorted = gtk.TreeModelSort(self.tzStore)
@@ -157,6 +193,7 @@ class AnacondaTZMap(TimezoneMap):
         self.tzCombo.connect("changed", self.selectionChanged)
         self.hbox.pack_start(self.tzCombo, False, False)
 
+        self.pack_start(search_hbox, False, False)
         self.pack_start(self.hbox, False, False)
 
     def selectionChanged(self, widget, *args):
-- 
1.7.1.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux