Skip to content

Create GUI self-tests & implement tutorial demos - #382

Merged
briantoby merged 13 commits into
mainfrom
ArgoDemo
Dec 2, 2026
Merged

briantoby merged 13 commits into
mainfrom
ArgoDemo

Conversation

@briantoby

Copy link
Copy Markdown
Collaborator

This pull request introduces a new automated GUI self-test workflow for GSAS-II, adds several scripted GUI demo/tutorials for key refinement scenarios, and enhances the GSAS-II GUI with a menu option to run such demos interactively. It also corrects a bug in the project closing logic and ensures the new driver module is installed. These changes together significantly improve automated testing, user guidance, and code maintainability.

Automated Testing and Demo Infrastructure:

  • Added a new GitHub Actions workflow (.github/workflows/gui-selftest.yml) to run GUI scenarios as self-tests on each push, including artifact upload for logs and screenshots.
  • Added a directory (.../demos/) with five tutorials in scripted form all usable as demos or self-tests.

GUI Enhancements:

  • Added a "Run tutorial as demo" option to the Help menu in the GSAS-II GUI, allowing users to select and run scripted GUI demos from the demos directory.
  • Implemented the OnRunDemo method to launch the demo selection dialog and run the chosen demo scenario.

Project Management Improvements:

  • Improved the OnFileClose method to better handle user cancellation and save failures, returning a boolean status to indicate whether the project was cleared.

Build System:

  • Ensured the new GSASIIGUIdriver.py module is included in the installation by updating GSASII/meson.build.

briantoby and others added 10 commits November 15, 2026 14:29
GSASII/GSASIIGUIdriver.py drives the real GSAS-II GUI from a scenario
script, in test, demo (captions, typing, pauses) or step (press Next)
mode: python -m GSASII.GSASIIGUIdriver [--demo|--step] demos/FILE.py

demos/ holds two scenarios: phase_basics.py, and CWCombined_tutorial.py,
which follows the PbSO4 combined X-ray/CW-neutron refinement tutorial
and compares each refinement's Rwp with the tutorial's. It reads the
tutorial data from tests/testinp, or downloads it if those are missing.

tests/test_gui_scenarios.py runs each demo as a self-test. It is
opt-in (G2_GUI_TESTS=1, or "require" to fail with no display), so the
smoke test skips it. The new gui-selftest workflow runs it on
ubuntu-22.04 under xvfb with the pixi py313 environment and uploads
logs, plus screenshots and a report on failure.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…d only

On Linux, GSAS-II imports files with its own G2FileBrowser dialog
instead of wx.FileDialog, so the CWCombined self-test hung at the first
import on the GitHub runner. The driver now replaces
GSASIIctrlGUI.G2FileBrowser with a stand-in answered from the same queue
as wx.FileDialog.

The gui-selftest workflow is now triggered only by workflow_dispatch;
the push, pull_request and schedule triggers are commented out.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…roject

GUI driver (demo and step modes):
- Draw a picture of each native dialog the driver answers (title,
  message or typed file name, answering button outlined); in step mode
  it waits for Next unless the step is wait=False
- Draw each d.menu path, with the highlight walking to the command
- Stop works in demo mode and between waits
- --workdir DIR / run(workdir=) keeps the demo's files in DIR

Help > Run a GUI demo... (when demos/ is next to the package): choose a
demo, step-by-step or continuous, delay, and a scratch or chosen
directory. It starts with File > New project, runs the demo in the open
GSAS-II, then restores the normal dialogs and reports the result.

Fix File > New project (OnFileClose): Yes now saves (it compared with
wx.ID_OK and called the missing OnFileSaveMenu, so it cleared without
saving). A cancelled or failed save keeps the project. It returns True
when the project is cleared.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A scenario can name the tutorial it follows with a module-level
TUTORIAL = '<tutorialIndex directory>' (or a full URL). The
Help > "Run a GUI demo..." chooser then enables an "Open the tutorial
in a browser" button, which builds the URL from G2TutURL and
tutorialCatalog and opens it with ShowWebPage, as Help > Tutorials does.
CWCombined_tutorial.py names the CWCombined tutorial.

Co-Authored-By: Claude Code <noreply@anthropic.com>
In step mode a dialog picture waits for Next inside the GUI call that
opened the dialog (e.g. a menu command), so a viewer who took more than
60 s got "GUI call _menu_command did not finish in 60 s". gui() and
wait_until() now measure their timeouts from the end of the last wait
for Next (_user_clock).

Co-Authored-By: Claude Code <noreply@anthropic.com>
…oser

New scenarios in demos/: CWNeutron (YIG), LabData (fluoroapatite),
TOFCombined (X-ray/TOF-neutron) and Simulation, each following the
CWCombined model. phase_basics is now a self-test only (GUI_DEMO = False).
CWCombined's Rwp list is renamed TUTORIAL_RWP.

