demo_input.py
author Radek Brich <radek.brich@devl.cz>
Wed, 03 Sep 2014 08:57:06 +0200
changeset 107 1822c37b2688
parent 77 fc1989059e19
permissions -rwxr-xr-x
Refactoring. Add ImmutablePoint.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import locale
locale.setlocale(locale.LC_ALL, '')

from tuikit.application import Application
from tuikit.scrollview import ScrollView
from tuikit.editbox import EditBox


class MyApplication(Application):
    def __init__(self):
        Application.__init__(self)

        self.text = ''
        self.editbox = EditBox(self.text)
        scroll = ScrollView()
        scroll.add(self.editbox)
        self.top.add(scroll, halign='fill', valign='fill')

        scroll.add_handler('keypress', self.on_any_input)
        scroll.add_handler('mousedown', self.on_any_input)
        scroll.add_handler('mouseup', self.on_any_input)
        scroll.add_handler('mousewheel', self.on_any_input)
        scroll.add_handler('mousemove', self.on_any_input)
        scroll.add_handler('mousehover', self.on_any_input)

    def on_any_input(self, ev):
        if ev.event_name == 'keypress' and ev.keyname == 'escape':
            self.terminate()
        line = ''.join((ev.event_name.ljust(10), ' : ', repr(ev)))
        self.editbox.add_line(line)
        return True


if __name__ == '__main__':
    app = MyApplication()
    app.start()