3 from model
import Interface
5 from gui
import policy
, pretty_size
7 class InterfaceBrowser(gtk
.ScrolledWindow
):
10 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, 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(_('Fetch'), text
,
43 text
= InterfaceBrowser
.DOWNLOAD_SIZE
)
44 tree_view
.append_column(column
)
46 column
= gtk
.TreeViewColumn(_('Description'), text
,
47 text
= InterfaceBrowser
.SUMMARY
)
48 tree_view
.append_column(column
)
53 tree_view
.set_enable_search(True)
55 selection
= tree_view
.get_selection()
58 store
, iter = sel
.get_selected()
59 self
.edit_properties
.set_property('sensitive', iter != None)
60 selection
.connect('changed', sel_changed
)
62 def button_press(tree_view
, bev
):
63 if bev
.button
!= 1 or bev
.type != gtk
.gdk
._2BUTTON
_PRESS
:
65 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
69 properties
.edit(self
.model
[path
][InterfaceBrowser
.INTERFACE
])
70 tree_view
.connect('button-press-event', button_press
)
72 def edit_selected(action
):
73 store
, iter = selection
.get_selected()
75 properties
.edit(self
.model
[iter][InterfaceBrowser
.INTERFACE
])
76 self
.edit_properties
.connect('activate', edit_selected
)
78 self
.connect('destroy', lambda s
: policy
.watchers
.remove(self
.build_tree
))
79 policy
.watchers
.append(self
.build_tree
)
81 def set_root(self
, root
):
82 assert isinstance(root
, Interface
)
84 policy
.recalculate() # Calls build_tree
89 def add_node(parent
, iface
):
90 iter = self
.model
.append(parent
)
91 self
.model
[iter][InterfaceBrowser
.INTERFACE
] = iface
92 self
.model
[iter][InterfaceBrowser
.INTERFACE_NAME
] = iface
.get_name()
93 self
.model
[iter][InterfaceBrowser
.SUMMARY
] = iface
.summary
95 impl
= policy
.implementation
.get(iface
, None)
97 self
.model
[iter][InterfaceBrowser
.VERSION
] = impl
.get_version()
98 if policy
.get_cached(impl
):
101 src
= policy
.get_best_source(impl
)
102 fetch
= pretty_size(src
.size
)
103 self
.model
[iter][InterfaceBrowser
.DOWNLOAD_SIZE
] = fetch
104 for child
in impl
.dependencies
.values():
105 add_node(iter, policy
.get_interface(child
.interface
))
107 self
.model
[iter][InterfaceBrowser
.VERSION
] = '(choose)'
108 add_node(None, self
.root
)
109 self
.tree_view
.expand_all()