show combobox in dataform widget when there are more than 5 options. see #3046
This commit is contained in:
parent
aa241a338a
commit
290df83c80
2 changed files with 44 additions and 17 deletions
|
@ -312,25 +312,35 @@ class SingleForm(gtk.Table, object):
|
||||||
xoptions=gtk.FILL, yoptions=gtk.FILL)
|
xoptions=gtk.FILL, yoptions=gtk.FILL)
|
||||||
|
|
||||||
elif field.type == 'list-single':
|
elif field.type == 'list-single':
|
||||||
# TODO: When more than few choices, make a list
|
|
||||||
# TODO: Think of moving that to another function (it could be used
|
|
||||||
# TODO: in stage2 of adhoc commands too).
|
|
||||||
# TODO: What if we have radio buttons and non-required field?
|
# TODO: What if we have radio buttons and non-required field?
|
||||||
# TODO: We cannot deactivate them all...
|
# TODO: We cannot deactivate them all...
|
||||||
widget = gtk.VBox()
|
if len(field.options) < 6:
|
||||||
first_radio = None
|
# 5 option max: show radiobutton
|
||||||
for value, label in field.iter_options():
|
widget = gtk.VBox()
|
||||||
radio = gtk.RadioButton(first_radio, label=label)
|
first_radio = None
|
||||||
radio.connect('toggled', self.on_list_single_radiobutton_toggled,
|
for value, label in field.iter_options():
|
||||||
field, value)
|
radio = gtk.RadioButton(first_radio, label=label)
|
||||||
if first_radio is None:
|
radio.connect('toggled',
|
||||||
first_radio = radio
|
self.on_list_single_radiobutton_toggled, field, value)
|
||||||
if field.value=='': # TODO: is None when done
|
if first_radio is None:
|
||||||
field.value = value
|
first_radio = radio
|
||||||
if value == field.value:
|
if field.value == '': # TODO: is None when done
|
||||||
radio.set_active(True)
|
field.value = value
|
||||||
widget.set_sensitive(readwrite)
|
if value == field.value:
|
||||||
widget.pack_start(radio, expand=False)
|
radio.set_active(True)
|
||||||
|
widget.pack_start(radio, expand=False)
|
||||||
|
else:
|
||||||
|
# more than 5 options: show combobox
|
||||||
|
def on_list_single_combobox_changed(combobox, f):
|
||||||
|
iter = combobox.get_active_iter()
|
||||||
|
if iter:
|
||||||
|
model = combobox.get_model()
|
||||||
|
f.value = model[iter][1]
|
||||||
|
else:
|
||||||
|
f.value = ''
|
||||||
|
widget = gtkgui_helpers.create_combobox(field.options, field.value)
|
||||||
|
widget.connect('changed', on_list_single_combobox_changed, field)
|
||||||
|
widget.set_sensitive(readwrite)
|
||||||
|
|
||||||
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
|
||||||
|
|
|
@ -817,3 +817,20 @@ default_name = ''):
|
||||||
|
|
||||||
def on_bm_header_changed_state(widget, event):
|
def on_bm_header_changed_state(widget, event):
|
||||||
widget.set_state(gtk.STATE_NORMAL) #do not allow selected_state
|
widget.set_state(gtk.STATE_NORMAL) #do not allow selected_state
|
||||||
|
|
||||||
|
def create_combobox(value_list, selected_value = None):
|
||||||
|
'''Value_list is [(label1, value1), ]'''
|
||||||
|
liststore = gtk.ListStore(str, str)
|
||||||
|
combobox = gtk.ComboBox(liststore)
|
||||||
|
cell = gtk.CellRendererText()
|
||||||
|
combobox.pack_start(cell, True)
|
||||||
|
combobox.add_attribute(cell, 'text', 0)
|
||||||
|
i = -1
|
||||||
|
for value in value_list:
|
||||||
|
liststore.append(value)
|
||||||
|
if selected_value == value[1]:
|
||||||
|
i = value_list.index(value)
|
||||||
|
if i > -1:
|
||||||
|
combobox.set_active(i)
|
||||||
|
combobox.show_all()
|
||||||
|
return combobox
|
||||||
|
|
Loading…
Add table
Reference in a new issue