Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news.d/bugfix/1808.core.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid error at startup if `hidapi` library is not available.
13 changes: 10 additions & 3 deletions plover/machine/plover_hid.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
Plover HID is a simple HID-based protocol that sends the current state
of the steno machine every time that state changes.
"""
from __future__ import annotations

from plover.machine.base import ThreadedStenotypeBase
from plover.misc import boolean
from plover import log

import hid
import time
import platform
import ctypes
Expand All @@ -21,6 +21,10 @@
from typing import Dict
from dataclasses import dataclass

try:
import hid
except ImportError:
hid = None

def _darwin_disable_exclusive_open():
lib = getattr(hid, "hidapi", None)
Expand All @@ -36,7 +40,7 @@ def _darwin_disable_exclusive_open():


# Invoke once at import time (before any devices are opened)
if platform.system() == "Darwin":
if platform.system() == "Darwin" and hid is not None:
_darwin_disable_exclusive_open()

USAGE_PAGE: int = 0xFF50
Expand Down Expand Up @@ -82,7 +86,7 @@ class PloverHid(ThreadedStenotypeBase):
A- O- -E -U
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10
X11 X12 X13 X14 X15 X16 X17 X18 X19 X20
X21 X22 X23 X24 X25 X26
X21 X22 X23 X24 X25 X26
'''
# fmt: on

Expand Down Expand Up @@ -250,6 +254,9 @@ def run(self):

def start_capture(self):
self.finished.clear()
global hid
if hid is None:
import hid # likely raises ImportError
self._initializing()
# Enumerate all hid devices on the machine and if we find one with our
# usage page and usage we try to connect to it.
Expand Down
Loading