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 Application, TextEdit |
7 from tuikit.application import Application |
|
8 from tuikit.scrollview import ScrollView |
|
9 from tuikit.editbox import EditBox |
8 |
10 |
9 |
11 |
10 class MyApplication(Application): |
12 class MyApplication(Application): |
11 def __init__(self): |
13 def __init__(self): |
12 Application.__init__(self) |
14 Application.__init__(self) |
13 |
15 |
14 self.text = '' |
16 self.text = '' |
15 self.textedit = TextEdit(self.text) |
17 self.editbox = EditBox(self.text) |
16 self.top.add(self.textedit, halign='fill', valign='fill') |
18 scroll = ScrollView() |
|
19 scroll.add(self.editbox) |
|
20 self.top.add(scroll, halign='fill', valign='fill') |
17 |
21 |
18 editbox = self.textedit.editbox |
22 self.editbox.add_handler('keypress', self.on_any_input) |
19 editbox.add_handler('keypress', self.on_any_input) |
23 self.editbox.add_handler('mousedown', self.on_any_input) |
20 editbox.add_handler('mousedown', self.on_any_input) |
24 self.editbox.add_handler('mouseup', self.on_any_input) |
21 editbox.add_handler('mouseup', self.on_any_input) |
25 self.editbox.add_handler('mousewheel', self.on_any_input) |
22 editbox.add_handler('mousewheel', self.on_any_input) |
26 self.editbox.add_handler('mousemove', self.on_any_input) |
23 editbox.add_handler('mousemove', self.on_any_input) |
27 self.editbox.add_handler('mousehover', self.on_any_input) |
24 editbox.add_handler('mousehover', self.on_any_input) |
|
25 |
28 |
26 def on_any_input(self, ev): |
29 def on_any_input(self, ev): |
27 if ev.event_name == 'keypress' and ev.char == 'q': |
30 if ev.event_name == 'keypress' and ev.keyname == 'escape': |
28 self.terminate() |
31 self.terminate() |
29 self.text += ''.join((ev.event_name.ljust(10), ' : ', repr(ev), '\n')) |
32 line = ''.join((ev.event_name.ljust(10), ' : ', repr(ev))) |
30 self.textedit.settext(self.text) |
33 self.editbox.add_line(line) |
31 self.textedit.scrolltoend() |
|
32 return True |
34 return True |
33 |
35 |
34 |
36 |
35 if __name__ == '__main__': |
37 if __name__ == '__main__': |
36 app = MyApplication() |
38 app = MyApplication() |