demo_layout.py
changeset 41 37b7dfc3eae6
parent 16 8791a7da6835
child 42 0224ce40792f
equal deleted inserted replaced
40:5faa38c10b67 41:37b7dfc3eae6
     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.globalkeypress)
    13         self.top.connect('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         vert = VerticalLayout(homogeneous=False)
    17         vert = VerticalLayout(homogeneous=False)
    18         self.top.layout(vert)
    18         self.top.layout(vert)
    19         
    19 
    20         self.buildrow()
    20         self.buildrow()
    21         self.buildrow(expand=True)
    21         self.buildrow(expand=True)
    22         self.buildrow(expand=True, fill=True)
    22         self.buildrow(expand=True, fill=True)
    23         self.buildrow(homogeneous=True)
    23         self.buildrow(homogeneous=True)
    24         self.buildrow(homogeneous=True, fill=True)
    24         self.buildrow(homogeneous=True, fill=True)
    25         self.buildrow(homogeneous=True, fill=True, spacing=1)
    25         self.buildrow(homogeneous=True, fill=True, spacing=1)
    26         self.buildrow(homogeneous=True, fill=True, spacing=2)
    26         self.buildrow(homogeneous=True, fill=True, spacing=2)
    27         
    27 
    28     def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
    28     def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
    29         horz = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
    29         horz = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
    30         hbox1 = Container()
    30         hbox1 = Container()
    31         hbox1.sizereq.h = 2
    31         hbox1.sizereq.h = 2
    32         hbox1.layout(horz)
    32         hbox1.layout(horz)
    33         self.top.add(hbox1)
    33         self.top.add(hbox1)
    34         for i in range(5):
    34         for i in range(5):
    35             btn = Button('Btn' + str(i) * i * i)
    35             btn = Button('Btn' + str(i) * i * i)
    36             hbox1.add(btn, expand=expand, fill=fill)
    36             hbox1.add(btn, expand=expand, fill=fill)
    37         
    37 
    38     def globalkeypress(self, keyname, char):
    38     def on_top_keypress(self, ev):
    39         if keyname == 'escape' or char == 'q':
    39         if ev.keyname == 'escape' or ev.char == 'q':
    40             self.terminate()
    40             self.terminate()
    41 
    41 
    42 
    42 
    43 if __name__ == '__main__':
    43 if __name__ == '__main__':
    44     app = MyApplication()
    44     app = MyApplication()