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
)
26 class ImplementationList(gtk
.ScrolledWindow
):
30 def __init__(self
, interface
):
31 gtk
.ScrolledWindow
.__init
__(self
, None, None)
32 self
.set_shadow_type(gtk
.SHADOW_IN
)
34 self
.model
= gtk
.ListStore(object, str, str, str,
35 gobject
.TYPE_BOOLEAN
, str, gobject
.TYPE_BOOLEAN
)
37 self
.tree_view
= gtk
.TreeView(self
.model
)
39 text
= gtk
.CellRendererText()
40 text_strike
= gtk
.CellRendererText()
41 toggle
= gtk
.CellRendererToggle()
43 stability
= gtk
.TreeViewColumn('Stability', text
, text
= STABILITY
)
45 for column
in (gtk
.TreeViewColumn('Version', text
, text
= VERSION
),
47 gtk
.TreeViewColumn('C', toggle
, active
= CACHED
),
48 gtk
.TreeViewColumn('Arch', text
, text
= ARCH
),
49 gtk
.TreeViewColumn('ID', text_strike
, text
= ID
,
50 strikethrough
= UNUSABLE
)):
51 self
.tree_view
.append_column(column
)
53 self
.add(self
.tree_view
)
55 def button_press(tree_view
, bev
):
56 if bev
.button
not in (1, 3):
58 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
63 impl
= self
.model
[path
][ITEM
]
64 upstream
= impl
.upstream_stability
or model
.testing
65 choices
= model
.stability_levels
.values()
69 if isinstance(new
, model
.Stability
):
70 impl
.user_stability
= new
72 impl
.user_stability
= None
73 writer
.save_interface(interface
)
75 popup_menu(bev
, ['Unset (%s)' % upstream
, None] + choices
,
77 self
.tree_view
.connect('button-press-event', button_press
)
79 def get_selection(self
):
80 return self
.tree_view
.get_selection()
82 def set_items(self
, items
):
85 new
= self
.model
.append()
86 self
.model
[new
][ITEM
] = item
87 self
.model
[new
][VERSION
] = item
.get_version()
88 self
.model
[new
][CACHED
] = policy
.get_cached(item
)
89 if item
.user_stability
:
90 self
.model
[new
][STABILITY
] = str(item
.user_stability
).upper()
92 self
.model
[new
][STABILITY
] = item
.upstream_stability
or \
94 self
.model
[new
][ARCH
] = item
.arch
or 'any'
95 self
.model
[new
][ID
] = item
.id
96 self
.model
[new
][UNUSABLE
] = policy
.is_unusable(item
)