coding standards
This commit is contained in:
parent
1c7c459c5f
commit
e52be0071b
|
@ -19,10 +19,10 @@
|
||||||
## You should have received a copy of the GNU General Public License
|
## You should have received a copy of the GNU General Public License
|
||||||
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
## along with Gajim. If not, see <http://www.gnu.org/licenses/>.
|
||||||
##
|
##
|
||||||
""" This module contains widget that can display data form (JEP-0004).
|
''' This module contains widget that can display data form (JEP-0004).
|
||||||
Words single and multiple refers here to types of data forms:
|
Words single and multiple refers here to types of data forms:
|
||||||
single means these with one record of data (without <reported/> element),
|
single means these with one record of data (without <reported/> element),
|
||||||
multiple - these which may contain more data (with <reported/> element)."""
|
multiple - these which may contain more data (with <reported/> element).'''
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import gobject
|
import gobject
|
||||||
|
@ -37,14 +37,15 @@ import itertools
|
||||||
|
|
||||||
class DataFormWidget(gtk.Alignment, object):
|
class DataFormWidget(gtk.Alignment, object):
|
||||||
# "public" interface
|
# "public" interface
|
||||||
""" Data Form widget. Use like any other widget. """
|
''' Data Form widget. Use like any other widget. '''
|
||||||
def __init__(self, dataformnode=None):
|
def __init__(self, dataformnode=None):
|
||||||
""" Create a widget. """
|
''' Create a widget. '''
|
||||||
gtk.Alignment.__init__(self, xscale=1.0, yscale=1.0)
|
gtk.Alignment.__init__(self, xscale=1.0, yscale=1.0)
|
||||||
|
|
||||||
self._data_form = None
|
self._data_form = None
|
||||||
|
|
||||||
self.xml=gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_vbox')
|
self.xml = gtkgui_helpers.get_glade('data_form_window.glade',
|
||||||
|
'data_form_vbox')
|
||||||
self.xml.signal_autoconnect(self)
|
self.xml.signal_autoconnect(self)
|
||||||
for name in ('instructions_label', 'instructions_hseparator',
|
for name in ('instructions_label', 'instructions_hseparator',
|
||||||
'single_form_viewport', 'data_form_types_notebook',
|
'single_form_viewport', 'data_form_types_notebook',
|
||||||
|
@ -63,7 +64,7 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
selection.set_mode(gtk.SELECTION_MULTIPLE)
|
selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||||
|
|
||||||
def set_data_form(self, dataform):
|
def set_data_form(self, dataform):
|
||||||
""" Set the data form (xmpp.DataForm) displayed in widget. """
|
''' Set the data form (xmpp.DataForm) displayed in widget. '''
|
||||||
assert isinstance(dataform, dataforms.DataForm)
|
assert isinstance(dataform, dataforms.DataForm)
|
||||||
|
|
||||||
self.del_data_form()
|
self.del_data_form()
|
||||||
|
@ -74,14 +75,14 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
self.build_multiple_data_form()
|
self.build_multiple_data_form()
|
||||||
|
|
||||||
# create appropriate description for instructions field if there isn't any
|
# create appropriate description for instructions field if there isn't any
|
||||||
if dataform.instructions=='':
|
if dataform.instructions == '':
|
||||||
self.instructions_label.set_no_show_all(True)
|
self.instructions_label.set_no_show_all(True)
|
||||||
self.instructions_label.hide()
|
self.instructions_label.hide()
|
||||||
else:
|
else:
|
||||||
self.instructions_label.set_text(dataform.instructions)
|
self.instructions_label.set_text(dataform.instructions)
|
||||||
|
|
||||||
def get_data_form(self):
|
def get_data_form(self):
|
||||||
""" Data form displayed in the widget or None if no form. """
|
''' Data form displayed in the widget or None if no form. '''
|
||||||
return self._data_form
|
return self._data_form
|
||||||
|
|
||||||
def del_data_form(self):
|
def del_data_form(self):
|
||||||
|
@ -89,20 +90,20 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
self._data_form = None
|
self._data_form = None
|
||||||
|
|
||||||
data_form = property(get_data_form, set_data_form, del_data_form,
|
data_form = property(get_data_form, set_data_form, del_data_form,
|
||||||
"Data form presented in a widget")
|
'Data form presented in a widget')
|
||||||
|
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
""" Get the title of data form, as a unicode object. If no
|
''' Get the title of data form, as a unicode object. If no
|
||||||
title or no form, returns u''. Useful for setting window title. """
|
title or no form, returns u''. Useful for setting window title. '''
|
||||||
if self._data_form is not None:
|
if self._data_form is not None:
|
||||||
if self._data_form.title is not None:
|
if self._data_form.title is not None:
|
||||||
return self._data_form.title
|
return self._data_form.title
|
||||||
return u''
|
return u''
|
||||||
|
|
||||||
title = property(get_title, None, None, "Data form title")
|
title = property(get_title, None, None, 'Data form title')
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
""" Treat 'us' as one widget. """
|
''' Treat 'us' as one widget. '''
|
||||||
self.show_all()
|
self.show_all()
|
||||||
|
|
||||||
# "private" methods
|
# "private" methods
|
||||||
|
@ -168,7 +169,8 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
field.value)
|
field.value)
|
||||||
|
|
||||||
# constructing columns...
|
# constructing columns...
|
||||||
for field, counter in zip(self._data_form.reported.iter_fields(), itertools.count()):
|
for field, counter in zip(self._data_form.reported.iter_fields(),
|
||||||
|
itertools.count()):
|
||||||
self.records_treeview.append_column(
|
self.records_treeview.append_column(
|
||||||
gtk.TreeViewColumn(field.label, gtk.CellRendererText(),
|
gtk.TreeViewColumn(field.label, gtk.CellRendererText(),
|
||||||
text=counter))
|
text=counter))
|
||||||
|
@ -237,19 +239,21 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
|
|
||||||
def on_remove_button_clicked(self, widget):
|
def on_remove_button_clicked(self, widget):
|
||||||
selection = self.records_treeview.get_selection()
|
selection = self.records_treeview.get_selection()
|
||||||
model, rowrefs = selection.get_selected_rows() # rowref is a list of paths
|
model, rowrefs = selection.get_selected_rows()
|
||||||
|
# rowref is a list of paths
|
||||||
for i in xrange(len(rowrefs)):
|
for i in xrange(len(rowrefs)):
|
||||||
rowrefs[i] = gtk.TreeRowReference(model, rowrefs[i])
|
rowrefs[i] = gtk.TreeRowReference(model, rowrefs[i])
|
||||||
# rowref is a list of row references; need to convert because we will modify the model,
|
# rowref is a list of row references; need to convert because we will
|
||||||
# paths would change
|
# modify the model, paths would change
|
||||||
for rowref in rowrefs:
|
for rowref in rowrefs:
|
||||||
del model[rowref.get_path()]
|
del model[rowref.get_path()]
|
||||||
|
|
||||||
def on_up_button_clicked(self, widget):
|
def on_up_button_clicked(self, widget):
|
||||||
selection = self.records_treeview.get_selection()
|
selection = self.records_treeview.get_selection()
|
||||||
model, (path,) = selection.get_selected_rows()
|
model, (path,) = selection.get_selected_rows()
|
||||||
iter = model.get_iter(path)
|
iter = model.get_iter(path)
|
||||||
previter = model.get_iter((path[0]-1,)) # constructing path for previous iter
|
# constructing path for previous iter
|
||||||
|
previter = model.get_iter((path[0]-1,))
|
||||||
model.swap(iter, previter)
|
model.swap(iter, previter)
|
||||||
|
|
||||||
self.refresh_multiple_buttons()
|
self.refresh_multiple_buttons()
|
||||||
|
@ -267,9 +271,9 @@ class DataFormWidget(gtk.Alignment, object):
|
||||||
self.refresh_multiple_buttons()
|
self.refresh_multiple_buttons()
|
||||||
|
|
||||||
class SingleForm(gtk.Table, object):
|
class SingleForm(gtk.Table, object):
|
||||||
""" Widget that represent DATAFORM_SINGLE mode form. Because this is used
|
''' Widget that represent DATAFORM_SINGLE mode form. Because this is used
|
||||||
not only to display single forms, but to form input windows of multiple-type
|
not only to display single forms, but to form input windows of multiple-type
|
||||||
forms, it is in another class."""
|
forms, it is in another class.'''
|
||||||
def __init__(self, dataform):
|
def __init__(self, dataform):
|
||||||
assert isinstance(dataform, dataforms.SimpleDataForm)
|
assert isinstance(dataform, dataforms.SimpleDataForm)
|
||||||
|
|
||||||
|
@ -280,11 +284,11 @@ class SingleForm(gtk.Table, object):
|
||||||
self.tooltips = gtk.Tooltips()
|
self.tooltips = gtk.Tooltips()
|
||||||
|
|
||||||
def decorate_with_tooltip(widget, field):
|
def decorate_with_tooltip(widget, field):
|
||||||
""" Adds a tooltip containing field's description to a widget.
|
''' Adds a tooltip containing field's description to a widget.
|
||||||
Creates EventBox if widget doesn't have its own gdk window.
|
Creates EventBox if widget doesn't have its own gdk window.
|
||||||
Returns decorated widget. """
|
Returns decorated widget. '''
|
||||||
if field.description!='':
|
if field.description != '':
|
||||||
if widget.flags()>k.NO_WINDOW:
|
if widget.flags() & gtk.NO_WINDOW:
|
||||||
evbox = gtk.EventBox()
|
evbox = gtk.EventBox()
|
||||||
evbox.add(widget)
|
evbox.add(widget)
|
||||||
widget = evbox
|
widget = evbox
|
||||||
|
@ -301,31 +305,32 @@ class SingleForm(gtk.Table, object):
|
||||||
|
|
||||||
# for each field...
|
# for each field...
|
||||||
for field in self._data_form.iter_fields():
|
for field in self._data_form.iter_fields():
|
||||||
if field.type=='hidden': continue
|
if field.type == 'hidden': continue
|
||||||
|
|
||||||
commonlabel = True
|
commonlabel = True
|
||||||
commonlabelcenter = False
|
commonlabelcenter = False
|
||||||
commonwidget = True
|
commonwidget = True
|
||||||
widget = None
|
widget = None
|
||||||
|
|
||||||
if field.type=='boolean':
|
if field.type == 'boolean':
|
||||||
commonlabelcenter = True
|
commonlabelcenter = True
|
||||||
widget = gtk.CheckButton()
|
widget = gtk.CheckButton()
|
||||||
widget.connect('toggled', self.on_boolean_checkbutton_toggled, field)
|
widget.connect('toggled', self.on_boolean_checkbutton_toggled,
|
||||||
|
field)
|
||||||
widget.set_active(field.value)
|
widget.set_active(field.value)
|
||||||
|
|
||||||
elif field.type=='fixed':
|
elif field.type == 'fixed':
|
||||||
leftattach = 1
|
leftattach = 1
|
||||||
rightattach = 2
|
rightattach = 2
|
||||||
if field.label is None:
|
if field.label is None:
|
||||||
commonlabel = False
|
commonlabel = False
|
||||||
leftattach = 0
|
leftattach = 0
|
||||||
|
|
||||||
commonwidget=False
|
commonwidget = False
|
||||||
widget = gtk.Label(field.value)
|
widget = gtk.Label(field.value)
|
||||||
widget.set_line_wrap(True)
|
widget.set_line_wrap(True)
|
||||||
self.attach(widget, leftattach, rightattach, linecounter, linecounter+1,
|
self.attach(widget, leftattach, rightattach, linecounter,
|
||||||
xoptions=gtk.FILL, yoptions=gtk.FILL)
|
linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL)
|
||||||
|
|
||||||
elif field.type == 'list-single':
|
elif field.type == 'list-single':
|
||||||
# TODO: What if we have radio buttons and non-required field?
|
# TODO: What if we have radio buttons and non-required field?
|
||||||
|
@ -354,7 +359,8 @@ class SingleForm(gtk.Table, object):
|
||||||
f.value = model[iter][1]
|
f.value = model[iter][1]
|
||||||
else:
|
else:
|
||||||
f.value = ''
|
f.value = ''
|
||||||
widget = gtkgui_helpers.create_combobox(field.options, field.value)
|
widget = gtkgui_helpers.create_combobox(field.options,
|
||||||
|
field.value)
|
||||||
widget.connect('changed', on_list_single_combobox_changed, field)
|
widget.connect('changed', on_list_single_combobox_changed, field)
|
||||||
widget.set_sensitive(readwrite)
|
widget.set_sensitive(readwrite)
|
||||||
|
|
||||||
|
@ -436,10 +442,10 @@ class SingleForm(gtk.Table, object):
|
||||||
|
|
||||||
textwidget = gtk.TextView()
|
textwidget = gtk.TextView()
|
||||||
textwidget.set_wrap_mode(gtk.WRAP_WORD)
|
textwidget.set_wrap_mode(gtk.WRAP_WORD)
|
||||||
textwidget.get_buffer().connect('changed', self.on_text_multi_textbuffer_changed,
|
textwidget.get_buffer().connect('changed',
|
||||||
field)
|
self.on_text_multi_textbuffer_changed, field)
|
||||||
textwidget.get_buffer().set_text(field.value)
|
textwidget.get_buffer().set_text(field.value)
|
||||||
|
|
||||||
widget = gtk.ScrolledWindow()
|
widget = gtk.ScrolledWindow()
|
||||||
widget.add(textwidget)
|
widget.add(textwidget)
|
||||||
|
|
||||||
|
@ -447,13 +453,15 @@ class SingleForm(gtk.Table, object):
|
||||||
widget=decorate_with_tooltip(widget, field)
|
widget=decorate_with_tooltip(widget, field)
|
||||||
self.attach(widget, 1, 2, linecounter, linecounter+1)
|
self.attach(widget, 1, 2, linecounter, linecounter+1)
|
||||||
|
|
||||||
else:# field.type == 'text-single' or field.type is nonstandard:
|
else:
|
||||||
|
# field.type == 'text-single' or field.type is nonstandard:
|
||||||
# JEP says that if we don't understand some type, we
|
# JEP says that if we don't understand some type, we
|
||||||
# should handle it as text-single
|
# should handle it as text-single
|
||||||
commonlabelcenter = True
|
commonlabelcenter = True
|
||||||
if readwrite:
|
if readwrite:
|
||||||
widget = gtk.Entry()
|
widget = gtk.Entry()
|
||||||
widget.connect('changed', self.on_text_single_entry_changed, field)
|
widget.connect('changed', self.on_text_single_entry_changed,
|
||||||
|
field)
|
||||||
widget.set_sensitive(readwrite)
|
widget.set_sensitive(readwrite)
|
||||||
if field.value is None:
|
if field.value is None:
|
||||||
field.value = u''
|
field.value = u''
|
||||||
|
|
Loading…
Reference in New Issue