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
|
||||
## 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:
|
||||
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 gobject
|
||||
|
@ -37,14 +37,15 @@ import itertools
|
|||
|
||||
class DataFormWidget(gtk.Alignment, object):
|
||||
# "public" interface
|
||||
""" Data Form widget. Use like any other widget. """
|
||||
''' Data Form widget. Use like any other widget. '''
|
||||
def __init__(self, dataformnode=None):
|
||||
""" Create a widget. """
|
||||
''' Create a widget. '''
|
||||
gtk.Alignment.__init__(self, xscale=1.0, yscale=1.0)
|
||||
|
||||
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)
|
||||
for name in ('instructions_label', 'instructions_hseparator',
|
||||
'single_form_viewport', 'data_form_types_notebook',
|
||||
|
@ -63,7 +64,7 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
selection.set_mode(gtk.SELECTION_MULTIPLE)
|
||||
|
||||
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)
|
||||
|
||||
self.del_data_form()
|
||||
|
@ -74,14 +75,14 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
self.build_multiple_data_form()
|
||||
|
||||
# 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.hide()
|
||||
else:
|
||||
self.instructions_label.set_text(dataform.instructions)
|
||||
|
||||
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
|
||||
|
||||
def del_data_form(self):
|
||||
|
@ -89,20 +90,20 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
self._data_form = None
|
||||
|
||||
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):
|
||||
""" Get the title of data form, as a unicode object. If no
|
||||
title or no form, returns u''. Useful for setting window title. """
|
||||
''' Get the title of data form, as a unicode object. If no
|
||||
title or no form, returns u''. Useful for setting window title. '''
|
||||
if self._data_form is not None:
|
||||
if self._data_form.title is not None:
|
||||
return self._data_form.title
|
||||
return u''
|
||||
|
||||
title = property(get_title, None, None, "Data form title")
|
||||
title = property(get_title, None, None, 'Data form title')
|
||||
|
||||
def show(self):
|
||||
""" Treat 'us' as one widget. """
|
||||
''' Treat 'us' as one widget. '''
|
||||
self.show_all()
|
||||
|
||||
# "private" methods
|
||||
|
@ -168,7 +169,8 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
field.value)
|
||||
|
||||
# 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(
|
||||
gtk.TreeViewColumn(field.label, gtk.CellRendererText(),
|
||||
text=counter))
|
||||
|
@ -237,11 +239,12 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
|
||||
def on_remove_button_clicked(self, widget):
|
||||
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)):
|
||||
rowrefs[i] = gtk.TreeRowReference(model, rowrefs[i])
|
||||
# rowref is a list of row references; need to convert because we will modify the model,
|
||||
# paths would change
|
||||
# rowref is a list of row references; need to convert because we will
|
||||
# modify the model, paths would change
|
||||
for rowref in rowrefs:
|
||||
del model[rowref.get_path()]
|
||||
|
||||
|
@ -249,7 +252,8 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
selection = self.records_treeview.get_selection()
|
||||
model, (path,) = selection.get_selected_rows()
|
||||
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)
|
||||
|
||||
self.refresh_multiple_buttons()
|
||||
|
@ -267,9 +271,9 @@ class DataFormWidget(gtk.Alignment, object):
|
|||
self.refresh_multiple_buttons()
|
||||
|
||||
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
|
||||
forms, it is in another class."""
|
||||
forms, it is in another class.'''
|
||||
def __init__(self, dataform):
|
||||
assert isinstance(dataform, dataforms.SimpleDataForm)
|
||||
|
||||
|
@ -280,11 +284,11 @@ class SingleForm(gtk.Table, object):
|
|||
self.tooltips = gtk.Tooltips()
|
||||
|
||||
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.
|
||||
Returns decorated widget. """
|
||||
if field.description!='':
|
||||
if widget.flags()>k.NO_WINDOW:
|
||||
Returns decorated widget. '''
|
||||
if field.description != '':
|
||||
if widget.flags() & gtk.NO_WINDOW:
|
||||
evbox = gtk.EventBox()
|
||||
evbox.add(widget)
|
||||
widget = evbox
|
||||
|
@ -301,31 +305,32 @@ class SingleForm(gtk.Table, object):
|
|||
|
||||
# for each field...
|
||||
for field in self._data_form.iter_fields():
|
||||
if field.type=='hidden': continue
|
||||
if field.type == 'hidden': continue
|
||||
|
||||
commonlabel = True
|
||||
commonlabelcenter = False
|
||||
commonwidget = True
|
||||
widget = None
|
||||
|
||||
if field.type=='boolean':
|
||||
if field.type == 'boolean':
|
||||
commonlabelcenter = True
|
||||
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)
|
||||
|
||||
elif field.type=='fixed':
|
||||
elif field.type == 'fixed':
|
||||
leftattach = 1
|
||||
rightattach = 2
|
||||
if field.label is None:
|
||||
commonlabel = False
|
||||
leftattach = 0
|
||||
|
||||
commonwidget=False
|
||||
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)
|
||||
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?
|
||||
|
@ -354,7 +359,8 @@ class SingleForm(gtk.Table, object):
|
|||
f.value = model[iter][1]
|
||||
else:
|
||||
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.set_sensitive(readwrite)
|
||||
|
||||
|
@ -436,8 +442,8 @@ class SingleForm(gtk.Table, object):
|
|||
|
||||
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().connect('changed',
|
||||
self.on_text_multi_textbuffer_changed, field)
|
||||
textwidget.get_buffer().set_text(field.value)
|
||||
|
||||
widget = gtk.ScrolledWindow()
|
||||
|
@ -447,13 +453,15 @@ class SingleForm(gtk.Table, object):
|
|||
widget=decorate_with_tooltip(widget, field)
|
||||
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
|
||||
# should handle it as text-single
|
||||
commonlabelcenter = True
|
||||
if readwrite:
|
||||
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)
|
||||
if field.value is None:
|
||||
field.value = u''
|
||||
|
|
Loading…
Reference in New Issue