3 from zeroinstall
.injector
.model
import Interface
5 from treetips
import TreeTips
6 from gui
import policy
, pretty_size
8 class InterfaceTips(TreeTips
):
9 def get_tooltip_text(self
, interface
):
11 text
= "(%s)\n" % interface
.uri
12 if interface
.description
:
14 lines
= filter(None, interface
.description
.split('\n'))
15 if len(lines
) > max_lines
:
16 lines
= lines
[:max_lines
] + ['...']
17 text
+= '\n'.join(lines
)
21 tips
= InterfaceTips()
23 class InterfaceBrowser(gtk
.ScrolledWindow
):
26 edit_properties
= None
35 self
.edit_properties
= gtk
.Action('edit_properties',
36 'Interface Properties...',
37 'Set which implementation of this interface to use.',
39 self
.edit_properties
.set_property('sensitive', False)
41 gtk
.ScrolledWindow
.__init
__(self
)
42 self
.set_policy(gtk
.POLICY_AUTOMATIC
, gtk
.POLICY_ALWAYS
)
43 self
.set_shadow_type(gtk
.SHADOW_IN
)
45 self
.model
= gtk
.TreeStore(object, str, str, str, str)
46 self
.tree_view
= tree_view
= gtk
.TreeView(self
.model
)
48 text
= gtk
.CellRendererText()
50 column
= gtk
.TreeViewColumn(_('Interface'), text
,
51 text
= InterfaceBrowser
.INTERFACE_NAME
)
52 tree_view
.append_column(column
)
54 column
= gtk
.TreeViewColumn(_('Version'), text
,
55 text
= InterfaceBrowser
.VERSION
)
56 tree_view
.append_column(column
)
58 column
= gtk
.TreeViewColumn(_('Fetch'), text
,
59 text
= InterfaceBrowser
.DOWNLOAD_SIZE
)
60 tree_view
.append_column(column
)
62 column
= gtk
.TreeViewColumn(_('Description'), text
,
63 text
= InterfaceBrowser
.SUMMARY
)
64 tree_view
.append_column(column
)
69 tree_view
.set_enable_search(True)
71 selection
= tree_view
.get_selection()
73 def motion(tree_view
, ev
):
74 if ev
.window
is not tree_view
.get_bin_window():
76 pos
= tree_view
.get_path_at_pos(int(ev
.x
), int(ev
.y
))
79 row
= self
.model
[path
]
80 tips
.prime(tree_view
, row
[InterfaceBrowser
.INTERFACE
])
84 tree_view
.connect('motion-notify-event', motion
)
85 tree_view
.connect('leave-notify-event', lambda tv
, ev
: tips
.hide())
88 store
, iter = sel
.get_selected()
89 self
.edit_properties
.set_property('sensitive', iter != None)
90 selection
.connect('changed', sel_changed
)
92 def button_press(tree_view
, bev
):
93 if bev
.button
!= 1 or bev
.type != gtk
.gdk
._2BUTTON
_PRESS
:
95 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
99 properties
.edit(self
.model
[path
][InterfaceBrowser
.INTERFACE
])
100 tree_view
.connect('button-press-event', button_press
)
102 def edit_selected(action
):
103 store
, iter = selection
.get_selected()
105 properties
.edit(self
.model
[iter][InterfaceBrowser
.INTERFACE
])
106 self
.edit_properties
.connect('activate', edit_selected
)
108 self
.connect('destroy', lambda s
: policy
.watchers
.remove(self
.build_tree
))
109 policy
.watchers
.append(self
.build_tree
)
111 def set_root(self
, root
):
112 assert isinstance(root
, Interface
)
114 policy
.recalculate() # Calls build_tree
116 def build_tree(self
):
117 if policy
.original_implementation
is None:
118 policy
.set_original_implementations()
122 def add_node(parent
, iface
):
123 iter = self
.model
.append(parent
)
124 self
.model
[iter][InterfaceBrowser
.INTERFACE
] = iface
125 self
.model
[iter][InterfaceBrowser
.INTERFACE_NAME
] = iface
.get_name()
126 self
.model
[iter][InterfaceBrowser
.SUMMARY
] = iface
.summary
128 impl
= policy
.implementation
.get(iface
, None)
130 old_impl
= policy
.original_implementation
.get(iface
, None)
131 version_str
= impl
.get_version()
132 if old_impl
is not None and old_impl
is not impl
:
133 version_str
+= " (was " + old_impl
.get_version() + ")"
134 self
.model
[iter][InterfaceBrowser
.VERSION
] = version_str
136 if policy
.get_cached(impl
):
139 src
= policy
.get_best_source(impl
)
140 fetch
= pretty_size(src
.size
)
141 self
.model
[iter][InterfaceBrowser
.DOWNLOAD_SIZE
] = fetch
142 for child
in impl
.dependencies
.values():
143 add_node(iter, policy
.get_interface(child
.interface
))
145 self
.model
[iter][InterfaceBrowser
.VERSION
] = '(choose)'
146 add_node(None, self
.root
)
147 self
.tree_view
.expand_all()