Hello - I'm curious what the state of tablet support is on osx and if
someone can provide me with an example of how to read pen pressure from a
stylus?
I've attached my attempt from a few days ago, but I've been informed that
my approach is wrong.
A friend linked me to this page:
https://github.com/jpaalasm/pyglet/blob/master/experimental/input/tablet-notes.txt#L37
which says that events are subscribeable via carbon or HID, but I can't
find a working example of this anywhere.
I also found this:
https://bitbucket.org/AnomalousUnderdog/pythonmactabletlib/downloads
but this requires wxwidgets to work, which is apparently still 32 bit, and
downgrading my python to get this to work seems less than ideal.
Am I barking up the wrong tree(s)? Any leads would be appreciated.
Andrew
--
You received this message because you are subscribed to the Google Groups
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.
"""
////-------------------------------------begin tablet.py
"""
import pyglet
from pyglet.input.evdev import *
import time
from pyglet.input.base import \
Device, DeviceException, DeviceOpenException, \
Control, Button, RelativeAxis, AbsoluteAxis
class RelHandler():
def on_change(self, val):
print "rel - change"
def on_press(value):
print "rel - press"
def on_release(button, value):
print "rel - release"
class AbsHandler():
def on_change(value):
print "abs - change"
def on_press(value):
print "abs - press"
def on_release(value):
print "rel - release"
class ButtonHandler():
def on_change(self, val):
print "btn - change"
def on_press(button,):
print "btn - press"
def on_release(button):
print "btn - release"
class WacomApp(object):
def __init__(self):
# this is a big NOPE on osx
tabs = pyglet.input.get_tablets()
if tabs:
# do something cool!?
return
devs = pyglet.input.get_devices()
devs = [x for x in devs if "Wacom" in x.device_identifier[0]]
self.devs = devs
self.butts = []
self.absxs = []
self.relxs = []
self.handle_b = ButtonHandler()
self.handle_a = AbsHandler()
self.handle_r = RelHandler()
for d in devs:
self.enum_device(d)
def open(self):
for d in self.devs:
d.open()
print len(self.devs), "Devices opened."
print len(self.absxs), "abs"
print len(self.relxs), "rel"
print len(self.butts), "but"
def close(self):
for d in self.devs:
d.close()
def ex(self):
import sys
sys.exit()
def enum_device(self, d):
print d
print dir(d)
print d.name
cs = d.get_controls()
self.absxs += [x for x in cs if "Absolute" in repr(x)]
self.relxs += [x for x in cs if "Relative" in repr(x)]
self.butts += [x for x in cs if "Button" in repr(x)]
for c in self.absxs:
c.push_handlers(self.handle_a)
for c in self.relxs:
c.push_handlers(self.handle_r)
for c in self.butts:
c.push_handlers(self.handle_b)
""" these don't seem to change at all in my setup,
figured it wouldn't hurt to test?
def print_butt_vals(self):
for a in self.butts:
v = a.value
print v
def print_absx_vals(self):
for a in self.absxs:
v = a.value
print v
def print_relx_vals(self):
for a in self.relxs:
v = a.value
print v
"""
def update(self):
pass
# self.print_butt_vals()
# self.print_absx_vals()
# self.print_relx_vals()
def loop(self):
done = False
while not done:
time.sleep(1)
"""
if __name__ == "__main__":
w = WacomApp()
done = False
while not done:
try:
w.loop()
except KeyboardInterrupt:
done = True
"""
"""
//------------------------------end tablet.py
"""
from pyglet.gl import *
from pyglet.window import *
window = pyglet.window.Window(640, 480)
window.set_caption("test")
#from pyglet.input.carbon_tablet import CarbonTablet
#ct = CarbonTablet()
#from tablet import WacomApp
#wa = WacomApp()
@window.event
def on_draw():
window.clear()
@window.event
def on_mouse_motion(x, y, dx, dy):
global mouse
mouse = (x, y)
@window.event
def on_mouse_press(x, y, button, modifiers):
pass
@window.event
def on_enter(x,y):
print x, y
@window.event
def on_motion(cursor, x, y, pressure):
print x
@window.event
def on_key_press(symbol, modifiers):
if symbol == key.C:
window.clear()
elif symbol == key.ESCAPE:
exit()
def update(dt):
pass
#wa.update()
def draw(dt):
on_draw()
tabs = pyglet.input.get_tablets()
print tabs
pyglet.clock.schedule_interval(update, .5)
pyglet.clock.schedule_interval(draw, 60./1.)
#wa.open()
pyglet.app.run()
#wa.close()