File: group.py

package info (click to toggle)
python-box2d 2.0.2%2Bsvn20100109.244-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, squeeze, wheezy
  • size: 2,864 kB
  • ctags: 3,280
  • sloc: cpp: 11,679; python: 10,103; xml: 477; makefile: 85; sh: 8
file content (43 lines) | stat: -rw-r--r-- 1,143 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"""
"""
from const import *
import widget

class Group(widget.Widget):
    """An object for grouping together Form elements.
    
    <pre>Group(name=None,value=None)</pre>
    
    <dl>
    <dt>name<dd>name as used in the Form
    <dt>value<dd>values that are currently selected in the group
    </dl>
    
    <p>See [[gui-button]] for several examples.</p>
    
    <p>When the value changes, an <tt>gui.CHANGE</tt> event is sent.
    Although note, that when the value is a list, it may have to be sent by hand via
    <tt>g.send(gui.CHANGE)</tt></p>
    """
    
    def __init__(self,name=None,value=None):
        widget.Widget.__init__(self,name=name,value=value)
        self.widgets = []
    
    def add(self,w):
        """Add a widget to this group.
        
        <pre>Group.add(w)</pre>
        """
        self.widgets.append(w)
    
    def __setattr__(self,k,v):
        _v = self.__dict__.get(k,NOATTR)
        self.__dict__[k] = v
        if k == 'value' and _v != NOATTR and _v != v:
            self._change()
    
    def _change(self):
        self.send(CHANGE)
        for w in self.widgets:
            w.repaint()