10 return '%d bytes' % size
12 for unit
in ('Kb', 'Mb', 'Gb', 'Tb'):
16 return '%.1f %s' % (size
, unit
)
18 def popup_menu(bev
, values
, fn
):
22 item
= gtk
.SeparatorMenuItem()
24 item
= gtk
.MenuItem(str(value
).capitalize())
25 item
.connect('activate', lambda item
, v
=value
: fn(v
))
28 menu
.popup(None, None, None, bev
.button
, bev
.time
)
40 class ImplementationList(gtk
.ScrolledWindow
):
44 def __init__(self
, interface
):
45 gtk
.ScrolledWindow
.__init
__(self
, None, None)
46 self
.set_shadow_type(gtk
.SHADOW_IN
)
48 self
.model
= gtk
.ListStore(object, str, str, str, bool, str, str, bool)
49 self
.tree_view
= gtk
.TreeView(self
.model
)
51 text
= gtk
.CellRendererText()
52 text_strike
= gtk
.CellRendererText()
53 toggle
= gtk
.CellRendererToggle()
55 stability
= gtk
.TreeViewColumn('Stability', text
, text
= STABILITY
)
57 for column
in (gtk
.TreeViewColumn('Version', text
, text
= VERSION
),
59 gtk
.TreeViewColumn('C', toggle
, active
= CACHED
),
60 gtk
.TreeViewColumn('Arch', text
, text
= ARCH
),
61 gtk
.TreeViewColumn('Size', text
, text
= SIZE
),
62 gtk
.TreeViewColumn('ID', text_strike
, text
= ID
,
63 strikethrough
= UNUSABLE
)):
64 self
.tree_view
.append_column(column
)
66 self
.add(self
.tree_view
)
68 def button_press(tree_view
, bev
):
69 if bev
.button
not in (1, 3):
71 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
76 impl
= self
.model
[path
][ITEM
]
77 upstream
= impl
.upstream_stability
or model
.testing
78 choices
= model
.stability_levels
.values()
82 if isinstance(new
, model
.Stability
):
83 impl
.user_stability
= new
85 impl
.user_stability
= None
86 writer
.save_interface(interface
)
88 popup_menu(bev
, ['Unset (%s)' % upstream
, None] + choices
,
90 self
.tree_view
.connect('button-press-event', button_press
)
92 def get_selection(self
):
93 return self
.tree_view
.get_selection()
95 def set_items(self
, items
):
98 new
= self
.model
.append()
99 self
.model
[new
][ITEM
] = item
100 self
.model
[new
][VERSION
] = item
.get_version()
101 self
.model
[new
][CACHED
] = policy
.get_cached(item
)
102 if item
.user_stability
:
103 self
.model
[new
][STABILITY
] = str(item
.user_stability
).upper()
105 self
.model
[new
][STABILITY
] = item
.upstream_stability
or \
107 self
.model
[new
][ARCH
] = item
.arch
or 'any'
108 self
.model
[new
][ID
] = item
.id
109 self
.model
[new
][SIZE
] = pretty_size(item
.size
)
110 self
.model
[new
][UNUSABLE
] = policy
.is_unusable(item
)