-
Notifications
You must be signed in to change notification settings - Fork 1
perchPy
perchPy is a pythonic implementation of the Perch base classes.
###Perch Python API
PerchThe Python modul containing all python bindings.
object classes
Object, PerchObject,
Point, Color
Image, Video, Sound, Slideshow, Textbox, Rectangle,
Handsensor, ProductsensorBase classes contained in Perch modul. Classes can be fully derived in python.
modul member functions
updateImage(Perch.Image , URI)
updateText(Perch.Textbox, text)
tween(Perch.PerchObject , tweenDict)Modul functions are headless functions. They are invoked as follows: Perch.updateImage(Perch.Image Object , Path/TO/IMAGE.png).
object fields and funtions
Perch.Object
//fields
scale
position
rotation
name
alpha
visible
//methods
update()
draw()
getParent()
addChild()
messageHandler()
Perch.PerchObject
//methods
getChildren()
init()
show()
hide()A PerchObject has access to all fields and methods of an Object. PerchObjects are the core container class of any PERCH Application.
Perch.Point
//fields
x
y
z
//methods
set(x,y,z)Perch.Point is a simple 3-dimensional Point.
Perch.Color
//fields
r
g
b
a
//methods
set(r,g,b,a)Simple RGB color.
Perch.Sound
//fields
loop //bool
multiplay //bool
//methods
load(URI)
play()A Soundobject that can play the most common digital sound formats (i.e. wav, mp3, aiff)
Perch.Video
//methods
load(URI)
play()
stop()A Videoplayer that can play back most video formats (all videos that run on a MacOSX system by default will run on PERCH)
Perch.Textbox
//methods
setup(w,h,pos)
setBackground(color)Simple Textbox. Text can be updated by using the modul function Perch.updateText(Perch.Textbox , "text to update")
Perch.Slideshow
//methods
load(URI)Slideshow that loads a folder.
Perch.Image
//methods
load(URI)Image implementation.
Perch.Handsensor
//methods
setup(x,y,w,h)
messageHandler(msg msg_dict);
Perch.Objectsensor
setup(x,y,w,h)
messageHandler(msg msg_dict);Two main sensor classes in pyPerch. Both have a messageHandler that is called from the core application to notify the object of a sensing event, i.e.
#Button Class implements Perch.Handsensor
class Button(Perch.Handsensor):
def __init__(self, listener=0):
super(Button, self).__init__()
self.img = Perch.Image() #img holder for button texture
self.sound = Perch.Sound() #click sound
self.state = 0
self.URI_d = ''
self.URI_s = ''
self.listener = listener
self.listenerList = list()
#define Image URIs to be swapped for button clicks
def loadTextures(self, URI_d, URI_s):
self.URI_d = URI_d
self.URI_s = URI_s
#self.img.load(self.URI_d)
def messageHandler(self, msg, d):
print 'got override'
if self.listener != 0:
self.listener.notify(msg, d , self)
else:
if state == 1:
self.state=0
else:
self.state=1
self.click(self.state)
print [entry for entry in d]
def setup(self, x,y,w,h):
super(Button , self).setup(x,y,w,h) #setup Button using Perch.Handsensor setup(int x, int y, int w ,int h) method
self.img.load(self.URI_d) #load image
self.addChild(self.img) #add Image to the Button (poCode style)
self.img.position = Perch.Point(x,y,0)
#self.sound.load("assets/button/btn.wav")
self.addChild(self.sound)
def updateImage(self, URI):
Perch.updateImage(self.img , URI)
#click method to swap textures and play click sound
def click(self , state):
self.state = state
if self.state == 1:
self.updateImage(self.URI_s)
# print 'playing sound'
# self.sound.play();
# print 'played sound'
else:
self.updateImage(self.URI_d)