demo_editor.py
author Radek Brich <radek.brich@devl.cz>
Sat, 29 Dec 2012 12:16:06 +0100
changeset 41 37b7dfc3eae6
parent 34 e3beacd5e536
child 45 43b2279b06e1
permissions -rwxr-xr-x
Update Emitter: All event handlers now have exactly one argument: object inherited from Event class, which carries any data.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
import os
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
from tuikit.application import Application
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
from tuikit.editfield import EditField
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
from tuikit.window import Window
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
from tuikit.button import Button
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
from tuikit.scrollbar import VScrollbar
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
from tuikit.textedit import TextEdit
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
class MyApplication(Application):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
    def __init__(self):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        Application.__init__(self)
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: 34
diff changeset
    20
        self.top.connect('keypress', self.on_top_keypress)
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
        #edit = EditField(50, 'DlouhyTest12')
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        #self.top.add(edit)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        t = open('tuikit/widget.py').read()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
        textedit = TextEdit(100, 40, t)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
        self.top.add(textedit)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
        textedit.x = 2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        self.textedit = textedit
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
        #win = Window()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
        #self.top.add(win)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
        #button = Button('click!')
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
        #win.add(button)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
        #button.x = 10
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
        #button.y = 7
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
        #button.connect('click', self.buttonclick)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
        #self.button = button
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
        #subwin = Window(8,8)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
        #win.add(subwin)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
    def buttonclick(self):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
        self.button.label = 'YES'
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
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: 34
diff changeset
    51
    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: 34
diff changeset
    52
        if ev.keyname == 'escape':
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
            self.terminate()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
if __name__ == '__main__':
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
    os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
    app = MyApplication()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
    app.start()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60