Better formatting of error messages.
[zeroinstall.git] / iface_browser.py
blobc0104f13c6a62e789a7dd5f19ed96ff678485d2d
1 import gtk
3 from model import Interface
4 import properties
5 from gui import policy
7 class InterfaceBrowser(gtk.ScrolledWindow):
8 model = None
9 root = None
10 edit_properties = None
12 INTERFACE = 0
13 INTERFACE_NAME = 1
14 VERSION = 2
15 SUMMARY = 3
17 def __init__(self):
18 self.edit_properties = gtk.Action('edit_properties',
19 'Interface Properties...',
20 'Set which implementation of this interface to use.',
21 gtk.STOCK_PROPERTIES)
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)
45 self.add(tree_view)
46 tree_view.show()
48 tree_view.set_enable_search(True)
50 selection = tree_view.get_selection()
52 def sel_changed(sel):
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:
59 return False
60 pos = tree_view.get_path_at_pos(int(bev.x), int(bev.y))
61 if not pos:
62 return False
63 path, col, x, y = pos
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()
69 assert iter
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)
78 self.root = root
79 policy.recalculate() # Calls build_tree
81 def build_tree(self):
82 self.model.clear()
83 parent = None
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)
91 if impl:
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))
95 else:
96 self.model[iter][InterfaceBrowser.VERSION] = '(choose)'
97 add_node(None, self.root)
98 self.tree_view.expand_all()