Skip to content

silx.gui.data: Fixed DataView creating orphan widgets - #4752

Merged
t20100 merged 1 commit into
mainfrom
fix-dataview-orphan-widgets
Oct 23, 2026
Merged

t20100 merged 1 commit into
mainfrom
fix-dataview-orphan-widgets

Conversation

@t20100

@t20100 t20100 commented Oct 23, 2026

Copy link
Copy Markdown
Member

PR summary

Alternative to PR #4749

This PR avoids the DataView mechanism to create orphan widgets when clearing or removing them and closes #4748.

As said in #4749 (comment) :

The overall pattern would still be not robust because it does not guarantee that created widgets are added the the QStackWidget

AI Disclosure

  • AI tool(s) Claude used for summarizing DataView logic and routes causing the issue and refactoring the code.

@t20100
t20100 requested review from loichuder and payno October 23, 2026 09:10
Comment on lines +155 to +158
if self.isWidgetInitialized():
self._clear()

def _clear(self):

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Putting the check in clear avoids to take care of checking isWidgetInitialized in callers.
This is compatible with already existing external custom DataView which overrides clear. It would be best if they now override _clear but it still work as before (i.e. with the bug) if not.

Comment on lines +443 to +444
if view.isWidgetInitialized():
self.__stack.removeWidget(view.getWidget())

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

That was pointless before


def clear(self):
for v in self.getViews():
v.clear()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For composite views, isWidgetInitialized always returns False. I left it as it was, though it could be better to return True if one of the sub-views is initialized. 🤷

Clearing all their sub-views anyway (no-op if none is initialized).

Comment on lines -229 to -231
def clear(self):
for v in self.__views.keys():
v.clear()

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No longer needed _CompositeView implements it in a generic way.

@loichuder loichuder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good !

@t20100
t20100 merged commit 62e64ca into main Oct 23, 2026
7 of 8 checks passed
@t20100
t20100 deleted the fix-dataview-orphan-widgets branch October 23, 2026 12:30
@t20100

t20100 commented Oct 23, 2026

Copy link
Copy Markdown
Member Author

According to @payno, this does not cover all orphan widgets cases but already fixes the main ones.

There is a structural issue to fix: any call to getWidget can create the widget without adding it to the stack.

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.

DataViewer: orphan cell

2 participants