3 from model
import Interface
8 class InterfaceBrowser(gtk
.ScrolledWindow
):
11 edit_properties
= None
19 self
.edit_properties
= gtk
.Action('edit_properties',
20 'Interface Properties...',
21 'Set which implementation of this interface to use.',
23 self
.edit_properties
.set_property('sensitive', False)
25 gtk
.ScrolledWindow
.__init
__(self
)
26 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
27 self
.set_shadow_type(gtk
.SHADOW_IN
)
29 self
.model
= gtk
.TreeStore(object, str, str, str)
30 self
.tree_view
= tree_view
= gtk
.TreeView(self
.model
)
32 text
= gtk
.CellRendererText()
34 column
= gtk
.TreeViewColumn(_('Interface'), text
,
35 text
= InterfaceBrowser
.INTERFACE_NAME
)
36 tree_view
.append_column(column
)
38 column
= gtk
.TreeViewColumn(_('Version'), text
,
39 text
= InterfaceBrowser
.VERSION
)
40 tree_view
.append_column(column
)
42 column
= gtk
.TreeViewColumn(_('Description'), text
,
43 text
= InterfaceBrowser
.SUMMARY
)
44 tree_view
.append_column(column
)
49 tree_view
.set_enable_search(True)
51 selection
= tree_view
.get_selection()
54 store
, iter = sel
.get_selected()
55 self
.edit_properties
.set_property('sensitive', iter != None)
56 selection
.connect('changed', sel_changed
)
58 def button_press(tree_view
, bev
):
59 if bev
.button
!= 1 or bev
.type != gtk
.gdk
._2BUTTON
_PRESS
:
61 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
65 properties
.edit(self
.model
[path
][InterfaceBrowser
.INTERFACE
])
66 tree_view
.connect('button-press-event', button_press
)
68 def edit_selected(action
):
69 store
, iter = selection
.get_selected()
71 properties
.edit(self
.model
[iter][InterfaceBrowser
.INTERFACE
])
72 self
.edit_properties
.connect('activate', edit_selected
)
74 self
.connect('destroy', lambda s
: policy
.watchers
.remove(self
.build_tree
))
75 policy
.watchers
.append(self
.build_tree
)
77 def set_root(self
, root
):
78 assert isinstance(root
, Interface
)
80 policy
.recalculate() # Calls build_tree
85 def add_node(parent
, iface
):
86 iter = self
.model
.append(parent
)
87 self
.model
[iter][InterfaceBrowser
.INTERFACE
] = iface
88 self
.model
[iter][InterfaceBrowser
.INTERFACE_NAME
] = iface
.get_name()
89 self
.model
[iter][InterfaceBrowser
.SUMMARY
] = iface
.summary
91 impl
= policy
.implementation
.get(iface
, None)
93 self
.model
[iter][InterfaceBrowser
.VERSION
] = impl
.get_version()
94 for child
in impl
.dependencies
.values():
95 add_node(iter, policy
.get_interface(child
.interface
))
97 self
.model
[iter][InterfaceBrowser
.VERSION
] = '(choose)'
98 add_node(None, self
.root
)
99 self
.tree_view
.expand_all()