GUIdriver: new helpers pick, answer_dialogs, import_phase,
simulate_powder, add_constraint, set_background, set_limits, copy_hap and
menu(finished=); refine() handles zero-cycle (Max cycles 0) runs.
gui() now keeps each dialog it returns until the scenario ends and
releases them on the GUI thread: freeing a dialog wrapper on the scenario
thread crashed (segfault / double free) or hung GSAS-II.

Co-Authored-By: Claude Code <noreply@anthropic.com>
A demo that sets SELF_TEST = False is skipped by
tests/test_gui_scenarios.py (read with ast, not run); only
Simulation_tutorial.py sets it. The fitting tutorials (CWCombined,
CWNeutron, LabData, TOFCombined) and phase_basics still run. Simulation
remains in Help > Run a GUI demo...

Co-Authored-By: Claude Code <noreply@anthropic.com>
Same trigger as the smoke test: pushes to any branch except master, plus
the manual Run workflow button. Pull-request and scheduled triggers stay
commented out.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@briantoby briantoby self-assigned this Nov 17, 2026
@briantoby briantoby added the enhancement New feature or request label Nov 17, 2026
@briantoby briantoby linked an issue Nov 17, 2026 that may be closed by this pull request
@briantoby briantoby added Done? Probably complete, but not yet closed Handholding Make the software more user-friendly, particularly for neophytes labels Nov 17, 2026
@briantoby
briantoby requested a balanced review from Copilot November 17, 2026 16:34

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Unresolved save-failure and demo-cleanup bugs can discard unsaved changes, leave global hooks installed, and allow stopped demos to continue modifying projects.

4 open issues
What changed in this PR

Adds GUI automation to GSAS-II so scripted scenarios can guide users through tutorials and exercise application workflows as self-tests.

Changes:

  • Introduces a GUI driver and Help-menu demo chooser with continuous and step-by-step playback.
  • Adds five tutorial demos, a phase save/reopen self-test, and opt-in pytest execution with CI failure artifacts.
  • Updates project-close handling and includes the driver in Meson installation.
File Description
tests/​test_gui_scenarios.py Runs eligible scenarios in subprocesses and captures logs.
GSASII/​meson.build Installs the GUI driver module.
GSASII/​GSASIIGUIdriver.py Implements GUI automation, demo playback, checks and diagnostics.
GSASII/​GSASIIdataGUI.py Adds cancellation and save-result handling when clearing projects.
GSASII/​GSASIIctrlGUI.py Adds the Help-menu entry for tutorial demos.
demos/​TOFCombined_tutorial.py Demonstrates combined X-ray and time-of-flight neutron refinement.
demos/​Simulation_tutorial.py Demonstrates powder-pattern simulation; excluded from automatic self-tests.
demos/​phase_basics.py Checks phase creation, saving, clearing and reopening.
demos/​LabData_tutorial.py Demonstrates laboratory X-ray refinement of fluoroapatite.
demos/​CWNeutron_tutorial.py Demonstrates constant-wavelength neutron refinement of garnet.
demos/​CWCombined_tutorial.py Demonstrates combined X-ray and constant-wavelength neutron refinement.
.github/​workflows/​gui-selftest.yml Runs GUI self-tests on a virtual display and uploads diagnostics.

Review effort: Balanced

Comment thread GSASII/GSASIIGUIdriver.py Outdated
Comment on lines +2834 to +2835
d = GUIDriver(G2frame, demo=True, delay=delay, step_mode=step,
workdir=workdir, terminal=False)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in e79c3395: setup now restores the installed hooks and clears _ACTIVE if the work directory cannot be created.

Comment thread GSASII/GSASIIGUIdriver.py
finally:
ANSWERS.on_show = None
try:
d.close_decorations()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in e79c3395: Stop cleanup now cancels modal dialogs from async demo actions and waits for those actions to finish before restoring hooks.

Comment thread GSASII/GSASIIdataGUI.py
Comment on lines +4686 to +4687
if result == wx.ID_YES and not self.OnFileSave(event):
return False # save cancelled or failed: keep the project

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handled in e79c3395: save results now propagate through both save handlers, and a failed Save As restores the current project path so it is not cleared.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Project saves now return an explicit success result, and both save handlers propagate it so a failed save does not clear the project. Added the success return in 6b430ee.

Comment thread GSASII/GSASIIGUIdriver.py Resolved
briantoby and others added 2 commits November 17, 2026 17:03
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
@briantoby
briantoby merged commit 660e83b into main Dec 2, 2026
36 of 37 checks passed
@briantoby
briantoby deleted the ArgoDemo branch December 2, 2026 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Done? Probably complete, but not yet closed enhancement New feature or request Handholding Make the software more user-friendly, particularly for neophytes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Can GUI testing be automated?

3 participants