[PATCH 06/17] grilo-test-ui.py: Query and search comboboxes



---
 tools/python/grilo-test-ui.py |   57 +++++++++++++++++++++++++++++++++-------
 1 files changed, 47 insertions(+), 10 deletions(-)

diff --git a/tools/python/grilo-test-ui.py b/tools/python/grilo-test-ui.py
index 250da87..bf61d3a 100644
--- a/tools/python/grilo-test-ui.py
+++ b/tools/python/grilo-test-ui.py
@@ -48,6 +48,8 @@ class MainWindow(Gtk.Window):
 
         query_combo = QueryComboBox()
         vbox.pack_start(query_combo, False, False, 0)
+
+        self._comboboxes = [query_combo, search_combo]
         hbox.add(vbox)
 
         vbox = Gtk.VBox()
@@ -132,6 +134,8 @@ class MainWindow(Gtk.Window):
 
     def _source_added_cb(self, plugin_registry, media_source):
         self._show_plugins()
+        for combo in self._comboboxes:
+            combo.update()
 
     def _source_removed_cb(self, plugin_registry, media_source):
         print media_source.get_name()
@@ -166,19 +170,53 @@ class MainWindow(Gtk.Window):
     def _quit(self, *args):
         Gtk.main_quit()
 
-class SearchComboBox(Gtk.ComboBox):
+class TextComboBox(Gtk.ComboBox):
+    def __init__(self):
+        super(TextComboBox, self).__init__()
+        model = ComboBoxStore()
+        self.set_model(model)
+        cell = Gtk.CellRendererText()
+        self.pack_start(cell, True)
+        self.set_properties(cell, 'text', model.NAME_COLUMN)
+
+    def update(self, operation):
+        registry = Grl.PluginRegistry.get_default()
+        sources = registry.get_sources_by_operations(operation,
+                                                     False)
+        model = ComboBoxStore()
+        self.set_model(model)
+        model.add(sources)
+
+class SearchComboBox(TextComboBox):
     def __init__(self):
         super(SearchComboBox, self).__init__()
-        renderer = Gtk.CellRendererText()
-        self.pack_start(renderer, False)
-        self.set_properties(renderer, 'text', 0)
 
-class QueryComboBox(Gtk.ComboBox):
+    def update(self):
+        super(SearchComboBox, self).update(Grl.SupportedOps.SEARCH)
+
+class QueryComboBox(TextComboBox):
     def __init__(self):
         super(QueryComboBox, self).__init__()
-        renderer = Gtk.CellRendererText()
-        self.pack_start(renderer, False)
-        self.set_properties(renderer, 'text', 0)
+
+    def update(self):
+        super(QueryComboBox, self).update(Grl.SupportedOps.QUERY)
+
+class ComboBoxStore(Gtk.ListStore):
+
+    NAME_COLUMN = 0
+    SOURCE_COLUMN = 1
+
+    def __init__(self):
+        super(ComboBoxStore, self).__init__(str,
+                                            object)
+
+    def add(self, sources):
+        self.clear()
+        for source in sources:
+            row = {self.NAME_COLUMN: source.get_name(),
+                   self.SOURCE_COLUMN: None,
+                  }
+            self.append(row.values())
 
 class BrowserScrolledWindow(Gtk.ScrolledWindow):
     def __init__(self):
@@ -224,8 +262,7 @@ class BrowserListStore(Gtk.ListStore):
     def add(self, sources):
         self.clear()
         for source in sources:
-            print 'Loaded source %(source)s' % {'source': source.get_name()}
-            row = {self.SOURCE_COLUMN: source,
+            row = {self.SOURCE_COLUMN: None, #source,
                    self.CONTENT_COLUMN: None,
                    self.TYPE_COLUMN: self.OBJECT_TYPE_SOURCE,
                    self.NAME_COLUMN: source.get_name(),
-- 
1.7.0.4



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