example.py
author Radek Brich <radek.brich@devl.cz>
Sun, 10 Apr 2011 22:54:38 +0200
changeset 5 ae128c885d0f
parent 2 684cdc352562
permissions -rwxr-xr-x
New GridLayout. Change cursor behavior (hide on unfocus event). Change resize event to propagate through containers. Change container clipping - allowlayout=false children are clipped without borders. More Widget doc.
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
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    18
        helpwin = Window()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    19
        self.top.add(helpwin)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    20
        helpwin.x = 10
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    21
        helpwin.y = 5
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    22
        helpwin.allowlayout = False
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    23
        helpwin.hidden = True
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    24
        helpwin.title = 'About'
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    25
        #helpwin.closebutton = False
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    26
        #helpwin.resizable = False
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    27
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    28
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    29
        filemenu = Menu([
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    30
            ('New', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    31
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    32
            ('Open', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    33
            ('Save', None),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    34
            None,
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    35
            ('Quit', self.terminate),
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    36
            ])
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
        self.top.add(filemenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    39
        editmenu = Menu([('Copy', None), ('Paste', None)])
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents: 1
diff changeset
    40
        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
    41
0
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
        self.top.add(editmenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
        self.top.add(helpmenu)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
        menubar.setitems([
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
            ('File', filemenu),
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
            ('Edit', editmenu),
1
69318aba22bf Menu development. New focus. Easier imports from tuikit package.
Radek Brich <radek.brich@devl.cz>
parents: 0
diff changeset
    48
            ('Help', helpmenu),
0
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
        vert = VerticalLayout()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
        self.top.layout(vert)
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
        #button = Button('click!')
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
        #win.add(button)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
        #button.x = 10
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
        #button.y = 7
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
        #button.connect('click', self.buttonclick)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
        #self.button = button
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
        #subwin = Window(8,8)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
        #win.add(subwin)
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
    def globalkeypress(self, keyname, char):
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
        if keyname == 'escape':
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
            self.terminate()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
if __name__ == '__main__':
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
    app = MyApplication()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
    app.start()
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75