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

Steven D. Majewski sdm7g@virginia.edu
Fri, 12 Mar 1999 16:48:21 -0500 (EST)

On Fri, 12 Mar 1999, Jack Jansen wrote:

> The problem is deeper, it is a deisng problem. Let me explain, and if
> someone knows an answer please help me in the right direction.
> When FindControl() or various other Ctl routines return a control they 
> return an existing control, and I would like to return the correct
> Python object to the Python program. So, for all controls created
> through NewControl or GetNewControl we set the refcon field to the
> Python object, and we can go back and forth between Python object and
> control.

Thanks. I was wondering about this -- how some of these calls keep
from duplicating objects in Python. 

I was also wondering: 

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 ? 

> Controls that have been created by other means (in dialog boxes, for
> instance) are a problem, though. They don't have a corresponding
> Python object and no refcon field, so it is a bit unclear what I
> should do with them. Currently I just refuse to return them, which is
> clearly not the optimal solution. I could create the control object
> and put in the refcon link, or I could create it without the refcon
> link. The first solution has the advantage that if the control is
> returned twice you get the same Python object twice, but the
> disadvantage that memory will be leaked (as the control is freed by
> some other package you won't get the chance to free the Python
> object).
> The second method doesn't leak memory, but if you call FindControl
> twice it will return two different Python objects pointing to the same 
> Control object.
> Comments and insights, anyone?

I would say try method #2, and add a function to set refcon to self
so that it can be registered. Doing it automatically (#1) would not
be a problem for any of my code, but I could imagine that using
Python in embedded apps or with other GUI extensions could likely
be a problem. For example, doesn't PowerPlant use the RefCon ? 
( Wrapping PowerPlant or maybe MacZoop is still one of my 
  one-of-these-days-when-I-have-more-time-to-play day dreams. [*])

[ Wasn't there a thread a while back in the newsgroup about the
  inverse of id() -- wanted to do some sort of similar registration
  in Windows ? i.e. a find-Python-object-by-address function. ] 

[(*) 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! ] 

---|  Steven D. Majewski   (804-982-0831)  <sdm7g@Virginia.EDU>  |---
---|  Department of Molecular Physiology and Biological Physics  |---
---|  University of Virginia             Health Sciences Center  |---
---|  P.O. Box 10011            Charlottesville, VA  22906-0011  |---

    Caldera Open Linux: "Powerful and easy to use!" -- Microsoft(*)
     (*) <http://www.pathfinder.com/fortune/1999/03/01/mic.html>