Skip to content

Instantly share code, notes, and snippets.

View cclauss's full-sized avatar

Christian Clauss cclauss

View GitHub Profile
cclauss /
Created July 17, 2014 19:34
# change the draw() method below to draw your plot
# using the ui.Path drawing commands documented at
import ui
class PlotView(ui.View):
def __init__(self, parent = None):
self.frame = (0, 0, 255, 255)
import ui
filename = 'name.txt'
def read_username(filename=filename):
username = None
with open(filename) as in_file:
for line in in_file.readlines():
username = line.strip() or username
cclauss /
Last active December 14, 2015 10:38
Play a blues melody on Pythonista on the iPad (iOS)
# Play a blues melody on Pythonista on the iPad (iOS)
import sound
import time
def playNotes(inNotes, inWithEmphisis=False):
for note in inNotes:
sound.play_effect('Piano_' + note)
if (inWithEmphisis):
sound.play_effect('Piano_' + note)
cclauss /
Created March 9, 2013 09:47
Using nyamuk on Pythonista on iOS. > Download from github the nyamuk Python library and install it for Pythonista on iOS.
#!/usr/bin/env python
# installNyamuk --
# download from github the nyamuk Python library and install it for Pythonista on iOS
#import nyamuk, sys # uncomment if you want to test if nyamuk is already installed
#print('got it...')
import os, shutil, urllib, zipfile
cclauss /
Created March 31, 2013 20:36
blueMaze -- just a hack to get to know the Pythonista graphics Scene class..
from scene import *
from random import random
class MyScene (Scene):
def setup(self):
# This will be called before the first frame is drawn.
self.root_layer = Layer(self.bounds)
self.mLines = []
self.mCount = 0
(self.mCurrLocX, self.mCurrLocY) =
cclauss /
Last active December 16, 2015 04:49
draggableImages demo for Pythonista on iOS.
import random, scene
sizeInPixels = 100
def rectFromPt(inPoint): # returns a scene.Rect centered on inPoint
half = sizeInPixels / 2
return scene.Rect(inPoint.x - half, inPoint.y - half, sizeInPixels, sizeInPixels)
cclauss /
Created April 22, 2013 14:55
Simple Pythonista utility script that you need to put this Pythonista Actions menu. It goes though the script currently open in the Pythonista Editor, converting all tab characters ('\t') into four space characters.
# replace ALL tab characters with four spaces
import editor, sys
theText = editor.get_text()
theCount = theText.count('\t')
if not theText.count('\t'):
print('no tabs found.')
theLength = len(theText)
cclauss /
Created August 11, 2013 05:00
Get and set the text content of the Mac OS X Pasteboard using pbcopy and pbpaste
#!/usr/bin/env python
# For details, in Mac OS X Terminal type: man pbcopy
import subprocess, sys
def getClipboardData(): # Only works for data types: {txt | rtf | ps}
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
retcode = p.wait()
data =
cclauss /
Last active December 21, 2015 13:38
Pythonista's canvas module's graphics origin (0, 0) is at the bottomLeft. "with flippedDisplay": will temporarily switch the graphics origin to be at the topLeft.
import canvas, scene
from contextlib import contextmanager
def privateGstate():
"""Save the canvas.gstate and then restore it when leaving the 'with' clause."""
try: yield None
finally: canvas.restore_gstate()
cclauss /
Last active December 21, 2015 18:48
A gravity hack that uses Pythonista's scene.gravity() method to change screen colors when the user tilts their device. Red = abs(pitch), Green = abs(yaw), Blue = abs(roll)
Moved to: