Skip to content

Decouple protocol layer from Qt - #382

Open
joshperry wants to merge 1 commit into
vial-kb:mainfrom
joshperry:deguify
Open

Decouple protocol layer from Qt#382
joshperry wants to merge 1 commit into
vial-kb:mainfrom
joshperry:deguify

Conversation

@joshperry

Copy link
Copy Markdown

This decouples the protocol layer from PyQt5 so it can be imported from headless/CLI contexts without pulling in the GUI toolkit.

Motivation

The protocol layer (keyboard_comm.py, vial_device.py, and friends) implements HID communication and keymap serialization — none of which requires Qt. However, transitive imports of util.py (which imports PyQt5 at the top level) and unlocker.py (a QDialog subclass) made it impossible to from protocol.keyboard_comm import Keyboard without having PyQt5 installed. This blocks use cases like CLI tooling, scripting, and CI/CD integration.

Changes

New file:

  • util_base.py — Contains hid_send, MSG_LEN, chunks, find_vial_devices, is_rawhid, pad_for_vibl, and the serial number magic constants. Zero GUI dependencies.

Refactored:

  • util.py — Re-exports everything from util_base via from util_base import ..., so all existing GUI code continues to work with no changes.
  • protocol/keyboard_comm.py, protocol/tap_dance.py, protocol/combo.py, protocol/key_override.py, protocol/alt_repeat_key.py, protocol/macro.py — Replaced top-level from unlocker import Unlocker with lazy imports inside the methods that actually use it (only triggered when writing QK_BOOT).
  • protocol/macro.py — Also made from macro.macro_action_ui import tag_to_action lazy (Qt dependency via QObject).
  • vial_device.py — Imports from util_base instead of util.

New test:

  • test/test_protocol_gui_free.py — AST-scans the protocol import chain for top-level Qt and GUI module imports. Catches regressions automatically.

What this does NOT change

  • No behavioral changes. The GUI works exactly as before.
  • The Unlocker unlock flow is unchanged; it's just imported at call time rather than module load time.
  • All existing from util import ... statements in GUI code continue to work via re-export.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant