demo_input.py
author Radek Brich <radek.brich@devl.cz>
Fri, 07 Oct 2011 12:36:14 +0200
changeset 20 472a753664f9
parent 19 tests/input.py@5e78d52ebb24
child 41 37b7dfc3eae6
permissions -rwxr-xr-x
Update utf8 character input to Python3. Reorganize tests.
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)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
        self.top.connect('keypress', self.globalkeypress)
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
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
    def globalkeypress(self, keyname, char):
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
        if char == 'q':
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
            self.terminate()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
        self.text += 'keyname: %s  char: %s\n' % (keyname, char)
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