tuikit/container.py
changeset 32 088b92ffb119
parent 23 4e72fd2a0e14
child 34 e3beacd5e536
equal deleted inserted replaced
31:629d5edb1602 32:088b92ffb119
     5 from tuikit.widget import Widget
     5 from tuikit.widget import Widget
     6 from tuikit.common import Borders
     6 from tuikit.common import Borders
     7 
     7 
     8 
     8 
     9 class Container(Widget):
     9 class Container(Widget):
    10     
    10 
    11     '''Container widget. Base for any widget which can contain other widgets.'''
    11     '''Container widget. Base for any widget which can contain other widgets.'''
    12     
    12 
    13     def __init__(self, width = 10, height = 10):
    13     def __init__(self, width = 10, height = 10):
    14         '''Create container of requested size.'''
    14         '''Create container of requested size.'''
    15         Widget.__init__(self, width, height)
    15         Widget.__init__(self, width, height)
    16 
    16 
    17         #: List of child widgets.
    17         #: List of child widgets.
    18         self.children = []
    18         self.children = []
    19         
    19 
    20         self.mousechild = None
    20         self.mousechild = None
    21 
    21 
    22         #: Width of borders (left, top, right, bottom).
    22         #: Width of borders (left, top, right, bottom).
    23         #: Child widgets are placed within borders.
    23         #: Child widgets are placed within borders.
    24         self.borders = Borders()
    24         self.borders = Borders()
    25         
    25 
    26         self._layout = None
    26         self._layout = None
    27         
    27 
    28         self.widthrequest = (None, None)
    28         self.widthrequest = (None, None)
    29         self.heightrequest = (None, None)
    29         self.heightrequest = (None, None)
    30 
    30 
    31         self.colorprefix = None
    31         self.colorprefix = None
    32 
    32 
    33         self.trapfocus = False  # if True, tab cycles inside container
    33         self.trapfocus = False  # if True, tab cycles inside container
       
    34 
       
    35         self.connect('resize', self.on_resize)
    34 
    36 
    35 
    37 
    36     def add(self, widget, **kw):
    38     def add(self, widget, **kw):
    37         '''Add widget into this container.'''
    39         '''Add widget into this container.'''
    38         self.children.append(widget)
    40         self.children.append(widget)
    73             self.focusnext()
    75             self.focusnext()
    74             return
    76             return
    75         Widget.keypress(self, keyname, char)
    77         Widget.keypress(self, keyname, char)
    76 
    78 
    77 
    79 
    78     def resize(self):
    80     def on_resize(self):
    79         Widget.resize(self)
       
    80         for child in self.children:
    81         for child in self.children:
    81             child.emit('resize')
    82             child.handle('resize')
    82 
    83 
    83 
    84 
    84     def draw(self, driver, x=0, y=0):
    85     def draw(self, driver, x=0, y=0):
    85         if self.hidden:
    86         if self.hidden:
    86             return
    87             return