1ImageBrowser 2============ 3 4This sample demonstrates the ImageKit ``ImageBrowser`` in a basic Cocoa 5application. It uses IB to create a window an ``ImageBrowser`` and a zoom 6slider. 7 8This sample should present a reasonably complete correctly formed Cocoa 9application which can be used as a starting point for using the ``ImageBrowser`` 10in a Cocoa applications. 11 12Usual steps to use the ImageKit image browser in your application: 13 141. setup your nib file 15 16 Add a custom view and set its class to IKImageBrowserView. 17 Connect an IBOutlet from your controller to your image browser view 18 and connect the ``IKImageBrowserView``'s ``_datasource`` ``IBOutlet`` to 19 your controller (if you want your controller to be the data source) 20 212. Don't forget to import the Quartz package:: 22 23 from Quartz import * 24 253. Create your own data source representation (here using a ``NSMutableArray``):: 26 27 class MyController (NSWindowController): 28 _myImages = objc.ivar() 29 _myImageView = objc.IBOutlet() 30 314. implement the required methods of the informal data source protocol 32 (``IKImageBrowserDataSource``):: 33 34 def numberOfItemsInImageBrowser_(self, browser): 35 return len(self._images) 36 37 def imageBrowser_itemAtIndex_(self, aBrowser, index): 38 return self._images[index] 39 40 415. The returned data source object must implement the 3 required 42 methods from the ``IKImageBrowserItemProtocol`` informal protocol: 43 44 def imageUID(self): pass 45 def mageRepresentationType(self): pass 46 def imageRepresentation(self): pass 47 48 * the id returned by ``imageUID`` MUST be different for each item 49 displayed in the image-view. Moreover, the image browser build it's 50 own internal cache according to this UID. the ``imageUID`` can be for 51 exemple the absolute path of an image existing on the filesystem or 52 another UID based on your own data structures. 53 54 * ``imageRepresentationType`` return one of the following string constant 55 depending of the client's choice of representation:: 56 57 IKImageBrowserPathRepresentationType 58 IKImageBrowserNSImageRepresentationType 59 IKImageBrowserCGImageRepresentationType 60 IKImageBrowserNSDataRepresentationType 61 IKImageBrowserNSBitmapImageRepresentationType 62 IKImageBrowserQTMovieRepresentationType 63 64 (see IKImageBrowserView.h for complete list) 65 66 * ``imageRepresentation`` return an object depending of the representation 67 type: 68 69 * a ``NSString`` for ``IKImageBrowserPathRepresentationType`` 70 * a ``NSImage`` for ``IKImageBrowserNSImageRepresentationType`` 71 * a ``CGImageRef`` for ``IKImageBrowserCGImageRepresentationType`` 72 * ... 73 74 Here is a sample code of a simple implementation of a data source item:: 75 76 class myItemObject (NSObject, IKImageBrowserItem): 77 _path = objc.ivar() 78 79 def mageRepresentationType(self): 80 return IKImageBrowserPathRepresentationType; 81 82 def mageRepresentation(self): 83 return self._path 84 85 def imageUID(self): 86 return self._path 87 886. Now to see your data displayed in your instance of the image browser view, 89 you have to tell the browser to read your data using your ``IBOutlet`` 90 connected to the browser and invoke ``reloadData`` on it:: 91 92 self._myImageView.reloadData() 93 94 Call ``reloadData`` each time you want the image browser to reflect changes 95 of your data source. 96 97That's all for a very basic use. Then you may need to add a scroller or a 98scrollview and a slider to your interface to let the user to scroll and zoom 99to browser his images. 100