[Pythonmac-SIG] Grokking bgen and the toolbox modules
Donovan Preston
dpreston@intersight.com
Mon, 8 Oct 2001 18:24:06 -0700
Hi,
I'm trying to figure out how best to program some functionality which
will heavily rely on the Mac OS Toolbox. I'd like to do some things with
creating a QuickTime movie, adding tracks to it, etc, as well as
managing controls created by Carbon from a Carbon Nib file.
First off, I was looking at the sample code provided by Apple on OS X in
/Developer/Examples/Carbon/AppearanceSample. It looks like they are
using two toolbox calls to get a reference to a control by ID and then
get it's data. It looks like this:
GetControlByID( GetWindowRef(), &kChoosePopup, &fChoosePopup );
GetControlData( fChoosePopup, 0, kControlPopupButtonMenuRefTag, sizeof
( menu ), &menu, &actual );
How would I go about converting this to Python code that calls bgen
generated functions? I note that there is a module named Ctl, and also
that there is a function GetControlByID in there. So far so good. I note
by looking at Apple's developer documentation that the parameter types
are WindowRef, ControlID, and ControlRef (is there a better way to find
out parameter types, like a docstring on a method? Is there a way to
find this out interactively in python?)
How do I generate a window reference which I can pass to this function,
as well as a ControlID record? I know from looking at some other bgen
code that the final parameter is actually being returned to me and
python will return a nice object with the Control.
I also can guess from looking at some other bgen generated code that
GetControlData will be a method of the Control object which is returned.
I am assuming that because I don't see GetControlData in dir(Ctl) and
GetControlData takes a ControlRef as the first parameter. Am I wrong?
I guess what I am asking, is how exactly is bgen generated code
produced? How does it know to be so smart as to turn some things into
return values and some returned data into objects? And how does one go
about using bgen generated code from Python, as far as having any sort
of reference or documentation, besides reading the code? (Which isn't
too hard, really...)
Also, Jack, you mentioned in passing a while back that you would like
for some of the CarbonNib functions I had written to be generated
automatically by bgen. How exactly would one go about doing that, and
how would someone know what functions have and have not been done?
Finally, when I was trying to create a QuickTime movie earlier, some of
the parameters needed to be set to NULL, but Python wouldn't allow me to
pass None. Here's the code:
(resRefNum, myMovie) = Qt.CreateMovieFile(fsspec, "TVOD",
smSystemScript, 0)
myTrack = myMovie.NewMovieTrack(170 << 16, 85 << 16, Sound.kNoVolume);
kSpriteMediaTimeScale = 600
myMedia = myTrack.NewTrackMedia("SPRT", kSpriteMediaTimeScale, None,
None);
I need to pass None as the final two parameters, but Python won't let
me. I fixed the NewTrackMedia function by setting the third parameter
conversion function (right terminology?) from ResObj_Convert, which
won't accept Python's None, to OptResObj_Convert, which accepts Python's
None object and returns NULL to the C code. However, the fourth
parameter, which uses the conversion function PyMac_GetOSType, doesn't
allow me to pass None, and I can't seem to find one that does.
I gave up on trying to get the above code to work. Is it even possible?
I'd like to help out maintaining these toolbox modules so I can use them
in my code, but I need help understanding them first.
Sorry for asking so many questions, but I feel like there's so much
power there that I just can't use because I don't quite understand it!
Donovan