After reading Apple’s docs a bit more closely, it looks like most of the tablet
events are automatically converted into corresponding mouse events. So you
will need to add some code to mouseDown_, mouseDragged_, and mouseUp_ in
pyglet_view to catch when this happens and then send out an on_tablet_point
event with the info you want. Here’s how I think I would rewrite mouseDown_
for example:
@PygletView.method(‘v@‘)
def mouseDown_(self, nsevent):
x, y = getMousePosition(self, nsevent)
buttons = mouse.LEFT
modifiers = getModifiers(nsevent)
# send out the mouse event as usual
self._window.dispatch_event(‘on_mouse_press’, x, y, buttons, modifiers)
# then also check if this was a tablet event
if nsevent.subtype() == 1: # I think NSTabletPointEventSubtype is defined
as 1 based on very limited testing
pressure = nsevent.pressure()
tilt = nsevent.tilt()
self._window.dispatch_event(‘on_tablet_point’, x, y, buttons, pressure,
tilt.x, tilt.y, modifiers)
Note that you can use getMousePosition even in the tabletPoint events.
Otherwise, I think the coordinates you get from absoluteX etc. are not scaled
to the window.
Also it might make more sense to define separate on_tablet_press,
on_tablet_release, on_tablet_drag events instead of sending everything out as
on_tablet_point. In which case the last line of the above code would be
changed to
self._window.dispatch_event(‘on_tablet_press’, x, y, buttons, pressure, tilt.x,
tilt.y, modifiers)
—phillip
> On Apr 20, 2016, at 2:38 PM, future stack <[email protected]> wrote:
>
> Okay, that got me a little further, many thanks! I've added the following
> code to pyglet_view
>
> @PygletView.method('v@')
> def tabletProximity_(self, nsevent):
>
> capabilityMask = nsevent.capabilityMask()
> deviceID = nsevent.deviceID()
> # these are listed
> https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSEvent_Class/#//apple_ref/doc/uid/20000016-SW32
> # but do not seem to work here
> #enteringProximity = nsevent.enteringProximity()
> pointingDeviceID = nsevent.pointingDeviceID()
> #pointDeviceSerialNumber = nsevent.pointDeviceSerialNumber()
> #pointDeviceType = nsevent.pointDeviceType()
> self._window.dispatch_event('on_tablet_proximity', capabilityMask,
> deviceID, pointingDeviceID)
>
> @PygletView.method('v@')
> def tabletPoint_(self, nsevent):
> absoluteX = nsevent.absoluteX()
> absoluteY = nsevent.absoluteY()
> absoluteZ = nsevent.absoluteZ()
> buttonMask = nsevent.buttonMask()
> rotation = nsevent.rotation()
> pressure = nsevent.pressure()
> tangentialPressure = nsevent.tangentialPressure()
> tilt = nsevent.tilt()
> vendorDefined = nsevent.vendorDefined()
> self._window.dispatch_event('on_tablet_point', absoluteX, absoluteY,
> absoluteZ, buttonMask, rotation, pressure, tangentialPressure, tilt,
> vendorDefined)
>
>
> and this is printing sporadic info - is there another type that I'm supposed
> to be looking for? I'm getting maybe 20% of my tablet presses, which is not
> helpful as I'm developing a drawing application.
> Maybe it has something to do with event coalescing?
>
> I'm unable to get tablet proximity information out either... any further tips
> or tricks would be greatly appreciated. Thanks again
>
> Andrew
>
>
> On Wednesday, April 20, 2016 at 2:40:07 PM UTC-4, Phillip Nguyen wrote:
>
> It’s been a really long time since I looked at this code, but I think you
> would want to add something like the following method:
>
> @PygletView.method(‘v@‘)
> def tabletPoint_(self, nsevent):
> // insert code here to extract relevant info from nsevent
> self._window.dispatch_event(‘on_tablet_point’, x, y, buttons, pressure,
> tilt, modifiers)
>
> to the existing code in pyglet/window/cocoa/pyglet_view.py. As there
> currently is no on_tablet_point event in pyglet, you would be defining it.
>
> —phillip
>
>
>
> > On Apr 20, 2016, at 12:00 PM, future stack <[email protected]> wrote:
> >
> > I feel like this topic might warrant adding something to the documentation,
> > since the current documentation is somewhat misleading.
> >
> > This page simply remarks that enumerating tablets is impossible on osx but
> > says nothing about an alternative approach
> > https://pyglet.readthedocs.org/en/pyglet-1.2-maintenance/api/pyglet/input/pyglet.input.get_tablets.html
> >
> >
> > This page on "other devices" covers joysticks and an apple remote but
> > nothing about tablets:
> > https://pyglet.readthedocs.org/en/pyglet-1.2-maintenance/programming_guide/input.html?highlight=devices
> >
> >
> > I can't tell if this is a failing on my part to understand something basic,
> > or what, but it's been somewhat frustrating digging around for a simple
> > example. This seems like a fairly common use case.
> >
> > Andrew
> >
> > On Wednesday, April 20, 2016 at 12:17:20 PM UTC-4, future stack wrote:
> > Pardon my ignorance, I've accessed this stuff via NSEvent in c++ but am
> > unsure how this would be done in a pyglet compatible way. I've tried
> > adding listeners to the window for the handlers defined in the tablet, and
> > I've tried enumerating and opening the devices directly with no luck. Am
> > I supposed to use pyobjc or NSpython?
> >
> > Cheers
> >
> >
> > On Wednesday, April 20, 2016 at 12:06:27 PM UTC-4, swiftcoder wrote:
> > I don't know what Pyglet's support for tablets is like at the moment, but
> > Wacom provides excellent documentation as to accessing tablet events on
> > Mac:
> >
> > http://www.wacomeng.com/mac/Developers%20Guide.htm
> >
> > At this point I don't honk any mucking around in Carbon or HID is required.
> > The standard Cocoa NSEvent object carries everything you need, which should
> > make it easy to expose to pyglet.
> > On Wed, Apr 20, 2016 at 9:00 AM, Tristam MacDonald <[email protected]>
> > wrote:
> > Aren't the
> >
> > On Wed, Apr 20, 2016 at 9:00 AM, Tristam MacDonald <[email protected]>
> > wrote:
> >
> > On Wed, Apr 20, 2016 at 7:57 AM, future stack <[email protected]> wrote:
> > 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.
> >
> > --
> > 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.
>
>
> --
> 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.
--
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.