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

Just van Rossum just@letterror.com
Fri, 12 Mar 1999 15:05:27 +0100


At 10:11 AM +0100 3/12/99, 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.
>
>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'd go for #2, and try to implement a compare method which will look at the
actual control instead of the Python object. Seems relatively nice and
clean. It's just like methods:

>>> class foo:
...     def a(self): pass
...
>>> foo.a == foo.a
1
>>> foo.a is foo.a
0
>>>

Just