What happened to the Python Bindings to Quartz 2D

11 views
Skip to first unread message

David Hoerl

unread,
Sep 28, 2011, 10:40:25 AM9/28/11
to quart...@lists.apple.com
I read with some interest about the Python bindings, and even found a
early 2010 version of the Quartz 2D Programming Guide with a section on
then.

Then, in late 2010, it disappeared from the guide, and seems to have
been totally erased.

Was this capability removed from OS X?

David
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/quartz-dev-garchive-50095%40googlegroups.com

This email sent to quartz-dev-g...@googlegroups.com

Michael Geary

unread,
Sep 28, 2011, 11:55:07 AM9/28/11
to David Duncan, quart...@lists.apple.com, David Hoerl
i would love more info on this. Can anyone point me to some sample scripts that use this newer approach to the Quartz functionality?

thanks,

michael

On Sep 28, 2011, at 9:51 AM, David Duncan wrote:

> On Sep 28, 2011, at 7:40 AM, David Hoerl wrote:
>
>> I read with some interest about the Python bindings, and even found a early 2010 version of the Quartz 2D Programming Guide with a section on then.
>>
>> Then, in late 2010, it disappeared from the guide, and seems to have been totally erased.
>>
>> Was this capability removed from OS X?
>

> The python bindings were deprecated in favor of general Scripting Bridge support that was introduced in Mac OS X 10.5 (iirc). Through the Scripting Bridge you have access to all of Mac OS X, as such you can use the Quartz C API directly rather than via the bridge.
> --
> Reality is what, when you stop believing in it, doesn't go away.
> Failure is not an option. It is a privilege reserved for those who try.
>
> David Duncan


