[d-feet/pygi] Fix bus list filter and add filter completion



commit 7c81e22fdb1974a6a634ade9b43981f0357056f8
Author: Thomas Bechtold <thomasbechtold jpberlin de>
Date:   Mon Sep 17 18:30:49 2012 +0200

    Fix bus list filter and add filter completion

 dfeet/bus_watch.py |   14 ++++++++++++++
 ui/buswatch.ui     |   12 ++++++++++--
 2 files changed, 24 insertions(+), 2 deletions(-)
---
diff --git a/dfeet/bus_watch.py b/dfeet/bus_watch.py
index f3db940..93438b7 100644
--- a/dfeet/bus_watch.py
+++ b/dfeet/bus_watch.py
@@ -54,6 +54,8 @@ class BusWatch:
         ui = UILoader(UILoader.UI_BUSWATCH)
         self.paned_buswatch = ui.get_root_widget()
         self.liststore_model = ui.get_widget('liststore_buswatch')
+        self.treemodelfilter_buswatch = ui.get_widget('treemodelfilter_buswatch')
+        self.treemodelfilter_buswatch.set_visible_func(self.__treemodelfilter_buswatch_cb)
         self.treeview = ui.get_widget('treeview_buswatch')
         self.entry_filter = ui.get_widget('entry_filter')
         self.grid_bus_name_selected_info = ui.get_widget('grid_bus_name_info')
@@ -64,6 +66,8 @@ class BusWatch:
         
         self.treeview.connect('cursor-changed',
                                self.__tree_view_cursor_changed_cb)
+        self.entry_filter.connect("changed",
+                                  self.__entry_filter_changed_cb)
 
 
         #setup the conection
@@ -90,6 +94,16 @@ class BusWatch:
                                  result_handler=self.__list_names_handler,
                                  error_handler=self.__list_names_error_handler)
 
+    def __treemodelfilter_buswatch_cb(self, model, iter, user_data):
+        #return model.get_value(iter, 1) in data
+        bus_name_obj = model.get(iter, 0)[0]
+        filter_text = self.entry_filter.get_text()
+        return filter_text.lower() in bus_name_obj.bus_name_unique.lower()
+
+    def __entry_filter_changed_cb(self, entry_filter):
+        self.treemodelfilter_buswatch.refilter()
+
+
     def __tree_view_cursor_changed_cb(self, treeview):
         """ do something when a row is selected """
         selection = self.treeview.get_selection()
diff --git a/ui/buswatch.ui b/ui/buswatch.ui
index fdba11a..31acc02 100644
--- a/ui/buswatch.ui
+++ b/ui/buswatch.ui
@@ -1,6 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
+  <object class="GtkEntryCompletion" id="entrycompletion_filter">
+    <property name="model">treemodelfilter_buswatch</property>
+    <property name="text_column">2</property>
+  </object>
   <object class="GtkListStore" id="liststore_buswatch">
     <columns>
       <!-- column-name bus_name_obj -->
@@ -13,6 +17,9 @@
       <column type="gchararray"/>
     </columns>
   </object>
+  <object class="GtkTreeModelFilter" id="treemodelfilter_buswatch">
+    <property name="child_model">liststore_buswatch</property>
+  </object>
   <object class="GtkPaned" id="paned_buswatch">
     <property name="visible">True</property>
     <property name="can_focus">True</property>
@@ -42,7 +49,8 @@
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
                 <property name="invisible_char">â</property>
-                <property name="invisible_char_set">True</property>
+                <property name="completion">entrycompletion_filter</property>
+                <signal name="changed" handler="entry_filter_changed_cb" swapped="no"/>
               </object>
               <packing>
                 <property name="expand">False</property>
@@ -69,7 +77,7 @@
                 <property name="has_tooltip">True</property>
                 <property name="halign">start</property>
                 <property name="valign">start</property>
-                <property name="model">liststore_buswatch</property>
+                <property name="model">treemodelfilter_buswatch</property>
                 <property name="search_column">2</property>
                 <property name="tooltip_column">2</property>
                 <child internal-child="selection">



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