summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/iphone-python/HelloPython.app/HelloPython.py118
-rw-r--r--data/iphone-python/HelloPython.app/start.wavbin0 -> 80856 bytes
-rw-r--r--data/iphone-python/_metadata/version2
3 files changed, 99 insertions, 21 deletions
diff --git a/data/iphone-python/HelloPython.app/HelloPython.py b/data/iphone-python/HelloPython.app/HelloPython.py
index c78b141e6..5c3ee21d2 100644
--- a/data/iphone-python/HelloPython.app/HelloPython.py
+++ b/data/iphone-python/HelloPython.app/HelloPython.py
@@ -1,42 +1,120 @@
+# Special thanks goes to Dave Arter (dave@minus-zero.org)
+# for actually writing most of this sample application!!
+
+# While I managed to get PyObjC working, I didn't actually
+# know any Python to go with it ;P. - Jay Freeman (saurik)
+
import objc
-import _uicaboodle
-from objc import YES, NO
-objc.loadBundle('UIKit', globals(), '/System/Library/Frameworks/UIKit.framework')
-UIApplication = objc.lookUpClass('UIApplication')
-UITable = objc.lookUpClass('UITable')
-UIWindow = objc.lookUpClass('UIWindow')
-UIHardware = objc.lookUpClass('UIHardware')
+from _uicaboodle import UIApplicationMain
+from objc import YES, NO, NULL
+from sqlite3 import dbapi2 as sqlite
+
+objc.loadBundle("Celestial", globals(), "/System/Library/Frameworks/Celestial.framework")
+objc.loadBundle("UIKit", globals(), "/System/Library/Frameworks/UIKit.framework")
class PYApplication(UIApplication):
+ def getName(self, contact):
+ name = contact["first"]
+ if contact["last"] is not None:
+ name += " " + contact["last"]
+ return name
+
+ @objc.signature("i@:@")
+ def numberOfSectionsInSectionList_(self, list):
+ return len(self.sections_)
+
+ @objc.signature("@@:@i")
+ def sectionList_titleForSection_(self, list, section):
+ return self.sections_[section]["title"]
+
+ @objc.signature("i@:@i")
+ def sectionList_rowForSection_(self, list, section):
+ return self.sections_[section]["row"]
+
+ @objc.signature("i@:@")
+ def numberOfRowsInTable_(self, table):
+ return len(self.contacts_)
+
+ @objc.signature("@@:@i@@")
+ def table_cellForRow_column_reusing_(self, table, row, col, reusing):
+ contact = self.contacts_[row]
+ if reusing is not None:
+ cell = reusing
+ else:
+ cell = UIImageAndTextTableCell.alloc().init()
+ cell.setTitle_(self.getName(contact))
+ return cell
+
+ @objc.signature("c@:@i")
+ def table_canSelectRow_(self, table, row):
+ return NO
+
+ @objc.signature("v@:@")
def applicationDidFinishLaunching_(self, unused):
- frame = UIHardware.fullScreenApplicationContentRect()
- self.window = UIWindow.alloc().initWithFrame_(frame)
+ self.contacts_ = []
+ self.sections_ = []
- self.view = UIView.alloc().initWithFrame_(self.window.bounds())
- self.window.setContentView_(self.view)
+ db = sqlite.connect(self.userHomeDirectory() + "/Library/AddressBook/AddressBook.sqlitedb")
+ cursor = db.cursor()
+ cursor.execute("select first, last from ABPerson where first is not null order by first")
+ for first, last in cursor.fetchall():
+ self.contacts_.append({"first": first, "last": last})
+ cursor.close()
+ db.close()
+
+ outer = UIHardware.fullScreenApplicationContentRect()
+ self.window = UIWindow.alloc().initWithFrame_(outer)
self.window.orderFront_(self)
self.window.makeKey_(self)
self.window._setHidden_(NO)
+ inner = self.window.bounds()
navsize = UINavigationBar.defaultSize()
- navrect = ((0, 0), navsize)
+ navrect = ((0, 0), (inner[1][0], navsize[1]))
+
+ self.view = UIView.alloc().initWithFrame_(self.window.bounds())
+ self.window.setContentView_(self.view)
self.navbar = UINavigationBar.alloc().initWithFrame_(navrect);
self.view.addSubview_(self.navbar)
self.navbar.setBarStyle_(1)
- self.navbar.setDelegate_(self)
- navitem = UINavigationItem.alloc().initWithTitle_('Contacts')
+ navitem = UINavigationItem.alloc().initWithTitle_("Contact List")
self.navbar.pushNavigationItem_(navitem)
- bounds = self.view.bounds()
- tblrect = ((0, navsize[0]), (bounds[1][0] - navsize[0], bounds[1][1]))
+ i = 0
+ letter = u""
+ for contact in self.contacts_:
+ name = self.getName(contact)
+ now = unicode(name[0])
+ if letter != now:
+ letter = now
+ self.sections_.append({"row": i, "title": now})
+ i += 1
+
+ lower = ((0, navsize[1]), (inner[1][0], inner[1][1] - navsize[1]));
+ self.list = UISectionList.alloc().initWithFrame_(lower)
+ self.view.addSubview_(self.list)
+
+ col = UITableColumn.alloc().initWithTitle_identifier_width_("Name", "name", 320)
+
+ table = self.list.table();
+ table.setSeparatorStyle_(1)
+ table.addTableColumn_(col)
+ table.setReusesTableCells_(YES)
- self.table = UITable.alloc().initWithFrame_(tblrect)
- self.view.addSubview_(self.table)
+ self.list.setDataSource_(self)
+ self.list.reloadData()
- self.table.reloadData()
+ # XXX: this isn't working... it does from Java...
+ controller = AVController.alloc().init()
+ wavfile = NSBundle.mainBundle().pathForResource_ofType_("start", "wav")
+ wavitem = AVItem.alloc().initWithPath_error_(wavfile, NULL)
+ wavitem.setVolume_(100)
+ controller.setCurrentItem_(wavitem)
+ controller.setCurrentTime_(0)
+ controller.play_(NULL)
-_uicaboodle.UIApplicationMain(['HelloPython'], PYApplication)
+UIApplicationMain(["HelloPython"], PYApplication)
diff --git a/data/iphone-python/HelloPython.app/start.wav b/data/iphone-python/HelloPython.app/start.wav
new file mode 100644
index 000000000..91a65a3f5
--- /dev/null
+++ b/data/iphone-python/HelloPython.app/start.wav
Binary files differ
diff --git a/data/iphone-python/_metadata/version b/data/iphone-python/_metadata/version
index 97a6d65a2..8937cece4 100644
--- a/data/iphone-python/_metadata/version
+++ b/data/iphone-python/_metadata/version
@@ -1 +1 @@
-1.0.2308
+1.0.2344