demo_layout.py
changeset 45 43b2279b06e1
parent 42 0224ce40792f
child 62 2f61931520c9
equal deleted inserted replaced
44:d77f1ae3786c 45:43b2279b06e1
     8 
     8 
     9 
     9 
    10 class MyApplication(Application):
    10 class MyApplication(Application):
    11     def __init__(self):
    11     def __init__(self):
    12         Application.__init__(self)
    12         Application.__init__(self)
    13         self.top.connect('keypress', self.on_top_keypress)
    13         self.top.add_handler('keypress', self.on_top_keypress)
    14 
    14 
    15         #self.top.borders = (1,1,1,1)
    15         #self.top.borders = (1,1,1,1)
    16 
    16 
    17         self.top.layout = VerticalLayout(homogeneous=False)
    17         self.top.layout = VerticalLayout(homogeneous=False)
    18 
    18 
       
    19         self._row_num = 0
    19         self.buildrow()
    20         self.buildrow()
    20         self.buildrow(expand=True)
    21         self.buildrow(expand=True)
    21         self.buildrow(expand=True, fill=True)
    22         self.buildrow(expand=True, fill=True)
    22         self.buildrow(homogeneous=True)
    23         self.buildrow(homogeneous=True)
    23         self.buildrow(homogeneous=True, fill=True)
    24         self.buildrow(homogeneous=True, fill=True)
    24         self.buildrow(homogeneous=True, fill=True, spacing=1)
    25         self.buildrow(homogeneous=True, fill=True, spacing=1)
    25         self.buildrow(homogeneous=True, fill=True, spacing=2)
    26         self.buildrow(homogeneous=True, fill=True, spacing=2)
    26 
    27 
    27     def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
    28     def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
    28         hbox1 = Container()
    29         hbox = Container()
    29         hbox1.sizereq.h = 2
    30         hbox.sizereq.h = 2
    30         hbox1.layout = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
    31         hbox.layout = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
    31         self.top.add(hbox1)
    32         self._row_num += 1
       
    33         hbox.name = 'hbox' + str(self._row_num)
       
    34         self.top.add(hbox)
    32         for i in range(5):
    35         for i in range(5):
    33             btn = Button('Btn' + str(i) * i * i)
    36             btn = Button('Btn' + str(i) * i * i)
    34             hbox1.add(btn, expand=expand, fill=fill)
    37             hbox.add(btn, expand=expand, fill=fill)
    35 
    38 
    36     def on_top_keypress(self, ev):
    39     def on_top_keypress(self, ev):
    37         if ev.keyname == 'escape' or ev.char == 'q':
    40         if ev.keyname == 'escape' or ev.char == 'q':
    38             self.terminate()
    41             self.terminate()
       
    42             return True
    39 
    43 
    40 
    44 
    41 if __name__ == '__main__':
    45 if __name__ == '__main__':
    42     app = MyApplication()
    46     app = MyApplication()
    43     app.start()
    47     app.start()