[Pythonmac-SIG] Python RAD tools

Donovan Preston dp@ulaluma.com
Mon, 14 Jan 2002 13:33:26 -0800


--Apple-Mail-1-524552443
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


On Monday, January 14, 2002, at 12:43 PM, Patrick Curtain wrote:

> Donovan, how does one -build- that library from _IBCarbon.c.  I'd love 
> to try it.  --p

Cool. Yeah, I meant to add that, but my message got a bit long.

First, let me start by assuming you have built Python as a framework on 
OS X from the 2.2 source or CVS. Details are in the README. I will also 
assume you have built the Python interpreter bundle in Mac/OSX as 
detailed in the README there. You also need to have installed the Mac 
subtree and add the Mac subtree to your path, also as detailed in the 
README in Mac/OSX.

It's possible to use the module on OS 9 as well, and I have done so, but 
it's a bit more involved so I'll leave that out for now.

In your Python source tree, navigate to Mac/Modules. Create a folder 
called ibcarbon. Place my attached files from the previous message there.

In the main level of the python source, there is a setup.py file. This 
file builds all of the modules. Open this in your favorite text editor 
and search for one of the Mac modules, say, CarbonEvt. Here are the 
lines that sets up the CarbonEvt module to be compiled:

                 exts.append( Extension('_CarbonEvt', 
['carbonevt/_CarbonEvtmodule.c'],
             		extra_link_args=['-framework', 'Carbon']) )

Copy and paste these two lines and change CarbonEvt to IBCarbon, like 
this:

                 exts.append( Extension('_IBCarbon', 
['ibcarbon/_IBCarbon.c'],
             		extra_link_args=['-framework', 'Carbon']) )

Save setup.py and in a terminal at the top level of the Python source 
tree, run 'make sharedinstall'. This will remake all the shared 
libraries and install them.

Oh, and one more thing. We've just created a module called _IBCarbon, 
but we want to say 'import IBCarbon' (no underscore).
Not sure why things are set up this way, but you need to create a file:

/Library/Frameworks/Python.framework/Versions/Current/Mac/Lib/Carbon/IBCarbon.
py

Containing the line:

from _IBCarbon import *

Next, we need to execute some Python code from within a Bundle. If you 
built the Python interpreter bundle as I mentioned previously, there 
will be one available in /Applications/Python.app. Right click (or 
control click) on this bundle and choose "Show package contents." 
Navigate into Contents/Resources inside of the bundle. Here is where we 
can put a __main__.py file which will be run when the application is 
double clicked. Inside of English.lproj is where the Interface Builder 
nib we will load goes.

I have attached a __main__.py file which you can drag into 
Contents/Resources. There's a few bug fixes from the code in my last 
message. I've also attached a nib which you can drag inside of 
English.lproj. Try adding widgets to this nib!

Now you can fire up Python.app and create all the new windows you want!

Donovan



--Apple-Mail-1-524552443
Content-Disposition: attachment
Content-Type: multipart/appledouble;
	boundary=Apple-Mail-2-524552446


--Apple-Mail-2-524552446
Content-Disposition: attachment;
	filename=__main__.py
Content-Transfer-Encoding: base64
Content-Type: application/applefile;
	name="__main__.py"

AAUWBwACAAAAAAAAAAAAAAAAAAAAAAAAAAMAAAAJAAAAPgAAAAoAAAADAAAASAAAAAsAAAACAAAA
UwAAAX5URVhUUipjaAAAX19tYWluX18ucHkAAAEAAAABTAAAAEwAAAAyAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
SAAJTW9uYWNvAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABgAEAC8AAwL3AxkALwADAvcDGbho
jOEAAANLAAADSwAAAAABAAAAAQAAAAFMAAAATAAAADIAJsCQAVoAAAAcADIAAE1QU1IAAAAKA+3/
/wAAAAAB5MDU

--Apple-Mail-2-524552446
Content-Disposition: attachment;
	filename=__main__.py
Content-Transfer-Encoding: 7bit
Content-Type: application/text;
	x-mac-creator=522A6368;
	x-unix-mode=0644;
	x-mac-type=54455854;
	name="__main__.py"

from Carbon import IBCarbon
from Carbon import CarbonEvt					# The CarbonEvents functions
from Carbon import CarbonEvents				# The CarbonEvents constants

windowlist = []

def commandCallback(handler, event):
	print "yo"
	# Get the event record describing what command was executed
	result = event.GetEventParameter(CarbonEvents.kEventParamDirectObject, CarbonEvents.typeHICommand)
	event = result[4:8]
	if event == 'new ':
		# If the user selected new window, load a nib and unarchive a window
		global windowlist
		# Create a reference to the nib named 'main' in my Application Bundle
		nib = IBCarbon.CreateNibReference('main')
		# Unarchive a window from the nib
		window = nib.CreateWindowFromNib('MainWindow')
		# Keep the window from disappearing  after the function falls out of scope
		windowlist.append(window)
		window.ShowWindow()
	return CarbonEvents.eventNotHandledErr

