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

Skip to content

Bug: AttributeError when loading v1.3 projects - all instances same color #2424

@eberrigan

Description

@eberrigan

Bug Description

When opening older SLEAP projects (created in v1.3) in SLEAP v1.5.1, callback errors occur preventing proper instance coloration, causing all instances to display in the same color.

Steps to Reproduce

  1. Install SLEAP 1.5.1 via pip install sleap[nn]
  2. Open a project created with SLEAP 1.3
  3. Observe error messages in console

Expected Behavior

  • Project should open without errors
  • Each instance should display with distinct colors based on the color palette settings

Actual Behavior

  • Console shows callback errors:
    • Error occurred during callback 0 for palette!
    • Error occurred during callback 0 for distinctly_color!
  • Technical error: 'PySide6.QtWidgets.QGraphicsDropShadowEffect' object has no attribute 'text'
  • All instances appear in the same color

Root Cause Analysis

The bug appears to be in sleap/gui/app.py:411 in the _menu_check_single() helper function:

def _menu_check_single(menu, item_text):
    """Helper method to select exactly one submenu item."""
    for menu_item in menu.children():
        if menu_item.text() == str(item_text):  # Assumes all children have .text()
            menu_item.setChecked(True)
        else:
            menu_item.setChecked(False)

The Problem:

  • menu.children() returns all child objects, not just QAction items
  • This includes QGraphicsDropShadowEffect objects and other Qt widgets that don't have a .text() method
  • When palette/distinctly_color state is emitted (lines 1102-1103), the callbacks fail because they try to call .text() on non-QAction objects

Proposed Fix

Filter to only process QAction objects:

def _menu_check_single(menu, item_text):
    """Helper method to select exactly one submenu item."""
    from qtpy.QtWidgets import QAction

    for menu_item in menu.children():
        # Only process QAction objects (skip graphics effects and other children)
        if isinstance(menu_item, QAction):
            if menu_item.text() == str(item_text):
                menu_item.setChecked(True)
            else:
                menu_item.setChecked(False)

Environment

  • SLEAP version: 1.5.1
  • Installation method: pip install sleap[nn]
  • Project version: 1.3

Additional Context

  • Reinstalling SLEAP did not resolve the issue
  • Project opens successfully but with degraded functionality
  • Error occurs during state callback execution (sleap/gui/state.py:185)
  • Likely introduced during PySide6 migration and sleap-io integration
  • Related commits: Fix Applying Distinct Colors To Edges and Nodes #2316 (Fix Applying Distinct Colors To Edges and Nodes)

Related Code Locations

  • Bug location: sleap/gui/app.py:408-414
  • Callback setup: sleap/gui/app.py:1087-1103
  • Color manager: sleap/gui/color.py
  • State management: sleap/gui/state.py:185

Related Discussion

Originally reported in #2422

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions