Skip to content

Instantly share code, notes, and snippets.

View cclauss's full-sized avatar

Christian Clauss cclauss

View GitHub Profile
@cclauss
cclauss / gpsForPythonista.py
Last active December 23, 2015 04:19
The GPS issue was fixed quite elegantly with the **location module** added in Pythonista v1.4. The code below is not longer required for Pythonista. gpsForPythonista using BaseHTTPServer and XMLHttpRequest Thanks to 'Hvmhvm' of Pythonisa fourm for working code Thanks to 'Anton2' of Pythonisa fourm for XMLHttpRequest
# The GPS issue was fixed quite elegantly with the location module
# added in Pythonista v1.4. The code below is not longer required.
# gpsForPythonista using BaseHTTPServer and XMLHttpRequest
# Source at https://gist.github.com/cclauss/6578926
# Thanks to 'Hvmhvm' of Pythonisa fourm for working code
# Thanks to 'Anton2' of Pythonisa fourm for XMLHttpRequest
# http://omz-software.com/pythonista/forums/discussion/92/gps-access-solved
# usage: from gpsForPythonista import getGPS; print(getGPS())
@cclauss
cclauss / fontCongaLine.py
Last active December 22, 2015 21:19
Conga line formed out of all available fonts in Pythonista.
import scene, os
colorLightBlue = scene.Color(.3, .3, 1)
colorWhite = scene.Color( 1, 1, 1)
fontBlackList = ('AcademyEngraved', 'AppleColorEmoji@2x',
'ArialHB', 'Bodoni72', 'ChalkboardSE',
'CourierNew', 'DB_LCD_Temp-Black',
'EuphemiaCAS', 'Fallback', 'HoeflerText',
'LastResort', 'KGPW3UI', 'LockClock',
@cclauss
cclauss / imageCongaLine.py
Last active December 22, 2015 04:08
Conga line formed out of .png images inside Pythonista.app
# imageCongaLine.py
# A Conga line formed out of .png images inside Pythonista.app
import os, scene
imageWidth = 32
#print(os.getcwd())
os.chdir('../Pythonista.app') # Look at files inside the app
#print(os.listdir('.'))
@cclauss
cclauss / sceneAndThread.py
Last active December 22, 2015 01:49
Pythonista's Scene module only wants a single scene to run so the last Scene that has had it's run() method called (either in the main thread or a child thread) will be the ONLY one to execute. All others will ignored. The scene will not get launched (i.e. it's setup() method called) until AFTER the main thread has completed.
import scene, threading, time
colorRed = scene.Color(1, 0, 0)
colorGreen = scene.Color(0, 1, 0)
colorBlue = scene.Color(0, 0, 1)
theColors = (colorRed, colorGreen, colorBlue)
greyLight = scene.Color(.7, .7, .7)
greyMedium = scene.Color(.5, .5, .5)
greyDark = scene.Color(.3, .3, .3)
@cclauss
cclauss / tiltingColor.py
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: https://github.com/cclauss/Pythonista_scene
@cclauss
cclauss / flippedDisplay.py
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
@contextmanager
def privateGstate():
"""Save the canvas.gstate and then restore it when leaving the 'with' clause."""
canvas.save_gstate()
try: yield None
finally: canvas.restore_gstate()
@cclauss
cclauss / macOSXPasteboard.py
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 = p.stdout.read()
@cclauss
cclauss / tabsTo4Spaces.py
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.')
sys.exit()
theLength = len(theText)
@cclauss
cclauss / draggableImages.py
Last active December 16, 2015 04:49
draggableImages demo for Pythonista on iOS.
# http://omz-forums.appspot.com/pythonista/post/5144563366756352
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
cclauss / blueMaze.py
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) = self.bounds.center()