Skip to content

Embedding API for host applications, CLI file argument, PNG-default preview#8

Merged
BenHuddart merged 3 commits into
mainfrom
feat/editor-embedding-api
Jul 6, 2026
Merged

Embedding API for host applications, CLI file argument, PNG-default preview#8
BenHuddart merged 3 commits into
mainfrom
feat/editor-embedding-api

Conversation

@BenHuddart

Copy link
Copy Markdown
Owner

What

Three related changes preparing gleplot's editor to serve as the figure editor inside host applications (concretely: Asymmetry, which ships gleplot as a library dependency and now opens exported .gle figures in this editor in-process).

1. Embedding API (feat)

  • gleplot.gui.open_editor(path=None, *, parent=None, settings=None, gle_executable=None) — opens a shown MainWindow inside an existing QApplication (raises RuntimeError if there is none). Unlike main(), it never mutates app-global identity (name, organization, app icon — the window icon is set window-locally), and never runs an event loop. Lazily re-exported from gleplot.gui so importing the subpackage stays PySide6-free.
  • MainWindow.open_path() — public wrapper over the File ▸ Open dispatch for embedders.
  • MainWindow.apply_gle_executable() — session-only GLE-binary override + preview/status refresh, factored out of the GLE Setup accept path, so a host can impose its configured binary without overwriting the user's standalone preference.
  • MainWindow.force_close() — closes without the dirty-document confirmation, for host shutdown (an unanswerable modal would hang a headless test run; pinned by a regression test).
  • CLI: gleplot-gui figure.gle opens the file after show(); a nonexistent path exits 2 before any QApplication is created; --smoke-test ignores the file argument entirely.

2. PNG-default preview (fix)

The raster path has proven more robust than GLE's Cairo SVG backend, so PNG is now the startup render format unconditionally. SVG remains opt-in via View ▸ Vector preview (SVG); the probe compile that used to run synchronously at every controller construction now runs on the first opt-in instead (one less subprocess at startup). A failed probe routes through the existing sticky PNG fallback so the toggle unchecks/disables with the reason.

3. QtSvg occlusion-clip diagnosis (docs)

Investigating "SVG renders but elements are missing": GLE's Cairo backend implements box/legend occlusion by clipping underlying content out of the box rectangle (multi-subpath <clipPath>), not by painting over it. QtSvg has no real clip-path support, so occluded content bleeds through (or vanishes, with partial clipping). The SVG file is correct — browsers render it faithfully; only the QtSvg preview is wrong. No mechanical validation rule can catch this (empirically 100% of Cairo clip defs are multi-subpath in affected and visually-fine figures), so the opt-in toggle now carries a tooltip and shows a status-bar caveat steering users back to PNG when rendering looks wrong; the full analysis is in preview.py's design notes.

Reviewer notes

  • Merging this triggers semantic-release: the feat commit cuts 1.6.0, which is the version gate Asymmetry's editor integration feature-detects against (gleplot.gui.open_editor present → editor opens in-app; absent → legacy static preview).
  • Tests: full suite 1276 passed, 2 skipped (tests/gui/ offscreen). New coverage: tests/gui/test_app.py (9 tests: embedding API, app-identity preservation, GLE-override plumbing/non-persistence, CLI paths, open-after-show ordering, force_close) and reworked tests/gui/test_svg_preview.py (PNG default, opt-in probe, probe-failure fallback, live-render fallback).
  • The no-QApplication guard test runs in a subprocess (every in-process test already shares a QApplication).

🤖 Generated with Claude Code

BenHuddart and others added 3 commits July 6, 2026 14:18
Host applications that ship gleplot as a library (e.g. Asymmetry) can now
open the editor inside their own QApplication:

- gleplot.gui.open_editor(path, *, parent, settings, gle_executable):
  opens a shown MainWindow without touching app-global identity (name,
  organization, icon) and without running an event loop; requires an
  existing QApplication. Lazily re-exported from gleplot.gui so importing
  the subpackage stays PySide6-free.
- MainWindow.open_path(): public wrapper over the File-Open dispatch for
  embedders.
- MainWindow.apply_gle_executable(): session-only GLE-binary override +
  preview/status refresh, factored out of the GLE Setup accept path so
  embedders can impose their configured binary without overwriting the
  user's standalone preference.
- gleplot-gui now accepts an optional .gle file argument, opened after
  show() so modal prompts appear over a visible window; nonexistent paths
  exit 2 before any QApplication is created; --smoke-test ignores the
  file argument entirely.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…t-in

The raster path has proven more robust than GLE's Cairo SVG backend, so
PNG is now the startup render format unconditionally. SVG remains
available via View > Vector preview (SVG), and the one-time probe compile
that used to run at controller construction now runs on the first opt-in
instead — removing a synchronous gle subprocess from every editor startup.
A failed probe routes through the existing sticky PNG fallback so the
toggle unchecks/disables with the reason rather than silently refusing.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…G opt-in

Diagnosis of "SVG preview renders but elements are missing/wrong": GLE's
Cairo backend implements box/legend occlusion by clipping underlying
content out of the box rectangle (multi-subpath <clipPath>), not by
painting over it. QtSvg has no real clip-path support, so occluded
content bleeds through (or, with partial clipping, vanishes). The SVG
file itself is correct — browsers render it faithfully; only the QtSvg
preview is wrong.

Empirically 100% of Cairo-emitted clip defs are multi-subpath in both
affected and visually-fine figures, so no mechanical validation rule can
discriminate; instead the View > Vector preview (SVG) toggle now carries
a tooltip and shows a status-bar caveat on enable, steering users back
to the (default) PNG preview when rendering looks wrong.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@BenHuddart BenHuddart merged commit da031a5 into main Jul 6, 2026
4 checks passed
@BenHuddart BenHuddart deleted the feat/editor-embedding-api branch July 6, 2026 14:28
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