[Pythonmac-SIG] Possibly OT: Get path to icon file for PIL?

Ronald Oussoren ronaldoussoren at mac.com
Fri Jan 4 07:45:12 CET 2008


On 3 Jan, 2008, at 23:08, Kevin Walzer wrote:

> I'm looking for a Python API that will return the path to an icon file
> which I can then read via PIL and display in my application.
>
> The available API's that I can find--NSWorkspace and
> IconServices--provide various hooks to obtaining and displaying an  
> icon,
> but neither appears to support finding the source file for an icon.  
> For
> instance, I can use something like this in Cocoa to get an icon:
>
> NSWorkspace * ws    = [NSWorkspace sharedWorkspace];
> NSString    * path  = [ws fullPathForApplication:@"Safari"];
> NSImage     * icon  = [ws iconForFile: path];

You can do this through the bundle API (open the bundle for an  
application, look up the name of the icon from the Info.plist and then  
locate that icon.

Something like:

path = ...
bundle = NSBundle.bundleWithPath_(path)
info = bundle.infoDictionary()
iconName = info['CFBundleIconFile']
iconPath = bundle.pathForResource_ofType_(iconName, 'icns')

Ronald
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2224 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20080104/91a4933d/attachment.bin 


More information about the Pythonmac-SIG mailing list