theodox / mGui

Python module for cleaner maya GUI layout syntax
MIT License
123 stars 23 forks source link

Layout.clear doesn't remove all child controls in Maya 2018 #90

Closed Zackaroni closed 6 years ago

Zackaroni commented 6 years ago

I'm dynamically generating controls under a VerticalForm. I've been trying to use the form's clear() method when I need to refresh the UI, but some of the controls aren't removed. I tried poking around in the code, and it looks to me like the culprit is the generator expression in mgui/core/init.py line 350. It looks like it's removing controls from the list as it's reading from the list, and some controls get skipped as a result. Replacing the generator expression with a list seems to work. I'll create a pull request with that change.

bob-white commented 6 years ago

Good catch. Yeah the generator expression is just relying on the underlying list, which we are rather wrongfully mutating during iteration.

theodox commented 6 years ago

hey @bob-white do we have test coverage for that behavior? it not it would be a good addition

bob-white commented 6 years ago

Good call.

Do we have a a decent way of representing the controls and the control hierarchy in unit tests? Or would we need to mock up some of the ui cmds to not return False?

theodox commented 6 years ago

Generally I have been relying on mocks by replacing the cmds call with a dummy object that does what we need.

theodox commented 6 years ago

reclosing