Skip to content

Instantly share code, notes, and snippets.

@jsbain
jsbain / screenspeedtest.py
Created October 23, 2018 15:38
screenspeedtest.py
import ui, io, Image, matplotlib.image,numpy, timeit
print(__file__)
A=numpy.random.rand(300,300,3)
Au=(255*A).astype('uint8')
B=io.BytesIO()
def p(format='jpeg'):
B.seek(0)
Image.fromarray(Au).save(B,format=format)
return ui.Image.from_data(B.getvalue())
def m(format='jpeg'):
@jsbain
jsbain / audiounittest.py
Created October 22, 2018 15:45
audiounittest.py
from objc_util import *
from ctypes import *
from coreaudioconstants import *
''' Adapted from https://www.cocoawithlove.com/2010/10/ios-tone-generator-introduction-to.html
'''
AudioUnitRenderActionFlags=c_uint32
OSStatus=c_int32
OSType=c_uint32
@jsbain
jsbain / inputAccessoryExample.py
Created October 14, 2018 10:01
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 / 3dview.py
Created September 24, 2018 06:31
3dview.py
from scene import *
#import sound
import random
import math
import numpy as np
A = Action
class Shape3D (object):
@jsbain
jsbain / navview_utils.py
Created August 21, 2018 15:24
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=[])
@jsbain
jsbain / Untitled_203.py
Created August 21, 2018 04:40
Untitled_203.py
import ui, random
pyui='''
\n[\n{\n"class":"View",\n"attributes":{\n"background_color":"RGBA(1.000000,1.000000,1.000000,1.000000)",\n"tint_color":"RGBA(0.000000,0.478000,1.000000,1.000000)",\n"enabled":true,\n"border_color":"RGBA(0.000000,0.000000,0.000000,1.000000)",\n"flex":""\n},\n"frame":"{{0,0},{240,240}}",\n"selected":false,\n"nodes":[\n{\n"class":"Button",\n"attributes":{\n"font_size":15,\n"tint_color":"RGBA(1.000000,0.511111,0.266667,1.000000)",\n"title":"Button",\n"name":"button1",\n"class":"Button",\n"frame":"{{80,104},{80,32}}",\n"background_color":"RGBA(1.000000,0.755556,0.633333,1.000000)",\n"uuid":"EBCC1C1F-4705-4F87-A6A1-07C0A50D7116"\n},\n"frame":"{{27,25},{80,87}}",\n"selected":true,\n"nodes":[\n\n]\n}\n]\n}\n]\n
'''
class bgLines(ui.View):
def draw(self): #drawing must happen in draw
self.w = ui.get_screen_size()[0]
self.h = ui.get_screen_size()[1]
self.lines=[]
@jsbain
jsbain / turtle2.py
Created August 6, 2018 06:19
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 / turtle2.py
Created August 6, 2018 06:09
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 / Untitled_200.py
Created July 9, 2018 15:14
Untitled_200.py
from objc_util import *
def foo_bar(_self,_cmd):
baz = 5
return baz
foo_bar.encoding = 'l@:'
'''
first character is return type, then each argument, per encodings below. @ is objc object, : is selector.
@jsbain
jsbain / multicb.py
Created June 24, 2018 05:57
multicb.py
import cb, threading
class Service(object):
'''wrapper for a cb.Service. Can index characteristics by
s[uuid] or s[index]
'''
def __init__(self,service):
self.primary=service.primary
self.uuid=service.uuid
self.characteristics={}