Ejemplo n.º 1
0
def _lsUI(**kwargs):
    long = kwargs.pop("long", kwargs.pop("l", True))
    head = kwargs.pop("head", kwargs.pop("hd", None))
    tail = kwargs.pop("tail", kwargs.pop("tl", None))

    if not kwargs:
        kwargs = {
            "windows": 1,
            "panels": 1,
            "editors": 1,
            "controls": 1,
            "controlLayouts": 1,
            "collection": 1,
            "radioMenuItemCollections": 1,
            "menus": 1,
            "menuItems": 1,
            "contexts": 0,
            "cmdTemplates": 1,
        }
    kwargs["long"] = long
    if head is not None:
        kwargs["head"] = head
    if tail is not None:
        kwargs["tail"] = tail
    return _util.listForNone(cmds.lsUI(**kwargs))
Ejemplo n.º 2
0
def _lsUI(**kwargs):
    long = kwargs.pop('long', kwargs.pop('l', True))
    head = kwargs.pop('head', kwargs.pop('hd', None))
    tail = kwargs.pop('tail', kwargs.pop('tl', None))

    if not kwargs:
        kwargs = {
            'windows': 1,
            'panels': 1,
            'editors': 1,
            'controls': 1,
            'controlLayouts': 1,
            'collection': 1,
            'radioMenuItemCollections': 1,
            'menus': 1,
            'menuItems': 1,
            'contexts': 0,
            'cmdTemplates': 1
        }
    kwargs['long'] = long
    if head is not None:
        kwargs['head'] = head
    if tail is not None:
        kwargs['tail'] = tail
    return _util.listForNone(cmds.lsUI(**kwargs))
Ejemplo n.º 3
0
def _lsUI( **kwargs ):
    long = kwargs.pop( 'long', kwargs.pop( 'l', True ) )
    head = kwargs.pop( 'head', kwargs.pop( 'hd', None ) )
    tail = kwargs.pop( 'tail', kwargs.pop( 'tl', None) )

    if not kwargs:
        kwargs = {
            'windows': 1, 'panels' : 1, 'editors' : 1, 'controls' : 1, 'controlLayouts' : 1,
            'collection' : 1, 'radioMenuItemCollections' : 1, 'menus' : 1, 'menuItems' : 1,
            'contexts' : 0, 'cmdTemplates' : 1
            }
    kwargs['long'] = long
    if head is not None: kwargs['head'] = head
    if tail is not None: kwargs['tail'] = tail
    return _util.listForNone(cmds.lsUI(**kwargs))
Ejemplo n.º 4
0
 def layout(self):
     name = self.name()
     for layout in sorted(cmds.lsUI(long=True, controlLayouts=True)):
         # since we are sorted, shorter will be first, and the first layout we come across will be the base layout
         if layout.startswith(name):
             return PyUI(layout)
Ejemplo n.º 5
0
    def __new__(cls, name=None, create=False, **kwargs):
        """
        Provides the ability to create the PyUI Element when creating a class::

            import pymel.core as pm
            n = pm.Window("myWindow",create=True)
            n.__repr__()
            # Result: Window('myWindow')
        """

        if cls is PyUI:
            try:
                uiType = objectTypeUI(name)
            except RuntimeError:
                uiType = 'PyUI'
            uiType = _uiTypesToCommands.get(uiType, uiType)

            try:
                newcls = getattr(dynModule, _util.capitalize(uiType))
            except AttributeError:
                newcls = PyUI
                # objectTypeUI for panels seems to return weird results -
                # ie, TmodelPane ... check for them this way.
                # Other types should be detected correctly by objectTypeUI,
                # but this just provides a failsafe...
                for testType in 'panel scriptedPanel window control layout menu'.split():
                    if getattr(cmds, testType)(name, ex=1, q=1):
                        newcls = getattr(dynModule, _util.capitalize(testType),
                                         PyUI)
                        if newcls != PyUI:
                            break
        else:
            newcls = cls

        if not newcls is PyUI:
            if cls._isBeingCreated(name, create, kwargs):
                name = newcls.__melcmd__(name, **kwargs)
                _logger.debug("PyUI: created... %s" % name)
            else:
                # find the long name
                if '|' not in name and not issubclass(newcls,
                                                      (Window,
                                                       Panel,
                                                       dynModule.ScriptedPanel,
                                                       dynModule.RadioCollection,
                                                       dynModule.ToolCollection)):
                    import windows
                    try:
                        if issubclass(newcls, Layout):
                            parent = windows.layout(name, q=1, p=1)
                        elif issubclass(newcls, OptionMenu):
                            parent = windows.optionMenu(name, q=1, p=1)
                        elif issubclass(newcls, Menu):
                            parent = windows.menu(name, q=1, p=1)
                        else:
                            parent = windows.control(name, q=1, p=1)
                        if parent:
                            name = parent + '|' + name

                    except RuntimeError:
                        # editors don't have a long name, so we keep the short name
                        if name not in cmds.lsUI(long=True, editors=True):
                            raise

        # correct for optionMenu
        if newcls == PopupMenu and cmds.optionMenu(name, ex=1):
            newcls = OptionMenu
        return unicode.__new__(newcls, name)
Ejemplo n.º 6
0
 def layout(self):
     name = self.name()
     for layout in sorted(cmds.lsUI(long=True, controlLayouts=True)):
         # since we are sorted, shorter will be first, and the first layout we come across will be the base layout
         if layout.startswith(name):
             return PyUI(layout)
