Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.9, 0.9.1, and 0.9.1.1

gtklib: add options to support markup()

Changeset 27cae0de1a84

Parent c387bab4f621

by Yuki KODAMA

Changes to one file · Browse files at 27cae0de1a84 Showing diff from parent c387bab4f621 Diff from another changeset...

 
396
397
398
399
400
401
 
 
 
 
402
403
404
 
413
414
415
416
 
417
418
 
419
420
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
421
422
423
 
447
448
449
450
451
 
 
 
 
452
453
454
 
458
459
460
461
 
 
 
462
463
464
 
468
469
470
471
 
 
 
 
 
 
472
473
474
 
481
482
483
484
 
485
486
487
 
488
489
490
 
493
494
495
496
 
497
498
499
 
396
397
398
 
 
 
399
400
401
402
403
404
405
 
414
415
416
 
417
418
 
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
 
465
466
467
 
 
468
469
470
471
472
473
474
 
478
479
480
 
481
482
483
484
485
486
 
490
491
492
 
493
494
495
496
497
498
499
500
501
 
508
509
510
 
511
512
513
 
514
515
516
517
 
520
521
522
 
523
524
525
526
@@ -396,9 +396,10 @@
  self.pack_start(self.table)   self.headers = []   - pads = {'xpad': -1, 'ypad': -1} - pads.update(kargs) - self.set_default_paddings(**pads) + self.set_default_paddings(kargs.get('xpad', -1), + kargs.get('ypad', -1)) + self.set_default_options(kargs.get('headopts', None), + kargs.get('bodyopts', None))     def set_default_paddings(self, xpad=None, ypad=None):   """ @@ -413,11 +414,28 @@
  Use -1 to reset padding to preset value.   Default: None (no change).   """ - if not xpad is None: + if xpad is not None:   self.xpad = xpad >= 0 and xpad or 4 - if not ypad is None: + if ypad is not None:   self.ypad = ypad >= 0 and ypad or 2   + def set_default_options(self, headopts=None, bodyopts=None): + """ + Set default options for markups of label. + + In default, LayoutTable doesn't use any markups and set the test + as plane text. See markup()'s description for more details of + option parameters. Note that if called add_row() with just one + widget, it will be tried to apply 'bodyopts', not 'headopts'. + + headopts: Dictionary. Options used for markups of gtk.Label. + This option is only availabled for the label. + The text will be escaped automatically. Default: None. + bodyopts: [same as 'headopts'] + """ + self.headopts = headopts + self.bodyopts = bodyopts +   def get_first_header(self):   """   Return the cell at top-left corner if exists. @@ -447,8 +465,10 @@
  expand: Number. Position of body element to expand. If you   specify this option, 'padding' option will be changed   to False automatically. Default: -1 (last element). - xpad: Number. Overwrite default 'xpad' value. - ypad: Number. Overwrite default 'ypad' value. + xpad: Number. Override default 'xpad' value. + ypad: [same as 'xpad'] + headopts: Dictionary. Override default 'headopts' value. + bodyopts: [same as 'headopts']   """   if len(widgets) == 0:   return @@ -458,7 +478,9 @@
  t.set_property('n-rows', rows + 1)   xpad = kargs.get('xpad', self.xpad)   ypad = kargs.get('ypad', self.ypad) - def getwidget(obj): + hopts = kargs.get('headopts', self.headopts) + bopts = kargs.get('bodyopts', self.bodyopts) + def getwidget(obj, opts=None):   '''element converter'''   if obj == None:   return gtk.Label('') @@ -468,7 +490,12 @@
  lbl.size_request()   return lbl   elif isinstance(obj, basestring): - lbl = gtk.Label(obj) + if opts is None: + lbl = gtk.Label(obj) + else: + obj = markup(obj, **opts) + lbl = gtk.Label() + lbl.set_markup(obj)   return lbl   return obj   def pack(*widgets, **kargs): @@ -481,10 +508,10 @@
  widgets += (None,)   expmap = [ w is None for w in widgets ]   expmap[expand] = True - widgets = [ getwidget(w) for w in widgets ] + widgets = [ getwidget(w, bopts) for w in widgets ]   hbox = gtk.HBox()   for i, obj in enumerate(widgets): - widget = getwidget(obj) + widget = getwidget(obj, bopts)   pad = i != 0 and 2 or 0   hbox.pack_start(widget, expmap[i], expmap[i], pad)   return hbox @@ -493,7 +520,7 @@
  widget = pack(*widgets, **kargs)   t.attach(widget, 0, cols, rows, rows + 1, FLAG, 0, xpad, ypad)   else: - first = getwidget(widgets[0]) + first = getwidget(widgets[0], hopts)   if isinstance(first, gtk.Label):   first.set_alignment(1, 0.5)   t.attach(first, 0, 1, rows, rows + 1, gtk.FILL, 0, xpad, ypad)