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!
8 from stdwinevents
import *
9 from mainloop
import mainloop
, register
, unregister
, windows
13 def open(title
): # Open a generic window
14 w
= stdwin
.open(title
)
15 stdwin
.setdefwinsize(0, 0)
16 # Set default event handlers
26 w
.activate
= w
.deactivate
= nop
28 # default command handlers
32 w
.backspace
= backspace
34 w
.kleft
= w
.kup
= w
.kright
= w
.kdown
= nop
35 w
.dispatch
= treatevent
40 def treatevent(e
): # Handle a stdwin event
46 m
.action
[item
](w
, m
, item
)
47 elif type == WE_COMMAND
:
48 treatcommand(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
:
56 elif type == WE_MOUSE_UP
:
57 if detail
[1] > 1: w
.m2up(w
, detail
)
58 else: w
.mup(w
, detail
)
60 w
.size(w
, w
.getwinsize())
61 elif type == WE_ACTIVATE
:
63 elif type == WE_DEACTIVATE
:
67 elif type == WE_TIMER
:
69 elif type == WE_CLOSE
:
72 def treatcommand(w
, type): # Handle a we_command event
75 elif type == WC_RETURN
:
79 elif type == WC_BACKSPACE
:
81 elif type in (WC_LEFT
, WC_UP
, WC_RIGHT
, WC_DOWN
):
87 def close(w
): # Close method
89 del w
.close
# Delete our close function
90 w
.close() # Call the close method
92 def arrow(w
, detail
): # Arrow key method
97 elif detail
== WC_RIGHT
:
99 elif detail
== WC_DOWN
:
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
)