[Pythonmac-SIG] Ctl.CreateRootControl( window ) always returns None

Jack Jansen Jack.Jansen@cwi.nl
Sat, 13 Mar 1999 22:46:25 +0100


Recently, "Steven D. Majewski" <sdm7g@virginia.edu> said:
> I currently use the following function
> 
> def ditl():
> 	return Res.Resource(struct.pack( 'h', -1 ))
> 
> 
> to generate an empty DITL reference for calls to NewDialog, and
> I was wondering if using this anonymously is a problem? -- the
> toolbox will expect that bit of memory to continue existing, while
> Python may dispose of it. Do I need to keep a reference to it 
> somewhere ? 

In this case: no. Res.Resource objects are among the ones that don't
get cleaned up automatically, mainly because the cleanup depends on
what is in the object (a real resource, a handle, or something like a
DialogHandle, etc). What I'd like to do some day is to have some way
of doing the right cleanup for the object, plus methods to change the
"class" of the object (which is needed when you DetachResource(), for
instance). The class hierarchy should be something like
class UnmanagedHandle:
	all handle methods, including DisposeHandle
	magic methods to_ManagedHandle, to_Resource, etc that change
	  the class of the object
class Handle(UnmanagedHandle):
	__del__ does implicit DisposeHandle
class Resource(UnmanagedHandle):
	resource methods, __del__ does FreeResource
class UnmanagedMenuHandle(UnmanagedHandle):
	all the things you do to menus
class MenuHandle(UnmanagedMenuHandle):
	 __del__ does FreeMenu or whatever
... etc

I think I'd have to change the actual object type (in stead of the
more normal-python-paradigm-conforming cast that copies the object)
because one of the reasons you'd want to cast the object is to change
the disposal semantics: if you have created a menu but you
subsequently pass it to some other (C-)package you don't want to
dispose it when you drop the Python object. Something similar holds
for Controls, where Apple in their infinite wisdom have decided to
auto-dispose them when the window containing them is disposed. Fine in 
C, but pretty gruesome in Python because if we'd automatically dispose 
the controls when the Python object dies this would mean serious
trouble if the window got garbage-collected first and the control
object later...

> [(*) However, at the moment I'm on a history binge after reading a 
>   bunch of Patrick O'Brian novels. I'm reading about what a bunch
>   of bloodthirsty warlike imperialists you Dutch used to be a 
>   couple hundred years ago! ] 

Ah, but that doesn't concern me. I'm half Irish, after all, and the
Irish are well-known for their abhorrence of violence:-)
--
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