summaryrefslogtreecommitdiffstats
path: root/Lib/stdwin/WindowParent.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1990-11-05 19:44:36 (GMT)
committerGuido van Rossum <guido@python.org>1990-11-05 19:44:36 (GMT)
commit2e4496710494391b12a8553f652494c035bae340 (patch)
tree45d17cfebddc961fb1316c7a4514d10e62e05e1d /Lib/stdwin/WindowParent.py
parent0c89ec778d684a13a656b6b3462ae7dfd2837148 (diff)
downloadcpython-2e4496710494391b12a8553f652494c035bae340.zip
cpython-2e4496710494391b12a8553f652494c035bae340.tar.gz
cpython-2e4496710494391b12a8553f652494c035bae340.tar.bz2
Initial revision
Diffstat (limited to 'Lib/stdwin/WindowParent.py')
-rwxr-xr-xLib/stdwin/WindowParent.py92
1 files changed, 92 insertions, 0 deletions
diff --git a/Lib/stdwin/WindowParent.py b/Lib/stdwin/WindowParent.py
new file mode 100755
index 0000000..39838f7
--- /dev/null
+++ b/Lib/stdwin/WindowParent.py
@@ -0,0 +1,92 @@
+# 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.
+
+import stdwin
+from stdwinevents import *
+
+from TransParent import ManageOneChild
+
+Error = 'WindowParent.Error' # Exception
+
+class WindowParent() = ManageOneChild():
+ #
+ def create(self, (title, size)):
+ self.title = title
+ self.size = size # (width, height)
+ self.child = 0 # i.e., no child yet
+ self.win = 0 # i.e., no window yet
+ self.itimer = 0
+ self.do_mouse = 0
+ self.do_timer = 0
+ return self
+ #
+ def need_mouse(self, child): self.do_mouse = 1
+ def no_mouse(self, child): self.do_mouse = 0
+ #
+ def need_timer(self, child): self.do_timer = 1
+ def no_timer(self, child): self.do_timer = 0
+ #
+ def realize(self):
+ if self.win:
+ raise Error, 'realize(): called twice'
+ if not self.child:
+ 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)
+ self.win = stdwin.open(self.title)
+ if self.itimer:
+ self.win.settimer(self.itimer)
+ bounds = (0, 0), self.win.getwinsize()
+ self.child.setbounds(bounds)
+ #
+ 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'
+ #
+ 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
+ #
+ # Only call dispatch if we have a child
+ #
+ def dispatch(self, (type, win, detail)):
+ if win <> self.win:
+ return
+ elif type = WE_DRAW:
+ d = self.win.begindrawing()
+ self.child.draw(d, 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 = 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)
+ #