1990-11-05 15:44:36 -04:00
|
|
|
# A 'WindowParent' is the only module that uses real stdwin functionality.
|
|
|
|
# It is the root of the tree.
|
|
|
|
# It should have exactly one child when realized.
|
1991-04-07 10:37:05 -03:00
|
|
|
#
|
1991-08-16 10:22:23 -03:00
|
|
|
# There is also an alternative interface to "mainloop" here.
|
1990-11-05 15:44:36 -04:00
|
|
|
|
|
|
|
import stdwin
|
|
|
|
from stdwinevents import *
|
1991-08-16 10:22:23 -03:00
|
|
|
import mainloop
|
1990-11-05 15:44:36 -04:00
|
|
|
|
|
|
|
from TransParent import ManageOneChild
|
|
|
|
|
|
|
|
Error = 'WindowParent.Error' # Exception
|
|
|
|
|
|
|
|
class WindowParent() = ManageOneChild():
|
|
|
|
#
|
|
|
|
def create(self, (title, size)):
|
|
|
|
self.title = title
|
|
|
|
self.size = size # (width, height)
|
1991-01-23 09:43:16 -04:00
|
|
|
self._reset()
|
1991-08-16 10:22:23 -03:00
|
|
|
self.close_hook = WindowParent.delayed_destroy
|
1991-01-23 09:43:16 -04:00
|
|
|
return self
|
|
|
|
#
|
|
|
|
def _reset(self):
|
1991-05-14 09:22:25 -03:00
|
|
|
self.child = None
|
|
|
|
self.win = None
|
1990-11-05 15:44:36 -04:00
|
|
|
self.itimer = 0
|
|
|
|
self.do_mouse = 0
|
1991-04-07 10:37:05 -03:00
|
|
|
self.do_keybd = 0
|
1990-11-05 15:44:36 -04:00
|
|
|
self.do_timer = 0
|
1991-04-07 10:37:05 -03:00
|
|
|
self.do_altdraw = 0
|
1991-04-21 16:28:44 -03:00
|
|
|
self.pending_destroy = 0
|
1991-05-14 09:22:25 -03:00
|
|
|
self.close_hook = None
|
1991-08-16 10:22:23 -03:00
|
|
|
self.menu_hook = None
|
1991-01-23 09:43:16 -04:00
|
|
|
#
|
|
|
|
def destroy(self):
|
1991-08-16 10:22:23 -03:00
|
|
|
mainloop.unregister(self.win)
|
1991-01-23 09:43:16 -04:00
|
|
|
if self.child: self.child.destroy()
|
|
|
|
self._reset()
|
1990-11-05 15:44:36 -04:00
|
|
|
#
|
1991-04-21 16:28:44 -03:00
|
|
|
def delayed_destroy(self):
|
|
|
|
# This interface to be used by 'Close' buttons etc.;
|
|
|
|
# destroying a window from within a button hook
|
|
|
|
# is not a good idea...
|
|
|
|
self.pending_destroy = 1
|
|
|
|
#
|
1991-05-14 09:22:25 -03:00
|
|
|
def close_trigger(self):
|
|
|
|
if self.close_hook: self.close_hook(self)
|
|
|
|
#
|
1991-08-16 10:22:23 -03:00
|
|
|
def menu_trigger(self, (menu, item)):
|
|
|
|
if self.menu_hook:
|
|
|
|
self.menu_hook(self, menu, item)
|
|
|
|
#
|
1990-11-05 15:44:36 -04:00
|
|
|
def need_mouse(self, child): self.do_mouse = 1
|
|
|
|
def no_mouse(self, child): self.do_mouse = 0
|
|
|
|
#
|
1991-08-16 10:22:23 -03:00
|
|
|
def need_keybd(self, child):
|
|
|
|
self.do_keybd = 1
|
|
|
|
self.child.activate()
|
|
|
|
def no_keybd(self, child):
|
|
|
|
self.do_keybd = 0
|
|
|
|
self.child.deactivate()
|
1991-04-07 10:37:05 -03:00
|
|
|
#
|
1990-11-05 15:44:36 -04:00
|
|
|
def need_timer(self, child): self.do_timer = 1
|
|
|
|
def no_timer(self, child): self.do_timer = 0
|
|
|
|
#
|
1991-04-07 10:37:05 -03:00
|
|
|
def need_altdraw(self, child): self.do_altdraw = 1
|
|
|
|
def no_altdraw(self, child): self.do_altdraw = 0
|
|
|
|
#
|
1990-11-05 15:44:36 -04:00
|
|
|
def realize(self):
|
|
|
|
if self.win:
|
|
|
|
raise Error, 'realize(): called twice'
|
|
|
|
if not self.child:
|
|
|
|
raise Error, 'realize(): no child'
|
1991-08-16 10:22:23 -03:00
|
|
|
# Compute suggested size
|
|
|
|
self.size = self.child.getminsize(self.beginmeasuring(), \
|
|
|
|
self.size)
|
|
|
|
save_defsize = stdwin.getdefwinsize()
|
|
|
|
scrwidth, scrheight = stdwin.getscrsize()
|
|
|
|
width, height = self.size
|
|
|
|
if width > scrwidth:
|
|
|
|
width = scrwidth * 2/3
|
|
|
|
if height > scrheight:
|
|
|
|
height = scrheight * 2/3
|
|
|
|
stdwin.setdefwinsize(width, height)
|
|
|
|
self.hbar, self.vbar = stdwin.getdefscrollbars()
|
1990-11-05 15:44:36 -04:00
|
|
|
self.win = stdwin.open(self.title)
|
1991-08-16 10:22:23 -03:00
|
|
|
stdwin.setdefwinsize(save_defsize)
|
1991-04-07 10:37:05 -03:00
|
|
|
self.win.setdocsize(self.size)
|
1990-11-05 15:44:36 -04:00
|
|
|
if self.itimer:
|
|
|
|
self.win.settimer(self.itimer)
|
1991-08-16 10:22:23 -03:00
|
|
|
width, height = self.win.getwinsize()
|
|
|
|
if self.hbar:
|
|
|
|
width = self.size[0]
|
|
|
|
if self.vbar:
|
|
|
|
height = self.size[1]
|
|
|
|
self.child.setbounds((0, 0), (width, height))
|
1991-04-07 10:37:05 -03:00
|
|
|
self.child.realize()
|
|
|
|
self.win.dispatch = self.dispatch
|
1991-08-16 10:22:23 -03:00
|
|
|
mainloop.register(self.win)
|
1991-04-07 10:37:05 -03:00
|
|
|
#
|
|
|
|
def fixup(self):
|
1991-08-16 10:22:23 -03:00
|
|
|
# XXX This could share code with realize() above
|
|
|
|
self.size = self.child.getminsize(self.beginmeasuring(), \
|
|
|
|
self.win.getwinsize())
|
1991-04-07 10:37:05 -03:00
|
|
|
self.win.setdocsize(self.size)
|
1991-08-16 10:22:23 -03:00
|
|
|
width, height = self.win.getwinsize()
|
|
|
|
if self.hbar:
|
|
|
|
width = self.size[0]
|
|
|
|
if self.vbar:
|
|
|
|
height = self.size[1]
|
|
|
|
self.child.setbounds((0, 0), (width, height))
|
1991-05-14 09:22:25 -03:00
|
|
|
# Force a redraw of the entire window:
|
1991-08-16 10:22:23 -03:00
|
|
|
self.win.change((0, 0), self.size)
|
1990-11-05 15:44:36 -04:00
|
|
|
#
|
|
|
|
def beginmeasuring(self):
|
|
|
|
# Return something with which a child can measure text
|
|
|
|
if self.win:
|
|
|
|
return self.win.begindrawing()
|
|
|
|
else:
|
|
|
|
return stdwin
|
|
|
|
#
|
|
|
|
def begindrawing(self):
|
|
|
|
if self.win:
|
|
|
|
return self.win.begindrawing()
|
|
|
|
else:
|
|
|
|
raise Error, 'begindrawing(): not realized yet'
|
|
|
|
#
|
1991-04-07 10:37:05 -03:00
|
|
|
def getwindow(self):
|
|
|
|
if self.win:
|
|
|
|
return self.win
|
|
|
|
else:
|
|
|
|
raise Error, 'getwindow(): not realized yet'
|
|
|
|
#
|
1990-11-05 15:44:36 -04:00
|
|
|
def change(self, area):
|
|
|
|
if self.win:
|
|
|
|
self.win.change(area)
|
|
|
|
#
|
|
|
|
def scroll(self, args):
|
|
|
|
if self.win:
|
|
|
|
self.win.scroll(args)
|
|
|
|
#
|
|
|
|
def settimer(self, itimer):
|
|
|
|
if self.win:
|
|
|
|
self.win.settimer(itimer)
|
|
|
|
else:
|
|
|
|
self.itimer = itimer
|
|
|
|
#
|
1991-04-21 16:28:44 -03:00
|
|
|
# Only call dispatch once we are realized
|
1990-11-05 15:44:36 -04:00
|
|
|
#
|
|
|
|
def dispatch(self, (type, win, detail)):
|
1991-04-21 16:28:44 -03:00
|
|
|
if type = WE_DRAW:
|
1990-11-05 15:44:36 -04:00
|
|
|
d = self.win.begindrawing()
|
|
|
|
self.child.draw(d, detail)
|
1991-04-07 10:37:05 -03:00
|
|
|
del d
|
|
|
|
if self.do_altdraw: self.child.altdraw(detail)
|
1990-11-05 15:44:36 -04:00
|
|
|
elif type = WE_MOUSE_DOWN:
|
|
|
|
if self.do_mouse: self.child.mouse_down(detail)
|
|
|
|
elif type = WE_MOUSE_MOVE:
|
|
|
|
if self.do_mouse: self.child.mouse_move(detail)
|
|
|
|
elif type = WE_MOUSE_UP:
|
|
|
|
if self.do_mouse: self.child.mouse_up(detail)
|
1991-04-07 10:37:05 -03:00
|
|
|
elif type in (WE_CHAR, WE_COMMAND):
|
|
|
|
if self.do_keybd: self.child.keybd(type, detail)
|
1990-11-05 15:44:36 -04:00
|
|
|
elif type = WE_TIMER:
|
|
|
|
if self.do_timer: self.child.timer()
|
|
|
|
elif type = WE_SIZE:
|
1991-04-07 10:37:05 -03:00
|
|
|
self.fixup()
|
|
|
|
elif type = WE_CLOSE:
|
1991-05-14 09:22:25 -03:00
|
|
|
self.close_trigger()
|
1991-08-16 10:22:23 -03:00
|
|
|
elif type = WE_MENU:
|
|
|
|
self.menu_trigger(detail)
|
1991-04-21 16:28:44 -03:00
|
|
|
if self.pending_destroy:
|
1991-04-07 10:37:05 -03:00
|
|
|
self.destroy()
|
1990-11-05 15:44:36 -04:00
|
|
|
#
|
1991-04-07 10:37:05 -03:00
|
|
|
|
|
|
|
def MainLoop():
|
1991-08-16 10:22:23 -03:00
|
|
|
mainloop.mainloop()
|
1991-04-07 10:37:05 -03:00
|
|
|
|
|
|
|
def Dispatch(event):
|
1991-08-16 10:22:23 -03:00
|
|
|
mainloop.dispatch(event)
|
1991-04-07 10:37:05 -03:00
|
|
|
|
|
|
|
# Interface used by WindowSched:
|
|
|
|
|
|
|
|
def CountWindows():
|
1991-08-16 10:22:23 -03:00
|
|
|
return mainloop.countwindows()
|
1991-04-07 10:37:05 -03:00
|
|
|
|
|
|
|
def AnyWindow():
|
1991-08-16 10:22:23 -03:00
|
|
|
return mainloop.anywindow()
|