theodox / mGui

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

Changed how the exiting context manager determines the new parent layout #34

Closed bob-white closed 7 years ago

bob-white commented 7 years ago

Instead of relying on splitting the widgets path, we instead just set the parent to the previous layout that we captured when entering the context. This fixes some issues when Maya will insert a '||' into the path, specifically when dealing with popup menus, and docked controls.

Also added an as_parent method to Nested instances, this allows you to reuse the object as a parent for more controls.

bob-white commented 7 years ago

With mGui I've been using this for a few months now. However pymel does a similar thing with its UI context managers, and I've been using that for years.

Pymel's:

_withParentStack = []
_withParentMenuStack = []

class Layout(PyUI):

    def __enter__(self):
        global _withParentStack
        _withParentStack.append(self)
        self.makeDefault()
        return self

    def __exit__(self, type, value, traceback):
        global _withParentStack
        _withParentStack.pop()
        if _withParentStack:
            parent = _withParentStack[-1]
        else:
            parent = self.pop()
            while parent and objectTypeUI(parent) == u'rowGroupLayout':
                parent = parent.pop()
        cmds.setParent(parent)