michael-mccracken.net

PyObjC notes

I’ve been hacking around with PyObjC, the Python-ObjC/Cocoa bridge recently, and it’s quickly becoming my favorite way to write Cocoa apps. It’s really natural to mix Python idioms with Cocoa objects.

The latest version of PyObjC is 2.0, it’s installed by default on OS X 10.5, and XCode now includes templates for starting a PyObjC project. There’s even code autocomplete in XCode for PyObjC and IB integration, so aside from some smart-indenting issues, writing PyObjC in XCode is almost as natural as writing in ObjC.

I thought I’d post a few nice shortcuts and tips here.


You can use tuples for NSRect/Range/Point, for instance, this -

r = NSInsetRect(((0, 0) ,
                 (100, 100)), 
                10, 10)

creates this NSRect -

NSRect origin=<NSPoint x=10.0 
                       y=10.0> 
       size=<NSSize width=80.0 
                   height=80.0>>


Passing python arrays as NSArray instances (and dictionaries as NSDictionaries) works great, but sometimes you need to pass a C array. The Python ‘array’ module handles that nicely:

import array
g = NSGradient.alloc().
   initWithColors_locations_colorSpace_(
    [NSColor.whiteColor(), 
     NSColor.blackColor()], <br/>
    array.array(’f', [0.0, 1.0]), 
    NSColorSpace.deviceRGBColorSpace())


ObjC selectors are just python strings in PyObjC.

defNC.addObserver_selector_name_object_(self,
  'windowDidResize:',
  NSWindowDidResizeNotification,
  self)
# or
self.performSelectorOnMainThread_withObject_waitUntilDone_('doIt:', None, False)
# or 
if o.respondsToSelector_("fun:"): return o.fun_(a)


Finally, something that comes in handy when working with KVC, the ‘_’ method now defined on NSObjects in PyObjC:

o = <Some ObjC object>
print o._.myKey
o._.myKey = 44
# is equivalent to:
print o.valueForKey_('myKey')
o.setValue_forKey_(44, 'myKey')


That last example is straight from the NEWS page, where lots of other useful info can be found.

Previously:
What is Site Reliability Engineering at Google
January 13, 2008

I’ve been looking around for some more detailed information about the “Site Reliability Engineering” positions at Google. Apparently the role is a real mix of very large-scale system administration, planning and automation.

I’ve collected some links to public info about the job.

The Google channel has a promotional video from one engineer about the role - he tells [...]

read the rest.
HPC blogs and news sites
May 4, 2007

I’ve always liked the programming-languages community website Lambda the Ultimate, and recently I went looking for something similar for the High-Performance Computing community. I didn’t find exactly that*, but I did find a few great resources for news about HPC and computing research policy:

HPCWire is a well-known news source for HPC. It has daily news [...]

read the rest.
The TRIPS processor
April 25, 2007

The UT-Austin TRIPS project will unveil their processor next Monday, and I take a look at what it looks like.

read the rest.
Next Page »
Feed, Endorsements & other Links

my bookmarks

© 2005 - 2007 Michael McCracken.