[Pythonmac-SIG] PyObjC tutorial without Xcode

Orestis Markou orestis at orestis.gr
Sat Jul 19 15:17:17 CEST 2008


I don't see why you don't want to use XCode. You can use an external  
editor for python files (I use MacVim), and let XCode manage the  
building and packaging.

You don't have to use Obj-C (although you can't really use PyObjC  
without understanding Obj-C).

The bundled examples should work out of the box, if you open the  
project with Xcode. You can find them in /Developer/Examples/Python/ 
PyObjC

Anyway, I have a little "Hello world" PyObjC project here: http://orestis.gr/en/blog/2008/05/17/pyobjc-hello-world/

It has some of the common gotchas annotated, but it's not a tutorial.

BTW, everything I say applies to Leopard, using the stock version of  
Python and PyObjC.

Hope I helped,
--
Orestis Markou
orestis at orestis.gr
http://orestis.gr/




On 19 Ιουλ 2008, at 11:00 ΠΜ, pythonmac-sig-request at python.org  
wrote:

> Send Pythonmac-SIG mailing list submissions to
> 	pythonmac-sig at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> 	http://mail.python.org/mailman/listinfo/pythonmac-sig
> or, via email, send a message with subject or body 'help' to
> 	pythonmac-sig-request at python.org
>
> You can reach the person managing the list at
> 	pythonmac-sig-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of Pythonmac-SIG digest..."
> Today's Topics:
>
>   1. Re: Mac IDLE Fonts? (-or- I guess I need glasses.) (Nate)
>   2. Re: Mac IDLE Fonts? (-or- I guess I need glasses.) (Kevin Walzer)
>   3. PyObjC tutorial without Xcode (Craig Marshall)
>   4. Re: PyObjC tutorial without Xcode (Dav Clark)
>   5. Re: PyObjC tutorial without Xcode (Craig Marshall)
>
> From: Nate <afraud at gmail.com>
> Date: 18 Ιουλίου 2008 12:28:42 ΜΜ GMT+01:00
> To: kw at codebykevin.com
> Cc: pythonmac-sig at python.org
> Subject: Re: [Pythonmac-SIG] Mac IDLE Fonts? (-or- I guess I need  
> glasses.)
>
>
> How can I identify the version of Tk that I'm running?  I installed  
> IDLE using the download of Python 2.5.2 from Python.org.
>
>
>
> On Thu, Jul 17, 2008 at 11:15 PM, Kevin Walzer <kw at codebykevin.com>  
> wrote:
> Nate wrote:
> I don't even have the "Preferences" item in my IDLE menu.  I'm  
> running IDLE
> 1.2.2 on Leopard (10.5.4).
>
> Maybe I should submit a bug-report?
>
>
>
> Hmmm. Are you using the system installation of Tk (8.4.7)?
>
> I'd install a later version of Tcl/Tk from here: http://www.categorifiedcoder.info/tcltk/ 
> . Try 8.4.19.
>
> There was some weirdness with the Preferences menu before--with  
> certain versions of Tk the menu item appeared twice--so I wrote a  
> patch that set it to appear only once, which Ronald committed. I  
> think the bug doesn't exist with Tk 8.4.7. However, that version is  
> so old that I'm disinclined to offer another patch.
>
> --Kevin
>
> ------
>
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
>
>
>
>
> From: Kevin Walzer <kw at codebykevin.com>
> Date: 18 Ιουλίου 2008 1:20:56 ΜΜ GMT+01:00
> To: Nate <afraud at gmail.com>
> Cc: pythonmac-sig at python.org
> Subject: Re: [Pythonmac-SIG] Mac IDLE Fonts? (-or- I guess I need  
> glasses.)
> Reply-To: kw at codebykevin.com
>
>
> Nate wrote:
>> How can I identify the version of Tk that I'm running?  I installed  
>> IDLE
>> using the download of Python 2.5.2 from Python.org.
>
> Look in /Library/Frameworks. If you don't see Tcl.framework and  
> Tk.framework, then you are most likely running the Apple-installed  
> version (8.4.7) installed in /System/Library/Frameworks.
>
> As I said, this version is very old (c. 2005?). 8.4.19 from the link  
> I gave you before will work with Python.
>
> -- 
> Kevin Walzer
> Code by Kevin
> http://www.codebykevin.com
>
>
>
>
> From: "Craig Marshall" <craig9 at gmail.com>
> Date: 18 Ιουλίου 2008 7:25:36 ΜΜ GMT+01:00
> To: pythonmac-sig at python.org
> Subject: [Pythonmac-SIG] PyObjC tutorial without Xcode
>
>
> Hi,
>
> I am familiar with python already, and I am familiar with the mac as a
> user, but otherwise have no mac development experience. I'm keen to
> learn pyobjc and write native mac/python GUI apps.
>
> I'm currently having problems with outdated-ness and inaccuracies with
> both tutorials* I can find on PyObjC, and I think it could be simpler
> if I could find a tutorial that didn't involve Xcode (and the xcode
> python support seems spotty). Can anyone point me in the right
> direction please? I'm happy to use a plain old text editor and
> run/debug from the command line, and also I'd rather leave obj-C alone
> if possible. I accept that I'll need to use interface builder (which
> seems like a great app, anyway).
>
> Is this possible? If so - pointers would be gratefully received.
>
> Thanks,
> Craig Marshall
>
> * (http://pyobjc.sourceforge.net/documentation/pyobjc-core/tutorial/index.html
> and http://developer.apple.com/cocoa/pyobjc.html)
>
>
>
>
> From: Dav Clark <dav at alum.mit.edu>
> Date: 19 Ιουλίου 2008 12:35:41 ΠΜ GMT+01:00
> To: pythonmac-sig at python.org
> Subject: Re: [Pythonmac-SIG] PyObjC tutorial without Xcode
>
>
> I sent this just to Craig, but figured I should probably send to the  
> group in retrospect - at least this way something'll be online in  
> the pythonmac-sig archives...
>
>
> Below my signature is a sample script demonstrating a really minimal  
> use of pyobjc.  This is meant to be run from the command line, and  
> uses the BTop2 framework from Perfectly Scientific.  You can  
> download that framework for free, but it won't do much if you don't  
> have the hardware!
>
> Not exactly a tutorial, but darned simple for sure... I can't  
> remember if that __getattr__ thing ever worked... I don't think it  
> did.  The Exception thing is _way_ useful (as indicated in the  
> comments there).  The standard exception messages you'll get while  
> using pyobjc are close to useless.
>
> I'll add also that I'd not be averse to chipping in to a non-Xcode  
> pyobjc tutorial online somewhere.  I'm not terribly self-motivated  
> on that, but would do if someone asked for more.
>
> Cheers,
> Dav
> --
> Statistical Motion R&D
> http://socrates.berkeley.edu/~ivrylab/
>
> import objc
>
> # # Way useful for debugging
> # import PyObjCTools.Debugging as Debugging
> # Debugging.installVerboseExceptionHandler()
>
> btop_path = objc.pathForFramework('/Users/dav/Code/bTop.framework')
> objc.loadBundle('btop', globals(), bundle_path=btop_path)
> # Not sure why I need to do this... I shouldn't!
> BTopBoard.setBTopFirmwareDirectory_(btop_path + '/Versions/A/ 
> Resources')
>
> class BoardContainer(NSObject):
>    """BoardContainer should be initialized by BoardControl below"""
>    board = None
>
>    def bTopAddBoard_(self, board):
>        self.board = board
>        self.board.setPortBit_direction_('B', 255)
>        self.board.refreshDigitalPortValues()
>
>    def send(self, val):
>        self.board.setPortBit_value_('B', 255-val)
>        self.board.refreshDigitalPortValues()
>
> class BoardControl:
>    """Instantiate the BoardContainer and provide a more pythonic  
> interface
>
>    Ultimately, this should implement a standard Parallel Port API"""
>    board = None
>
>    def __init__(self):
>        # Cocoa objects are constructed differently...
>        self.board = BoardContainer.alloc().init()
>        BTopBoard.setBTopPrimaryObserver_(self.board)
>        BTopBoard.allocBTopObserver()
>
>    # # try writing a function dispatch to catch undeclared funcs...  
> see
>    # # what's going on!
>    # def __getattr__(self, name):
>    #     def handler(*args, **kwargs):
>    #         print '*name*', name
>    #         print '*args*', args
>    #         print '*kwargs*', kwargs
>    #     return handler
>
>    def send(self, val):
>        self.board.send(val)
>
>
>
>
>
>
>
> From: "Craig Marshall" <craig9 at gmail.com>
> Date: 19 Ιουλίου 2008 9:16:53 ΠΜ GMT+01:00
> To: pythonmac-sig at python.org
> Subject: Re: [Pythonmac-SIG] PyObjC tutorial without Xcode
>
>
> Hi all again,
>
>> Below my signature is a sample script demonstrating a really  
>> minimal use of
>> pyobjc.  This is meant to be run from the command line, and uses  
>> the BTop2
>> framework from Perfectly Scientific.  You can download that  
>> framework for
>> free, but it won't do much if you don't have the hardware!
>
> Thanks for sending the above dav, I think I'm more interested in
> trying to get a very basic GUI up and running, which from the look of
> it your script doesn't handle..
>
> I tried another tactic. I went through all the example folders that
> the xcode 3.1 installation put on my hard drive
> (/Developer/Documentation/Python/PyObjC/tutorial/ specifically) and
> found again the official pyobjc tutorial. My new tactic is to start
> with the final piece of code there (step 12), build and run it and
> then play with it until I know how it works.
>
> The problem is, when I build it and run it (out of the box!), it
> doesn't work (cue hair-pulling sounds). I open a terminal, tell it to
> build (python setup.py py2app), then tell it to run (open
> dist/CurrencyConverter.app), and it gives me a dialog box with an
> error inside:
>
> CurrencyConverter Error
> An unexpected error has occured during excution of the main script
> ImportError: No module named Foundation
>
> Open Console or Terminate
>
> So - I'm beginning to think either these are the useless errors that
> dav talked about and that I need to somehow shoe-horn the useful
> exception code into the py2app build instructions, or that it really
> can't find the Foundation module. I would have thought py2app could
> find and insert the bits and pieces it needs just from the import
> statements, or do I have to declare that I want to use Foundation in
> the setup.py somehow?
>
> A third possibility is that I've somehow broken my setup - how else
> could a tutorial that came with the latest xcode not work out of the
> box?
>
> I'd be very grateful if someone can point me in the direction of at
> least a very small working pyobjc GUI app that works out of the box
> with modern software ....
>
> Craig
>
>
>



More information about the Pythonmac-SIG mailing list