Skip to content

mcgui: template folder handling, monkey-test crash fixes, app icon; mcplot/mcdisplay fixes - #2942

Merged
willend merged 5 commits into
mainfrom
2026-10-mcgui-template-dir
Oct 30, 2026
Merged

willend merged 5 commits into
mainfrom
2026-10-mcgui-template-dir

Conversation

@willend

@willend willend commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

What changed

mcgui: New From Template (7c56a6c)

The save-file dialog made an existing template folder impossible to select (typing its name navigates into it), so users had to invent a new folder name. Now:

  • A folder dialog picks the parent folder; the template folder name is derived. Picking the template-named folder itself also works.
  • If the folder exists: Open existing / New copy (<name>_N) (default, first free _2, _3, …) / Replace with template / Cancel.
  • Copies use shutil.copytree (subfolders included). The old merge path silently overwrote edited .instr files and failed on subfolders.

mcgui: crash fixes from a monkey test (d009067)

  • Compile while compiling aborted the app ("QThread: Destroyed while thread is still running"). Now ignored with a status message.
  • Run: cancelled if the instrument is closed/changed while mcrun --info runs (GUI stays live in that loop); Run ignored when no instrument is loaded.
  • Run dialog: validates ray count and random seed instead of raising later.
  • Run dialog inspect off-by-one: selecting a component inspected the next one, and the last one raised IndexError.
  • Save As with no instrument: no more UnboundLocalError.
  • Component header parse errors show a message instead of raising.
  • Configuration: GUICOLS/GUIFONTSIZE kept unless a positive integer is given.
  • "Set as default": stray trailing comma made the reply a tuple, so it never ran.

Components (e17376d)

Add missing header tags required by ComponentParser: %D in misc/Cone.comp (McStas and McXtrace), %E in contrib/SpinWave_BCO.comp and union/Union_NCrystal_material.comp. Documentation-only change, no code/physics change.

mcplot / mcdisplay (a2b56fd)

  • matplotlib mcplot and mcdisplay: numbered re-saves dropped the dot (mcplot_1pdf), so savefig wrote a PNG named mcplot_1pdf.png and kept overwriting it.
  • mcplot-matplotlib: clicks on non-panel axes (colorbars) no longer raise ValueError.
  • mcplot-pyqtgraph: clicks whose target was deleted by a replot no longer raise RuntimeError.
  • mcplot-pyqtgraph: SVG export (s) prints a message instead of a traceback. Root cause is upstream: pyqtgraph 0.14.0 can't parse Qt 6.11's SVG path output (reproduced with bare pyqtgraph).

mcgui app icon (17a3ff4)

QApplication.setWindowIcon with the already-installed <flavour>-py.png: Dock icon on macOS, window/taskbar icon on Windows/Linux. The PNG is 115 px wide, so a larger PNG would look sharper on Retina.

Testing

  • macOS arm64, Python 3.14 / PyQt6 6.11 from a conda dev env. No visible window: random menu actions, clicks, keys, wheel events and dialog answers (~3,500 mcgui steps; 24 × 250 steps over mcplot-pyqtgraph, mcplot-matplotlib and mcdisplay-pyqtgraph with real McStas output). Every failing seed was re-run clean after the fixes.
  • Template copy logic checked with a small test script (fresh, open, _2/_3, cancel, replace).
  • Icon checked by launching mcgui on macOS.
  • Not tested: Linux, Windows, McXtrace-specific runs, native file dialogs, mcplot HTML/plopp frontends.

No numerical behaviour changes.

🤖 Generated with Claude Code

willend and others added 5 commits October 30, 2026 15:51
The save-file dialog made an existing template folder unselectable (typing
its name navigates into it), forcing users to invent a new folder name.
Now a folder dialog picks the parent; if the template folder already
exists the user can open it, make a numbered new copy (_2, _3, ...),
or replace it with the template. Copies now include subfolders.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Ignore Compile while a compile is running (replacing the running
  QThread aborted the application)
- Cancel Run if the instrument is closed/changed while mcrun --info runs,
  and ignore Run when no instrument is loaded
- Validate ray count and random seed in the Run dialog
- Fix off-by-one in the Run dialog "inspect" component lookup (picked
  the next component, IndexError on the last one)
- Save As with no instrument loaded: return instead of UnboundLocalError
- Show an error instead of raising when a component header can't be parsed
- Configuration: keep GUICOLS/GUIFONTSIZE unless a positive integer is given
- "Set as default": remove stray trailing comma that made the answer a tuple

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cone (McStas and McXtrace) lacked %D; SpinWave_BCO and
Union_NCrystal_material lacked %E. mccodelib's ComponentParser requires
both, so mcgui's Insert-component dialog failed on these.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- matplotlib mcplot/mcdisplay: numbered re-saves used the format without
  its dot ("mcplot_1pdf"), so savefig wrote a PNG named mcplot_1pdf.png
  and kept overwriting it
- mcplot-matplotlib: ignore clicks on non-panel axes (colorbars) instead
  of raising ValueError from subplts.index()
- mcplot-pyqtgraph: ignore clicks whose target item was deleted by a
  replot (RuntimeError)
- mcplot-pyqtgraph: report SVG export failure (pyqtgraph 0.14.0 can't
  parse Qt 6.11's SVG path output) instead of a traceback

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sets the already-installed <flavour>-py.png as the QApplication window
icon: Dock icon on macOS, window/taskbar icon on Windows and Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@willend
willend merged commit a4bc088 into main Oct 30, 2026
21 checks passed
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