Changeset 9031
- Timestamp:
- 11/21/07 14:02:06 (13 months ago)
- Files:
-
- 1 modified
-
trunk/src/dataforms_widget.py (modified) (18 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/dataforms_widget.py
r8959 r9031 20 20 ## along with Gajim. If not, see <http://www.gnu.org/licenses/>. 21 21 ## 22 """This module contains widget that can display data form (JEP-0004).22 ''' This module contains widget that can display data form (JEP-0004). 23 23 Words single and multiple refers here to types of data forms: 24 24 single means these with one record of data (without <reported/> element), 25 multiple - these which may contain more data (with <reported/> element). """25 multiple - these which may contain more data (with <reported/> element).''' 26 26 27 27 import gtk … … 38 38 class DataFormWidget(gtk.Alignment, object): 39 39 # "public" interface 40 """ Data Form widget. Use like any other widget. """40 ''' Data Form widget. Use like any other widget. ''' 41 41 def __init__(self, dataformnode=None): 42 """ Create a widget. """42 ''' Create a widget. ''' 43 43 gtk.Alignment.__init__(self, xscale=1.0, yscale=1.0) 44 44 45 45 self._data_form = None 46 46 47 self.xml=gtkgui_helpers.get_glade('data_form_window.glade', 'data_form_vbox') 47 self.xml = gtkgui_helpers.get_glade('data_form_window.glade', 48 'data_form_vbox') 48 49 self.xml.signal_autoconnect(self) 49 50 for name in ('instructions_label', 'instructions_hseparator', … … 64 65 65 66 def set_data_form(self, dataform): 66 """ Set the data form (xmpp.DataForm) displayed in widget. """67 ''' Set the data form (xmpp.DataForm) displayed in widget. ''' 67 68 assert isinstance(dataform, dataforms.DataForm) 68 69 … … 75 76 76 77 # create appropriate description for instructions field if there isn't any 77 if dataform.instructions =='':78 if dataform.instructions == '': 78 79 self.instructions_label.set_no_show_all(True) 79 80 self.instructions_label.hide() … … 82 83 83 84 def get_data_form(self): 84 """ Data form displayed in the widget or None if no form. """85 ''' Data form displayed in the widget or None if no form. ''' 85 86 return self._data_form 86 87 … … 90 91 91 92 data_form = property(get_data_form, set_data_form, del_data_form, 92 "Data form presented in a widget")93 'Data form presented in a widget') 93 94 94 95 def get_title(self): 95 """Get the title of data form, as a unicode object. If no96 title or no form, returns u''. Useful for setting window title. """96 ''' Get the title of data form, as a unicode object. If no 97 title or no form, returns u''. Useful for setting window title. ''' 97 98 if self._data_form is not None: 98 99 if self._data_form.title is not None: … … 100 101 return u'' 101 102 102 title = property(get_title, None, None, "Data form title")103 title = property(get_title, None, None, 'Data form title') 103 104 104 105 def show(self): 105 """ Treat 'us' as one widget. """106 ''' Treat 'us' as one widget. ''' 106 107 self.show_all() 107 108 … … 169 170 170 171 # constructing columns... 171 for field, counter in zip(self._data_form.reported.iter_fields(), itertools.count()): 172 for field, counter in zip(self._data_form.reported.iter_fields(), 173 itertools.count()): 172 174 self.records_treeview.append_column( 173 175 gtk.TreeViewColumn(field.label, gtk.CellRendererText(), … … 238 240 def on_remove_button_clicked(self, widget): 239 241 selection = self.records_treeview.get_selection() 240 model, rowrefs = selection.get_selected_rows() # rowref is a list of paths 242 model, rowrefs = selection.get_selected_rows() 243 # rowref is a list of paths 241 244 for i in xrange(len(rowrefs)): 242 245 rowrefs[i] = gtk.TreeRowReference(model, rowrefs[i]) 243 # rowref is a list of row references; need to convert because we will modify the model,244 # paths would change246 # rowref is a list of row references; need to convert because we will 247 # modify the model, paths would change 245 248 for rowref in rowrefs: 246 249 del model[rowref.get_path()] 247 250 248 251 def on_up_button_clicked(self, widget): 249 252 selection = self.records_treeview.get_selection() 250 253 model, (path,) = selection.get_selected_rows() 251 254 iter = model.get_iter(path) 252 previter = model.get_iter((path[0]-1,)) # constructing path for previous iter 255 # constructing path for previous iter 256 previter = model.get_iter((path[0]-1,)) 253 257 model.swap(iter, previter) 254 258 … … 268 272 269 273 class SingleForm(gtk.Table, object): 270 """Widget that represent DATAFORM_SINGLE mode form. Because this is used274 ''' Widget that represent DATAFORM_SINGLE mode form. Because this is used 271 275 not only to display single forms, but to form input windows of multiple-type 272 forms, it is in another class. """276 forms, it is in another class.''' 273 277 def __init__(self, dataform): 274 278 assert isinstance(dataform, dataforms.SimpleDataForm) … … 281 285 282 286 def decorate_with_tooltip(widget, field): 283 """Adds a tooltip containing field's description to a widget.287 ''' Adds a tooltip containing field's description to a widget. 284 288 Creates EventBox if widget doesn't have its own gdk window. 285 Returns decorated widget. """286 if field.description !='':287 if widget.flags() >k.NO_WINDOW:289 Returns decorated widget. ''' 290 if field.description != '': 291 if widget.flags() & gtk.NO_WINDOW: 288 292 evbox = gtk.EventBox() 289 293 evbox.add(widget) … … 302 306 # for each field... 303 307 for field in self._data_form.iter_fields(): 304 if field.type =='hidden': continue308 if field.type == 'hidden': continue 305 309 306 310 commonlabel = True … … 309 313 widget = None 310 314 311 if field.type =='boolean':315 if field.type == 'boolean': 312 316 commonlabelcenter = True 313 317 widget = gtk.CheckButton() 314 widget.connect('toggled', self.on_boolean_checkbutton_toggled, field) 318 widget.connect('toggled', self.on_boolean_checkbutton_toggled, 319 field) 315 320 widget.set_active(field.value) 316 321 317 elif field.type =='fixed':322 elif field.type == 'fixed': 318 323 leftattach = 1 319 324 rightattach = 2 … … 322 327 leftattach = 0 323 328 324 commonwidget =False329 commonwidget = False 325 330 widget = gtk.Label(field.value) 326 331 widget.set_line_wrap(True) 327 self.attach(widget, leftattach, rightattach, linecounter, linecounter+1,328 xoptions=gtk.FILL, yoptions=gtk.FILL)332 self.attach(widget, leftattach, rightattach, linecounter, 333 linecounter+1, xoptions=gtk.FILL, yoptions=gtk.FILL) 329 334 330 335 elif field.type == 'list-single': … … 355 360 else: 356 361 f.value = '' 357 widget = gtkgui_helpers.create_combobox(field.options, field.value) 362 widget = gtkgui_helpers.create_combobox(field.options, 363 field.value) 358 364 widget.connect('changed', on_list_single_combobox_changed, field) 359 365 widget.set_sensitive(readwrite) … … 437 443 textwidget = gtk.TextView() 438 444 textwidget.set_wrap_mode(gtk.WRAP_WORD) 439 textwidget.get_buffer().connect('changed', self.on_text_multi_textbuffer_changed,440 field)445 textwidget.get_buffer().connect('changed', 446 self.on_text_multi_textbuffer_changed, field) 441 447 textwidget.get_buffer().set_text(field.value) 442 448 443 449 widget = gtk.ScrolledWindow() 444 450 widget.add(textwidget) … … 448 454 self.attach(widget, 1, 2, linecounter, linecounter+1) 449 455 450 else:# field.type == 'text-single' or field.type is nonstandard: 456 else: 457 # field.type == 'text-single' or field.type is nonstandard: 451 458 # JEP says that if we don't understand some type, we 452 459 # should handle it as text-single … … 454 461 if readwrite: 455 462 widget = gtk.Entry() 456 widget.connect('changed', self.on_text_single_entry_changed, field) 463 widget.connect('changed', self.on_text_single_entry_changed, 464 field) 457 465 widget.set_sensitive(readwrite) 458 466 if field.value is None:
