Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / audiounit_lib.py
Created Oct 28, 2018
audiounittest3.py
View audiounit_lib.py
from ctypes import *
from objc_util import c
AudioUnitRenderActionFlags=c_uint32
OSStatus=c_int32
OSType=c_uint32
class SMPTETimeType(c_uint32):
kSMPTETimeType24 = 0
kSMPTETimeType25 = 1
kSMPTETimeType30Drop = 2
kSMPTETimeType30 = 3
View turtle2.py
#\input texinfo
# coding: utf-8
# ui-based iOS port of the turtle module (not 100% compatible with standard library
# turtle module, but most things beginners would use should work)
import ui
from math import *
import math
import time
@jsbain
jsbain / mapscene.py
Last active Aug 18, 2020
mapscene.py
View mapscene.py
from scene import *
import sound
import random
import math
A = Action
mapsprites=['plc:Brown_Block','plc:Dirt_Block','plc:Grass_Block','plc:Plain_Block',]
def choose_random_node():
tx=random.choice(mapsprites)
sn=SpriteNode(tx)
View navview_utils.py
import ui,console,time
from objc_util import on_main_thread
@on_main_thread
def get_top_view(navigation_view):
'''returns the top (aka visible) view from a navigation view'''
import ctypes
nc= navigation_view.objc_instance.navigationController()
tc=nc.topViewController()
v=tc.view()
return v.pyObject(restype=ctypes.py_object,argtypes=[])
View simple_recorder.py
import sound,ui
from sound import Recorder
from sound import Player
sound.set_volume(1)
filename='4.m4a' #could have this come from a textfield in the ui...
play_image=ui.Image('iob:play_256')
stop_image=ui.Image('iob:stop_256')
record_image=ui.Image('iob:ios7_circle_filled_256')
View simple_recorder.py
import sound,ui
from sound import Recorder
from sound import Player
sound.set_volume(1)
filename='4.m4a' #could have this come from a textfield in the ui...
play_image=ui.Image('iob:play_256')
stop_image=ui.Image('iob:stop_256')
record_image=ui.Image('iob:ios7_circle_filled_256')
View detector.py
# coding: utf-8
# based on Cethric's image capture gist....
FRAME_PROC_INTERVAL=15 #num frames to skip. 1=go as fast as possible, 5=every fifth frame
import ui
from objc_util import *
import ctypes
from objc_util import autoreleasepool
AVCaptureDevice = ObjCClass('AVCaptureDevice')
AVCaptureDeviceInput = ObjCClass('AVCaptureDeviceInput')
AVCaptureVideoDataOutput = ObjCClass('AVCaptureVideoDataOutput')
View customMenuItem.py
from objc_util import *
from objc_hacks import swizzle # github.com/jsbain/objc_hacks.git
NSNotificationCenter=ObjCClass('NSNotificationCenter')
class PYUIMenuItem(object):
'''Base class representing a uimenuitem, which can be added to the manager.
Each item must have a title string, a selector name, and an action callback.
Must define subclasses with __selector__ field, __title__ string
Action callback must be of form
@jsbain
jsbain / inputAccessoryExample.py
Created Oct 14, 2018
inputAccessoryExample.py
View inputAccessoryExample.py
# coding: utf-8
'''Creates a custom input accessory view, and attaches it to textfield and textview
this example demonstrates custom text buttons (emoji, etc), and custom actions
'''
from objc_util import *
import ui
'''set up top level view and textfield'''
v=ui.View(frame=[0,0,300,300],bg_color=(.92, .92, .92))
tf=ui.TextField(frame=[10,10,200,30])
@jsbain
jsbain / Map View Demo2.py
Created May 10, 2018
Map View Demo2.py
View Map View Demo2.py
# coding: utf-8
'''
NOTE: This requires Pythonista 3
Demo of a custom ui.View subclass that embeds a native map view using MapKit (via objc_util). Tap and hold the map to drop a pin.
The MapView class is designed to be reusable, but it doesn't implement *everything* you might need. I hope that the existing methods give you a basic idea of how to add new capabilities though. For reference, here's Apple's documentation about the underlying MKMapView class: http://developer.apple.com/library/ios/documentation/MapKit/reference/MKMapView_Class/index.html
adapted from original code by omz