Skip to content

Instantly share code, notes, and snippets.

Created January 13, 2016 22:55
  • Star 9 You must be signed in to star a gist
  • Fork 7 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save steventroughtonsmith/51edd66425998e5fca37 to your computer and use it in GitHub Desktop.
Insert a custom browser tab into Pythonista
# coding: utf-8
from Foundation import *
from QuartzCore import *
from UIKit import *
import console
WKWebView = ObjCClass('WKWebView')
def main():
rootVC = UIApplication.sharedApplication().windows()[0].rootViewController()
tabVC = rootVC.detailViewController()
methods = [openURL, search]
protocols = ['OMTabContent']
CustomViewController = create_objc_class('CustomViewController', UIViewController, methods=methods, protocols=protocols)
vc =
vc.title = 'Web'
urlBarItem = UIBarButtonItem.alloc().initWithImage_style_target_action_(UIImage.imageNamed_('Textures/ionicons-link-24'),0,vc,sel('openURL'))
searchBarItem = UIBarButtonItem.alloc().initWithImage_style_target_action_(UIImage.imageNamed_('Textures/ionicons-search-24'),0,vc,sel('search'))
vc.navigationItem().rightBarButtonItems = [urlBarItem, searchBarItem]
webView =
vc.view = webView
def openURL(_self, _cmd):
address = console.input_alert('Open URL')
if len(address) > 0:
def search(_self, _cmd):
term = console.input_alert('Search')
if len(term) > 0:
if __name__ == '__main__':
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment