wolfhece.tablet_wintab

Direct WinTab pressure reader via Wintab32.dll (ctypes).

wx.glcanvas.GLCanvas is not registered as a WinTab context by wxPython, so wx.MouseEvent.GetPressure() always returns 0.0 on OpenGL canvases even with a working Wacom driver. This module bypasses wx and opens its own WinTab context, then polls the packet queue in EVT_MOTION handlers.

Usage:

# In WolfMapViewer.__init__ (after super().__init__):
try:
    from wolfhece.tablet_wintab import WinTabContext
    self._wintab = WinTabContext(self.GetHandle())
except Exception as exc:
    logging.warning("WinTab unavailable: %s", exc)
    self._wintab = None

# In _get_event_pressure:
if self._wintab is not None:
    return self._wintab.get_pressure()

# On window close:
if self._wintab is not None:
    self._wintab.close()

Module Contents

exception wolfhece.tablet_wintab.DllNotFoundError[source]

Bases: RuntimeError

Inheritance diagram of wolfhece.tablet_wintab.DllNotFoundError

Raised when Wintab32.dll cannot be found on this machine.

wolfhece.tablet_wintab.log[source]
wolfhece.tablet_wintab._WTI_DEFCONTEXT = 3[source]
wolfhece.tablet_wintab._WTI_DEVICES = 100[source]
wolfhece.tablet_wintab._DVC_NPRESSURE = 15[source]
wolfhece.tablet_wintab._CXO_MESSAGES = 4[source]
wolfhece.tablet_wintab._PK_NORMAL_PRESSURE = 1024[source]
class wolfhece.tablet_wintab._LOGCONTEXTA[source]

Bases: ctypes.Structure

Inheritance diagram of wolfhece.tablet_wintab._LOGCONTEXTA

LOGCONTEXTA — WinTab logical context (ASCII variant).

_fields_[source]
class wolfhece.tablet_wintab._AXIS[source]

Bases: ctypes.Structure

Inheritance diagram of wolfhece.tablet_wintab._AXIS

AXIS — range and resolution of one tablet axis.

_fields_[source]
class wolfhece.tablet_wintab._PACKET[source]

Bases: ctypes.Structure

Inheritance diagram of wolfhece.tablet_wintab._PACKET

Minimal WinTab packet containing only normal pressure.

Must match the lcPktData mask set in the LOGCONTEXT (only _PK_NORMAL_PRESSURE is requested, so the packet is one UINT).

_fields_[source]
class wolfhece.tablet_wintab.WinTabContext(hwnd: int)[source]

Reads stylus pressure via Wintab32.dll (polling mode).

Parameters:

hwnd – Native window handle, typically wx.Window.GetHandle().

Raises:

RuntimeError – If Wintab32.dll is not found or the tablet context cannot be opened (driver absent, no tablet connected, etc.).

_MAX_PACKETS = 32[source]
_hctx: int | None = None[source]
_enabled: bool = False[source]
_pressure: float = 1.0[source]
_pressure_max: int = 1023[source]
_bind_functions() None[source]

Set argtypes/restype on the WinTab functions we use.

_open_context(hwnd: int) None[source]
enable() None[source]

Enable the WinTab context so it starts delivering packets.

Called via wx.CallAfter from _init_wintab_context so that activation happens after the wx event loop has started, avoiding the Wacom driver heap-corruption bug triggered during app initialisation.

get_pressure() float[source]

Drain the WinTab packet queue and return the latest pressure.

Returns a float in [0.0, 1.0]. Returns the last known value when no new packets are available, and 1.0 if the context is closed.

close() None[source]

Close the WinTab context and release the DLL handle.