demo_input.py
author Radek Brich <radek.brich@devl.cz>
Tue, 18 Mar 2014 22:39:21 +0100
changeset 88 90d00354dc70
parent 77 fc1989059e19
permissions -rwxr-xr-x
Add WindowManager, basic event handling.
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
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
     7
from tuikit.application import Application
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
     8
from tuikit.scrollview import ScrollView
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
     9
from tuikit.editbox import EditBox
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
class MyApplication(Application):
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
    def __init__(self):
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
        Application.__init__(self)
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
        self.text = ''
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    17
        self.editbox = EditBox(self.text)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    18
        scroll = ScrollView()
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    19
        scroll.add(self.editbox)
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    20
        self.top.add(scroll, halign='fill', valign='fill')
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
77
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    22
        scroll.add_handler('keypress', self.on_any_input)
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    23
        scroll.add_handler('mousedown', self.on_any_input)
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    24
        scroll.add_handler('mouseup', self.on_any_input)
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    25
        scroll.add_handler('mousewheel', self.on_any_input)
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    26
        scroll.add_handler('mousemove', self.on_any_input)
fc1989059e19 Propagate "quit" event, do not just terminate application. Resize: flag widgets to be resized, do resizes only once before draw. Draw: flag widgets to be redrawn, do not draw everything on any event.
Radek Brich <radek.brich@devl.cz>
parents: 76
diff changeset
    27
        scroll.add_handler('mousehover', self.on_any_input)
55
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    28
1ab0edd5d784 DriverSDL: mousewheel, key repeation.
Radek Brich <radek.brich@devl.cz>
parents: 45
diff changeset
    29
    def on_any_input(self, ev):
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    30
        if ev.event_name == 'keypress' and ev.keyname == 'escape':
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
            self.terminate()
76
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    32
        line = ''.join((ev.event_name.ljust(10), ' : ', repr(ev)))
fa5301e58eca Update demo_input, demo_editor. Update ScrollView: show/hide scrollbars as needed on child size requests.
Radek Brich <radek.brich@devl.cz>
parents: 73
diff changeset
    33
        self.editbox.add_line(line)
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
    34
        return True
3
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
if __name__ == '__main__':
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
    app = MyApplication()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
    app.start()
33ec838dc021 Fixed escape sequence handling.
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40