demo_menu.py
author Radek Brich <radek.brich@devl.cz>
Sat, 19 Jan 2013 13:05:21 +0100
changeset 63 2a0e04091898
parent 45 43b2279b06e1
child 64 03f591f5fe5c
permissions -rwxr-xr-x
Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters. LinearLayout: spacing now applies to all children, not just those with expand. Fix Window resize request inside layouts. UnicodeGraphics: prepare for styling/theming.

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

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

from tuikit import Application, MenuBar, MenuButton, Menu, Window


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)
        self.top.add_handler('keypress', self.on_top_keypress, last=True)

        helpwin = Window()
        helpwin.title = 'About'
        helpwin.hide()
        self.top.add(helpwin)
        helpwin.move(10, 5)
        #helpwin.closebutton = False
        #helpwin.resizable = False

        filemenu = Menu([
            ('New', None),
            None,
            ('Open', None),
            ('Save', None),
            None,
            ('Quit', self.terminate),
            ])
        editmenu = Menu([('Copy', None), ('Paste', None)])
        helpmenu = Menu([('About', helpwin)])

        menubar_items = [
            ('File', filemenu),
            ('Edit', editmenu),
            ('Help', helpmenu),
            ]

        menubar = MenuBar(menubar_items)
        self.top.add(menubar, halign='fill')

        menu = Menu([('Copy', None), ('Paste', None)])
        menubtn = MenuButton('MenuButton', menu)
        self.top.add(menubtn, halign='center', valign='center')

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


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