>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Quartz-dev mailing list (Quart...@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:

> http://lists.apple.com/mailman/options/quartz-dev/michael%40gearyweb.com
>
> This email sent to mic...@gearyweb.com

David Duncan

unread,
Sep 28, 2011, 11:51:47 AM9/28/11
to David Hoerl, quart...@lists.apple.com
On Sep 28, 2011, at 7:40 AM, David Hoerl wrote:

> I read with some interest about the Python bindings, and even found a early 2010 version of the Quartz 2D Programming Guide with a section on then.
>
> Then, in late 2010, it disappeared from the guide, and seems to have been totally erased.
>
> Was this capability removed from OS X?

The python bindings were deprecated in favor of general Scripting Bridge support that was introduced in Mac OS X 10.5 (iirc). Through the Scripting Bridge you have access to all of Mac OS X, as such you can use the Quartz C API directly rather than via the bridge.


--
Reality is what, when you stop believing in it, doesn't go away.
Failure is not an option. It is a privilege reserved for those who try.

David Duncan

_______________________________________________

David Hoerl

unread,
Sep 28, 2011, 4:43:48 PM9/28/11
to quart...@lists.apple.com
Let me second Michael's suggestion. The whole reason this seemed of
interest is as follows.

I'm trying to build a "Service" that downloads images from my companies
web sites, saves them in a folder named after the current web page, then
modifies the images.

In my case I need to crop the images - that is, to extract a subimage in
the interior of the downloaded images.

Now, I told my boss that this was a piece of cake, Apple has this
powerful Automator and the "sips" (Scriptable Image Processing System)
command line tool, and I could knock this out in a few hours.

Well - to my chagrin, sips cannot be coerced into extracting arbitrary
crops - it does so from the center and there is no way to do what I
needed :-(

In the end I wrote a small command line program to do what was needed -
its like 10 lines of code - but now I cannot distribute the Automator
action as it needs an executable (well, I probably COULD embed that
program in the Automator based service but it seems like cheating.

So, today, I tripped on a page referring to Python bindings, so I
thought - ahah - I can do this with a Python script.

---
So, as Michael asked, are there some example scripts I can read to see
how to do this? Could I really read in an image from a file, operate on
it, then write out another image to a file using the Scripting Bridge???

David

PS: in case anyone cares, it would be just GREAT if someone could
enhance sips - which appears to have not been touched since Tiger. There
are many people who have complained on the web of the inability to
specify a crop offset: rdar://10185319

David Duncan

unread,
Sep 28, 2011, 4:57:31 PM9/28/11
to David Hoerl, quart...@lists.apple.com
On Sep 28, 2011, at 1:43 PM, David Hoerl wrote:

So, as Michael asked, are there some example scripts I can read to see how to do this? Could I really read in an image from a file, operate on it, then write out another image to a file using the Scripting Bridge???

I'm not a Python expert, but the scripting bridge is the exact same API as the C API. So you call CGBitmapContextCreate, CGImageCreate, CGImageSourceCreate, etc, just as you would in C. The only difference is in how you import functionality, which uses the scripting language's syntax instead of C syntax.

I think there are some examples of using the Scripting Bridge to get at native functionality, but I don't know of anything Quartz specific.
--
David Duncan

Michael Geary

unread,
Sep 28, 2011, 5:00:58 PM9/28/11
to David Duncan, quart...@lists.apple.com, David Hoerl
speaking for myself, it's exactly because i'm not really skilled at C that I want the python examples. A good example is worth far more than a page of documentation. If anyone out there has anything they could share, at least some of us would be very grateful!

michael


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:

Michael B Johnson

unread,
Sep 28, 2011, 6:50:21 PM9/28/11
to David Hoerl, quart...@lists.apple.com
We use sips here at Pixar all the time. We love the fact that it embeds an ICC profile in its output if it is in the src image.

We'd love, love, love to see Apple spend some more time on it. I've expressed this to Apple folks in the past - if there's something more formal I could do, please, Apple folks, let me know.


On Sep 28, 2011, at 1:43 PM, David Hoerl wrote:

> http://lists.apple.com/mailman/options/quartz-dev/wave%40pixar.com
>
> This email sent to wa...@pixar.com

Michael Geary

unread,
Sep 28, 2011, 6:58:40 PM9/28/11
to Michael B Johnson, quart...@lists.apple.com, David Hoerl
wait, you're at Pixar, and you don't have any better contact to Apple than this list?? How depressing.

michael

_______________________________________________

Troy Koelling

unread,
Sep 28, 2011, 7:29:01 PM9/28/11
to Michael Geary, quart...@lists.apple.com, David Hoerl

On Sep 28, 2011, at 3:58 PM, Michael Geary wrote:

> wait, you're at Pixar, and you don't have any better contact to Apple than this list?? How depressing.
>

Hopefully it's not depressing that you have access to the same help as Pixar tools developers, plus the help from them too from time to time :) _______________________________________________

Michael Geary

unread,
Sep 28, 2011, 7:56:02 PM9/28/11
to Troy Koelling, quart...@lists.apple.com, David Hoerl
well, that was mostly an attempt at humor, given the whole Apple/Jobs/Pixar thing, before Disney got involved. However, i'd be much less depressed if Apple had any Quartz scripting bridge sample code snippets on par with the excellent python Quartz code samples that used to install alongside Xcode.... Any chances of that?

michael

Mark Butler

unread,
Sep 28, 2011, 8:36:36 PM9/28/11
to Michael Geary, quart...@lists.apple.com, David Hoerl
If you are trying to use Quartz from python have you tried obj-c bridge?

in interactive mode.. (python -i in terminal)
from Quartz import *
help(CIImage)
CIImage.imageWithContentsOfURL_("somevalidpath")
help(CIImage.imageWithContentsOfURL_)

fun!

m

> http://lists.apple.com/mailman/options/quartz-dev/markusca%40mac.com
>
> This email sent to mark...@mac.com

David Hoerl

unread,
Sep 28, 2011, 9:24:09 PM9/28/11
to quart...@lists.apple.com
Let me shout to the wind:

suppose that Apple put "sips" on github - and they adjudicated the "pull
requests". So many of us would contribute, they could pick and choose
what to take.

sips cannot be anything more than good demo code - what they post on
their dev sites all the time.

Why keep it internal, especially after so many updates?

Ah - "Shangri-La" - for those of you old enough to remember what that
means...

David

Scott Thompson

unread,
Sep 28, 2011, 10:56:14 PM9/28/11
to Quartz Dev List, David Hoerl
And if you're not entirely fixated on Python, you can also use MacRuby and/or RubyCocoa to script Quartz.  I use it quite often.

I was under the impression that the Scripting Bridge was not a way to connect scripting languages to Cocoa so much as a way to expose the AppleScript capabilities of applications to scripting languages like Ruby and Python.

see e.g. the article from two days ago:

For the scripting languages to cocoa thing I would expect PyObjC, Camel Bones (for Perl), RubyCocoa for those who like pain, and MacRuby for folks who want to make their lives easier.

Scott

Kyle Sluder

unread,
Sep 29, 2011, 1:11:31 AM9/29/11
to Scott Thompson, Quartz Dev List, David Hoerl
> I'm not a Python expert, but the scripting bridge is the exact same API as
> the C API. So you call CGBitmapContextCreate, CGImageCreate,
> CGImageSourceCreate, etc, just as you would in C. The only difference is in
> how you import functionality, which uses the scripting language's syntax
> instead of C syntax.
> I think there are some examples of using the Scripting Bridge to get at
> native functionality, but I don't know of anything Quartz specific.

I believe David was really referring to BridgeSupport, which is the
foundation of the Python and Ruby bridges. "Scripting Bridge" is
indeed a technology for generating Objective-C wrappers to Apple
Events.

--Kyle Sluder

David Hoerl

unread,
Sep 29, 2011, 9:02:06 AM9/29/11
to Mark Butler, quart...@lists.apple.com
On 9/28/11 8:36 PM, Mark Butler wrote:
> If you are trying to use Quartz from python have you tried obj-c bridge?
>
> in interactive mode.. (python -i in terminal)
> from Quartz import *
> help(CIImage)
> CIImage.imageWithContentsOfURL_("somevalidpath")
> help(CIImage.imageWithContentsOfURL_)
>
> fun!
>
> m

Mark - OK - now we're cookin! So you knew the magic incantation - "from
Quartz import *". How is a mere mortal such as me suppose to know these
magic commands?

That's what I was really trying to get at - there must be some
documentation on this somewhere, and example scripts. For instance, how
would I ever know I needed to import Quartz?

David

David Hoerl

unread,
Sep 29, 2011, 9:02:21 AM9/29/11
to Kyle Sluder, Quartz Dev List
On 9/29/11 1:11 AM, Kyle Sluder wrote:
>> I'm not a Python expert, but the scripting bridge is the exact same API as
>> the C API. So you call CGBitmapContextCreate, CGImageCreate,
>> CGImageSourceCreate, etc, just as you would in C. The only difference is in
>> how you import functionality, which uses the scripting language's syntax
>> instead of C syntax.
>> I think there are some examples of using the Scripting Bridge to get at
>> native functionality, but I don't know of anything Quartz specific.
>
> I believe David was really referring to BridgeSupport, which is the
> foundation of the Python and Ruby bridges. "Scripting Bridge" is
> indeed a technology for generating Objective-C wrappers to Apple
> Events.
>
> --Kyle Sluder


Well, I was responding to David Duncan's comment early on in this thread:

The python bindings were deprecated in favor of general Scripting Bridge
support that was introduced in Mac OS X 10.5 (iirc). Through the
Scripting Bridge you have access to all of Mac OS X, as such you can
use the Quartz C API directly rather than via the bridge.

David Duncan

unread,
Sep 29, 2011, 9:09:58 AM9/29/11
to David Hoerl, Quartz Dev List
On Sep 29, 2011, at 6:02 AM, David Hoerl wrote:

That's what I was really trying to get at - there must be some documentation on this somewhere, and example scripts. For instance, how would I ever know I needed to import Quartz?

Because that's the framework name :). The example you posted is actually for using Core Image from Python, not Core Graphics (aka Quartz). 


On Sep 29, 2011, at 6:02 AM, David Hoerl wrote:

Well, I was responding to David Duncan's comment early on in this thread:

The python bindings were deprecated in favor of general Scripting Bridge support that was introduced in Mac OS X 10.5 (iirc). Through the Scripting Bridge you have access to all of Mac OS X, as such you can use the Quartz C API directly rather than via the bridge.

And as Kyle surmised, I really meant BridgeSupport. Sorry for the confusion.
--
David Duncan

Mark Butler

unread,
Sep 29, 2011, 10:58:16 AM9/29/11
to Quartz Dev List
I think.. and please correct me if I am wrong the scripting bridge (cocoa framework) is very different then the objc bridge.
You could however use the scripting bridge through the objc bridge if thats what you wanted to accomplish (but I dont think it is based on the initial question)

python -i
from ScriptingBridge import SBApplication
iTunes = SBApplication.applicationWithBundleIdentifier_("com.apple.iTunes")
iTunes.activate()
help(iTunes)

If you need to interact with other applications scripting bridge is great this exposes applescript api to cocoa at about 1000x faster (YMMV)
Need current song playing in iTunes etc.

If you want documentation for either one these are using the objc framework in python so really its documentation in Xcode for the framework you need to see.
python's help help(Python) will give you some idea of what you can call on this object but it is not as verbose as the framework documentation.
That would hold true with any framework that has bridge support.

Course if you want to use something with no bridge support you can do that too.. But it may be a little sketchy.
import ctypes
iokit = ctypes.cdll.LoadLibrary("/System/Library/Frameworks/IOKit.framework/IOKit")
iokit.IOHIDElementAttach

import objc
objc.loadBundle("Automator", globals(), bundle_path=objc.pathForFramework('/System/Library/Frameworks/Automator.framework'))
AMAction

m


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:

Kyle Sluder

unread,
Sep 29, 2011, 11:00:31 AM9/29/11
to Mark Butler, Quartz Dev List
On Thu, Sep 29, 2011 at 7:58 AM, Mark Butler <mark...@mac.com> wrote:
> I think.. and please correct me if I am wrong the scripting bridge (cocoa
> framework) is very different then the objc bridge.

Yes, it is. David originally meant to refer to BridgeSupport, which is
the "objc bridge" your'e talking about. It actually bridges more than
just ObjC.

--Kyle Sluder


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list (Quart...@lists.apple.com)
Help/Unsubscribe/Update your Subscription:

Reply all
Reply to author
Forward
0 new messages