demo_menu.py
author Radek Brich <radek.brich@devl.cz>
Sun, 20 Jan 2013 00:49:19 +0100
changeset 64 03f591f5fe5c
parent 63 2a0e04091898
child 77 fc1989059e19
permissions -rwxr-xr-x
Drop Container.offset, add special layout for that - OffsetLayout. Add Widget.bring_up(): moves child to end of children list.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
     7
from tuikit import Application, MenuBar, MenuButton, Menu, Window
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
class MyApplication(Application):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        Application.__init__(self)
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    13
        self.top.add_handler('keypress', self.on_top_keypress, last=True)
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    15
        helpwin = Window()
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    16
        helpwin.title = 'About'
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    17
        helpwin.hide()
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    18
        self.top.add(helpwin)
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    19
        helpwin.move(10, 5)
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    20
        #helpwin.closebutton = False
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    21
        #helpwin.resizable = False
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    22
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    23
        filemenu = Menu([
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    24
            ('New', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    25
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    26
            ('Open', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    27
            ('Save', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    28
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    29
            ('Quit', self.terminate),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    30
            ])
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    31
        editmenu = Menu([('Copy', None), ('Paste', None)])
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    32
        helpmenu = Menu([('About', helpwin)])
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    33
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    34
        menubar_items = [
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
            ('File', filemenu),
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
            ('Edit', editmenu),
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    37
            ('Help', helpmenu),
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    38
            ]
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
63
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    40
        menubar = MenuBar(menubar_items)
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    41
        self.top.add(menubar, halign='fill')
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    42
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    43
        menu = Menu([('Copy', None), ('Paste', None)])
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    44
        menubtn = MenuButton('MenuButton', menu)
2a0e04091898 Rework MenuBar. Add MenuButton. Add mouse event cascading to floaters.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    45
        self.top.add(menubtn, halign='center', valign='center')
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
64
03f591f5fe5c Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 63
diff changeset
    47
        helpwin.bring_up()
03f591f5fe5c Drop Container.offset, add special layout for that - OffsetLayout.
Radek Brich <radek.brich@devl.cz>
parents: 63
diff changeset
    48
41
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    49
    def on_top_keypress(self, ev):
37b7dfc3eae6 Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Radek Brich <radek.brich@devl.cz>
parents: 40
diff changeset
    50
        if ev.keyname == 'escape':
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
            self.terminate()
45
43b2279b06e1 Clean up Emitter class, simplify event handling. Fix Container.focusnext() method. Add events test (handler auto-registration, order).
Radek Brich <radek.brich@devl.cz>
parents: 42
diff changeset
    52
            return True
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
if __name__ == '__main__':
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
    app = MyApplication()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
    app.start()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58