demo_menu.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Dec 2012 12:16:06 +0100
changeset 41 37b7dfc3eae6
parent 40 5faa38c10b67
child 42 0224ce40792f
permissions -rwxr-xr-x
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.

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

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

from tuikit import *


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)
        self.top.connect('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),
            ])

        vert = VerticalLayout()
        self.top.layout(vert)


        #button = Button('click!')
        #win.add(button)
        #button.x = 10
        #button.y = 7

        #button.connect('click', self.buttonclick)
        #self.button = button

        #subwin = Window(8,8)
        #win.add(subwin)


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


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