Building Cocoa GUIs in Python with PyObjC, Part Four
Creating an Open Dialog
Our controller doesn't really do anything at this point. We'll begin by adding an open dialog for the user. This will require us to really delve into the Objective C bridge provided by PyObjC. We'll start by reading some documentation that ships with Xcode.
Let's launch the local documentation browser in Xcode. Under "Help" click "Documentation". In the newly opened documentation browser select the "Mac OS X 10.5" documentation set and search for NSOpenPanel. This is the class we'll be working with to create our open dialog. Have a look through the documentation, then let's code.
First we do some basic stuff, creating the object and setting some permissions. A modified open method on our controller.py looks like this:
filetypes = ('mp3', 'ogg', 'mp4', 'flac', 'm4a', 'm4p')
@IBAction
def open_(self, sender):
panel = NSOpenPanel.openPanel()
panel.setCanChooseDirectories_(NO)
panel ...

