demo_input.py
author Radek Brich <radek.brich@devl.cz>
Thu, 10 Jan 2013 00:03:34 +0100
changeset 61 15088f62c4ac
parent 55 1ab0edd5d784
child 62 2f61931520c9
permissions -rwxr-xr-x
DriverSDL: Fix.
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
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
     7
from tuikit import Application, TextEdit
3
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
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
        self.text = ''
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    15
        self.textedit = TextEdit(100, 40, self.text)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    16
        self.top.add(self.textedit)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    17
        self.textedit.x = 2
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    19
        editbox = self.textedit.editbox
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    20
        editbox.add_handler('keypress', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    21
        editbox.add_handler('mousedown', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    22
        editbox.add_handler('mouseup', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    23
        editbox.add_handler('mousewheel', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    24
        editbox.add_handler('mousemove', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    25
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    26
    def on_any_input(self, ev):
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    27
        if ev.event_name == 'keypress' and ev.char == 'q':
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
            self.terminate()
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    29
        self.text += ''.join((ev.event_name.ljust(10), ' : ', repr(ev), '\n'))
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        self.textedit.settext(self.text)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
        self.textedit.scrolltoend()
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
    32
        return True
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
if __name__ == '__main__':
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
    app = MyApplication()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
    app.start()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38