1# 2# FilteringControllerDocument.py 3# FilteringController 4# 5# Converted by u.fiedler on 05.02.05. 6# 7# The original version was written in Objective-C by Malcolm Crawford 8# at http://homepage.mac.com/mmalc/CocoaExamples/controllers.html 9 10from PyObjCTools import AppHelper 11from Cocoa import * 12 13 14 15class FilteringControllerDocument (NSDocument): 16 peopleController = objc.IBOutlet() 17 18 def init(self): 19 self = super(FilteringControllerDocument, self).init() 20 if self is None: return None 21 self._k_people = [] 22 return self 23 24 def windowNibName(self): 25 return u"FilteringControllerDocument" 26 27 def windowControllerDidLoadNib_(self, controller): 28 super(FilteringControllerDocument, self).windowControllerDidLoadNib_(controller) 29 30 def dataRepresentationOfType_(self, aType): 31 return NSKeyedArchiver.archivedDataWithRootObject_(self._k_people) 32 33 def loadDataRepresentation_ofType_(self, data, aType): 34 self.setPeople_(NSKeyedUnarchiver.unarchiveObjectWithData_(data)) 35 return True 36 37 38 ### indexed accessors 39 40 def people(self): 41 return self._k_people 42 43 def setPeople_(self, people): 44 self._k_people[:] = people 45 46 @objc.accessor 47 def countOfPeople(self): 48 return len(self._k_people) 49 50 @objc.accessor 51 def objectInPeopleAtIndex_(self, idx): 52 return self._k_people[idx] 53 54 @objc.accessor 55 def insertObject_inPeopleAtIndex_(self, obj, idx): 56 self._k_people.insert(idx, obj) 57 58 @objc.accessor 59 def removeObjectFromPeopleAtIndex_(self, idx): 60 del self._k_people[idx] 61 62 @objc.accessor 63 def replaceObjectInPeopleAtIndex_withObject_(self, idx, obj): 64 self._k_people[idx] = obj 65