1990-10-13 16:23:40 -03:00
|
|
|
# Module 'gwin'
|
|
|
|
# Generic stdwin windows
|
|
|
|
|
|
|
|
# This is used as a base class from which to derive other window types.
|
1992-12-14 08:57:56 -04:00
|
|
|
# XXX DON'T USE THIS CODE ANY MORE! It is ages old!
|
1991-12-26 09:04:16 -04:00
|
|
|
|
1991-08-16 10:24:58 -03:00
|
|
|
import stdwin, stdwinq
|
1990-12-26 11:37:05 -04:00
|
|
|
from stdwinevents import *
|
1992-12-14 08:57:56 -04:00
|
|
|
from mainloop import mainloop, register, unregister, windows
|
1990-10-13 16:23:40 -03:00
|
|
|
|
|
|
|
# Open a window
|
|
|
|
|
|
|
|
def open(title): # Open a generic window
|
|
|
|
w = stdwin.open(title)
|
|
|
|
stdwin.setdefwinsize(0, 0)
|
|
|
|
# Set default event handlers
|
|
|
|
w.draw = nop
|
|
|
|
w.char = nop
|
|
|
|
w.mdown = nop
|
|
|
|
w.mmove = nop
|
|
|
|
w.mup = nop
|
|
|
|
w.m2down = m2down
|
|
|
|
w.m2up = m2up
|
|
|
|
w.size = nop
|
|
|
|
w.move = nop
|
|
|
|
w.activate = w.deactivate = nop
|
|
|
|
w.timer = nop
|
|
|
|
# default command handlers
|
|
|
|
w.close = close
|
|
|
|
w.tab = tab
|
|
|
|
w.enter = enter
|
|
|
|
w.backspace = backspace
|
|
|
|
w.arrow = arrow
|
|
|
|
w.kleft = w.kup = w.kright = w.kdown = nop
|
1992-12-14 08:57:56 -04:00
|
|
|
w.dispatch = treatevent
|
|
|
|
register(w)
|
1990-10-13 16:23:40 -03:00
|
|
|
return w
|
|
|
|
|
|
|
|
|
|
|
|
def treatevent(e): # Handle a stdwin event
|
|
|
|
type, w, detail = e
|
1992-01-01 15:35:13 -04:00
|
|
|
if type == WE_DRAW:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.draw(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_MENU:
|
1990-10-13 16:23:40 -03:00
|
|
|
m, item = detail
|
|
|
|
m.action[item](w, m, item)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_COMMAND:
|
1990-10-13 16:23:40 -03:00
|
|
|
treatcommand(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_CHAR:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.char(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_MOUSE_DOWN:
|
1990-10-13 16:23:40 -03:00
|
|
|
if detail[1] > 1: w.m2down(w, detail)
|
|
|
|
else: w.mdown(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_MOUSE_MOVE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.mmove(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_MOUSE_UP:
|
1990-10-13 16:23:40 -03:00
|
|
|
if detail[1] > 1: w.m2up(w, detail)
|
|
|
|
else: w.mup(w, detail)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_SIZE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.size(w, w.getwinsize())
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_ACTIVATE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.activate(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_DEACTIVATE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.deactivate(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_MOVE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.move(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_TIMER:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.timer(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WE_CLOSE:
|
1990-12-26 11:37:05 -04:00
|
|
|
w.close(w)
|
1990-10-13 16:23:40 -03:00
|
|
|
|
|
|
|
def treatcommand(w, type): # Handle a we_command event
|
1992-01-01 15:35:13 -04:00
|
|
|
if type == WC_CLOSE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.close(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WC_RETURN:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.enter(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WC_TAB:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.tab(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif type == WC_BACKSPACE:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.backspace(w)
|
1991-12-26 09:04:16 -04:00
|
|
|
elif type in (WC_LEFT, WC_UP, WC_RIGHT, WC_DOWN):
|
1990-10-13 16:23:40 -03:00
|
|
|
w.arrow(w, type)
|
|
|
|
|
|
|
|
|
|
|
|
# Methods
|
|
|
|
|
|
|
|
def close(w): # Close method
|
1992-12-14 08:57:56 -04:00
|
|
|
unregister(w)
|
|
|
|
del w.close # Delete our close function
|
|
|
|
w.close() # Call the close method
|
1990-10-13 16:23:40 -03:00
|
|
|
|
|
|
|
def arrow(w, detail): # Arrow key method
|
1992-01-01 15:35:13 -04:00
|
|
|
if detail == WC_LEFT:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.kleft(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif detail == WC_UP:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.kup(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif detail == WC_RIGHT:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.kright(w)
|
1992-01-01 15:35:13 -04:00
|
|
|
elif detail == WC_DOWN:
|
1990-10-13 16:23:40 -03:00
|
|
|
w.kdown(w)
|
|
|
|
|
|
|
|
|
|
|
|
# Trivial methods
|
|
|
|
|
|
|
|
def tab(w): w.char(w, '\t')
|
|
|
|
def enter(w): w.char(w, '\n') # 'return' is a Python reserved word
|
|
|
|
def backspace(w): w.char(w, '\b')
|
|
|
|
def m2down(w, detail): w.mdown(w, detail)
|
|
|
|
def m2up(w, detail): w.mup(w, detail)
|
1992-12-14 08:57:56 -04:00
|
|
|
def nop(*args): pass
|