Code:
#!/usr/bin/env python
import re
from subprocess import *
PEN = 'ISD-V4 Pen stylus'
ERASER = 'ISD-V4 Pen eraser'
TOUCH = 'ISD-V4 Finger touch'
TRACKPOINT = 'TPPS/2 IBM TrackPoint'
COORDMAT = "Coordinate Transformation Matrix" #"129"
# Get Trackpoint transformation matrix
MAT = Popen(["xinput","list-props",TRACKPOINT],stdout=PIPE).communicate()[0]
MAT = [x for x in MAT.splitlines() if COORDMAT in x][0]
MAT = [eval(x) for x in MAT[MAT.find(':')+1:].strip().replace(',',' ').split(' ') if x]
# Store pen matrix
OLDMAT = Popen(["xinput","list-props",PEN],stdout=PIPE).communicate()[0]
OLDMAT = [x for x in OLDMAT.splitlines() if COORDMAT in x][0]
OLDMAT = [eval(x) for x in OLDMAT[OLDMAT.find(':')+1:].strip().replace(',',' ').split(' ') if x]
# Set pen matrix
call(["xinput","set-prop",PEN,COORDMAT]+map(str,MAT))
try:
# Get old coordinates
T = Popen(["xsetwacom","get",PEN,"Area"],stdout=PIPE).communicate()[0]
x1,y1,x2,y2 = map(int,T.strip().split(' '))
print "OLD AREA:",x1,y1,x2,y2
# Get points
T = Popen(["xinput_calibrator","--device",PEN,"--precalib",`x1`,`x2`,`y1`,`y2`],stdout=PIPE).communicate()[0]
x1,x2,y1,y2 = [int(re.search('Option\s*"%s"\s*"([-0-9]*)"'%x,T).group(1)) for x in ["MinX","MaxX","MinY","MaxY"]]
print "NEW AREA:",x1,y1,x2,y2
# Apply calibration
call(["xsetwacom","set",PEN,"Area",`x1`,`y1`,`x2`,`y2`])
call(["xsetwacom","set",ERASER,"Area",`x1`,`y1`,`x2`,`y2`])
except Exception,e:
print "CALIBRATION FAILED!\n"+T+`e`
# Restore old pen matrix
call(["xinput","set-prop",PEN,COORDMAT]+map(str,OLDMAT))
Currently the script calibrates both pen and eraser according to the input but it would be easy to make the behavior (set only one of them, or finger touch) flag-dependent.
Bookmarks