PyTouch SDK
PyTouch is an SDK developed in python with the intended purpose of creating applications for touch surfaces. PyTouch will also prepare you for developing for many other types of touch enabled devices since it follows many of the same design practices.
init(bgcolor)
Initializes the pytouch app.
bgcolor : (r,g,b)
Sets the background color of the app
Defaults to (0,0,0)
update
Update is used to refresh the application each frame. All changes to objects will come into effect after update is called.
import pytouch
p = pytouch.init()
while 1:
p.update()
If any touches are received update will call any necessary callback functions.
redraw
Redraw draws all objects in reverse order of their z_index, if no z_index was specified then it just draws objects in the reverse order in which they were created. It will not draw any objects which have visibility turned off.
clear
Clear empties the screen of all objects but does not delete them, if redraw is called all of the objects will be placed back on the screen in their last positions or if they were moved in their new positions.
Rect(x, y, width, height, color, alpha, z_index, drag_enabled, edge_thickness)
Rect calls the pyobject.rect constructor and adds the object to the list of all other objects that have been created.
x : integer
The x position of where the rect is going to be drawn.
y : integer
The y position of where the rect is going to be drawn.
width : integer
Width of the rect to be drawn
height : integer
Height of the rect to be drawn
color : string
Color of the rect to be drawn
Defaults to 'white'
alpha : integer
Alpha (transparency) of the rect to be drawn
Defaults to None
Valid input is 0 to 255
z_index : integer
z_index of the rect to be drawn which specifies depth of objects.
A z_index with a higher value will be drawn on top of objects with lower z_indices.
Defaults to 0
drag_enabled : boolean
Specifies whether this object will respond to drag events and can be moved.
Defaults to False
edge_thickness : integer
Applies a border with the specified width.
Defaults to 0
Image(image, x, y, z_index, drag_enabled)
Image calls the pyobject.image constructor and adds the object to the list of all other objects that have been created.
image : string
Path of the image to be loading
x : integer
The x position of where the rect is going to be drawn.
y : integer
The y position of where the rect is going to be drawn.
z_index : integer
z_index of the rect to be drawn which specifies depth of objects.
A z_index with a higher value will be drawn on top of objects with lower z_indices.
Defaults to 0
drag_enabled : boolean
Specifies whether this object will respond to drag events and can be moved.
Defaults to False
Text(x,y,text,fontsize,fontcolor,font,aa,z_index,drag_enabled)
Text calls the pyobject.text constructor and adds the object to the list of all other objects that have been created.
x : integer
The x position of where the rect is going to be drawn.
y : integer
The y position of where the rect is going to be drawn.
text : string
Actual text to be added
fontsize : integer
Size of the text to be added
fontcolor : (r,g,b)
Color of the text to be added
Defaults to (255,255,255)
font : string
Font of the text to be added
Defaults to None
aa : boolean
Sets the anti-aliasing value, true means that there will be anti-aliasing
Defaults to 1
z_index : integer
z_index of the rect to be drawn which specifies depth of objects.
A z_index with a higher value will be drawn on top of objects with lower z_indices.
Defaults to 0
drag_enabled : boolean
Specifies whether this object will respond to drag events and can be moved.
Defaults to False
Touch
Touch
Represents a single touch from a user.
xpos
X position of the touch
ypos
Y position of the touch
origin
Origin of the touch, can be either mouse or Tuio
sessionid
Unique id of the touch, mouse touches are negative numbers, TUIO are positive
status
Status of the click, can be clicked, dragging, holding, held
time_held
Time that the touch has been held in the same place.
Touch Tracker
All touches from mouse and tuio are merged into Touch objects and then will return the most recent touch.
init(window_width, window_height)
Initializes the touch tracker
window_width : integer
Width of the window of the app
window_height : integer
Height of the window of the app
update
Update checks for all new touch inputs every time it is called and will return one if found. It responds to both mouse and tuio inputs and will merge them all into Touch objects.
Pyobject
Pyobject is an abstract class that contains methods that are implemented by classes that inherit from it including Rect, Image, and Text.
init(x,y,width,height,z_index,drag_enabled)
Initializes a new instance of a pyobject
x : integer
The x position of where the rect is going to be drawn.
y : integer
The y position of where the rect is going to be drawn.
width : integer
Width of the rect to be drawn
height : integer
Height of the rect to be drawn
z_index : integer
z_index of the rect to be drawn which specifies depth of objects.
A z_index with a higher value will be drawn on top of objects with lower z_indices.
Defaults to 0
drag_enabled : boolean
Specifies whether this object will respond to drag events and can be moved.
Defaults to False
draw
Draws the object to the screen, this must be implemented by a class that inherits from pyobject
update
An optional function to implemented by a user, will be called every time pytouch.update() is called.
move(x,y)
Moves the object to the specified coordinations
x : integer
X position of where the object should be moved.
y : integer
Y position of where the object should be moved.
setVisible(visible)
Sets the visibility of an object
visibile : boolean
If visible is true then object will be drawn to the screen, otherwise it will not.
remove
Will remove the object from existence within the app
touchInside(touch)
Checks to see if a touch is within an object, if it is it will call the corresponding callback function based on the status of the touch.
touch : Touch
Instance of the Touch class.
dragHandler(obj,touch,extra)
Handler that gets called when an object has a click and drag event on it. Default event is to check if drag_enabled is true and if it is the object will move with the touch. User may override this to complete a different action on drag.
obj : pyobject
Object that is being touched
touch : Touch
Instance of the Touch class.
extra : dictionary
Any additional values that the user may need.
Default value is None
holdHandler(obj,touch,extra)
Handler that gets called when an object has a click and hold event on it. Default event is to do nothing. User may override this to complete a different action on click and hold.
obj : pyobject
Object that is being touched
touch : Touch
Instance of the Touch class.
extra : dictionary
Any additional values that the user may need.
Default value is None
touchUpInsideHandler(obj,touch,extra)
Handler that gets called when an object has a click event on it. Default event is to do nothing. User may override this to complete a different action on click.
obj : pyobject
Object that is being touched
touch : Touch
Instance of the Touch class.
extra : dictionary
Any additional values that the user may need.
Default value is None
collide(obj)
Checks to see if a pyobject collides with another one.
obj : pyobject
Object that will be checked for collision.
collidelist(objlist)
Checks to see if a pyobject within a list of pyobjects collides with another one, returns the first collision.
objlist : list
List of pyobjects that will be checked for collision.
collidelistall(objlist)
Checks to see if pyobjects within a list of pyobjects collide with another one, returns all collisions.
objlist : list
List of pyobjects that will be checked for collision.
Image
init(image,x,y,z_index,drag_enabled)
See pytouch.Image
draw(surface)
Draws the image onto the provided surface
change_image(image)
Changes the image of the object.
image : string
Path to image
resize(width,height)
Resizes image to the specified dimensions.
Rectangle
init(x,y,width,height,color,alpha,z_index,drag_enabled,edge_thickness)
See pytouch.Rect
draw(surface)
Draws the rect onto the provided surface
change_color(color,g,b,a)
Changes the color of the object.
color : string or integer
If g,b,a are provided this should be an integer representing r in rgba
g,b,a : integer
Integers reprenting gba in rgba values
Default to None
Text
init(x,y,text,fontsize,fontcolor,font,aa,z_index,drag_enabled)
See pytouch.Text
draw(surface)
Draws the text onto the provided surface
changeText(text)
Changes the text of the object.
text : string
Text to change the current text to.
Time
get_ticks
Returns time in milliseconds since start of app.
wait(milliseconds)
Wait sleeps the process for a given number of milliseconds.
delay(milliseconds)
Delay stops the app for a given number of milliseconds but does not sleep the process.
Time
init
Starts the app clock.
tick(framerate)
Returns the number of milliseconds since the last time tick was called, should be called every frame.
tick_busy_loop(framerate)
Returns the number of milliseconds since that last time tick_busy_loop was called, should be called every frame. More accurate but also requires more cpu than tick.
get_time
Returns the number of milliseconds between the last two calls to tick.
get_rawtime
Similar to time but does not include delays from tick
get_fps
Computes game's framerate by averaging the last 10 calls to tick