Commits

Anonymous committed c4a377b

Fixed various bugs and unclear items that showed up when actually
doing the tutorial once all the way through.

  • Participants
  • Parent commits 3f54ac0

Comments (0)

Files changed (5)

pyobjc/Doc/tutorial_embed/extending_objc_with_python.html

 the Python dynamic library, so you cannot embed this Python in your
 application.</p>
 <p>You will also need the Apple Developer Kit, and it is expected you are familiar
-with using Project Builder, Interface Builder and Terminal. MacPython is expected in the
+with using Project Builder, Interface Builder and Terminal. MacPython 2.3b2
+or later is expected in the
 standard location (<tt class="literal"><span class="pre">/Library/Frameworks</span></tt>, with auxiliary executables
 in <tt class="literal"><span class="pre">/usr/local/bin</span></tt> and on your <tt class="literal"><span class="pre">$PATH</span></tt>).</p>
 <p>The application we are going to modify is Apple's SimpleComboBox example.
 <li><p class="first">Open it in Project Builder, build it, and see what it does.</p>
 </li>
 <li><p class="first">Copy <tt class="literal"><span class="pre">PythonGlue.h</span></tt>, <tt class="literal"><span class="pre">PythonGlue.m</span></tt> and <tt class="literal"><span class="pre">PythonGlue.py</span></tt> from <tt class="literal"><span class="pre">src</span></tt>
-into the <tt class="literal"><span class="pre">SimpleComboBoxPlus</span></tt> folder.</p>
+into the <tt class="literal"><span class="pre">SimpleComboBoxPlus</span></tt> folder:</p>
+<pre class="literal-block">
+% cp -R src/PythonGlue.* SimpleComboBoxPlus
+</pre>
 </li>
 <li><p class="first">Add <tt class="literal"><span class="pre">PythonGlue.h</span></tt> and <tt class="literal"><span class="pre">PythonGlue.m</span></tt> to the &quot;Classes&quot; group.</p>
 <blockquote>
 </li>
 <li><p class="first">Add <tt class="literal"><span class="pre">PythonGlue.py</span></tt> to the &quot;Resources&quot; group.</p>
 </li>
-<li><p class="first">&quot;Add Framework...&quot;, select <tt class="literal"><span class="pre">/Library/Frameworks/Python.framework</span></tt>.</p>
+<li><p class="first">Select the &quot;Frameworks&quot; group, &quot;Add Framework...&quot;, 
+select <tt class="literal"><span class="pre">/Library/Frameworks/Python.framework</span></tt>.</p>
 </li>
 <li><p class="first">Now we need to arrange to have a <tt class="literal"><span class="pre">PythonGlue</span></tt> object be instantiated
 being called early during startup. A good place to do this for the
 but all else should be well.</p>
 </li>
 <li><p class="first">Open <tt class="literal"><span class="pre">CDInfoDocument.nib</span></tt>. Select the Class View, <tt class="literal"><span class="pre">NSObject</span></tt>, subclass
-as <tt class="literal"><span class="pre">ITunesCommunication</span></tt>. Give the class an <tt class="literal"><span class="pre">askITunes:</span></tt> action.</p>
+as <tt class="literal"><span class="pre">ITunesCommunication</span></tt>. Give the class an <tt class="literal"><span class="pre">askITunes:</span></tt> action.
+Instantiate the class as object <tt class="literal"><span class="pre">ITunesCommunication</span></tt>.</p>
 </li>
 <li><p class="first">Go to the object view again, open the Window.</p>
 </li>
 <li><p class="first">Move the text box down a bit to make space, add a button &quot;ask iTunes&quot;.</p>
 </li>
-<li><dl class="first">
-<dt>Connect this button to the <tt class="literal"><span class="pre">askITunes:</span></tt> action of the <tt class="literal"><span class="pre">ITunesCommunication</span></tt></dt>
-<dd><p class="first last">object.</p>
-</dd>
-</dl>
+<li><p class="first">Connect this button to the <tt class="literal"><span class="pre">askITunes:</span></tt> action of the <tt class="literal"><span class="pre">ITunesCommunication</span></tt>
+object.</p>
 </li>
 <li><p class="first">We now need to write the code implementing the <tt class="literal"><span class="pre">ITunesCommunication</span></tt> class.
 Create a file <tt class="literal"><span class="pre">ITunesCommunication.py</span></tt> in the Resources group. As this tutorial
 we are going to skip the code itself and simply copy it from <tt class="literal"><span class="pre">src/ITunesCommunication_1.py</span></tt>.
 Note that this is not the final code yet, it is a debug version that does not
 yet talk to iTunes.</p>
