3 from model
import Interface
7 class InterfaceBrowser(gtk
.ScrolledWindow
):
10 edit_properties
= None
18 self
.edit_properties
= gtk
.Action('edit_properties',
19 'Interface Properties...',
20 'Set which implementation of this interface to use.',
22 self
.edit_properties
.set_property('sensitive', False)
24 gtk
.ScrolledWindow
.__init
__(self
)
25 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
26 self
.set_shadow_type(gtk
.SHADOW_IN
)
28 self
.model
= gtk
.TreeStore(object, str, str, str)
29 self
.tree_view
= tree_view
= gtk
.TreeView(self
.model
)
31 text
= gtk
.CellRendererText()
33 column
= gtk
.TreeViewColumn(_('Interface'), text
,
34 text
= InterfaceBrowser
.INTERFACE_NAME
)
35 tree_view
.append_column(column
)
37 column
= gtk
.TreeViewColumn(_('Version'), text
,
38 text
= InterfaceBrowser
.VERSION
)
39 tree_view
.append_column(column
)
41 column
= gtk
.TreeViewColumn(_('Description'), text
,
42 text
= InterfaceBrowser
.SUMMARY
)
43 tree_view
.append_column(column
)
48 tree_view
.set_enable_search(True)
50 selection
= tree_view
.get_selection()
53 store
, iter = sel
.get_selected()
54 self
.edit_properties
.set_property('sensitive', iter != None)
55 selection
.connect('changed', sel_changed
)
57 def button_press(tree_view
, bev
):
58 if bev
.button
!= 1 or bev
.type != gtk
.gdk
._2BUTTON
_PRESS
:
60 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
64 properties
.edit(self
.model
[path
][InterfaceBrowser
.INTERFACE
])
65 tree_view
.connect('button-press-event', button_press
)
67 def edit_selected(action
):
68 store
, iter = selection
.get_selected()
70 properties
.edit(self
.model
[iter][InterfaceBrowser
.INTERFACE
])
71 self
.edit_properties
.connect('activate', edit_selected
)
73 self
.connect('destroy', lambda s
: policy
.watchers
.remove(self
.build_tree
))
74 policy
.watchers
.append(self
.build_tree
)
76 def set_root(self
, root
):
77 assert isinstance(root
, Interface
)
79 policy
.recalculate() # Calls build_tree
84 def add_node(parent
, iface
):
85 iter = self
.model
.append(parent
)
86 self
.model
[iter][InterfaceBrowser
.INTERFACE
] = iface
87 self
.model
[iter][InterfaceBrowser
.INTERFACE_NAME
] = iface
.get_name()
88 self
.model
[iter][InterfaceBrowser
.SUMMARY
] = iface
.summary
90 impl
= policy
.implementation
.get(iface
, None)
92 self
.model
[iter][InterfaceBrowser
.VERSION
] = impl
.get_version()
93 for child
in impl
.dependencies
.values():
94 add_node(iter, policy
.get_interface(child
.interface
))
96 self
.model
[iter][InterfaceBrowser
.VERSION
] = '(choose)'
97 add_node(None, self
.root
)
98 self
.tree_view
.expand_all()