demo_layout.py
author Radek Brich <radek.brich@devl.cz>
Sun, 27 Jan 2013 23:51:59 +0100
changeset 70 db2eab0beb45
parent 63 2a0e04091898
permissions -rwxr-xr-x
Update drivers: Rename setcolor to defcolor, add real setcolor which ignores color stack. Application: Add overridable startup() method. Fix Widget draw clipping.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import locale
locale.setlocale(locale.LC_ALL, '')

from tuikit import Application, VerticalLayout, HorizontalLayout, Button


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)

        self.top = VerticalLayout(homogeneous=False)
        self.top.add_handler('keypress', self.on_top_keypress)
        #self.top.borders = (1,1,1,1)

        self._row_num = 0
        self.buildrow()
        self.buildrow(spacing=1)
        self.buildrow(expand=True)
        self.buildrow(expand=True, fill=True)
        self.buildrow(homogeneous=True)
        self.buildrow(homogeneous=True, fill=True)
        self.buildrow(homogeneous=True, fill=True, spacing=1)
        self.buildrow(homogeneous=True, fill=True, spacing=2)

    def buildrow(self, homogeneous=False, spacing=0, expand=False, fill=False):
        hbox = HorizontalLayout(homogeneous=homogeneous, spacing=spacing)
        hbox.resize(h=2)
        self._row_num += 1
        hbox.name = 'hbox' + str(self._row_num)
        self.top.add(hbox)
        for i in range(5):
            btn = Button('Btn' + str(i) * i * i)
            hbox.add(btn, expand=expand, fill=fill)

    def on_top_keypress(self, ev):
        if ev.keyname == 'escape' or ev.char == 'q':
            self.terminate()
            return True


if __name__ == '__main__':
    app = MyApplication()
    app.start()