Skip to content

Restructure the GUI into separate functions - #12

Draft
boriskaus wants to merge 1 commit into
mainfrom
restructure-gui
Draft

boriskaus wants to merge 1 commit into
mainfrom
restructure-gui

Conversation

@boriskaus

Copy link
Copy Markdown
Member

Draft. Not meant to be merged before the course week. This is a proposal for the restructuring Marcel is planning. Take whatever parts are useful.

The GUI used to be a single 570-line start_AdA_Picker function that shared state through global variables. It is now split into small functions, and a struct holds the state of each window. The GUI looks and works as before (screenshots compared).

New structure (src/)

File Contents
Data/profile_data.jl Get the data to plot from a GMG ProfileData: field/surface/point names, topography, grid, slices. Doesn't need the GUI.
Picks/picks_io.jl Picks → table with lat/lon, save_picks, load_picks, pick_points. Doesn't need the GUI.
Layout/building_blocks.jl Reusable pieces for new GUIs: titled_panel, styled_toggle, toggle_list!, visible_if, add_logo!, hide_axis!
GUI/gui_state.jl PickerGUI struct (figure, panels, controls, profile, plots, picks). It replaces the global dragging, idx, picks, ax1, p1. The GUI started last is available with current_gui().
Layout/main_layout.jl Figure and main panels
Controls/layout_main_controls.jl Main menu and picking controls
Controls/data_controls.jl Field data controls (menu, colormap, color range slider/textboxes) and toggle panels
Plotting/profile_plot.jl Axes, topography, heatmap, surfaces, points, picks, colorbar and legends
Picks/picking_interaction.jl Mouse callbacks for adding, deleting and dragging picks
FileIO/fileIO_utils.jl File dialogs, load_profile!, and the menu actions as a Dict (menu entry → function)
AdA_Picker.jl start_AdA_Picker, which puts everything together (~20 lines)

To build a different GUI (e.g. horizontal profiles), you can reuse the data, picks and building-block functions and write another short start_... function. Adding a menu entry means adding it to MAIN_MENU_OPTIONS and MAIN_MENU_ACTIONS.

Small changes in behavior

  • Errors in the asynchronous menu actions are now printed. Before, they were silently swallowed by the task.
  • Cancelling the "Load Profile..." file dialog no longer throws an error.
  • start_AdA_Picker(data = ...) now loads a profile directly (a ProfileData or a jld2 filename). Before, the keyword argument was ignored.
  • The field menu shows the field that is plotted (e.g. dVs) instead of "Select...".
  • The helper fields x_profile and FlatCrossSection are removed from the field list by name, instead of dropping the last two entries.
  • Profiles without surface or point data no longer crash.
  • Removed utils.jl (only commented-out code, replaced by add_logo!/hide_axis!) and the unused menu_fileIO_response. test_playground.jl and AdA_VizPickTool_V1.txt are left untouched.

Not changed: loading a second profile still draws the new plots on top of the old ones, and dragging picks still doesn't work.

Tests

The existing GUI tests only needed to switch from the old globals (ax1, picks) to current_gui(). I added test/test_data.jl for the functions that don't need a GUI; those tests also run on the macOS CI runners, which have no OpenGL. Marcel wanted to add tests after the restructuring, so feel free to replace or extend them. All 52 tests pass locally on Julia 1.10 and 1.12.

🤖 Generated with Claude Code

The single 570-line start_AdA_Picker function is split into:
- Data/profile_data.jl: extracting the data to plot from a ProfileData (no GUI)
- Picks/picks_io.jl: converting, saving and loading picks (no GUI)
- Layout/building_blocks.jl: reusable pieces (titled panels, toggle lists, logo)
- GUI/gui_state.jl: PickerGUI struct that replaces the global variables
- Layout/main_layout.jl, Controls/*, Plotting/profile_plot.jl,
  Picks/picking_interaction.jl, FileIO/fileIO_utils.jl: the parts of this GUI
- AdA_Picker.jl: start_AdA_Picker, which puts them together

Also: errors in the asynchronous menu actions are now printed, cancelling the
file dialog no longer throws, and start_AdA_Picker(data = ...) loads a profile
directly.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
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