demo_menu.py
author Radek Brich <radek.brich@devl.cz>
Fri, 04 Jan 2013 00:13:59 +0100
changeset 45 43b2279b06e1
parent 42 0224ce40792f
child 63 2a0e04091898
permissions -rwxr-xr-x
Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).

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

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

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


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

        menubar = MenuBar()
        self.top.add(menubar)

        helpwin = Window()
        self.top.add(helpwin)
        helpwin.x = 10
        helpwin.y = 5
        helpwin.allow_layout = False
        helpwin.hidden = True
        helpwin.title = 'About'
        #helpwin.closebutton = False
        #helpwin.resizable = False


        filemenu = Menu([
            ('New', None),
            None,
            ('Open', None),
            ('Save', None),
            None,
            ('Quit', self.terminate),
            ])
        self.top.add(filemenu)

        editmenu = Menu([('Copy', None), ('Paste', None)])
        helpmenu = Menu([('About', helpwin)])

        self.top.add(editmenu)
        self.top.add(helpmenu)

        menubar.setitems([
            ('File', filemenu),
            ('Edit', editmenu),
            ('Help', helpmenu),
            ])

        self.top.layout = VerticalLayout()

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


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