3 from gui
import policy
, pretty_size
6 def popup_menu(bev
, values
, fn
):
10 item
= gtk
.SeparatorMenuItem()
12 item
= gtk
.MenuItem(str(value
).capitalize())
13 item
.connect('activate', lambda item
, v
=value
: fn(v
))
16 menu
.popup(None, None, None, bev
.button
, bev
.time
)
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, bool, str, str, bool)
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('Size', text
, text
= SIZE
),
50 gtk
.TreeViewColumn('ID', text_strike
, text
= ID
,
51 strikethrough
= UNUSABLE
)):
52 self
.tree_view
.append_column(column
)
54 self
.add(self
.tree_view
)
56 def button_press(tree_view
, bev
):
57 if bev
.button
not in (1, 3):
59 pos
= tree_view
.get_path_at_pos(int(bev
.x
), int(bev
.y
))
64 impl
= self
.model
[path
][ITEM
]
65 upstream
= impl
.upstream_stability
or model
.testing
66 choices
= model
.stability_levels
.values()
70 if isinstance(new
, model
.Stability
):
71 impl
.user_stability
= new
73 impl
.user_stability
= None
74 writer
.save_interface(interface
)
76 popup_menu(bev
, ['Unset (%s)' % upstream
, None] + choices
,
78 self
.tree_view
.connect('button-press-event', button_press
)
80 def get_selection(self
):
81 return self
.tree_view
.get_selection()
83 def set_items(self
, items
):
86 new
= self
.model
.append()
87 self
.model
[new
][ITEM
] = item
88 self
.model
[new
][VERSION
] = item
.get_version()
89 self
.model
[new
][CACHED
] = policy
.get_cached(item
)
90 if item
.user_stability
:
91 self
.model
[new
][STABILITY
] = str(item
.user_stability
).upper()
93 self
.model
[new
][STABILITY
] = item
.upstream_stability
or \
95 self
.model
[new
][ARCH
] = item
.arch
or 'any'
96 self
.model
[new
][ID
] = item
.id
97 self
.model
[new
][SIZE
] = pretty_size(item
.size
)
98 self
.model
[new
][UNUSABLE
] = policy
.is_unusable(item
)