-
Notifications
You must be signed in to change notification settings - Fork 14
Python
Python bindings
If you want to use libpointing with Python, you need to compile it yourself (look this page).
Once you compiled the bindings, you can import pylibpointing
and start using it.
Or import main classes:
from pylibpointing import PointingDevice, DisplayDevice, TransferFunction
from pylibpointing import PointingDeviceManager, PointingDeviceDescriptor
Creating a pointing device:
input = PointingDevice("any:?debugLevel=1") # Any input URI
Start receiving HID events from a device:
def cb_fct(timestamp, dx, dy, button):
print(dx, dy, timestamp, button)
input.setCallback(cd_fct)
Hot-plugging callback for input devices:
def cb_man(desc, wasAdded):
print desc
print "was added" if wasAdded else "was removed"
pm = PointingDeviceManager()
pm.addDeviceUpdateCallback(cb_man)
Enumerating PointingDeviceDescriptors:
for desc in pm:
print desc
You can access the following properties of a PointingDevice
:
- uri
- vendorID
- productID
- vendor
- product
- resolution
- updatefrequency
Creating a display device:
output = DisplayDevice("any:");
You can access the following properties of a DisplayDevice
:
- uri
- size { width, height }
- bounds { size: { width, height }, origin: { x, y } }
- refreshrate
- resolution { hppi, vppi }
TransferFunction
class maps the input counts of a PointingDevice
to the pixel coordinates of a DisplayDevice
.
Creating a transfer function:
tfunc = TransferFunction("any:", input, output);
List of available methods:
applyi(dx, dy, timestamp) // Integer output
applyd(dx, dy, timestamp) // Float output
clearState()
setSubPixeling(value) // By default it is turned off
setHumanResolution(resolution)
setCardinalitySize(cardinality, size)
List of properties:
- uri
- subPixeling
- cardinality
- widgetSize
- humanResolution
Note that in Python version of libpointing all transfer functions support subpixeling and the uri property returns the original transfer function URI.
Applying a transfer function to the input:
def cb_fct(timestamp, dx, dy, button):
rx,ry = tfunc.applyd(dx, dy, timestamp)
print("%s: %d %d %d -> %.2f %.2f"%(str(timestamp), dx, dy, button, rx, ry ))
input.setCallback(cb_fct)
Copyright © 2016, INRIA Lille, Mjolnir.