Commits

Anonymous committed 64aefc0

Workaround for double-callback bug; some more ui

  • Participants
  • Parent commits e46d4e1

Comments (0)

Files changed (5)

pyobjc/Examples/Twisted/PackMan/MainMenu.nib/classes.nib

 {
     IBClasses = (
         {
+            ACTIONS = {addDb = id; }; 
             CLASS = DatabasesController; 
             LANGUAGE = ObjC; 
-            OUTLETS = {databaseTable = id; }; 
+            OUTLETS = {databaseTable = id; newDatabaseURL = id; packageController = id; }; 
             SUPERCLASS = NSObject; 
         }, 
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 

pyobjc/Examples/Twisted/PackMan/MainMenu.nib/info.nib

 <plist version="1.0">
 <dict>
 	<key>IBDocumentLocation</key>
-	<string>851 8 516 438 0 0 1440 878 </string>
+	<string>309 31 516 438 0 0 1440 878 </string>
 	<key>IBEditorPositions</key>
 	<dict>
 		<key>29</key>
 		<integer>21</integer>
 	</array>
 	<key>IBSystem Version</key>
-	<string>7B85</string>
+	<string>7C107</string>
 </dict>
 </plist>

pyobjc/Examples/Twisted/PackMan/MainMenu.nib/keyedobjects.nib

Binary file modified.

pyobjc/Examples/Twisted/PackMan/PackMan.py

 NibClassBuilder.extractClasses("MainMenu")
 
 
-class DatabasesController(NSObject):
+class DatabasesController(NibClassBuilder.AutoBaseClass):
+    _databases = [
+        {'description': "Standard", 'url': ''}
+    ]
+
+    def addDb_(self, sender):
+        if len(self._databases) is 1:
+            self._databases = self._databases[:]
+        url = self.newDatabaseURL.stringValue()
+        try:
+            self.packageController.openDatabase(str(url))
+        except ValueError, e:
+            print "bad url", `url`, e
+            return
+        self._databases.append({'description': '', 'url': url})
+        self.databaseTable.reloadData()
+        self.databaseTable.selectRowIndexes_byExtendingSelection_(
+            NSIndexSet.indexSetWithIndex_(len(self._databases)-1), NO
+        )
+
     def numberOfRowsInTableView_(self, view):
-        return 1
+        return len(self._databases)
 
     def tableView_objectValueForTableColumn_row_(self, view, column, row):
-        return "Standard"
+        row = self._databases[row]
+        return row['description'] or row['url']
 
     def tableViewSelectionDidChange_(self, aNotification):
         pass
         self.databaseList.selectRowIndexes_byExtendingSelection_(
             NSIndexSet.indexSetWithIndex_(0), NO
         )
+        self.openDatabase('http://undefined.org/python/pimp/darwin-7.0.0-Power_Macintosh.plist')
+        reactor.run()
+
+    def openDatabase(self, url):
         o = newclient.opener()
         d = o.open(
-            newclient.Request('http://undefined.org/python/pimp/darwin-6.6-Power_Macintosh.plist')
+            newclient.Request(str(url))
         ).addCallback(
             newclient.read
         ).addCallback(
         ).addErrback(
             self.errorOpening
         )
-        reactor.run()
 
     def gotPlist(self, pliststring):
         fl = StringIO(pliststring)

pyobjc/Examples/Twisted/PackMan/newclient.py

 """
 from twisted.internet import protocol, defer
 from twisted.protocols import http
+from twisted.internet import error
 import urllib2, urlparse
 
 class Request(urllib2.Request):
 
 def read(response):
     d, l = defer.Deferred(), []
+    done = []
+    def dataDone():
+        if not done:
+            d.callback(''.join(l))
+            done.append(True)
     response.setHandler(
         dataReceived=l.append,
-        dataDone=lambda:d.callback(''.join(l)),
+        dataDone=dataDone,
         connectionLost=d.errback,
     )
     return d