Package elisa :: Package plugins :: Package bad :: Package gtk_frontend :: Module gtk_tree_view
[hide private]
[frames] | no frames]

Source Code for Module elisa.plugins.bad.gtk_frontend.gtk_tree_view

 1  # -*- coding: utf-8 -*- 
 2  # Elisa - Home multimedia server 
 3  # Copyright (C) 2006-2008 Fluendo Embedded S.L. (www.fluendo.com). 
 4  # All rights reserved. 
 5  # 
 6  # This file is available under one of two license agreements. 
 7  # 
 8  # This file is licensed under the GPL version 3. 
 9  # See "LICENSE.GPL" in the root of this distribution including a special 
10  # exception to use Elisa with Fluendo's plugins. 
11  # 
12  # The GPL part of Elisa is also available under a commercial licensing 
13  # agreement from Fluendo. 
14  # See "LICENSE.Elisa" in the root directory of this distribution package 
15  # for details on that license. 
16   
17   
18  __maintainer__ = 'Lionel Martin <lionel@fluendo.com>' 
19   
20   
21  import pygtk 
22  pygtk.require('2.0') 
23  import gtk 
24   
25  from elisa.core import plugin_registry 
26  TreeViewClass = plugin_registry.get_component_class('base:tree_view') 
27   
28 -class GtkTreeView(TreeViewClass):
29 """ 30 This class implements gtk tree view support 31 """ 32 33 supported_controllers = ('base:tree_controller', 'poblenou:tree_controller') 34
35 - def __init__(self):
36 TreeViewClass.__init__(self) 37 self.treeview = None 38 self._create_gtk_tree()
39
40 - def _create_gtk_tree(self):
41 treestore = gtk.TreeStore(str) 42 self.treeview = gtk.TreeView(treestore) 43 self.context_handle = self.treeview 44 tvcolumn = gtk.TreeViewColumn('Column 0') 45 self.treeview.append_column(tvcolumn) 46 cell = gtk.CellRendererText() 47 #self.cell1.set_property('cell-background', 'pink') 48 tvcolumn.pack_start(cell, True) 49 tvcolumn.add_attribute(cell, 'text', 0) 50 self.treeview.set_search_column(0) 51 52 tree_selection = self.treeview.get_selection() 53 tree_selection.set_mode(gtk.SELECTION_SINGLE) 54 self.treeview.connect("cursor-changed", self._gtk_selection_changed)
55 56
57 - def controller_changed(self, old_controller, new_controller):
58 TreeViewClass.controller_changed(self, old_controller, new_controller) 59 self.select_from_view(self)
60 61
62 - def child_view_creating(self, view, controller, position):
65 66
67 - def get_path(self):
68 return []
69
70 - def select_from_view(self, view):
71 path = tuple( view.get_path() ) 72 if path == (): 73 path = (0,) 74 selection = self.treeview.get_selection() 75 selection.select_path( path )
76
77 - def get_view_from_path(self, path):
78 v = self 79 for i in path: 80 v = v[i] 81 return v
82
83 - def attribute_set(self, origin, key, old_value, new_value):
84 if key == 'current_index': 85 self.select_from_view(self[new_value]) 86 if key == 'selected': 87 if new_value == True: 88 index = self.controller.current_index 89 self.root.select_from_view(self[index])
90
91 - def _gtk_selection_changed(self, treeview):
92 treemodel, iter = self.treeview.get_selection().get_selected() 93 path = treemodel.get_path(iter) 94 selected_view = self.get_view_from_path(path) 95 selected_view.parent.controller.current_index = path[-1] 96 selected_view.parent.controller.selected = True
97