demo_menu.py
changeset 63 2a0e04091898
parent 45 43b2279b06e1
child 64 03f591f5fe5c
equal deleted inserted replaced
62:2f61931520c9 63:2a0e04091898
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 import locale
     4 import locale
     5 locale.setlocale(locale.LC_ALL, '')
     5 locale.setlocale(locale.LC_ALL, '')
     6 
     6 
     7 from tuikit import Application, MenuBar, Menu, Window, VerticalLayout
     7 from tuikit import Application, MenuBar, MenuButton, Menu, Window
     8 
     8 
     9 
     9 
    10 class MyApplication(Application):
    10 class MyApplication(Application):
    11     def __init__(self):
    11     def __init__(self):
    12         Application.__init__(self)
    12         Application.__init__(self)
    13         self.top.add_handler('keypress', self.on_top_keypress)
    13         self.top.add_handler('keypress', self.on_top_keypress, last=True)
    14 
       
    15         menubar = MenuBar()
       
    16         self.top.add(menubar)
       
    17 
    14 
    18         helpwin = Window()
    15         helpwin = Window()
       
    16         helpwin.title = 'About'
       
    17         helpwin.hide()
    19         self.top.add(helpwin)
    18         self.top.add(helpwin)
    20         helpwin.x = 10
    19         helpwin.move(10, 5)
    21         helpwin.y = 5
       
    22         helpwin.allow_layout = False
       
    23         helpwin.hidden = True
       
    24         helpwin.title = 'About'
       
    25         #helpwin.closebutton = False
    20         #helpwin.closebutton = False
    26         #helpwin.resizable = False
    21         #helpwin.resizable = False
    27 
       
    28 
    22 
    29         filemenu = Menu([
    23         filemenu = Menu([
    30             ('New', None),
    24             ('New', None),
    31             None,
    25             None,
    32             ('Open', None),
    26             ('Open', None),
    33             ('Save', None),
    27             ('Save', None),
    34             None,
    28             None,
    35             ('Quit', self.terminate),
    29             ('Quit', self.terminate),
    36             ])
    30             ])
    37         self.top.add(filemenu)
       
    38 
       
    39         editmenu = Menu([('Copy', None), ('Paste', None)])
    31         editmenu = Menu([('Copy', None), ('Paste', None)])
    40         helpmenu = Menu([('About', helpwin)])
    32         helpmenu = Menu([('About', helpwin)])
    41 
    33 
    42         self.top.add(editmenu)
    34         menubar_items = [
    43         self.top.add(helpmenu)
       
    44 
       
    45         menubar.setitems([
       
    46             ('File', filemenu),
    35             ('File', filemenu),
    47             ('Edit', editmenu),
    36             ('Edit', editmenu),
    48             ('Help', helpmenu),
    37             ('Help', helpmenu),
    49             ])
    38             ]
    50 
    39 
    51         self.top.layout = VerticalLayout()
    40         menubar = MenuBar(menubar_items)
       
    41         self.top.add(menubar, halign='fill')
       
    42 
       
    43         menu = Menu([('Copy', None), ('Paste', None)])
       
    44         menubtn = MenuButton('MenuButton', menu)
       
    45         self.top.add(menubtn, halign='center', valign='center')
    52 
    46 
    53     def on_top_keypress(self, ev):
    47     def on_top_keypress(self, ev):
    54         if ev.keyname == 'escape':
    48         if ev.keyname == 'escape':
    55             self.terminate()
    49             self.terminate()
    56             return True
    50             return True