1 import gtk
, gobject
, os
2 from zeroinstall
.injector
import model
, writer
3 from gui
import policy
, pretty_size
5 def popup_menu(bev
, values
, fn
):
9 item
= gtk
.SeparatorMenuItem()
11 item
= gtk
.MenuItem(str(value
).capitalize())
12 item
.connect('activate', lambda item
, v
=value
: fn(v
))
15 menu
.popup(None, None, None, bev
.button
, bev
.time
)
17 rox_filer
= 'http://rox.sourceforge.net/2005/interfaces/ROX-Filer'
28 class ImplementationList(gtk
.ScrolledWindow
):
32 def __init__(self
, interface
):
33 gtk
.ScrolledWindow
.__init
__(self
, None, None)
34 self
.set_shadow_type(gtk
.SHADOW_IN
)
36 self
.model
= gtk
.ListStore(object, str, str, str,
37 gobject
.TYPE_BOOLEAN
, str, gobject
.TYPE_BOOLEAN
)
39 self
.tree_view
= gtk
.TreeView(self
.model
)
41 text
= gtk
.CellRendererText()
42 text_strike
= gtk
.CellRendererText()
43 toggle
= gtk
.CellRendererToggle()
45 stability
= gtk
.TreeViewColumn('Stability', text
, text
= STABILITY
)
47 for column
in (gtk
.TreeViewColumn('Version', text
, text
= VERSION
),
49 gtk
.TreeViewColumn('C', toggle
, active
= CACHED
),
50 gtk
.TreeViewColumn('Arch', text
, text
= ARCH
),
51 gtk
.TreeViewColumn('ID', text_strike
, text
= ID
,
52 strikethrough
= UNUSABLE
)):
53 self
.tree_view
.append_column(column
)
55 self
.add(self
.tree_view
)
57 def button_press(tree_view
, bev
):
58 if bev
.button
not in (1, 3):
60 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
64 impl
= self
.model
[path
][ITEM
]
66 upstream
= impl
.upstream_stability
or model
.testing
67 choices
= model
.stability_levels
.values()
71 if isinstance(new
, model
.Stability
):
72 impl
.user_stability
= new
74 impl
.user_stability
= None
75 writer
.save_interface(interface
)
77 popup_menu(bev
, ['Unset (%s)' % upstream
, None] + choices
,
79 elif bev
.button
== 3 and policy
.get_cached(impl
):
81 os
.spawnlp(os
.P_WAIT
, '0launch',
82 '0launch', rox_filer
, '-d',
83 policy
.get_implementation_path(impl
))
84 popup_menu(bev
, ['Open cached copy'], open)
85 self
.tree_view
.connect('button-press-event', button_press
)
87 def get_selection(self
):
88 return self
.tree_view
.get_selection()
90 def set_items(self
, items
):
93 new
= self
.model
.append()
94 self
.model
[new
][ITEM
] = item
95 self
.model
[new
][VERSION
] = item
.get_version()
96 self
.model
[new
][CACHED
] = policy
.get_cached(item
)
97 if item
.user_stability
:
98 self
.model
[new
][STABILITY
] = str(item
.user_stability
).upper()
100 self
.model
[new
][STABILITY
] = item
.upstream_stability
or \
102 self
.model
[new
][ARCH
] = item
.arch
or 'any'
103 self
.model
[new
][ID
] = item
.id
104 self
.model
[new
][UNUSABLE
] = policy
.is_unusable(item
)