Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / TouchDispatcher.py
Created November 22, 2014 21:28
TouchDispatcher.py
# example of custom touch dispatch module
import ui
# wrapper class for Touch, since ui.Touch is readonly
class Touch(object):
def __init__(self,touch):
self.location=touch.location
self.touch_id=touch.touch_id
self.phase=touch.phase
self.prev_location=touch.prev_location
@jsbain
jsbain / ZoomView.py
Created November 25, 2014 10:06
ZoomView.py
import ui
class Touch(object):
''' writable version of ui.Touch'''
def __init__(self,touch):
self.location=touch.location
self.touch_id=touch.touch_id
self.phase=touch.phase
self.prev_location=touch.prev_location
self.timestamp=touch.timestamp
@jsbain
jsbain / ZoomView.py
Created November 25, 2014 10:25
ZoomView.py
import ui
class Touch(object):
''' writable version of ui.Touch'''
def __init__(self,touch):
self.location=touch.location
self.touch_id=touch.touch_id
self.phase=touch.phase
self.prev_location=touch.prev_location
self.timestamp=touch.timestamp
@jsbain
jsbain / path_edit.py
Created January 8, 2015 08:40
path_edit.py
'''
useless path editor.
tap to add a point. tap again to add a control point.
then, another control point, and finally another point on the curve.
existing points and control points can be dragged around, to change the curve.
clicking save button saves an image of the path, without the handles.
@jsbain
jsbain / world.py
Created February 18, 2015 15:56
world
class world (object):
def webview_should_start_load(self,webview, url, nav_type):
if url.startswith('world://'):
print 'country selected:', urlparse.unquote(urlparse.urlparse(url).netloc)
return False
else:
return True
import ui,os
w=ui.WebView()
@jsbain
jsbain / gistcheck.py
Created March 25, 2015 06:15
updated for ios8
# Source: https://gist.github.com/5212628
#
# All-purpose gist tool for Pythonista.
#
# When run directly, this script sets up four other scripts that call various
# functions within this file. Each of these sub-scripts are meant for use as
# action menu items. They are:
#
# Set Gist ID.py - Set the gist id that the current file should be
# associated with.
@jsbain
jsbain / mail.py
Last active August 30, 2019 18:23
mail.py
# coding: utf-8
import objc_util
from objc_util import *
# setup an array of objects we cannot discard
objc_util.retain=getattr(objc_util,'retain',[])
root_vc = UIApplication.sharedApplication().keyWindow().rootViewController()
def mailComposeController_didFinishWithResult_error_(self, sel, controller, result, error):
root_vc.dismissModalViewControllerAnimated_(True)
@jsbain
jsbain / kbtest.py
Created October 31, 2015 06:14
kbtest.py
# coding: utf-8
import console,ui
ptype=console.alert('select present type','select one','fullscreen','panel','sheet')
ptypes=('fullscreen','panel','sheet')
class KBTest(ui.View):
def __init__(self):
self.kb_callback=None
self.frame=(0,0,768,768)
self.flex='wh'
@jsbain
jsbain / view_setup_demo.py
Created December 22, 2015 17:33
view_setup_demo.py
# coding: utf-
import ui,time
def setup_view(v):
''' a very slow and complicated setup'''
for i in xrange(10):
b=ui.Button(bg_color=(1,i/20.,0))
b.frame=(200,0,50,50)
b.y=i*50
v.add_subview(b)
@jsbain
jsbain / view_setup_demo.py
Created December 22, 2015 17:38
view_setup_demo.py
# coding: utf-
import ui,time
def setup_view(v):
''' a very slow and complicated setup'''
for i in xrange(10):
b=ui.Button(bg_color=(1,i/20.,0))
b.frame=(200,0,50,50)
b.y=i*50
v.add_subview(b)