11 |
11 |
12 |
12 |
13 class MyApplication(Application): |
13 class MyApplication(Application): |
14 def __init__(self): |
14 def __init__(self): |
15 Application.__init__(self) |
15 Application.__init__(self) |
16 self.top.connect('keypress', self.globalkeypress) |
16 self.top.add_handler('keypress', self.on_top_keypress) |
17 |
17 |
18 #edit = EditField(50, 'DlouhyTest12') |
18 #edit = EditField(50, 'DlouhyTest12') |
19 #self.top.add(edit) |
19 #self.top.add(edit) |
20 |
20 |
21 win = Window() |
21 win = Window() |
24 button = Button('click!') |
24 button = Button('click!') |
25 win.add(button) |
25 win.add(button) |
26 button.x = 10 |
26 button.x = 10 |
27 button.y = 7 |
27 button.y = 7 |
28 |
28 |
29 button.connect('click', self.buttonclick) |
29 button.add_handler('click', self.on_button_click) |
30 self.button = button |
30 self.button = button |
31 |
31 |
32 subwin = Window(8,8) |
32 subwin = Window(8,8) |
33 win.add(subwin) |
33 win.add(subwin) |
34 |
34 |
35 |
35 |
36 def buttonclick(self): |
36 def on_button_click(self, ev): |
37 self.button.label = 'YES' |
37 self.button.label = 'YES' |
|
38 return True |
38 |
39 |
39 |
40 |
40 def globalkeypress(self, keyname, char): |
41 def on_top_keypress(self, ev): |
41 if keyname == 'escape': |
42 if ev.keyname == 'escape': |
42 self.terminate() |
43 self.terminate() |
|
44 return True |
43 |
45 |
44 |
46 |
45 if __name__ == '__main__': |
47 if __name__ == '__main__': |
46 locale.setlocale(locale.LC_ALL, '') |
48 locale.setlocale(locale.LC_ALL, '') |
47 os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key |
49 os.environ['ESCDELAY'] = '25' # do not wait 1 second after pressing Escape key |
48 app = MyApplication() |
50 app = MyApplication() |
49 #app.start() |
51 #app.start() |
50 |
52 |
51 cProfile.run('app.start()', 'demo_window.appstats') |
53 cProfile.run('app.start()', 'demo_window.appstats') |
52 p = pstats.Stats('demo_window.appstats') |
54 p = pstats.Stats('demo_window.appstats') |
53 p.sort_stats('time', 'cumulative').print_stats(20) |
55 p.sort_stats('time', 'cumulative').print_stats(20) |
54 |
56 |