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)
|
||||
|
||||
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: We cannot deactivate them all...
|
||||
if len(field.options) < 6:
|
||||
# 5 option max: show radiobutton
|
||||
widget = gtk.VBox()
|
||||
first_radio = None
|
||||
for value, label in field.iter_options():
|
||||
radio = gtk.RadioButton(first_radio, label=label)
|
||||
radio.connect('toggled', self.on_list_single_radiobutton_toggled,
|
||||
field, value)
|
||||
radio.connect('toggled',
|
||||
self.on_list_single_radiobutton_toggled, field, value)
|
||||
if first_radio is None:
|
||||
first_radio = radio
|
||||
if field.value == '': # TODO: is None when done
|
||||
field.value = value
|
||||
if value == field.value:
|
||||
radio.set_active(True)
|
||||
widget.set_sensitive(readwrite)
|
||||
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':
|
||||
# TODO: When more than few choices, make a list
|
||||
|
|
|
@ -817,3 +817,20 @@ default_name = ''):
|
|||
|
||||
def on_bm_header_changed_state(widget, event):
|
||||
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