楽しくなってきた

なんか、PyObjC のまとめサイトとか欲しいなぁ > pateo さん

lastPathComponent は os.path の何で代用可能なはず。

動作未確認、自分用メモ

# vim: sts=4 sw=4

import os

from objc import YES, NO, IBAction, IBOutlet, NULL
from Foundation import *
from AppKit import *
from Quartz import *

class ImageObject(NSObject):
    path = ''

    def imageRepresentionType(self):
        return IKImageBrowserPathRepresentationType

    def imageRepresentation(self):
        return self.path

    def imageUID(self):
        return self.path

    def imageTitle(self):
        #os.path


class Controller(NSObject):
    image_view = IKImageView.alloc()
    image_browser_view = IKImageBrowserView.alloc()

    def awakeFromNib(self):
        self.images = []

        dir_path = '/Library/Desktop Pictures'
        for root, dirs, files in os.walk(dir_path):
            for f in files:
                subpath, ext = os.path.splitext(f)
                if ext == '.jpg':
                    path = os.path.join(root, f)
                    ns_image = NSImage.alloc()
                    image = ns_image.initWithContentsOfFile_(path)
                    self.images.append(image)

        self.image_browser_view.reloadData
        self.image_view.setImageWithURL(NULL)
        self.image_view.setAutoreseizes(YES)

    def numberOfItemsInImageBrowser(self, view):
        return len(self.images)

    def imageBrowser(self, view, index):
        return self.images[index]

    def imageBrowserSelectionDidChange(self, browser):
        indexes = self.image_browser_view.selectionIndexes()
        selectedIndex = indexes.firstIndex()
        if selectedIndex == NSNotFound:
            self.image_view.setImageWithURL_(NULL)
        else:
            image_object = images[selectedIndex]
            url = NSURL.fileURLWithPath_(image_object.path)
            self.image_view.setImageWithURL_(url)