Skip to content
Snippets Groups Projects
Commit b3704d37 authored by Yann Leboulanger's avatar Yann Leboulanger
Browse files

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

parent 3392e493
No related branches found
No related tags found
No related merge requests found
...@@ -370,14 +370,32 @@ class SingleForm(gtk.Table, object): ...@@ -370,14 +370,32 @@ class SingleForm(gtk.Table, object):
elif field.type == 'list-multi': elif field.type == 'list-multi':
# TODO: When more than few choices, make a list # TODO: When more than few choices, make a list
widget = gtk.VBox() if len(field.options) < 6:
for value, label in field.iter_options(): # 5 option max: show checkbutton
check = gtk.CheckButton(label, use_underline=False) widget = gtk.VBox()
check.set_active(value in field.values) for value, label in field.iter_options():
check.connect('toggled', self.on_list_multi_checkbutton_toggled, check = gtk.CheckButton(label, use_underline=False)
field, value) check.set_active(value in field.values)
widget.set_sensitive(readwrite) check.connect('toggled',
self.on_list_multi_checkbutton_toggled, field, value)
widget.pack_start(check, expand=False) 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': elif field.type == 'jid-single':
widget = gtk.Entry() widget = gtk.Entry()
......
...@@ -863,7 +863,25 @@ def create_combobox(value_list, selected_value = None): ...@@ -863,7 +863,25 @@ def create_combobox(value_list, selected_value = None):
combobox.show_all() combobox.show_all()
return combobox 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 '''load full iconset from the given path, and add
pixbuf2 on top left of each static images''' pixbuf2 on top left of each static images'''
path += '/' path += '/'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment