Skip to content

Comments

[SWM-220][perf] GUI: only load the tabs necessary based on the microscope role#3366

Open
pieleric wants to merge 1 commit intodelmic:masterfrom
pieleric:perf-gui-only-load-the-tabs-necessary-based-on-the-microscope-role
Open

[SWM-220][perf] GUI: only load the tabs necessary based on the microscope role#3366
pieleric wants to merge 1 commit intodelmic:masterfrom
pieleric:perf-gui-only-load-the-tabs-necessary-based-on-the-microscope-role

Conversation

@pieleric
Copy link
Member

@pieleric pieleric commented Feb 13, 2026

Each tab is shown or not depending the hardware. However, until now, all the tab were loaded, and then a call to get_display_priority() by the tab controller would decide whether it's worthy showing or not.

However, just based on the microscope role, we can have already a pretty good idea of which tab is certainly not useful.

=> load only the tabs that could be used for the current microscope role.

This mainly avoids failures due to a missing an external module imported by a non-used tab.
In theory, it should also improve the loading time of the GUI. However, tests on the viewer (were the saving should be most noticeable) show it barely improved: going from ~3.34 to ~3.28 (-> 0.06s faster)

Copilot AI review requested due to automatic review settings February 13, 2026 12:19
@pieleric pieleric changed the title [perf] GUI: only load the tabs necessary based on the microscope role [SWM-220][perf] GUI: only load the tabs necessary based on the microscope role Feb 13, 2026
@coderabbitai
Copy link

coderabbitai bot commented Feb 13, 2026

📝 Walkthrough

Walkthrough

The PR changes the GUI tab system to load tabs conditionally based on the detected microscope role rather than loading all tabs and hiding unused ones. The package public exports were reduced to only TabBarController and Tab. Tab button visibility is handled during tab creation (shown immediately) instead of via a post-creation cleanup. Many XRC GUI elements (tab buttons and other controls) are marked hidden by default in resource files.

Sequence Diagram

sequenceDiagram
    participant Main as GUI Main Initialization
    participant RoleDetector as Microscope Role Detection
    participant TabDef as Tab Definition Builder
    participant TabCtrl as TabBarController
    participant Tab as Tab Instances
    participant UI as UI Components

    Main->>RoleDetector: Query microscope role
    RoleDetector-->>Main: Return role (e.g., secom, sparc, meteor, mbsem, None)

    Main->>TabDef: Build role-specific tab_defs
    TabDef-->>Main: Return tab_defs for role

    Main->>TabCtrl: Initialize with tab_defs
    TabCtrl->>Tab: Instantiate each tab in tab_defs
    Tab-->>TabCtrl: Tab instance created
    TabCtrl->>UI: Show corresponding tab button (explicit Show())
    UI-->>TabCtrl: Button becomes visible

    TabCtrl-->>Main: TabBar initialization complete
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Merge Conflict Detection ⚠️ Warning ❌ Merge conflicts detected (17 files):

⚔️ .github/workflows/unit_tests_cloud.yml (content)
⚔️ src/odemis/acq/align/test/z_localization_test.py (content)
⚔️ src/odemis/acq/move.py (content)
⚔️ src/odemis/acq/test/move_tescan_test.py (content)
⚔️ src/odemis/acq/test/move_tfs3_test.py (content)
⚔️ src/odemis/acq/test/move_zeiss_test.py (content)
⚔️ src/odemis/acq/test/stream_static_test.py (content)
⚔️ src/odemis/driver/xt_client.py (content)
⚔️ src/odemis/gui/cont/acquisition/cryo_acq.py (content)
⚔️ src/odemis/gui/cont/milling.py (content)
⚔️ src/odemis/gui/cont/multi_point_correlation.py (content)
⚔️ src/odemis/gui/cont/tabs/__init__.py (content)
⚔️ src/odemis/gui/cont/tabs/secom_streams_tab.py (content)
⚔️ src/odemis/gui/cont/tabs/tab_bar_controller.py (content)
⚔️ src/odemis/gui/main.py (content)
⚔️ src/odemis/gui/main_xrc.py (content)
⚔️ src/odemis/gui/xmlh/resources/frame_main.xrc (content)

These conflicts must be resolved before merging into master.
Resolve conflicts locally and push changes to this branch.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: loading only necessary tabs based on microscope role for performance optimization.
Description check ✅ Passed The description is directly related to the changeset, explaining the rationale for conditional tab loading based on microscope role and the measured performance improvement.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
⚔️ Resolve merge conflicts (beta)
  • Auto-commit resolved conflicts to branch perf-gui-only-load-the-tabs-necessary-based-on-the-microscope-role
  • Post resolved changes as copyable diffs in a comment

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
src/odemis/gui/cont/tabs/tab_bar_controller.py (1)

160-182: The buttons set is now only used for the assertion — consider simplifying.

After removing the post-creation cleanup that hid unused buttons, the buttons set (line 161) is only consumed by the assert on line 180. Since assertions can be stripped with -O, this is effectively dead state tracking. You could inline the check or remove it entirely if the invariant is guaranteed by the new per-role tab loading in main.py.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@src/odemis/gui/main.py`:
- Around line 253-297: The code creates a CryoMainGUIData for roles ("meteor",
"enzel", "mimas") but only registers meteor tabs for main_data.role == "meteor",
leaving enzel/mimas without their expected UI and causing warnings/errors; fix
by making the role checks consistent: either remove "enzel" and "mimas" from the
CryoMainGUIData creation (in the code that instantiates CryoMainGUIData) or
expand the tab-registration branch (the elif that imports
CorrelationTab/CryoChamberTab/LocalizationTab/FibsemTab) to include "enzel" and
"mimas" (e.g., main_data.role in ("meteor","enzel","mimas")) and add a
deprecation log when role is "enzel" or "mimas" so they still get the cryo tabs
but are flagged as deprecated.
🧹 Nitpick comments (1)
src/odemis/gui/main.py (1)

284-296: Commented-out code for deprecated enzel/mimas align tabs.

If these roles are fully deprecated and no longer supported, consider removing the commented-out blocks entirely rather than leaving dead code. The git history preserves the old definitions if they're ever needed again.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request optimizes GUI initialization by conditionally loading tabs based on the microscope role, rather than loading all tabs upfront. This change aims to avoid failures from missing external modules imported by unused tabs and potentially improve loading time.

Changes:

  • Modified tab loading to be role-based, importing tab classes only when needed for the current microscope role
  • Updated XRC resource files to hide all tab buttons by default, showing them programmatically when tabs are loaded
  • Removed bulk imports from tabs/init.py, keeping only essential TabBarController and Tab imports
  • Updated tab_bar_controller.py to show buttons for loaded tabs instead of hiding unused ones
  • Simplified secom_streams_tab.py get_display_priority method since role filtering now happens earlier

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/odemis/gui/xmlh/resources/frame_main.xrc Hidden all tab buttons by default to be shown programmatically when loaded
src/odemis/gui/main_xrc.py Generated XRC file synced with frame_main.xrc changes
src/odemis/gui/main.py Implemented conditional tab loading based on microscope role with on-demand imports
src/odemis/gui/cont/tabs/tab_bar_controller.py Changed to show buttons for loaded tabs instead of hiding unused ones
src/odemis/gui/cont/tabs/secom_streams_tab.py Simplified get_display_priority by removing redundant role checks
src/odemis/gui/cont/tabs/init.py Removed tab class imports, keeping only TabBarController and Tab, and updated copyright to 2026

Each tab is shown or not dependening the hardware. However, until now,
all the tab were loaded, and then a call to get_display_priority() by
the tab controller would decide whether it's worthy showing or not.

However, just based on the microscope role, we can have already a pretty
good idea of which tab is certainly not useful.

=> load only the tabs that could be used for the current microscope
role.
This mainly avoids failures due to a missing an external module imported by a non-used tab.
In theory, it should also improve the loading time of the GUI. However,
tests on the viewer (were the saving should be most noticeable) show it
barely improved: going from ~3.34 to ~3.28 (-> 0.06s faster)
@pieleric pieleric force-pushed the perf-gui-only-load-the-tabs-necessary-based-on-the-microscope-role branch from 3a142f1 to dbae6e8 Compare February 13, 2026 17:04
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.

3 participants