[Pythonmac-SIG] mac event loop

Jack Jansen Jack.Jansen@cwi.nl
Thu, 22 Oct 1998 11:39:59 +0200


> 
> For various reasons I've made my event loop from scratch an do not use
> FrameWork.py. As expected I've got some problems :)
> 
> (1) I would like to override the std zoom in / zoom out behavior for
> something like a full screen mode. According to "Inside Macintosh" I have to
> change the stdState of the WStateData structure in the dataHandle field of
> the window record. 
> 
> in PASCAL: (Toolbox Essentials 4-55)
> 
>     WSTateDataHandle(WindowPeek(thisWindow)^.dataHandle)^^stdState :=
> zoomRect 
> 
> Can that be done in python and if so, how ? If not I can use SizeWindow()
> with an flag but I prefer to avoid that way.

You cannot get at the dataHandle attribute currently. But, note that you don't 
need this to implement zooming: ZoomWindow() is usually enough. You only need 
to get at the stdState structure if you want to maximized state to be 
something different than (almost) the whole screen.

> (2) The multiple event loop problem bites me too :). I normally use JvR's
> IDE and have to update it's windows manually after running my application.
> This is annoying on the long run. May be I could check for the wid attribute
> of the frontmost window like FrameWork.py but I understood that there are
> other loops/windows too. Is there or will be there a generalized way to
> handle this ?

Passing your event to MacOS.HandleEvent() when you notice that the event isn't 
for you will do part of the work: it will at least update the stdio window and 
do cmd-. processing if you haven't disabled it. There may be something similar 
for IDE, but I'll leave it to Just to answer that.

A generalized way to do this is actually pretty simple to implement, but I 
haven't gotten around to it yet. A python module EventLoops would be needed, 
with an API something like
    register(identity, myeventhandler)
    unregister(identity)
    handle_event(identity, event)
Where identity is an opaque object identifying the module/object with a 
mainloop. In each mainloop you handle all the events that are yours, and pass 
the rest to handle_event. Handle_event will then call the myeventhandler 
routines of all the other mainloop objects (except for the one of the module 
passing the event in, hence the identity object) until one returns non-zero, 
signifying the event is fully handled.

> (3) I (presently) don't think that my application will need multi threading.
> Is there a need to implement async events anyway ? (I dont have any clue
> about multi threading on Mac/Python up to now :)

It depends. For my applications a combination of select() and WaitNextEvent() 
usually does the trick. You can integrate the select stuff into your mainloop 
by adding an interface setiocallback(selectableobject, callback), and in your 
mainloop calling select() when WaitNextEvent returns. You can also change the 
timeout to WNE depending on whether or not any I/O objects are being waited on.
Idle routines for things like pushing quicktime movies along can be 
implemented in the same way.

> 
> (4) My last point is a suggestion. It is recommended by Apple to use
> menuID's from 1 to 235 for application *submenus* and each other number >
> 128 for menus (Toolbox Essentials 3-44). When I used 1 I got a conflict with
> the IDE or python-out. I didn't check submenus up to now but I think there
> is a need for two funktions like
> 
> GetMenuID()    -> menuID
> GetSubMenuID() -> submenuID

This sounds like a good idea, but I'm unsure where to add the methods. 
FrameWork.py?

Also, does anyone _really_ understand the section in IM (menu manager, page 
3-44)? I get the impression that the restriction that main menus should have 
IDs > 128 only holds for menus read from resources, and the description of 
NewMenu also doesn't mention the >128 restriction...
--
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