demo_input.py
author Radek Brich <radek.brich@devl.cz>
Wed, 02 Jan 2013 11:48:36 +0100
changeset 44 d77f1ae3786c
parent 41 37b7dfc3eae6
child 45 43b2279b06e1
permissions -rwxr-xr-x
Add Widget.spot property. TreeView: move spot with cursor node. ScrollView: scroll when spot moves.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
#!/usr/bin/env python3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
import locale
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
locale.setlocale(locale.LC_ALL, '')
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
from tuikit import *
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
class MyApplication(Application):
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
    def __init__(self):
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
        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: 20
diff changeset
    13
        self.top.connect('keypress', self.on_top_keypress)
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
        self.text = ''
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        textedit = TextEdit(100, 40, self.text)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
        self.top.add(textedit)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
        textedit.x = 2
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
        self.textedit = textedit
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
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: 20
diff changeset
    22
    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: 20
diff changeset
    23
        if ev.char == 'q':
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
            self.terminate()
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: 20
diff changeset
    25
        self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
        self.textedit.settext(self.text)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
        self.textedit.scrolltoend()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
if __name__ == '__main__':
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
    app = MyApplication()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
    app.start()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33