[PYTHONMAC-SIG] Show/Hide Window?

Jack Jansen Jack.Jansen@cwi.nl
Tue, 30 Sep 1997 10:29:52 +0200


> MacPython just laughs at me when I try to invoke Win.ShowWindow.

Python turns the procedural interface of the toolbox into an OO interface as 
much as possible. So, you should say:

>>> import Win
>>> w = Win.NewWindow((100,100,200,200), "title", 0, 0, -1, 1, 0)
>>> w.ShowWindow()

and it all works fine. For most toolboxes, if the first argument of a routine 
is the "natural" type of the toolbox the routine will be turned into a method.

There are some exceptions: Qd.SetPort(), for instance, since there are so many 
things that can be passed to it as an argument.

> Well, I finally noticed that everything gets imported into the Framework
> twice, e.g. Win, Windows and QD, QuickDraw.  I even found them.  Windows
> and QuickDraw are .py files that seem to have only constants in them, and
> QD and Win have the puzzle-piece icons that mean extensions to me.  I guess
> they have the executable code, but I have no idea how to find out what
> routines are actually there.

The long-named modules Window, QuickDraw, etc. have the symbolic constants, 
the short-named modules are indeed dynamically loaded C modules with the real 
interface. Use "dir(Win)" to find out which functions are defined in the Win 
module. Use "w = NewWindow(....); dir(w)" to find out which methods the Window 
objects support. Use "print Win.NewWindow.__doc__" to print the argument list 
and return values of the Python implementation of the method or function. Use 
these three snippets of information plus a Mac programmers manual plus a lot 
of creativity to find out how to use the routine.

I agree that this is all very tricky, but documenting all the calls is beyond 
me.

> 
> Here's another puzzlement: I can't find any code in the Framework that
> either hides a window or disposes of it, yet the windows disappear when I
> click the close box.

When a Window object's reference count drops to zero the window is disposed, 
which removes it from the screen, hence the DisposeWindow call is also missing 
as it is implicit in Python.  There is one situation where you have to be 
aware of this: when a reference to your window is tucked away somewhere 
(usually in a stacktrace in sys.last_exc and friends). Then you close your 
FrameWork object and the window doesn't go away. The workaround is to raise a 
dummy exception and catch it, to clear the stacktrace.

--
Jack Jansen             | ++++ stop the execution of Mumia Abu-Jamal ++++
Jack.Jansen@cwi.nl      | ++++ if you agree copy these lines to your sig ++++
http://www.cwi.nl/~jack | see http://www.xs4all.nl/~tank/spg-l/sigaction.htm 



_______________
PYTHONMAC-SIG  - SIG on Python for the Apple Macintosh

send messages to: pythonmac-sig@python.org
administrivia to: pythonmac-sig-request@python.org
_______________