Touch: Base for all touch objects

Touch: Base for all touch objects

Every touch in PyMT derives from the abstract Touch class. A touch can have more or less attributes, depending on the provider. For example, the TUIO provider can give you a lot of information about the touch, like position, acceleration, width/height of the shape and so on. Another provider might just give you x/y coordinates and pressure.

We call these attributes “capabilities”. Every touch indicates its capabilities in its “profile” property. A profile is just a simple list with strings, containing for example:

  • pos (property x, y)
  • pos3d (property x, y, z)
  • mov (tuio/property X, Y)
  • mov3d (tuio/property X, Y, Z)
  • dim (tuio/property w, h)
  • dim3d (tuio/property w, h, d)
  • markerid (tuio/property i (fid property))
  • sessionid (tuio/property s (id property))
  • angle (tuio/property a)
  • angle3D (tuio/property a, b, c)
  • rotacc (tuio/property A)
  • rotacc3d (tuio/property A, B, C)
  • motacc (tuio/property m)
  • shape (property shape)
  • kinetic
  • ... and others could be added by new classes

If you’re only interested in a certain kind of touches, check the profile:

def on_touch_down(self, touch):
    if 'markerid' not in touch.profile:
        # not a fiducial, not interesting
        return
class pymt.input.touch.Touch(device, id, args)

Bases: object

Abstract class to represent a touch, and support TUIO 1.0 definition.

Parameters :
id : str

uniq ID of the touch

args : list

list of parameters, passed to depack() function

apply_transform_2d(transform)

Apply a transformation on x, y, dxpos, dypos, oxpos, oypos

copy_to(to)

Copy some attribute to another touch object.

depack(args)

Depack args into attributes in class

dpos

Return previous position of the touch in the screen coordinate system (self.dxpos, self.dypos)

grab(class_instance, exclusive=False)

Grab a touch. You can grab a touch if you absolutly want to receive on_touch_move() and on_touch_up(), even if the touch is not dispatched by your parent

def on_touch_down(self, touch):
    touch.grab(self)

def on_touch_move(self, touch):
    if touch.grab_current == self:
        # i receive my grabbed touch
    else:
        # it's a normal touch

def on_touch_up(self, touch):
    if touch.grab_current == self:
        # i receive my grabbed touch, i must ungrab it !
        touch.ungrab(self)
    else:
        # it's a normal touch
move(args)

Move the touch to another position.

opos

Return the initial position of the touch in the screen coordinate system (self.oxpos, self.oypos)

pop()

Pop attributes values from the stack

pos

Return position of the touch in the screen coordinate system (self.x, self.y)

push(attrs=None)

Push attributes values in attrs in the stack

scale_for_screen(w, h, p=None)

Scale position for the screen

spos

Return the position in the 0-1 coordinate system (self.sx, self.sy)

ungrab(class_instance)

Ungrab a previous grabbed touch

Previous topic

Touch Shape: Represent the shape of the touch

Next topic

Lib: some libraries used by PyMT

This Page