def pop(self): """ set the default parent to the parent of this layout """ p = self.parent() cmds.setParent(p) return p
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)
def __exit__(self, type, value, traceback): p = self.parent() #Ensure we set the parent back to a layout not some ui element # like say a button which does not accept children if not cmds.layout(p, exists=True): p = p.parent() #However we want to be careful not to attach to a rowGroupLayout(textFieldButtonGrp etc) # in this case set the parent to the rowGroupLayout's parent if cmds.objectTypeUI(p) == u'rowGroupLayout': p = p.parent() cmds.setParent(p) return p
def __exit__(self, type, value, traceback): global _withParentMenuStack _withParentMenuStack.pop() if _withParentMenuStack: cmds.setParent(_withParentMenuStack[-1], menu=True) else: parent = self while True: parent = parent.parent() try: cmds.setParent(parent, menu=True) except RuntimeError: continue break
def menu(*args, **kwargs): """ Modifications - added ability to query parent """ if _versions.current() < _versions.v2011: # on create only if not ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and not ( kwargs.get('edit', False) or kwargs.get('e', False) ) \ and not ( kwargs.get('parent', False) or kwargs.get('p', False) ): kwargs['parent'] = cmds.setParent(q=1) if ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and ( kwargs.get('parent', False) or kwargs.get('p', False) ): name = unicode(args[0]) if '|' not in name: try: name = _findLongName(name, 'menu') except ValueError: name = _findLongName(name, 'popupMenu') return name.rsplit('|',1)[0] result = cmds.menu(*args, **kwargs) if ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and ( kwargs.get('itemArray', False) or kwargs.get('ia', False) ) \ and result is None: result = [] return result
def menu(*args, **kwargs): """ Modifications - added ability to query parent """ if _versions.current() < _versions.v2011: # on create only if not ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and not ( kwargs.get('edit', False) or kwargs.get('e', False) ) \ and not (kwargs.get('parent', False) or kwargs.get('p', False)): kwargs['parent'] = cmds.setParent(q=1) if ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and (kwargs.get('parent', False) or kwargs.get('p', False)): name = unicode(args[0]) if '|' not in name: try: name = _findLongName(name, 'menu') except ValueError: name = _findLongName(name, 'popupMenu') return name.rsplit('|', 1)[0] result = cmds.menu(*args, **kwargs) if ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and ( kwargs.get('itemArray', False) or kwargs.get('ia', False) ) \ and result is None: result = [] return result
def __exit__(self, type, value, traceback): global _withParentMenuStack _withParentMenuStack.pop() if _withParentMenuStack: cmds.setParent(_withParentMenuStack[-1], menu=True) else: parent = self while True: parent = parent.parent() # Maya 2012 Service Pack 2 (or SAP1, SP1) introduces a bug where # '' is returned, instead of None; problem being that doing # cmds.setParent(None, menu=True) is valid, but # cmds.setParent('', menu=True) is not if parent == '': parent = None try: cmds.setParent(parent, menu=True) except RuntimeError: continue break
def setParent(*args, **kwargs): """ Modifications - returns None object instead of the string 'NONE' """ import uitypes result = cmds.setParent(*args, **kwargs) if kwargs.get('query', False) or kwargs.get('q', False): if result == 'NONE': result = None else: result = uitypes.PyUI(result) return result
def menu(*args, **kwargs): """ Modifications - added ability to query parent """ if _versions.current() < _versions.v2011: # on create only if not ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and not ( kwargs.get('edit', False) or kwargs.get('e', False) ) \ and not ( kwargs.get('parent', False) or kwargs.get('p', False) ): kwargs['parent'] = cmds.setParent(q=1) if ( kwargs.get('query', False) or kwargs.get('q', False) ) \ and ( kwargs.get('parent', False) or kwargs.get('p', False) ): name = unicode(args[0]) if '|' not in name: name = _findLongName(name, 'menu') return name.rsplit('|',1)[0] return cmds.menu(*args, **kwargs)
def menu(*args, **kwargs): """ Modifications - added ability to query parent """ if _versions.current() < _versions.v2011: # on create only if ( not (kwargs.get("query", False) or kwargs.get("q", False)) and not (kwargs.get("edit", False) or kwargs.get("e", False)) and not (kwargs.get("parent", False) or kwargs.get("p", False)) ): kwargs["parent"] = cmds.setParent(q=1) if (kwargs.get("query", False) or kwargs.get("q", False)) and ( kwargs.get("parent", False) or kwargs.get("p", False) ): name = unicode(args[0]) if "|" not in name: name = _findLongName(name, "menu") return name.rsplit("|", 1)[0] return cmds.menu(*args, **kwargs)
def makeDefault(self): """ set this layout as the default parent """ cmds.setParent(self, menu=True)
def __enter__(self): cmds.setParent(self,menu=True) return self
def __exit__(self, type, value, traceback): p = self.parent() cmds.setParent(p,menu=True) return p
def currentParent(): "shortcut for ``ui.PyUI(setParent(q=1))`` " return _uitypes.PyUI(cmds.setParent(q=1))