summaryrefslogtreecommitdiffstats
path: root/Lib/stdwin
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1991-04-07 13:37:05 (GMT)
committerGuido van Rossum <guido@python.org>1991-04-07 13:37:05 (GMT)
commit117dbcb2fe96b772212e557b843f61d4c2b59141 (patch)
tree28172b79994a5bc944576a2ffe7ef333afdca72d /Lib/stdwin
parent4f4794a9a0efe3261405875620fd0c2ebca8f7be (diff)
downloadcpython-117dbcb2fe96b772212e557b843f61d4c2b59141.zip
cpython-117dbcb2fe96b772212e557b843f61d4c2b59141.tar.gz
cpython-117dbcb2fe96b772212e557b843f61d4c2b59141.tar.bz2
Added window list management functionality.
Automatically call self.destroy() if WE_CLOSE event dispatched. Added keyboard, alternate drawing and getwindow interface. Call child's realize method.
Diffstat (limited to 'Lib/stdwin')
-rwxr-xr-xLib/stdwin/WindowParent.py69
1 files changed, 63 insertions, 6 deletions
diff --git a/Lib/stdwin/WindowParent.py b/Lib/stdwin/WindowParent.py
index 5c72984..cc0add9 100755
--- a/Lib/stdwin/WindowParent.py
+++ b/Lib/stdwin/WindowParent.py
@@ -1,6 +1,8 @@
# 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.
+#
+# There is also some support for a standard main loop here.
import stdwin
from stdwinevents import *
@@ -9,6 +11,8 @@ from TransParent import ManageOneChild
Error = 'WindowParent.Error' # Exception
+WindowList = [] # List containing all windows
+
class WindowParent() = ManageOneChild():
#
def create(self, (title, size)):
@@ -22,18 +26,29 @@ class WindowParent() = ManageOneChild():
self.win = 0
self.itimer = 0
self.do_mouse = 0
+ self.do_keybd = 0
self.do_timer = 0
+ self.do_altdraw = 0
#
def destroy(self):
+ if self.win in WindowList:
+ import util
+ util.remove(self.win, WindowList)
if self.child: self.child.destroy()
self._reset()
#
def need_mouse(self, child): self.do_mouse = 1
def no_mouse(self, child): self.do_mouse = 0
#
+ def need_keybd(self, child): self.do_keybd = 1
+ def no_keybd(self, child): self.do_keybd = 0
+ #
def need_timer(self, child): self.do_timer = 1
def no_timer(self, child): self.do_timer = 0
#
+ def need_altdraw(self, child): self.do_altdraw = 1
+ def no_altdraw(self, child): self.do_altdraw = 0
+ #
def realize(self):
if self.win:
raise Error, 'realize(): called twice'
@@ -41,15 +56,25 @@ class WindowParent() = ManageOneChild():
raise Error, 'realize(): no child'
size = self.child.minsize(self.beginmeasuring())
self.size = max(self.size[0], size[0]), \
- max(self.size[1], size[1])
- #stdwin.setdefwinsize(self.size)
+ max(self.size[1], size[1])
+ # XXX stdwin.setdefwinsize(self.size)
# XXX Compensate stdwin bug:
- stdwin.setdefwinsize(self.size[0]+4, self.size[1]+2)
+ stdwin.setdefwinsize(self.size[0]+4, min(300, self.size[1]+2))
self.win = stdwin.open(self.title)
+ self.win.setdocsize(self.size)
if self.itimer:
self.win.settimer(self.itimer)
bounds = (0, 0), self.win.getwinsize()
self.child.setbounds(bounds)
+ self.child.realize()
+ self.win.dispatch = self.dispatch
+ WindowList.append(self.win)
+ #
+ def fixup(self):
+ self.size = self.child.minsize(self.beginmeasuring())
+ self.win.setdocsize(self.size)
+ bounds = (0, 0), self.win.getwinsize()
+ self.child.setbounds(bounds)
#
def beginmeasuring(self):
# Return something with which a child can measure text
@@ -64,6 +89,12 @@ class WindowParent() = ManageOneChild():
else:
raise Error, 'begindrawing(): not realized yet'
#
+ def getwindow(self):
+ if self.win:
+ return self.win
+ else:
+ raise Error, 'getwindow(): not realized yet'
+ #
def change(self, area):
if self.win:
self.win.change(area)
@@ -86,16 +117,42 @@ class WindowParent() = ManageOneChild():
elif type = WE_DRAW:
d = self.win.begindrawing()
self.child.draw(d, detail)
+ del d
+ if self.do_altdraw: self.child.altdraw(detail)
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)
+ elif type in (WE_CHAR, WE_COMMAND):
+ if self.do_keybd: self.child.keybd(type, detail)
elif type = WE_TIMER:
if self.do_timer: self.child.timer()
elif type = WE_SIZE:
- self.win.change((0, 0), (10000, 10000)) # XXX
- bounds = (0, 0), self.win.getwinsize()
- self.child.setbounds(bounds)
+ self.fixup()
+ elif type = WE_CLOSE:
+ self.destroy()
#
+
+def MainLoop():
+ while WindowList:
+ Dispatch(stdwin.getevent())
+
+def Dispatch(event):
+ window = event[1]
+ if window in WindowList:
+ window.dispatch(event)
+ else:
+ stdwin.fleep()
+
+# Interface used by WindowSched:
+
+def CountWindows():
+ return len(WindowList)
+
+def AnyWindow():
+ if not WindowList:
+ return None
+ else:
+ return WindowList[0]