Skip to content

Draft: Reimplement halshow in Python#4231

Open
petterreinholdtsen wants to merge 3 commits into
LinuxCNC:masterfrom
petterreinholdtsen:reimplement-halshow-python
Open

Draft: Reimplement halshow in Python#4231
petterreinholdtsen wants to merge 3 commits into
LinuxCNC:masterfrom
petterreinholdtsen:reimplement-halshow-python

Conversation

@petterreinholdtsen

Copy link
Copy Markdown
Collaborator

Replace the tcl/tk implementation of halshow with a Python/Qt implementation, and add new graph support using graphviz to show the interconnection in HAL between pins and signals.

Replace the Tcl/Tk halshow (tcl/bin/halshow.tcl) with a Python/Qt
implementation using qtpy for cross-backend compatibility. The new
edition provides identical functionality plus additional features:

Core architecture:
- Direct shared memory access via _hal C extension, eliminating
  subprocess overhead. Creates a minimal component "_halshow_{pid}"
  that is cleanly removed on exit (ready() -> exit()) to prevent
  zombie accumulation.
- Added get_info_components(), get_info_functions(),
  get_info_threads() to halmodule.cc for SHM-based listing of
  components/functions/threads without halcmd subprocess calls.
- Robust cleanup: atexit handler + signal handlers (SIGINT/SIGTERM/SIGHUP)
  ensure component is removed from SHM on any exit path. Fixed a bug where
  the old Tcl edition leaked components when exiting via SIGPIPE or
  "linuxcnc -l" (which raises SystemExit).

Watch tab:
- Value|Name|Buttons layout matching Tcl halshow order
- Full pin names shown in watch rows (not truncated)
- [Tgl]/[Set]/[Clr] buttons for writable bit signals, plain value for read-only
- Buttons dynamically disabled when signal gains writers at runtime
- Halcmd fallback for writer detection on old _hal.so lacking WRITERS field

Show tab:
- Signal detail matches halcmd "show sig" monospace table format exactly
- Value right-aligned in 5-char field, matching Tcl edition
- Tree view uses monospace font with no word wrap

Main window layout:
- Tree view and tabs side-by-side in a splitter
- Command entry and status bar span full width below the splitter (Tcl match)
- All user-facing GUI text translatable via PO files / gettext (_() wrappers)

This patch was created with help from OpenCode using local llama.cpp
server with Qwen 3.6.
…zation

Add a new GRAPH tab (between WATCH and SETTINGS) that renders HAL topology as
a bipartite graph (component → signal → component), laid out by Graphviz dot.

Graph data model:
- GraphDataBuilder collects pins/signals from SHM into structured component/signal dicts,
  with O(1) pin-to-component index for fast edge resolution
- Three-tier fallback for resolving signal connections: pure-SHM pin SIGNAL field,
  _hal.get_signal_connections(), or halcmd show sig via background QThread
- Owner detection falls back to heuristics when old _hal.so lacks OWNER field

Layout engine (GraphLayout.compute):
- Builds directed AGraph with component boxes and diamond-shaped signal nodes
- Runs dot for crossing-minimized placement; extracts edge splines for rendering
- Coordinates scaled from points (72 dpi) to device pixels (96 dpi)

Rendering (QGraphicsView scene):
- ComponentItem: rounded rectangles with blue header, green IN pins (left column),
  red OUT pins (right column), and connection markers on edges
- SignalNodeItem: orange diamonds sized to fit signal names
- Edges route from writer pin → signal diamond perimeter → reader pin marker,
  each segment with arrowhead; uses dot splines when available, cubic bezier fallback
- Multi-edge spreading between same component pair

Interaction:
- Pan via middle/left mouse drag; zoom via scroll wheel or +/- buttons
- Right-click context menus on components (add pins to watch) and edges (watch signal)
- "Hide unused pins" toggle filters component boxes to only connected pins
- Lazy layout computation deferred until first tab activation

CLI --dotty flag:
- Print HAL topology as DOT source to stdout then exit, with layout parameters
  matching the GRAPH tab for debugging purposes

This patch was created with help from OpenCode using local llama.cpp
server with Qwen 3.6.
@petterreinholdtsen petterreinholdtsen changed the title Draft: Reimplement halshow python Draft: Reimplement halshow in Python Jul 9, 2026
@grandixximo

grandixximo commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

You might want to enable the executable bit in git for halshow.py
I did quick testing, not looked at the graph yet, should pygraphviz become a dependency?
The grouped view of pins and parameters is the new default, but seems not working in the port?

@petterreinholdtsen

petterreinholdtsen commented Jul 10, 2026 via email

Copy link
Copy Markdown
Collaborator Author

@grandixximo

Copy link
Copy Markdown
Contributor

What is this? I do not believe I have used or seen this myself.
Something from after 2.9?

Yes, just made it in 2.10 a few weeks back, see #4147

In PyQt6 and PySide6, WindowStaysOnTop moved from Qt to
Qt.WindowType. Add a compatibility shim that resolves the flag for
both backend families.

Fixes crash when applying settings (alwaysOnTop toggle) in halshow.py.

This patch was created with help from OpenCode using local llama.cpp
server with Qwen 3.6.
@petterreinholdtsen

petterreinholdtsen commented Jul 10, 2026 via email

Copy link
Copy Markdown
Collaborator Author

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.

2 participants