demo_input.py
author Radek Brich <radek.brich@devl.cz>
Fri, 18 Jan 2013 22:36:50 +0100
changeset 62 2f61931520c9
parent 55 1ab0edd5d784
child 73 85a282b5e4fc
permissions -rwxr-xr-x
Rework layouts: Layout is now normal Container which places its children upon resize event. Drop TopWindow, top is now any subclass of Container. Add floater concept: floaters are widgets drawn over normal widgets, not clipped by parent. Add HScrollbar and Scrollbar abstract base class.
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 = ''
62
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
    15
        self.textedit = TextEdit(self.text)
2f61931520c9 Rework layouts: Layout is now normal Container which places its children upon resize event.
Radek Brich <radek.brich@devl.cz>
parents: 55
diff changeset
    16
        self.top.add(self.textedit, halign='fill', valign='fill')
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    18
        editbox = self.textedit.editbox
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    19
        editbox.add_handler('keypress', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    20
        editbox.add_handler('mousedown', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    21
        editbox.add_handler('mouseup', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    22
        editbox.add_handler('mousewheel', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    23
        editbox.add_handler('mousemove', self.on_any_input)
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    24
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    25
    def on_any_input(self, ev):
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    26
        if ev.event_name == 'keypress' and ev.char == 'q':
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
            self.terminate()
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    28
        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
    29
        self.textedit.settext(self.text)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
        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
    31
        return True
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
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
if __name__ == '__main__':
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
    app = MyApplication()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
    app.start()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37