demo_input.py
changeset 55 1ab0edd5d784
parent 45 43b2279b06e1
child 62 2f61931520c9
equal deleted inserted replaced
54:86b84535726e 55:1ab0edd5d784
     2 # -*- coding: utf-8 -*-
     2 # -*- coding: utf-8 -*-
     3 
     3 
     4 import locale
     4 import locale
     5 locale.setlocale(locale.LC_ALL, '')
     5 locale.setlocale(locale.LC_ALL, '')
     6 
     6 
     7 from tuikit import *
     7 from tuikit import Application, TextEdit
     8 
     8 
     9 
     9 
    10 class MyApplication(Application):
    10 class MyApplication(Application):
    11     def __init__(self):
    11     def __init__(self):
    12         Application.__init__(self)
    12         Application.__init__(self)
    13         self.top.add_handler('keypress', self.on_top_keypress)
       
    14 
    13 
    15         self.text = ''
    14         self.text = ''
    16         textedit = TextEdit(100, 40, self.text)
    15         self.textedit = TextEdit(100, 40, self.text)
    17         self.top.add(textedit)
    16         self.top.add(self.textedit)
    18         textedit.x = 2
    17         self.textedit.x = 2
    19         self.textedit = textedit
       
    20 
    18 
    21     def on_top_keypress(self, ev):
    19         editbox = self.textedit.editbox
    22         if ev.char == 'q':
    20         editbox.add_handler('keypress', self.on_any_input)
       
    21         editbox.add_handler('mousedown', self.on_any_input)
       
    22         editbox.add_handler('mouseup', self.on_any_input)
       
    23         editbox.add_handler('mousewheel', self.on_any_input)
       
    24         editbox.add_handler('mousemove', self.on_any_input)
       
    25 
       
    26     def on_any_input(self, ev):
       
    27         if ev.event_name == 'keypress' and ev.char == 'q':
    23             self.terminate()
    28             self.terminate()
    24         self.text += 'keyname: %(keyname)s  char: %(char)s\n' % ev
    29         self.text += ''.join((ev.event_name.ljust(10), ' : ', repr(ev), '\n'))
    25         self.textedit.settext(self.text)
    30         self.textedit.settext(self.text)
    26         self.textedit.scrolltoend()
    31         self.textedit.scrolltoend()
    27         return True
    32         return True
    28 
    33 
    29 
    34