Edit: the project is hosted here on GitHub
I have the idea to create a Pythonista class to wrap the various things that can be done with the Pythonista app thanks to obcj_util and UIApplication. Examples (e.g by @omz, @JonB , @Webmaster4o) are currently scattered in various places, the class would bring them together and make them easy to find and use. Something like below (tab is just a stub and needs a lot of fleshing out)
Pythonista.py
# coding: utf-8
from objc_util import *
class Pythonista(object):
@on_main_thread
def __init__(self):
self.app = UIApplication.sharedApplication()
self.rootVC = self.app.keyWindow().rootViewController()
self.tabVC = self.rootVC.detailViewController()
self.consoleVC = self.app.delegate().consoleViewController()
self.userDefaults = ObjCClass('NSUserDefaults').standardUserDefaults()
@on_main_thread
def setBadgeString(self, s):
self.app.setApplicationBadgeString_(s)
@on_main_thread
def setBadgeNumber(self, i):
self.app.setApplicationIconBadgeNumber_(i)
@on_main_thread
def openURL(self, s):
self.app._openURL_(nsurl(s))
@on_main_thread
def getConsoleFont(self):
self.consoleVC.view()
return self.consoleVC.outputFont()
@on_main_thread
def getDefaultFont(self):
return [str(self.userDefaults.stringForKey_('OutputFontName')), self.userDefaults.integerForKey_('OutputFontSize')]
@on_main_thread
def addTab(self, s):
newVC = create_objc_class('CustomViewController', ObjCClass('UIViewController'), methods=[], protocols=['OMTabContent',]).new().autorelease()
newVC.title = s
self.tabVC.addTabWithViewController_(newVC)
if __name__ == "__main__":
p = Pythonista()
#p.setBadgeString('test')
#p.setBadgeNumber(1)
#p.openURL('pythonita://')
#print p.getConsoleFont()
#print p.getDefaultFont()
p.addTab('New')