Re: [PATCH 05/17] python: Started cloning grilo-test-ui
- From: Víctor M. Jáquez L. <vjaquez igalia com>
- To: grilo-list gnome org
- Subject: Re: [PATCH 05/17] python: Started cloning grilo-test-ui
- Date: Tue, 17 Aug 2010 13:14:55 +0200
On Sat, Aug 14, 2010 at 10:07:36PM +0200, Simón Pena wrote:
> Started cloning grilo-test-ui using Gtk and Grilo introspection
> bindings with PyGObject
I'd squash all the grilo-test-ui commits in a single one. There's no need to
know your personal development track.
vmjl
> ---
> tools/python/grilo-test-ui.py | 298 +++++++++++++++++++++++++++++++++++++++++
> 1 files changed, 298 insertions(+), 0 deletions(-)
> create mode 100644 tools/python/grilo-test-ui.py
>
> diff --git a/tools/python/grilo-test-ui.py b/tools/python/grilo-test-ui.py
> new file mode 100644
> index 0000000..250da87
> --- /dev/null
> +++ b/tools/python/grilo-test-ui.py
> @@ -0,0 +1,298 @@
> +#!/bin/env python
> +
> +from gi.repository import Grl
> +from gi.repository import Gtk
> +from gi.repository import GdkPixbuf
> +
> +class MainWindow(Gtk.Window):
> +
> + def __init__(self):
> + super(MainWindow, self).__init__(type=Gtk.WindowType.TOPLEVEL)
> + self.connect('destroy', self._quit)
> + self.set_title('Grilo Test UI using introspection')
> +
> + Grl.init([])
> + self._setup_ui()
> + self._load_plugins()
> +
> + self.show_all()
> +
> + def _load_plugins(self):
> + registry = Grl.PluginRegistry.get_default()
> + registry.connect('source-added',
> + self._source_added_cb)
> + registry.connect('source-removed',
> + self._source_removed_cb)
> + registry.load_all()
> +
> + def _setup_ui(self):
> + main_box = Gtk.HPaned()
> + left_pane = Gtk.VBox()
> + right_pane = Gtk.VBox()
> +
> + main_box.add(left_pane)
> + main_box.add(right_pane)
> + self.add(main_box)
> +
> + hbox = Gtk.HBox()
> + vbox = Gtk.VBox()
> + search_text = Gtk.Entry()
> + vbox.add(search_text)
> + query_text = Gtk.Entry()
> + vbox.add(query_text)
> + hbox.add(vbox)
> +
> + vbox = Gtk.VBox()
> + search_combo = SearchComboBox()
> + vbox.pack_start(search_combo, False, False, 0)
> +
> + query_combo = QueryComboBox()
> + vbox.pack_start(query_combo, False, False, 0)
> + hbox.add(vbox)
> +
> + vbox = Gtk.VBox()
> + search_btn = self._create_button('Search', self._search_btn_clicked_cb)
> + vbox.pack_start(search_btn, False, False, 0)
> + query_btn = self._create_button('Query', self._query_btn_clicked_cb)
> + vbox.pack_start(query_btn, False, False, 0)
> + hbox.add(vbox)
> +
> + left_pane.pack_start(hbox, False, False, 0)
> +
> + toolbar_buttons = self._create_toolbar_buttons()
> + left_pane.pack_start(toolbar_buttons, False, False, 0)
> +
> + self._browser_window = self._create_browser_scrolled_window()
> + left_pane.add(self._browser_window)
> +
> + show_button = self._create_button('Show', self._show_btn_clicked_cb)
> + show_button.set_sensitive(False)
> + right_pane.pack_start(show_button, False, False, 0)
> +
> + self._contents_window = self._create_contents_window()
> + right_pane.add(self._contents_window)
> +
> + self._show_plugins()
> +
> + def _create_button(self, name, callback):
> + button = Gtk.Button()
> + button.set_label(name)
> + button.connect('clicked', callback)
> + return button
> +
> + def _show_plugins(self):
> + registry = Grl.PluginRegistry.get_default()
> + self._clear_panes()
> + sources = registry.get_sources_by_operations(Grl.SupportedOps.BROWSE, False)
> + self._browser_window.get_browser().add_sources(sources)
> +
> + def _clear_panes(self):
> + pass
> +
> + def _create_contents_window(self):
> + scrolled_window = ContentScrolledWindow()
> + return scrolled_window
> +
> + def _create_browser_scrolled_window(self):
> + scrolled_window = BrowserScrolledWindow()
> + scrolled_window.get_browser().connect('row-activated',
> + self._browser_activated_cb)
> + scrolled_window.get_browser().connect('cursor-changed',
> + self._browser_row_selected_cb)
> + return scrolled_window
> +
> + def _create_toolbar_buttons(self):
> + toolbar_buttons = Gtk.HBox()
> + back_btn = Gtk.Button()
> + back_btn.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_GO_BACK,
> + Gtk.IconSize.BUTTON))
> + store_btn = Gtk.Button()
> + store_btn.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_ADD,
> + Gtk.IconSize.BUTTON))
> + remove_btn = Gtk.Button()
> + remove_btn.set_image(Gtk.Image.new_from_stock(Gtk.STOCK_REMOVE,
> + Gtk.IconSize.BUTTON))
> +
> + toolbar_buttons.pack_start(back_btn, False, False, 0)
> + toolbar_buttons.pack_start(store_btn, False, False, 0)
> + toolbar_buttons.pack_start(remove_btn, False, False, 0)
> +
> + back_btn.connect('clicked',
> + self._back_btn_clicked_cb)
> +
> + store_btn.connect('clicked',
> + self._store_btn_clicked_cb)
> +
> + remove_btn.connect('clicked',
> + self._remove_btn_clicked_cb)
> +
> + store_btn.set_sensitive(False)
> + remove_btn.set_sensitive(False)
> + return toolbar_buttons
> +
> + def _source_added_cb(self, plugin_registry, media_source):
> + self._show_plugins()
> +
> + def _source_removed_cb(self, plugin_registry, media_source):
> + print media_source.get_name()
> +
> + def _browser_activated_cb(self, *args):
> + pass
> +
> + def _browser_row_selected_cb(self, *args):
> + pass
> +
> + def _show_btn_clicked_cb(self, *args):
> + pass
> +
> + def _back_btn_clicked_cb(self, *args):
> + pass
> +
> + def _store_btn_clicked_cb(self, *args):
> + pass
> +
> + def _remove_btn_clicked_cb(self, *args):
> + pass
> +
> + def _query_btn_clicked_cb(self, *args):
> + pass
> +
> + def _search_btn_clicked_cb(self, *args):
> + pass
> +
> + def run(self):
> + Gtk.main()
> +
> + def _quit(self, *args):
> + Gtk.main_quit()
> +
> +class SearchComboBox(Gtk.ComboBox):
> + 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 __init__(self):
> + super(QueryComboBox, self).__init__()
> + renderer = Gtk.CellRendererText()
> + self.pack_start(renderer, False)
> + self.set_properties(renderer, 'text', 0)
> +
> +class BrowserScrolledWindow(Gtk.ScrolledWindow):
> + def __init__(self):
> + super(BrowserScrolledWindow, self).__init__()
> + self.set_policy(Gtk.PolicyType.AUTOMATIC,
> + Gtk.PolicyType.AUTOMATIC)
> + self._browser = BrowserTreeView()
> + self.add(self._browser)
> +
> + def get_browser(self):
> + return self._browser
> +
> +class ContentScrolledWindow(Gtk.ScrolledWindow):
> + def __init__(self):
> + super(ContentScrolledWindow, self).__init__()
> + self.set_policy(Gtk.PolicyType.AUTOMATIC,
> + Gtk.PolicyType.AUTOMATIC)
> + self._metadata = MetadataTreeView()
> + self.add(self._metadata)
> +
> + def get_metadata(self):
> + return self._metadata
> +
> +class BrowserListStore(Gtk.ListStore):
> +
> + SOURCE_COLUMN = 0
> + CONTENT_COLUMN = 1
> + TYPE_COLUMN = 2
> + NAME_COLUMN = 3
> + ICON_COLUMN = 4
> +
> + OBJECT_TYPE_SOURCE = 0
> + OBJECT_TYPE_CONTAINER = 1
> + OBJECT_TYPE_MEDIA = 2
> +
> + def __init__(self):
> + super(BrowserListStore, self).__init__(object,
> + object,
> + int,
> + str,
> + GdkPixbuf.Pixbuf)
> +
> + def add(self, sources):
> + self.clear()
> + for source in sources:
> + print 'Loaded source %(source)s' % {'source': source.get_name()}
> + row = {self.SOURCE_COLUMN: source,
> + self.CONTENT_COLUMN: None,
> + self.TYPE_COLUMN: self.OBJECT_TYPE_SOURCE,
> + self.NAME_COLUMN: source.get_name(),
> + self.ICON_COLUMN: None,
> + }
> + self.append(row.values())
> +
> +class BrowserTreeView(Gtk.TreeView):
> +
> + BROWSER_MIN_WIDTH = 320
> + BROWSER_MIN_HEIGHT = 400
> +
> + def __init__(self):
> + super(BrowserTreeView, self).__init__()
> + self.set_headers_visible(False)
> +
> + model = BrowserListStore()
> + self.set_model(model)
> +
> + col_attributes = [ 'pixbuf', 'text' ]
> + col_model = [ model.ICON_COLUMN, model.NAME_COLUMN ]
> + col_renders = [ Gtk.CellRendererPixbuf(),
> + Gtk.CellRendererText()]
> +
> + col = Gtk.TreeViewColumn()
> + for i in range(2):
> + col.pack_start(col_renders[i], False)
> + col.add_attribute(col_renders[i], col_attributes[i], col_model[i])
> +
> + col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
> + self.insert_column(col, -1)
> + self.set_size_request(self.BROWSER_MIN_WIDTH, self.BROWSER_MIN_HEIGHT)
> +
> + def add_sources(self, sources=[]):
> + model = self.get_model()
> + model.add(sources)
> +
> +class MetadataTreeView(Gtk.TreeView):
> +
> + METADATA_MIN_WIDTH = 320
> + METADATA_MIN_HEIGHT = 400
> +
> + METADATA_MODEL_NAME = 0
> + METADATA_MODEL_VALUE = 1
> +
> + def __init__(self):
> + super(MetadataTreeView, self).__init__()
> + self.set_headers_visible(False)
> +
> + col_renders = [Gtk.CellRendererText(),
> + Gtk.CellRendererText()]
> + col_attributes = ['text', 'text']
> + col_model = [self.METADATA_MODEL_NAME,
> + self.METADATA_MODEL_VALUE]
> +
> + col = Gtk.TreeViewColumn()
> + for i in range(2):
> + col.pack_start(col_renders[i], False)
> + col.add_attribute(col_renders[i],
> + col_attributes[i],
> + col_model[i])
> +
> + col.set_sizing(Gtk.TreeViewColumnSizing.AUTOSIZE)
> + self.insert_column(col, -1)
> + self.set_size_request(self.METADATA_MIN_WIDTH,
> + self.METADATA_MIN_HEIGHT)
> +
> +if __name__ == '__main__':
> + main_window = MainWindow()
> + main_window.run()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]