def __init__(self, dataform, selectable=False): assert isinstance(dataform, dataforms.SimpleDataForm) gtk.Table.__init__(self) self.set_col_spacings(12) self.set_row_spacings(6) def decorate_with_tooltip(widget, field): """ Adds a tooltip containing field's description to a widget. Creates EventBox if widget doesn't have its own gdk window. Returns decorated widget """ if field.description != '': if widget.flags() & gtk.NO_WINDOW: evbox = gtk.EventBox() evbox.add(widget) widget = evbox widget.set_tooltip_text(field.description) return widget self._data_form = dataform # building widget linecounter = 0 # is the form changeable? readwrite = dataform.type_ != 'result' # for each field... for field in self._data_form.iter_fields(): if field.type_ == 'hidden': continue commonlabel = True commonlabelcenter = False commonwidget = True widget = None if field.type_ == 'boolean': commonlabelcenter = True widget = gtk.CheckButton() widget.connect('toggled', self.on_boolean_checkbutton_toggled, field) widget.set_active(field.value) elif field.type_ == 'fixed': leftattach = 1 rightattach = 2 if field.label is None: commonlabel = False leftattach = 0 commonwidget = False widget = gtk.Label(field.value) widget.set_property('selectable', selectable) widget.set_line_wrap(True) self.attach(widget, leftattach, rightattach, linecounter, linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) elif field.type_ == 'list-single': # 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(): if not label: label = value radio = gtk.RadioButton(first_radio, label=label) 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.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 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) widget.set_sensitive(readwrite) 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) tv.set_sensitive(readwrite) elif field.type_ == 'jid-single': widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_text(field.value) elif field.type_ == 'jid-multi': commonwidget = False xml = gtkgui_helpers.get_gtk_builder('data_form_window.ui', 'multiple_form_hbox') widget = xml.get_object('multiple_form_hbox') treeview = xml.get_object('records_treeview') listmodel = gtk.ListStore(str) for value in field.iter_values(): # nobody will create several megabytes long stanza listmodel.insert(999999, (value,)) treeview.set_model(listmodel) renderer = gtk.CellRendererText() renderer.set_property('editable', True) renderer.connect('edited', self.on_jid_multi_cellrenderertext_edited, treeview, listmodel, field) treeview.append_column(gtk.TreeViewColumn(None, renderer, text=0)) decorate_with_tooltip(treeview, field) add_button=xml.get_object('add_button') add_button.connect('clicked', self.on_jid_multi_add_button_clicked, treeview, listmodel, field) edit_button=xml.get_object('edit_button') edit_button.connect('clicked', self.on_jid_multi_edit_button_clicked, treeview) remove_button=xml.get_object('remove_button') remove_button.connect('clicked', self.on_jid_multi_remove_button_clicked, treeview, field) clear_button=xml.get_object('clear_button') clear_button.connect('clicked', self.on_jid_multi_clean_button_clicked, listmodel, field) if not readwrite: add_button.set_no_show_all(True) edit_button.set_no_show_all(True) remove_button.set_no_show_all(True) clear_button.set_no_show_all(True) widget.set_sensitive(readwrite) self.attach(widget, 1, 2, linecounter, linecounter+1) del xml elif field.type_ == 'text-private': commonlabelcenter = True widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_visibility(False) widget.set_text(field.value) elif field.type_ == 'text-multi': # TODO: bigger text view commonwidget = False textwidget = gtk.TextView() textwidget.set_wrap_mode(gtk.WRAP_WORD) textwidget.get_buffer().connect('changed', self.on_text_multi_textbuffer_changed, field) textwidget.get_buffer().set_text(field.value) if readwrite: textwidget.set_sensitive(True) else: if selectable: textwidget.set_editable(True) else: textwidget.set_sensitive(False) widget = gtk.ScrolledWindow() widget.add(textwidget) widget=decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1) else: # field.type_ == 'text-single' or field.type_ is nonstandard: # JEP says that if we don't understand some type, we # should handle it as text-single commonlabelcenter = True if readwrite: widget = gtk.Entry() def kpe(widget, event): if event.keyval == gtk.keysyms.Return or \ event.keyval == gtk.keysyms.KP_Enter: self.emit('validated') widget.connect('key-press-event', kpe) widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_sensitive(readwrite) if field.value is None: field.value = u'' widget.set_text(field.value) else: commonwidget=False widget = gtk.Label(field.value) widget.set_property('selectable', selectable) widget.set_sensitive(True) widget.set_alignment(0.0, 0.5) widget=decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1, yoptions=gtk.FILL) if commonlabel and field.label is not None: label = gtk.Label(field.label) if commonlabelcenter: label.set_alignment(0.0, 0.5) else: label.set_alignment(0.0, 0.0) label = decorate_with_tooltip(label, field) self.attach(label, 0, 1, linecounter, linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) if field.media is not None: for uri in field.media.uris: if uri.type_.startswith('image/'): try: img_data = base64.decodestring(uri.uri_data) pixbuf_l = gtk.gdk.PixbufLoader() pixbuf_l.write(img_data) pixbuf_l.close() media = gtk.image_new_from_pixbuf(pixbuf_l.\ get_pixbuf()) except Exception: media = gtk.Label(_('Unable to load image')) else: media = gtk.Label(_('Media type not supported: %s') % \ uri.type_) linecounter += 1 self.attach(media, 0, 1, linecounter, linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) if commonwidget: assert widget is not None widget.set_sensitive(readwrite) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1, yoptions=gtk.FILL) if field.required: label = gtk.Label('*') label.set_tooltip_text(_('This field is required')) self.attach(label, 2, 3, linecounter, linecounter+1, xoptions=0, yoptions=0) linecounter+=1 if self.get_property('visible'): self.show_all()
def __init__(self, dataform): assert isinstance(dataform, dataforms.SimpleDataForm) gtk.Table.__init__(self) self.set_col_spacings(12) self.set_row_spacings(6) self.tooltips = gtk.Tooltips() def decorate_with_tooltip(widget, field): ''' Adds a tooltip containing field's description to a widget. Creates EventBox if widget doesn't have its own gdk window. Returns decorated widget. ''' if field.description != '': if widget.flags() & gtk.NO_WINDOW: evbox = gtk.EventBox() evbox.add(widget) widget = evbox self.tooltips.set_tip(widget, field.description) return widget self._data_form = dataform # building widget linecounter = 0 # is the form changeable? readwrite = dataform.type != 'result' # for each field... for field in self._data_form.iter_fields(): if field.type == 'hidden': continue commonlabel = True commonlabelcenter = False commonwidget = True widget = None if field.type == 'boolean': commonlabelcenter = True widget = gtk.CheckButton() widget.connect('toggled', self.on_boolean_checkbutton_toggled, field) widget.set_active(field.value) elif field.type == 'fixed': leftattach = 1 rightattach = 2 if field.label is None: commonlabel = False leftattach = 0 commonwidget = False widget = gtk.Label(field.value) widget.set_line_wrap(True) self.attach(widget, leftattach, rightattach, linecounter, linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) elif field.type == 'list-single': # 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(): if not label: label = value radio = gtk.RadioButton(first_radio, label=label) 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.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 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) widget.pack_start(check, expand=False) elif field.type == 'jid-single': widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_text(field.value) elif field.type == 'jid-multi': commonwidget = False xml = gtkgui_helpers.get_glade('data_form_window.glade', 'item_list_table') widget = xml.get_widget('item_list_table') treeview = xml.get_widget('item_treeview') listmodel = gtk.ListStore(str) for value in field.iter_values(): # nobody will create several megabytes long stanza listmodel.insert(999999, (value,)) treeview.set_model(listmodel) renderer = gtk.CellRendererText() renderer.set_property('editable', True) renderer.connect('edited', self.on_jid_multi_cellrenderertext_edited, treeview, listmodel, field) treeview.append_column(gtk.TreeViewColumn(None, renderer, text=0)) decorate_with_tooltip(treeview, field) add_button=xml.get_widget('add_button') add_button.connect('clicked', self.on_jid_multi_add_button_clicked, treeview, listmodel, field) edit_button=xml.get_widget('edit_button') edit_button.connect('clicked', self.on_jid_multi_edit_button_clicked, treeview) remove_button=xml.get_widget('remove_button') remove_button.connect('clicked', self.on_jid_multi_remove_button_clicked, treeview, field) clear_button=xml.get_widget('clear_button') clear_button.connect('clicked', self.on_jid_multi_clean_button_clicked, listmodel, field) if not readwrite: add_button.set_no_show_all(True) edit_button.set_no_show_all(True) remove_button.set_no_show_all(True) clear_button.set_no_show_all(True) widget.set_sensitive(readwrite) self.attach(widget, 1, 2, linecounter, linecounter+1) del xml elif field.type == 'text-private': commonlabelcenter = True widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_visibility(False) widget.set_text(field.value) elif field.type == 'text-multi': # TODO: bigger text view commonwidget = False textwidget = gtk.TextView() textwidget.set_wrap_mode(gtk.WRAP_WORD) textwidget.get_buffer().connect('changed', self.on_text_multi_textbuffer_changed, field) textwidget.get_buffer().set_text(field.value) widget = gtk.ScrolledWindow() widget.add(textwidget) widget.set_sensitive(readwrite) widget=decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1) else: # field.type == 'text-single' or field.type is nonstandard: # JEP says that if we don't understand some type, we # should handle it as text-single commonlabelcenter = True if readwrite: widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_sensitive(readwrite) if field.value is None: field.value = u'' widget.set_text(field.value) else: commonwidget=False widget = gtk.Label(field.value) widget.set_sensitive(True) widget.set_alignment(0.0, 0.5) widget=decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1, yoptions=gtk.FILL) if commonlabel and field.label is not None: label = gtk.Label(field.label) if commonlabelcenter: label.set_alignment(0.0, 0.5) else: label.set_alignment(0.0, 0.0) label = decorate_with_tooltip(label, field) self.attach(label, 0, 1, linecounter, linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) if commonwidget: assert widget is not None widget.set_sensitive(readwrite) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter+1, yoptions=gtk.FILL) widget.show_all() linecounter+=1 if self.get_property('visible'): self.show_all()
def __init__(self, dataform, selectable=False): assert isinstance(dataform, dataforms.SimpleDataForm) GObject.GObject.__init__(self) self.set_col_spacings(12) self.set_row_spacings(6) def decorate_with_tooltip(widget, field): """ Adds a tooltip containing field's description to a widget. Creates EventBox if widget doesn't have its own gdk window. Returns decorated widget """ if field.description != '': if not widget.get_window(): #if widget.flags() & Gtk.NO_WINDOW: evbox = Gtk.EventBox() evbox.add(widget) widget = evbox widget.set_tooltip_text(field.description) return widget self._data_form = dataform # building widget linecounter = 0 # is the form changeable? readwrite = dataform.type_ != 'result' # for each field... for field in self._data_form.iter_fields(): if field.type_ == 'hidden': continue commonlabel = True commonlabelcenter = False commonwidget = True widget = None if field.type_ == 'boolean': commonlabelcenter = True widget = Gtk.CheckButton() widget.connect('toggled', self.on_boolean_checkbutton_toggled, field) widget.set_active(field.value) elif field.type_ == 'fixed': leftattach = 1 rightattach = 2 if field.label is None: commonlabel = False leftattach = 0 commonwidget = False widget = Gtk.Label(label=field.value) widget.set_property('selectable', selectable) widget.set_line_wrap(True) self.attach(widget, leftattach, rightattach, linecounter, linecounter + 1, xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL) elif field.type_ == 'list-single': # 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(): if not label: label = value radio = Gtk.RadioButton.new_with_label_from_widget( first_radio, label) 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.pack_start(radio, False, True, 0) 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 if len(field.options) < 6: # 5 option max: show checkbutton widget = Gtk.VBox() for value, label in field.iter_options(): check = Gtk.CheckButton(label=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, False, True, 0) widget.set_sensitive(readwrite) 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.PolicyType.AUTOMATIC, Gtk.PolicyType.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) tv.set_sensitive(readwrite) elif field.type_ == 'jid-single': widget = Gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_text(field.value) elif field.type_ == 'jid-multi': commonwidget = False xml = gtkgui_helpers.get_gtk_builder('data_form_window.ui', 'multiple_form_hbox') widget = xml.get_object('multiple_form_hbox') treeview = xml.get_object('records_treeview') listmodel = Gtk.ListStore(str) for value in field.iter_values(): # nobody will create several megabytes long stanza listmodel.insert(999999, (value, )) treeview.set_model(listmodel) renderer = Gtk.CellRendererText() renderer.set_property('editable', True) renderer.connect('edited', self.on_jid_multi_cellrenderertext_edited, treeview, listmodel, field) treeview.append_column( Gtk.TreeViewColumn(None, renderer, text=0)) decorate_with_tooltip(treeview, field) add_button = xml.get_object('add_button') add_button.connect('clicked', self.on_jid_multi_add_button_clicked, treeview, listmodel, field) edit_button = xml.get_object('edit_button') edit_button.connect('clicked', self.on_jid_multi_edit_button_clicked, treeview) remove_button = xml.get_object('remove_button') remove_button.connect('clicked', self.on_jid_multi_remove_button_clicked, treeview, field) clear_button = xml.get_object('clear_button') clear_button.connect('clicked', self.on_jid_multi_clean_button_clicked, listmodel, field) if not readwrite: add_button.set_no_show_all(True) edit_button.set_no_show_all(True) remove_button.set_no_show_all(True) clear_button.set_no_show_all(True) widget.set_sensitive(readwrite) self.attach(widget, 1, 2, linecounter, linecounter + 1) del xml elif field.type_ == 'text-private': commonlabelcenter = True widget = Gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_visibility(False) widget.set_text(field.value) elif field.type_ == 'text-multi': # TODO: bigger text view commonwidget = False textwidget = Gtk.TextView() textwidget.set_wrap_mode(Gtk.WrapMode.WORD) textwidget.get_buffer().connect( 'changed', self.on_text_multi_textbuffer_changed, field) textwidget.get_buffer().set_text(field.value) if readwrite: textwidget.set_sensitive(True) else: if selectable: textwidget.set_editable(True) else: textwidget.set_sensitive(False) widget = Gtk.ScrolledWindow() widget.add(textwidget) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1) else: # field.type_ == 'text-single' or field.type_ is nonstandard: # JEP says that if we don't understand some type, we # should handle it as text-single commonlabelcenter = True if readwrite: widget = Gtk.Entry() def kpe(widget, event): if event.keyval == Gdk.KEY_Return or \ event.keyval == Gdk.KEY_KP_Enter: self.emit('validated') widget.connect('key-press-event', kpe) widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_sensitive(readwrite) if field.value is None: field.value = '' widget.set_text(field.value) else: commonwidget = False widget = Gtk.Label(label=field.value) widget.set_property('selectable', selectable) widget.set_sensitive(True) widget.set_halign(Gtk.Align.START) widget.set_valign(Gtk.Align.CENTER) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1, yoptions=Gtk.AttachOptions.FILL) if commonlabel and field.label is not None: label = Gtk.Label(label=field.label) if commonlabelcenter: label.set_halign(Gtk.Align.START) label.set_valign(Gtk.Align.CENTER) else: label.set_halign(Gtk.Align.START) label.set_valign(Gtk.Align.START) label = decorate_with_tooltip(label, field) self.attach(label, 0, 1, linecounter, linecounter + 1, xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL) if field.media is not None: for uri in field.media.uris: if uri.type_.startswith('image/'): try: img_data = base64.b64decode(uri.uri_data) pixbuf_l = GdkPixbuf.PixbufLoader() pixbuf_l.write(img_data) pixbuf_l.close() media = Gtk.Image.new_from_pixbuf(pixbuf_l.\ get_pixbuf()) except Exception: media = Gtk.Label(label=_('Unable to load image')) else: media = Gtk.Label(label=_('Media type not supported: %s') % \ uri.type_) linecounter += 1 self.attach(media, 0, 1, linecounter, linecounter + 1, xoptions=Gtk.AttachOptions.FILL, yoptions=Gtk.AttachOptions.FILL) if commonwidget: assert widget is not None widget.set_sensitive(readwrite) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1, yoptions=Gtk.AttachOptions.FILL) if field.required: label = Gtk.Label(label='*') label.set_tooltip_text(_('This field is required')) self.attach(label, 2, 3, linecounter, linecounter + 1, xoptions=0, yoptions=0) linecounter += 1 if self.get_property('visible'): self.show_all()
def __init__(self, dataform): assert isinstance(dataform, dataforms.SimpleDataForm) gtk.Table.__init__(self) self.set_col_spacings(12) self.set_row_spacings(6) self.tooltips = gtk.Tooltips() def decorate_with_tooltip(widget, field): ''' Adds a tooltip containing field's description to a widget. Creates EventBox if widget doesn't have its own gdk window. Returns decorated widget. ''' if field.description != '': if widget.flags() & gtk.NO_WINDOW: evbox = gtk.EventBox() evbox.add(widget) widget = evbox self.tooltips.set_tip(widget, field.description) return widget self._data_form = dataform # building widget linecounter = 0 # is the form changeable? readwrite = dataform.type != 'result' # for each field... for field in self._data_form.iter_fields(): if field.type == 'hidden': continue commonlabel = True commonlabelcenter = False commonwidget = True widget = None if field.type == 'boolean': commonlabelcenter = True widget = gtk.CheckButton() widget.connect('toggled', self.on_boolean_checkbutton_toggled, field) widget.set_active(field.value) elif field.type == 'fixed': leftattach = 1 rightattach = 2 if field.label is None: commonlabel = False leftattach = 0 commonwidget = False widget = gtk.Label(field.value) widget.set_line_wrap(True) self.attach(widget, leftattach, rightattach, linecounter, linecounter + 1, xoptions=gtk.FILL, yoptions=gtk.FILL) elif field.type == 'list-single': # 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(): if not label: label = value radio = gtk.RadioButton(first_radio, label=label) 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.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 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) widget.pack_start(check, expand=False) elif field.type == 'jid-single': widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_text(field.value) elif field.type == 'jid-multi': commonwidget = False xml = gtkgui_helpers.get_glade('data_form_window.glade', 'item_list_table') widget = xml.get_widget('item_list_table') treeview = xml.get_widget('item_treeview') listmodel = gtk.ListStore(str) for value in field.iter_values(): # nobody will create several megabytes long stanza listmodel.insert(999999, (value, )) treeview.set_model(listmodel) renderer = gtk.CellRendererText() renderer.set_property('editable', True) renderer.connect('edited', self.on_jid_multi_cellrenderertext_edited, treeview, listmodel, field) treeview.append_column( gtk.TreeViewColumn(None, renderer, text=0)) decorate_with_tooltip(treeview, field) add_button = xml.get_widget('add_button') add_button.connect('clicked', self.on_jid_multi_add_button_clicked, treeview, listmodel, field) edit_button = xml.get_widget('edit_button') edit_button.connect('clicked', self.on_jid_multi_edit_button_clicked, treeview) remove_button = xml.get_widget('remove_button') remove_button.connect('clicked', self.on_jid_multi_remove_button_clicked, treeview, field) clear_button = xml.get_widget('clear_button') clear_button.connect('clicked', self.on_jid_multi_clean_button_clicked, listmodel, field) if not readwrite: add_button.set_no_show_all(True) edit_button.set_no_show_all(True) remove_button.set_no_show_all(True) clear_button.set_no_show_all(True) widget.set_sensitive(readwrite) self.attach(widget, 1, 2, linecounter, linecounter + 1) del xml elif field.type == 'text-private': commonlabelcenter = True widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_visibility(False) widget.set_text(field.value) elif field.type == 'text-multi': # TODO: bigger text view commonwidget = False textwidget = gtk.TextView() textwidget.set_wrap_mode(gtk.WRAP_WORD) textwidget.get_buffer().connect( 'changed', self.on_text_multi_textbuffer_changed, field) textwidget.get_buffer().set_text(field.value) widget = gtk.ScrolledWindow() widget.add(textwidget) widget.set_sensitive(readwrite) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1) else: # field.type == 'text-single' or field.type is nonstandard: # JEP says that if we don't understand some type, we # should handle it as text-single commonlabelcenter = True if readwrite: widget = gtk.Entry() widget.connect('changed', self.on_text_single_entry_changed, field) widget.set_sensitive(readwrite) if field.value is None: field.value = u'' widget.set_text(field.value) else: commonwidget = False widget = gtk.Label(field.value) widget.set_sensitive(True) widget.set_alignment(0.0, 0.5) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1, yoptions=gtk.FILL) if commonlabel and field.label is not None: label = gtk.Label(field.label) if commonlabelcenter: label.set_alignment(0.0, 0.5) else: label.set_alignment(0.0, 0.0) label = decorate_with_tooltip(label, field) self.attach(label, 0, 1, linecounter, linecounter + 1, xoptions=gtk.FILL, yoptions=gtk.FILL) if commonwidget: assert widget is not None widget.set_sensitive(readwrite) widget = decorate_with_tooltip(widget, field) self.attach(widget, 1, 2, linecounter, linecounter + 1, yoptions=gtk.FILL) widget.show_all() linecounter += 1 if self.get_property('visible'): self.show_all()