# Install a menu bar
nib = IBCarbon.CreateNibReference('main')
nib.SetMenuBarFromNib('MenuBar')


# Get the application event target
AppTarget = CarbonEvt.GetApplicationEventTarget()
# Install a handler for "command" events on the application
# Command events can be set using the inspector panel in Interface Builder
# Many basic commands, such as new, quit, copy, paste, are already set (and many are handled automatically)
cmdsHandler = AppTarget.InstallEventHandler(('cmds', 1), commandCallback)

CarbonEvt.RunApplicationEventLoop()
--Apple-Mail-2-524552446--

--Apple-Mail-1-524552443
Content-Disposition: attachment;
	filename=main.nib
Content-Type: multipart/x-folder;
	boundary=Apple-Mail-3-524552448;
	x-unix-mode=0777;
	name="main.nib"


--Apple-Mail-3-524552448
Content-Disposition: attachment;
	filename=classes.nib
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="classes.nib"

{
IBClasses = ();
IBVersion = 1;
}

--Apple-Mail-3-524552448
Content-Disposition: attachment;
	filename=objects.xib
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="objects.xib"

<?xml version="1.0" standalone="yes"?>
<object class="NSIBObjectData">
  <string name="targetFramework">IBCarbonFramework</string>
  <object name="rootObject" class="NSCustomObject" id="1">
    <string name="customClass">NSApplication</string>
  </object>
  <array count="37" name="allObjects">
    <object class="IBCarbonMenu" id="29">
      <string name="title">main</string>
      <array count="4" name="items">
        <object class="IBCarbonMenuItem" id="185">
          <string name="title">NewApplication</string>
          <object name="submenu" class="IBCarbonMenu" id="184">
            <string name="title">NewApplication</string>
            <array count="2" name="items">
              <object class="IBCarbonMenuItem" id="187">
                <string name="title">About NewApplication</string>
                <int name="keyEquivalentModifier">0</int>
                <ostype name="command">abou</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="186">
                <boolean name="separator">TRUE</boolean>
              </object>
            </array>
            <string name="name">_NSAppleMenu</string>
          </object>
        </object>
        <object class="IBCarbonMenuItem" id="127">
          <string name="title">File</string>
          <object name="submenu" class="IBCarbonMenu" id="131">
            <string name="title">File</string>
            <array count="10" name="items">
              <object class="IBCarbonMenuItem" id="139">
                <string name="title">New</string>
                <string name="keyEquivalent">n</string>
                <ostype name="command">new </ostype>
              </object>
              <object class="IBCarbonMenuItem" id="134">
                <string name="title">Open...</string>
                <string name="keyEquivalent">o</string>
                <ostype name="command">open</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="133">
                <boolean name="separator">TRUE</boolean>
              </object>
              <object class="IBCarbonMenuItem" id="130">
                <string name="title">Close</string>
                <string name="keyEquivalent">w</string>
                <ostype name="command">clos</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="138">
                <string name="title">Save</string>
                <string name="keyEquivalent">s</string>
                <ostype name="command">save</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="137">
                <string name="title">Save As...</string>
                <string name="keyEquivalent">S</string>
                <ostype name="command">svas</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="132">
                <string name="title">Revert</string>
                <string name="keyEquivalent">r</string>
                <ostype name="command">rvrt</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="128">
                <boolean name="separator">TRUE</boolean>
              </object>
              <object class="IBCarbonMenuItem" id="135">
                <string name="title">Page Setup...</string>
                <string name="keyEquivalent">P</string>
                <ostype name="command">page</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="136">
                <string name="title">Print...</string>
                <string name="keyEquivalent">p</string>
                <ostype name="command">prnt</ostype>
              </object>
            </array>
          </object>
        </object>
        <object class="IBCarbonMenuItem" id="152">
          <string name="title">Edit</string>
          <object name="submenu" class="IBCarbonMenu" id="147">
            <string name="title">Edit</string>
            <array count="8" name="items">
              <object class="IBCarbonMenuItem" id="141">
                <string name="title">Undo</string>
                <string name="keyEquivalent">z</string>
                <ostype name="command">undo</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="146">
                <string name="title">Redo</string>
                <string name="keyEquivalent">Z</string>
                <ostype name="command">redo</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="142">
                <boolean name="separator">TRUE</boolean>
              </object>
              <object class="IBCarbonMenuItem" id="143">
                <string name="title">Cut</string>
                <string name="keyEquivalent">x</string>
                <ostype name="command">cut </ostype>
              </object>
              <object class="IBCarbonMenuItem" id="149">
                <string name="title">Copy</string>
                <string name="keyEquivalent">c</string>
                <ostype name="command">copy</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="144">
                <string name="title">Paste</string>
                <string name="keyEquivalent">v</string>
                <ostype name="command">past</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="151">
                <string name="title">Clear</string>
                <ostype name="command">clea</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="148">
                <string name="title">Select All</string>
                <string name="keyEquivalent">a</string>
                <ostype name="command">sall</ostype>
              </object>
            </array>
          </object>
        </object>
        <object class="IBCarbonMenuItem" id="153">
          <string name="title">Window</string>
          <object name="submenu" class="IBCarbonMenu" id="154">
            <string name="title">Window</string>
            <array count="5" name="items">
              <object class="IBCarbonMenuItem" id="155">
                <boolean name="dynamic">TRUE</boolean>
                <string name="title">Minimize Window</string>
                <string name="keyEquivalent">m</string>
                <ostype name="command">mini</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="188">
                <boolean name="dynamic">TRUE</boolean>
                <string name="title">Minimize All Windows</string>
                <string name="keyEquivalent">m</string>
                <int name="keyEquivalentModifier">1572864</int>
                <ostype name="command">mina</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="156">
                <boolean name="separator">TRUE</boolean>
              </object>
              <object class="IBCarbonMenuItem" id="157">
                <boolean name="dynamic">TRUE</boolean>
                <string name="title">Bring All to Front</string>
                <ostype name="command">bfrt</ostype>
              </object>
              <object class="IBCarbonMenuItem" id="189">
                <boolean name="dynamic">TRUE</boolean>
                <string name="title">Arrange in Front</string>
                <int name="keyEquivalentModifier">1572864</int>
                <ostype name="command">frnt</ostype>
              </object>
            </array>
            <string name="name">_NSWindowsMenu</string>
          </object>
        </object>
      </array>
      <string name="name">_NSMainMenu</string>
    </object>
    <reference idRef="127"/>
    <reference idRef="128"/>
    <reference idRef="130"/>
    <reference idRef="131"/>
    <reference idRef="132"/>
    <reference idRef="133"/>
    <reference idRef="134"/>
    <reference idRef="135"/>
    <reference idRef="136"/>
    <reference idRef="137"/>
    <reference idRef="138"/>
    <reference idRef="139"/>
    <reference idRef="141"/>
    <reference idRef="142"/>
    <reference idRef="143"/>
    <reference idRef="144"/>
    <reference idRef="146"/>
    <reference idRef="147"/>
    <reference idRef="148"/>
    <reference idRef="149"/>
    <reference idRef="151"/>
    <reference idRef="152"/>
    <reference idRef="153"/>
    <reference idRef="154"/>
    <reference idRef="155"/>
    <reference idRef="156"/>
    <reference idRef="157"/>
    <object class="IBCarbonWindow" id="166">
      <string name="windowRect">49 5 209 501 </string>
      <string name="title">Window</string>
      <object name="rootControl" class="IBCarbonRootControl" id="167">
        <string name="bounds">0 0 160 496 </string>
        <array count="1" name="subviews">
          <object class="IBCarbonStaticText" id="191">
            <string name="bounds">20 142 36 341 </string>
            <string name="title">Hello from IBCarbonRuntime!</string>
          </object>
        </array>
      </object>
      <int name="carbonWindowClass">6</int>
      <int name="themeBrush">5</int>
      <int name="windowPosition">4</int>
    </object>
    <reference idRef="167"/>
    <reference idRef="184"/>
    <reference idRef="185"/>
    <reference idRef="186"/>
    <reference idRef="187"/>
    <reference idRef="188"/>
    <reference idRef="189"/>
    <reference idRef="191"/>
  </array>
  <array count="37" name="allParents">
    <reference idRef="1"/>
    <reference idRef="29"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="127"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="131"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="152"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="147"/>
    <reference idRef="29"/>
    <reference idRef="29"/>
    <reference idRef="153"/>
    <reference idRef="154"/>
    <reference idRef="154"/>
    <reference idRef="154"/>
    <reference idRef="1"/>
    <reference idRef="166"/>
    <reference idRef="185"/>
    <reference idRef="29"/>
    <reference idRef="184"/>
    <reference idRef="184"/>
    <reference idRef="154"/>
    <reference idRef="154"/>
    <reference idRef="167"/>
  </array>
  <dictionary count="3" name="nameTable">
    <string>Files Owner</string>
    <reference idRef="1"/>
    <string>MainWindow</string>
    <reference idRef="166"/>
    <string>MenuBar</string>
    <reference idRef="29"/>
  </dictionary>
  <unsigned_int name="nextObjectID">197</unsigned_int>
</object>

--Apple-Mail-3-524552448
Content-Disposition: attachment;
	filename=info.nib
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="info.nib"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist SYSTEM "file://localhost/System/Library/DTDs/PropertyList.dtd">
<plist version="0.9">
<dict>
	<key>IBEditorPositions</key>
	<dict>
		<key>29</key>
		<string>69 252 273 44 0 0 1024 746 </string>
	</dict>
	<key>IBFramework Version</key>
	<string>219.0</string>
	<key>IBMainMenuLocation</key>
	<string>69 252 273 44 0 0 1024 746 </string>
	<key>IBOpenObjects</key>
	<array>
		<integer>29</integer>
		<integer>166</integer>
	</array>
	<key>IBSystem Version</key>
	<string>5P48</string>
	<key>targetFramework</key>
	<string>IBCarbonFramework</string>
</dict>
</plist>

--Apple-Mail-3-524552448--

--Apple-Mail-1-524552443--