example.py
author Radek Brich <radek.brich@devl.cz>
Thu, 17 Feb 2011 23:35:05 +0100
changeset 1 69318aba22bf
parent 0 a35731b5e31a
child 2 684cdc352562
permissions -rwxr-xr-x
Menu development. New focus. Easier imports from tuikit package.
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
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
     7
from tuikit import *
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)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        self.top.connect('keypress', self.globalkeypress)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        menubar = MenuBar()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        self.top.add(menubar)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    18
        win = Window()
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    19
        self.top.add(win)
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    20
        win.x = 10
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    21
        win.y = 5
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    22
        win.allowlayout = False
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    23
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    24
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    25
        filemenu = Menu([
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    26
            ('New', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    27
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    28
            ('Open', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    29
            ('Save', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    30
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    31
            ('Quit', self.terminate),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    32
            ])
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
        self.top.add(filemenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    35
        editmenu = Menu([('Copy', None), ('Paste', None)])
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    36
        helpmenu = Menu([('About', None)])
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    37
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
        self.top.add(editmenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
        self.top.add(helpmenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
        menubar.setitems([
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
            ('File', filemenu),
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
            ('Edit', editmenu),
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    44
            ('Help', helpmenu),
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
            ])
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
        vert = VerticalLayout()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
        self.top.layout(vert)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
        #button = Button('click!')
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
        #win.add(button)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
        #button.x = 10
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
        #button.y = 7
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
        #button.connect('click', self.buttonclick)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
        #self.button = button
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
        #subwin = Window(8,8)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
        #win.add(subwin)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
    def globalkeypress(self, keyname, char):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
        if keyname == 'escape':
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
            self.terminate()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
if __name__ == '__main__':
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
    app = MyApplication()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
    app.start()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71