+<blockquote>
+<p>Double-clicking on <tt class="literal"><span class="pre">ITunesCommunication.py</span></tt> in Project Builder may cause
+it to try and run the code in stead of editing it. In this case bring up the
+contextual menu and select &quot;Open As...&quot;-&gt;&quot;Plain Text File&quot;.</p>
+</blockquote>
 </li>
 <li><p class="first">Build and run. When you press the &quot;Ask iTunes&quot; the &quot;CD Title&quot; and &quot;Band Name&quot;
 fields will be filled with one of the best albums of the last few years:-)</p>
 the following hefty command line which you should run in the
 <tt class="literal"><span class="pre">SimpleComboBoxPlus</span></tt> directory:</p>
 <pre class="literal-block">
+% cd SimpleComboBoxPlus
 % setenv FWPYTHON /Library/Frameworks/Python.framework/Versions/Current
 % pythonw $FWPYTHON/lib/python2.3/plat-mac/gensuitemodule.py \
         --output iTunes --resource --creator hook \

pyobjc/Doc/tutorial_embed/extending_objc_with_python.txt

 application.
 
 You will also need the Apple Developer Kit, and it is expected you are familiar
-with using Project Builder, Interface Builder and Terminal. MacPython is expected in the
+with using Project Builder, Interface Builder and Terminal. MacPython 2.3b2
+or later is expected in the
 standard location (``/Library/Frameworks``, with auxiliary executables
 in ``/usr/local/bin`` and on your ``$PATH``).
 
 2. Open it in Project Builder, build it, and see what it does.
 
 3. Copy ``PythonGlue.h``, ``PythonGlue.m`` and ``PythonGlue.py`` from ``src``
-   into the ``SimpleComboBoxPlus`` folder.
+   into the ``SimpleComboBoxPlus`` folder::
+
+	% cp -R src/PythonGlue.* SimpleComboBoxPlus
    
 4. Add ``PythonGlue.h`` and ``PythonGlue.m`` to the "Classes" group.
 
 
 5. Add ``PythonGlue.py`` to the "Resources" group.
 
-6. "Add Framework...", select ``/Library/Frameworks/Python.framework``.
+6. Select the "Frameworks" group, "Add Framework...", 
+   select ``/Library/Frameworks/Python.framework``.
 
 7. Now we need to arrange to have a ``PythonGlue`` object be instantiated
    being called early during startup. A good place to do this for the
    
 9. Open ``CDInfoDocument.nib``. Select the Class View, ``NSObject``, subclass
    as ``ITunesCommunication``. Give the class an ``askITunes:`` action.
+   Instantiate the class as object ``ITunesCommunication``.
    
 10. Go to the object view again, open the Window.
 
 11. Move the text box down a bit to make space, add a button "ask iTunes".
 
 12. Connect this button to the ``askITunes:`` action of the ``ITunesCommunication``
-	object.
+    object.
 	
 13. We now need to write the code implementing the ``ITunesCommunication`` class.
     Create a file ``ITunesCommunication.py`` in the Resources group. As this tutorial
     we are going to skip the code itself and simply copy it from ``src/ITunesCommunication_1.py``.
     Note that this is not the final code yet, it is a debug version that does not
     yet talk to iTunes.
+    
+	Double-clicking on ``ITunesCommunication.py`` in Project Builder may cause
+	it to try and run the code in stead of editing it. In this case bring up the
+	contextual menu and select "Open As..."->"Plain Text File".
 
 14. Build and run. When you press the "Ask iTunes" the "CD Title" and "Band Name"
     fields will be filled with one of the best albums of the last few years:-)
     the following hefty command line which you should run in the
     ``SimpleComboBoxPlus`` directory::
     
+    	% cd SimpleComboBoxPlus
     	% setenv FWPYTHON /Library/Frameworks/Python.framework/Versions/Current
     	% pythonw $FWPYTHON/lib/python2.3/plat-mac/gensuitemodule.py \
     		--output iTunes --resource --creator hook \

pyobjc/Doc/tutorial_embed/src/ITunesCommunication_1.py

 
 class ITunesCommunication(NibClassBuilder.AutoBaseClass):
     def init(self):
-        self = super(MyDocument, self).init()
+        self = super(ITunesCommunication, self).init()
         if self:
             # subclass specific initialization here
             # nib not loaded yet

pyobjc/Doc/tutorial_embed/src/PythonGlue.m

+/*
+PythonGlue is a class implementing a singleton object that does
+nothing, but it has one side effect: it initializes Python (which
+should be linked into the bundle containing this class) and executes
+Contents/Resourcs/PythonGlue.py from the main bundle.
+
+No error checking is done, but Python errors will result in messages
+on standard error (or the console, for programs started from the Finder).
+*/
+
 #import <Foundation/Foundation.h>
 #import "PythonGlue.h"
 #import <Python/Python.h>

pyobjc/Doc/tutorial_embed/src/PythonGlue.py

 # Skeleton Python source for embedding Python into ObjC programs.
+# This source file expects to be run by the ObjC code in PythonGlue.m
+# and it expects to live in Contents/Resources of some .app bundle.
+# It will add the Resources folder and its PyObjC subfolder to
+# sys.path and import any modules found in Resources (which in
+# turn makes any PyObjC classes in these modules available to the
+# ObjC runtime system).
 import os
 import sys