Use py_resource module
[python/dscho.git] / Lib / stdwin / gwin.py
blob626c8fa2fb4fd6afe98ae26f2dc6c39a6976cecf
1 # Module 'gwin'
2 # Generic stdwin windows
4 # This is used as a base class from which to derive other window types.
5 # XXX DON'T USE THIS CODE ANY MORE! It is ages old!
7 import stdwin, stdwinq
8 from stdwinevents import *
9 from mainloop import mainloop, register, unregister, windows
11 # Open a window
13 def open(title): # Open a generic window
14 w = stdwin.open(title)
15 stdwin.setdefwinsize(0, 0)
16 # Set default event handlers
17 w.draw = nop
18 w.char = nop
19 w.mdown = nop
20 w.mmove = nop
21 w.mup = nop
22 w.m2down = m2down
23 w.m2up = m2up
24 w.size = nop
25 w.move = nop
26 w.activate = w.deactivate = nop
27 w.timer = nop
28 # default command handlers
29 w.close = close
30 w.tab = tab
31 w.enter = enter
32 w.backspace = backspace
33 w.arrow = arrow
34 w.kleft = w.kup = w.kright = w.kdown = nop
35 w.dispatch = treatevent
36 register(w)
37 return w
40 def treatevent(e): # Handle a stdwin event
41 type, w, detail = e
42 if type == WE_DRAW:
43 w.draw(w, detail)
44 elif type == WE_MENU:
45 m, item = detail
46 m.action[item](w, m, item)
47 elif type == WE_COMMAND:
48 treatcommand(w, detail)
49 elif type == WE_CHAR:
50 w.char(w, detail)
51 elif type == WE_MOUSE_DOWN:
52 if detail[1] > 1: w.m2down(w, detail)
53 else: w.mdown(w, detail)
54 elif type == WE_MOUSE_MOVE:
55 w.mmove(w, detail)
56 elif type == WE_MOUSE_UP:
57 if detail[1] > 1: w.m2up(w, detail)
58 else: w.mup(w, detail)
59 elif type == WE_SIZE:
60 w.size(w, w.getwinsize())
61 elif type == WE_ACTIVATE:
62 w.activate(w)
63 elif type == WE_DEACTIVATE:
64 w.deactivate(w)
65 elif type == WE_MOVE:
66 w.move(w)
67 elif type == WE_TIMER:
68 w.timer(w)
69 elif type == WE_CLOSE:
70 w.close(w)
72 def treatcommand(w, type): # Handle a we_command event
73 if type == WC_CLOSE:
74 w.close(w)
75 elif type == WC_RETURN:
76 w.enter(w)
77 elif type == WC_TAB:
78 w.tab(w)
79 elif type == WC_BACKSPACE:
80 w.backspace(w)
81 elif type in (WC_LEFT, WC_UP, WC_RIGHT, WC_DOWN):
82 w.arrow(w, type)
85 # Methods
87 def close(w): # Close method
88 unregister(w)
89 del w.close # Delete our close function
90 w.close() # Call the close method
92 def arrow(w, detail): # Arrow key method
93 if detail == WC_LEFT:
94 w.kleft(w)
95 elif detail == WC_UP:
96 w.kup(w)
97 elif detail == WC_RIGHT:
98 w.kright(w)
99 elif detail == WC_DOWN:
100 w.kdown(w)
103 # Trivial methods
105 def tab(w): w.char(w, '\t')
106 def enter(w): w.char(w, '\n') # 'return' is a Python reserved word
107 def backspace(w): w.char(w, '\b')
108 def m2down(w, detail): w.mdown(w, detail)
109 def m2up(w, detail): w.mup(w, detail)
110 def nop(*args): pass