demo_editor.py
author Radek Brich <radek.brich@devl.cz>
Tue, 08 Jan 2013 23:36:01 +0100
changeset 58 50308ed5e4f9
parent 45 43b2279b06e1
child 62 2f61931520c9
permissions -rwxr-xr-x
sdlterm: Cleanup exceptions.
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.textedit import TextEdit
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
class MyApplication(Application):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
    def __init__(self):
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        Application.__init__(self)
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: 41
diff changeset
    17
        self.top.add_handler('keypress', self.on_top_keypress)
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        #edit = EditField(50, 'DlouhyTest12')
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
        #self.top.add(edit)
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
        t = open('tuikit/widget.py').read()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        textedit = TextEdit(100, 40, t)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
        self.top.add(textedit)
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        textedit.x = 2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        self.textedit = textedit
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
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
    28
    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
    29
        if ev.keyname == 'escape':
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
            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: 41
diff changeset
    31
            return True
2
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
if __name__ == '__main__':
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    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
    36
    app = MyApplication()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
    app.start()
684cdc352562 Menu, Window and other improvements.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38