Re: [Pythonmac-SIG] About Obj-C 2.0 language bridge

2006-12-18 Thread Jacob Rus
Nehemiah Dacres wrote:
 I just wanted to bring the attention to the community that there will
 be a python/Objective C language bridge implemented come the
 release of Leopard, Mac OS 10.5
 
 These are a few questions I wanted to ask the MacPython Dev team
 I was wondering how are we going to tailor the  MacPython programming
 environment for those who want to use the bridge in programming for python?
 Will Py2App take advantage of this new ability and if so, how?
 How does this contrast with using PyObjC?

I don't actually have any inside knowledge (I don't have access to 
Leopard developer builds, etc.), but I rather doubt that Apple is 
completely re-implementing PyObjC.  At least a few of the people who 
work on PyObjC are Apple employees, and there was a tutorial showing how 
to make a Cocoa app using PyObjC at apple.com a few months ago.  It was 
my impression that the Cocoa-python bridge discussed in the leopard 
preview docs *is* PyObjC, though of course I could be way off the mark, etc.

-Jacob

___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


[Pythonmac-SIG] How to fathom appscript

2006-12-18 Thread Hamish Allan
Hi,

I'm new to appscript (and relatively new to python) and I'm having
trouble fathoming out how to determine what can be done with each type
of object.

For example,

itunes = app('iTunes')
x = itunes.sources.first.playlists[its.name.contains('MyName')]

This code fetches any playlists containing the string 'MyName'. But I
want an exact match. Using 'equals' rather than 'contains' doesn't
work. How do I find out which operations its.name supports? And more
generally, what is possible in other similar situations with different
objects?

I also want to do what the following code suggests:

x = itunes.sources.first.playlist_folders[its.name.equals('MyFolder')]
y = itunes.sources.first.playlists[its.parent.equals(x)]

Is this possible?

Many thanks,
Hamish
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig


Re: [Pythonmac-SIG] How to fathom appscript

2006-12-18 Thread Nicholas Riley
On Mon, Dec 18, 2006 at 11:11:27PM +, Hamish Allan wrote:
 itunes = app('iTunes')
 x = itunes.sources.first.playlists[its.name.contains('MyName')]
 
 This code fetches any playlists containing the string 'MyName'. But I
 want an exact match. Using 'equals' rather than 'contains' doesn't
 work.

You just use '==' instead.

In [4]: itunes.sources.first.playlists[its.name == 'Stations']()
Out[4]: 
[app(u'/Applications/iTunes.app').sources.ID(41).user_playlists.ID(1936)]

But in this case, you don't need to.

In [6]: itunes.sources.first.playlists['Stations']()
Out[6]: app(u'/Applications/iTunes.app').sources.ID(41).user_playlists.ID(1936)

Most objects support multiple reference forms, as you'll see if you
look at their documentation.

 How do I find out which operations its.name supports? And more
 generally, what is possible in other similar situations with different
 objects?

Use .help().  So, for example, you can see that the playlists can be
referenced by index, name or ID:

In [7]: itunes.sources.first.playlists.help()
==
Appscript Help (-t)

Reference: app(u'/Applications/iTunes.app').sources.first.playlists

--
Description of reference

Element: playlists -- by index, name, id
[...]

Note the reference forms above.

It also helps to view the scripting dictionary, either using
appscript's tools for doing so in a Web browser, or just with Script
Editor (as I normally do).

 I also want to do what the following code suggests:
 
 x = itunes.sources.first.playlist_folders[its.name.equals('MyFolder')]

You want 'folder_playlists' not 'playlist_folders'.  So again it's
pretty simple:

In [15]: itunes.sources.first.folder_playlists['Statistics']()
Out[15]: 
app(u'/Applications/iTunes.app').sources.ID(41).folder_playlists.ID(122340)

 y = itunes.sources.first.playlists[its.parent.equals(x)]

Unfortunately here you run into a problem, as Apple didn't fully
implement terminology for 'folder playlists', but you can view the
scripting dictionary to figure it out.  'parent', while a property of
playlists, isn't always set.  So the only thing I could figure out was
to iterate through them in Python:

In [45]: stats_id = itunes.folder_playlists['Statistics'].id()
In [46]: [p for p in itunes.user_playlists() if p.parent.exists()
   :  and p.parent.id() == stats_id]
Out[46]: 
[app(u'/Applications/iTunes.app').sources.ID(41).user_playlists.ID(1032),
 app(u'/Applications/iTunes.app').sources.ID(41).user_playlists.ID(1158),
 app(u'/Applications/iTunes.app').sources.ID(41).user_playlists.ID(1060)]

-- 
Nicholas Riley [EMAIL PROTECTED] | http://www.uiuc.edu/ph/www/njriley
___
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig