Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Stay on 2D tab when switching between two 2D files #201

@rodolakis

Description

@rodolakis

Overview

This summarizes first attempt at implementing a feature to make the application stay on the 2D tab when switching between 2D files, instead of automatically switching to the 1D tab.

Problem Statement

When switching from one 2D file to another 2D file, the application was automatically switching to the 1D tab (index 0) instead of staying on the 2D tab (index 3).

Root Cause Analysis

The issue was caused by multiple mechanisms triggering tab switches and control changes:

  1. Tab switching during file loading: The update2DTabVisibility method was calling setTabVisible which caused unwanted tab switches
  2. Plot widget switching: 1D plot calls were switching the plot widget from ChartView2D to regular ChartView
  3. X2 spinbox signal emission: When 2D controls were populated, the X2 spinbox value change was emitting signals that triggered 1D plot calls
  4. Control visibility issues: The 1D plot calls were affecting control visibility through updateControlVisibility

Implemented Fixes

1. Early Flag Setting (mda_file.py)

  • Location: addFileTab method
  • Change: Set _should_stay_on_2d_tab flag early in the file loading process
  • Purpose: Prevent tab switching before it can occur
# Set flag early to stay on 2D tab
self._should_stay_on_2d_tab = True
self.mda_mvc.mda_file_viz._should_stay_on_2d_tab = True

2. Prevent Tab Switching (mda_file_viz.py)

  • Location: update2DTabVisibility method
  • Change: Check flag before calling setTabVisible
  • Purpose: Prevent unwanted tab switches during file loading
# Check if we should stay on 2D tab before making the setTabVisible call
if hasattr(self, "_should_stay_on_2d_tab") and self._should_stay_on_2d_tab:
    logger.debug("Should stay on 2D tab, not calling setTabVisible to avoid tab switch")
    return

3. Prevent Plot Widget Switching (mda_file_viz.py)

  • Location: setPlot method
  • Change: Check flag before switching to 1D plot widget
  • Purpose: Keep 2D plot widget active when staying on 2D tab
# Check if we should stay on 2D tab and prevent switching to 1D plot widget
if (hasattr(self, "_should_stay_on_2d_tab") and self._should_stay_on_2d_tab
    and not hasattr(plot_widget, "_plot_type")  # This is a 1D ChartView
    and self.tabWidget.currentIndex() == 3):  # We're on the 2D tab
    logger.debug("Preventing switch to 1D plot widget while staying on 2D tab")
    return

4. Force 2D Controls (mda_file_viz.py)

  • Location: updateControlVisibility method
  • Change: Force 2D controls when flag is set
  • Purpose: Ensure correct controls are shown for 2D tab
# Check if we should stay on 2D tab and force 2D controls
if hasattr(self, "_should_stay_on_2d_tab") and self._should_stay_on_2d_tab:
    logger.debug("Forcing 2D controls due to _should_stay_on_2d_tab flag")
    # Force 2D tab controls
    tab_index = 3  # 2D tab

5. Prevent X2 Signal Emission (mda_file_table_view.py)

  • Location: onX2ValueChanged method
  • Change: Check flag before emitting X2 value change signal
  • Purpose: Prevent 1D plot calls triggered by X2 spinbox value changes
# Check if we should stay on 2D tab and prevent 1D plot calls
if hasattr(parent.mda_file_viz, "_should_stay_on_2d_tab") and parent.mda_file_viz._should_stay_on_2d_tab:
    logger.debug("Preventing X2 value change signal while staying on 2D tab")
    return

Current Status

✅ What's Working

  • Core functionality: The application now stays on the 2D tab when switching between 2D files
  • Tab switching prevention: The unwanted switch to 1D tab is prevented
  • Plot widget protection: The 2D plot widget is not being replaced by 1D plot widget
  • Flag mechanism: The _should_stay_on_2d_tab flag is being set and checked correctly

❌ Remaining Problems

  • YDetControl disappearing: The YDetControl still disappears when switching between 2D files
  • X2 spinbox appearing: The X2 spinbox still appears when it shouldn't
  • 1D plot calls: 1D plot calls are still happening (is_2d_selection: False in logs)
  • Control visibility: The controls are still being affected through some unidentified mechanism

Debug Evidence

From the logs:

  • DEBUG - mdaviz.mda_file_viz - Preventing switch to 1D plot widget while staying on 2D tab
  • DEBUG - mdaviz.mda_folder - doPlot called: action=replace
  • DEBUG - mdaviz.mda_folder - doPlot - is_2d_selection: False

Next Steps

The core feature (staying on 2D tab) is working, but there are still UI control visibility issues that need to be resolved. The 1D plot calls are still happening and affecting the controls through a mechanism we haven't fully identified yet. Stashing those changes for now.

Files Modified

  • src/mdaviz/mda_file.py - Early flag setting
  • src/mdaviz/mda_file_viz.py - Tab switching prevention, plot widget protection, control forcing
  • src/mdaviz/mda_file_table_view.py - X2 signal prevention

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions