demo_input.py
author Radek Brich <radek.brich@devl.cz>
Fri, 01 Feb 2013 00:24:02 +0100
changeset 74 23767a33a781
parent 73 85a282b5e4fc
child 76 fa5301e58eca
permissions -rwxr-xr-x
Add ScrollWindow. Rewrite EditBox to work with OffsetLayout. Add propery "exposed" to DrawEvent. Add Widget._view_size. Add config file (driver, log_level).

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

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

from tuikit import Application, TextEdit


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

        self.text = ''
        self.textedit = TextEdit(self.text)
        self.top.add(self.textedit, halign='fill', valign='fill')

        editbox = self.textedit.editbox
        editbox.add_handler('keypress', self.on_any_input)
        editbox.add_handler('mousedown', self.on_any_input)
        editbox.add_handler('mouseup', self.on_any_input)
        editbox.add_handler('mousewheel', self.on_any_input)
        editbox.add_handler('mousemove', self.on_any_input)
        editbox.add_handler('mousehover', self.on_any_input)

    def on_any_input(self, ev):
        if ev.event_name == 'keypress' and ev.char == 'q':
            self.terminate()
        self.text += ''.join((ev.event_name.ljust(10), ' : ', repr(ev), '\n'))
        self.textedit.settext(self.text)
        self.textedit.scrolltoend()
        return True


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