show list-multi in a treeview when there are too much options. Fixes #3046

This commit is contained in:
Yann Leboulanger 2009-08-31 21:45:52 +02:00
parent 3392e493ab
commit b3704d37c5
2 changed files with 44 additions and 8 deletions

View File

@ -370,14 +370,32 @@ class SingleForm(gtk.Table, object):
elif field.type == 'list-multi':
# TODO: When more than few choices, make a list
widget = gtk.VBox()
for value, label in field.iter_options():
check = gtk.CheckButton(label, use_underline=False)
check.set_active(value in field.values)
check.connect('toggled', self.on_list_multi_checkbutton_toggled,
field, value)
widget.set_sensitive(readwrite)
if len(field.options) < 6:
# 5 option max: show checkbutton
widget = gtk.VBox()
for value, label in field.iter_options():
check = gtk.CheckButton(label, use_underline=False)
check.set_active(value in field.values)
check.connect('toggled',
self.on_list_multi_checkbutton_toggled, field, value)
widget.pack_start(check, expand=False)
else:
# more than 5 options: show combobox
def on_list_multi_treeview_changed(selection, f):
def for_selected(treemodel, path, iter):
vals.append(treemodel[iter][1])
vals = []
selection.selected_foreach(for_selected)
field.values = vals[:]
widget = gtk.ScrolledWindow()
widget.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
tv = gtkgui_helpers.create_list_multi(field.options,
field.values)
widget.add(tv)
widget.set_size_request(-1, 120)
tv.get_selection().connect('changed',
on_list_multi_treeview_changed, field)
widget.set_sensitive(readwrite)
elif field.type == 'jid-single':
widget = gtk.Entry()

View File

@ -863,7 +863,25 @@ def create_combobox(value_list, selected_value = None):
combobox.show_all()
return combobox
def load_iconset(path, pixbuf2 = None, transport = False):
def create_list_multi(value_list, selected_values=None):
'''Value_list is [(label1, value1), ]'''
liststore = gtk.ListStore(str, str)
treeview = gtk.TreeView(liststore)
treeview.get_selection().set_mode(gtk.SELECTION_MULTIPLE)
treeview.set_headers_visible(False)
col = gtk.TreeViewColumn()
treeview.append_column(col)
cell = gtk.CellRendererText()
col.pack_start(cell, True)
col.set_attributes(cell, text=0)
for value in value_list:
iter = liststore.append(value)
if value[1] in selected_values:
treeview.get_selection().select_iter(iter)
treeview.show_all()
return treeview
def load_iconset(path, pixbuf2=None, transport=False):
'''load full iconset from the given path, and add
pixbuf2 on top left of each static images'''
path += '/'