Ejemplo n.º 7
0
    def __new__(cls, name=None, create=False, **kwargs):
        """
        Provides the ability to create the PyUI Element when creating a class::

            import pymel.core as pm
            n = pm.Window("myWindow",create=True)
            n.__repr__()
            # Result: Window('myWindow')
        """

        if cls is PyUI:
            try:
                uiType = objectTypeUI(name)
            except RuntimeError:
                uiType = 'PyUI'
            uiType = _uiTypesToCommands.get(uiType, uiType)

            try:
                newcls = getattr(dynModule, _util.capitalize(uiType))
            except AttributeError:
                newcls = PyUI
                # objectTypeUI for panels seems to return weird results -
                # ie, TmodelPane ... check for them this way.
                # Other types should be detected correctly by objectTypeUI,
                # but this just provides a failsafe...
                for testType in 'panel scriptedPanel window control layout menu'.split(
                ):
                    if getattr(cmds, testType)(name, ex=1, q=1):
                        newcls = getattr(dynModule, _util.capitalize(testType),
                                         PyUI)
                        if newcls != PyUI:
                            break
        else:
            newcls = cls

        if not newcls is PyUI:
            if cls._isBeingCreated(name, create, kwargs):
                name = newcls.__melcmd__(name, **kwargs)
                _logger.debug("PyUI: created... %s" % name)
            else:
                # find the long name
                if '|' not in name and not issubclass(
                        newcls,
                    (Window, Panel, dynModule.ScriptedPanel,
                     dynModule.RadioCollection, dynModule.ToolCollection)):
                    import windows
                    try:
                        if issubclass(newcls, Layout):
                            parent = windows.layout(name, q=1, p=1)
                        elif issubclass(newcls, OptionMenu):
                            parent = windows.optionMenu(name, q=1, p=1)
                        elif issubclass(newcls, Menu):
                            parent = windows.menu(name, q=1, p=1)
                        else:
                            parent = windows.control(name, q=1, p=1)
                        if parent:
                            name = parent + '|' + name

                    except RuntimeError:
                        # editors don't have a long name, so we keep the short name
                        if name not in cmds.lsUI(long=True, editors=True):
                            raise

        # correct for optionMenu
        if newcls == PopupMenu and cmds.optionMenu(name, ex=1):
            newcls = OptionMenu
        return unicode.__new__(newcls, name)
Ejemplo n.º 8
0
    def __new__(cls, name=None, create=False, **kwargs):
        """
        Provides the ability to create the PyUI Element when creating a class::

            import pymel.core as pm
            n = pm.Window("myWindow",create=True)
            n.__repr__()
            # Result: Window('myWindow')
        """

        if cls is PyUI:
            try:
                uiType = cmds.objectTypeUI(name)
                uiType = _uiTypesToCommands.get(uiType, uiType)
            except RuntimeError:
                try:
                    # some ui types (radioCollections) can only be identified with their shortname
                    uiType = cmds.objectTypeUI(name.split("|")[-1])
                    uiType = _uiTypesToCommands.get(uiType, uiType)
                except RuntimeError:
                    # we cannot query the type of rowGroupLayout children: check common types for these
                    uiType = None
                    for control in (
                        "checkBox floatField button floatSlider intSlider "
                        "floatField textField intField optionMenu radioButton".split()
                    ):
                        if getattr(cmds, control)(name, ex=1, q=1):
                            uiType = control
                            break
                    if not uiType:
                        uiType = "PyUI"
            try:
                newcls = getattr(dynModule, _util.capitalize(uiType))
            except AttributeError:
                newcls = PyUI
                # objectTypeUI for panels seems to return weird results -
                # ie, TmodelPane ... check for them this way.
                # Other types should be detected correctly by objectTypeUI,
                # but this just provides a failsafe...
                for testType in "panel scriptedPanel window control layout menu".split():
                    if getattr(cmds, testType)(name, ex=1, q=1):
                        newcls = getattr(dynModule, _util.capitalize(testType), PyUI)
                        if newcls != PyUI:
                            break
        else:
            newcls = cls

        if not newcls is PyUI:
            if cls._isBeingCreated(name, create, kwargs):
                name = newcls.__melcmd__(name, **kwargs)
                _logger.debug("PyUI: created... %s" % name)
            else:
                # find the long name
                if "|" not in name and not issubclass(
                    newcls,
                    (Window, Panel, dynModule.ScriptedPanel, dynModule.RadioCollection, dynModule.ToolCollection),
                ):
                    import windows

                    try:
                        if issubclass(newcls, Layout):
                            parent = windows.layout(name, q=1, p=1)
                        elif issubclass(newcls, OptionMenu):
                            parent = windows.optionMenu(name, q=1, p=1)
                        elif issubclass(newcls, Menu):
                            parent = windows.menu(name, q=1, p=1)
                        else:
                            parent = windows.control(name, q=1, p=1)
                        if parent:
                            name = parent + "|" + name

                    except RuntimeError:
                        # editors don't have a long name, so we keep the short name
                        if name not in cmds.lsUI(long=True, editors=True):
                            raise

        # correct for optionMenu
        if newcls == PopupMenu and cmds.optionMenu(name, ex=1):
            newcls = OptionMenu
        return unicode.__new__(newcls, name)