Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 1.9, 1.9.1, and 1.9.2

qtlib: add WidgetGroups class

Changeset 2d1a32b89b77

Parent bf51451f18d9

by Yuki KODAMA

Changes to one file · Browse files at 2d1a32b89b77 Showing diff from parent bf51451f18d9 Diff from another changeset...

 
403
404
405
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
406
407
408
 
403
404
405
406
407
408
409
410
411
412
413
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
442
443
444
445
446
447
448
449
450
451
452
453
@@ -403,6 +403,51 @@
    self.setLayout(box)   +class WidgetGroups(object): + """ Support for bulk-updating properties of Qt widgets """ + + def __init__(self): + object.__init__(self) + + self.clear(all=True) + + ### Public Methods ### + + def add(self, widget, group='default'): + if group not in self.groups: + self.groups[group] = [] + widgets = self.groups[group] + if widget not in widgets: + widgets.append(widget) + + def remove(self, widget, group='default'): + if group not in self.groups: + return + widgets = self.groups[group] + if widget in widgets: + widgets.remove(widget) + + def clear(self, group='default', all=True): + if all: + self.groups = {} + else: + del self.groups[group] + + def set_prop(self, prop, value, group='default', cond=None): + if group not in self.groups: + return + widgets = self.groups[group] + if callable(cond): + widgets = [w for w in widgets if cond(w)] + for widget in widgets: + getattr(widget, prop)(value) + + def set_visible(self, *args, **kargs): + self.set_prop('setVisible', *args, **kargs) + + def set_enable(self, *args, **kargs): + self.set_prop('setEnabled', *args, **kargs) +  def fileEditor(filename):   'Open a simple modal file editing dialog'   dialog = QtGui.QDialog()