Example #1
0
def _addPluginCommand(pluginName, funcName):
    global _pluginData

    if funcName not in _pluginData[pluginName].setdefault('commands', []):
        _pluginData[pluginName]['commands'].append(funcName)
    _logger.debug("Adding command: %s" % funcName)
    #_logger.debug("adding new command:", funcName)
    _factories.cmdlist[funcName] = _cmdcache.getCmdInfoBasic(funcName)
    _factories.cmdlist[funcName]['plugin'] = pluginName
    _pmcmds.addWrappedCmd(funcName)
    func = _factories.functionFactory(funcName)
    try:
        if func:
            coreModule = 'pymel.core.%s' % _cmdcache.getModule(
                funcName, _factories.moduleCmds)
            if coreModule in sys.modules:
                setattr(sys.modules[coreModule], funcName, func)
            # Note that we add the function to both a core module (ie,
            # pymel.core.other), the pymel.core itself, and pymel.all; this
            # way, we mirror the behavior of 'normal' functions
            setattr(_module, funcName, func)
            if 'pymel.all' in sys.modules:
                setattr(sys.modules['pymel.all'], funcName, func)
        else:
            _logger.warning("failed to create function")
    except Exception, msg:
        _logger.warning("exception: %s" % str(msg))
Example #2
0
def _addPluginCommand(pluginName, funcName):
    global _pluginData

    if funcName not in _pluginData[pluginName].setdefault('commands', []):
        _pluginData[pluginName]['commands'].append(funcName)
    _logger.debug("Adding plugin command: {} (plugin: {})".format(
        funcName, pluginName))
    #_logger.debug("adding new command:", funcName)
    _factories.cmdlist[funcName] = _cmdcache.getCmdInfoBasic(funcName)
    _factories.cmdlist[funcName]['plugin'] = pluginName
    _pmcmds.addWrappedCmd(funcName)
    # FIXME: I think we can call a much simpler factory function, because
    # plugins cannnot opt into the complex mutations that functionFactory can apply
    func = _factories.functionFactory(funcName)
    try:
        if func:
            # FIXME: figure out what to do about moduleCmds. could a plugin function be in moduleCmds???
            coreModule = 'pymel.core.%s' % _cmdcache.getModule(
                funcName, {})  # _factories.moduleCmds)
            if coreModule in sys.modules:
                setattr(sys.modules[coreModule], funcName, func)
            # Note that we add the function to both a core module (ie,
            # pymel.core.other), the pymel.core itself, and pymel.all; this
            # way, we mirror the behavior of 'normal' functions
            setattr(_module, funcName, func)
            if 'pymel.all' in sys.modules:
                setattr(sys.modules['pymel.all'], funcName, func)
        else:
            _logger.warning("failed to create function")
    except Exception, msg:
        _logger.warning("exception: %s" % str(msg))
Example #3
0
def _createClassCommands():
    def createCallback(classname):
        """
        create a callback that will trigger lazyLoading
        """
        def callback(*args, **kwargs):
            import uitypes
            res = getattr(uitypes, classname)(*args, **kwargs)
            return res

        return callback

    for funcName in _factories.uiClassList:
        # Create Class
        classname = _util.capitalize(funcName)
        #cls = _uitypes[classname]

        # Create Function
        func = _factories.functionFactory(funcName,
                                          createCallback(classname),
                                          _thisModule,
                                          uiWidget=True)
        if func:
            func.__module__ = __name__
            setattr(_thisModule, funcName, func)
Example #4
0
def _addPluginCommand(pluginName, funcName):
    global _pluginData
    
    if funcName not in _pluginData[pluginName].setdefault('commands', []):
        _pluginData[pluginName]['commands'].append(funcName)
    _logger.debug("Adding command: %s" % funcName)
    #_logger.debug("adding new command:", funcName)
    _factories.cmdlist[funcName] = _cmdcache.getCmdInfoBasic( funcName )
    _factories.cmdlist[funcName]['plugin'] = pluginName
    _pmcmds.addWrappedCmd(funcName)
    func = _factories.functionFactory( funcName )
    try:
        if func:
            coreModule = 'pymel.core.%s' % _cmdcache.getModule(funcName,
                                                               _factories.moduleCmds)
            if coreModule in sys.modules:
                setattr( sys.modules[coreModule], funcName, func )
            # Note that we add the function to both a core module (ie,
            # pymel.core.other), the pymel.core itself, and pymel.all; this
            # way, we mirror the behavior of 'normal' functions 
            setattr( _module, funcName, func )
            if 'pymel.all' in sys.modules:
                setattr( sys.modules['pymel.all'], funcName, func )
        else:
            _logger.warning( "failed to create function" )
    except Exception, msg:
        _logger.warning("exception: %s" % str(msg) )
Example #5
0
def _createOtherCommands():
    moduleShortName = __name__.split(".")[-1]
    nonClassFuncs = set(_factories.moduleCmds[moduleShortName]).difference(_factories.uiClassList)
    for funcName in nonClassFuncs:
        func = _factories.functionFactory(funcName, returnFunc=None, module=_thisModule)
        if func:
            func.__module__ = __name__
            setattr(_thisModule, funcName, func)
            # want this call to work regardless of order we call _createClassCommandParis / _createCommands
            if sys.modules[__name__] != _thisModule:
                setattr(sys.modules[__name__], funcName, func)
Example #6
0
def _createOtherCommands():
    moduleShortName = __name__.split('.')[-1]
    nonClassFuncs = set(_factories.moduleCmds[moduleShortName]).difference(
        _factories.uiClassList)
    for funcName in nonClassFuncs:
        func = _factories.functionFactory(funcName,
                                          returnFunc=None,
                                          module=_thisModule)
        if func:
            func.__module__ = __name__
            setattr(_thisModule, funcName, func)
            # want this call to work regardless of order we call _createClassCommandParis / _createCommands
            if sys.modules[__name__] != _thisModule:
                setattr(sys.modules[__name__], funcName, func)
Example #7
0
def _pluginLoaded( *args ):

    if len(args) > 1:
        # 2009 API callback, the args are ( [ pathToPlugin, pluginName ], clientData )
        pluginName = args[0][1]
    else:
        pluginName = args[0]

    if not pluginName:
        return

    _logger.debug("Plugin loaded: %s", pluginName)

    _pluginData[pluginName] = {}

    try:
        commands = _pmcmds.pluginInfo(pluginName, query=1, command=1)
    except:
        _logger.error("Failed to get command list from %s", pluginName)
        commands = None


    # Commands
    if commands:
        _pluginData[pluginName]['commands'] = commands
        _logger.debug( "adding new commands: %s" % ', '.join(commands) )
        for funcName in commands:
            _logger.debug("Adding command: %s..." % funcName)
            #__logger.debug("adding new command:", funcName)
            _factories.cmdlist[funcName] = _factories.cmdcache.getCmdInfoBasic( funcName )
            _pmcmds.addWrappedCmd(funcName)
            func = _factories.functionFactory( funcName )
            try:
                if func:
                    setattr( _module, funcName, func )
                    if 'pymel.all' in sys.modules:
                        setattr( sys.modules['pymel.all'], funcName, func )
                else:
                    _logger.warning( "failed to create function" )
            except Exception, msg:
                _logger.warning("exception: %s" % str(msg) )
            _logger.debug("Done adding command %s" % funcName)
Example #8
0
def _createClassCommands():
    def createCallback( classname ):
        """
        create a callback that will trigger lazyLoading
        """
        def callback(*args, **kwargs):
            import uitypes
            res = getattr(uitypes, classname)(*args, **kwargs)
            return res
        return callback

    for funcName in _factories.uiClassList:
        # Create Class
        classname = _util.capitalize(funcName)
        #cls = _uitypes[classname]

        # Create Function
        func = _factories.functionFactory( funcName, createCallback(classname), _thisModule, uiWidget=True )
        if func:
            func.__module__ = __name__
            setattr(_thisModule, funcName, func)
class PyUI(unicode):
    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)

    @staticmethod
    def _isBeingCreated(name, create, kwargs):
        """
        create a new node when any of these conditions occur:
           name is None
           create is True
           parent flag is set
        """
        return not name or create or ('q' not in kwargs and kwargs.get(
            'parent', kwargs.get('p', None)))

    def __repr__(self):
        return u"ui.%s('%s')" % (self.__class__.__name__, self)

    def parent(self):
        buf = unicode(self).split('|')[:-1]
        if len(buf) == 2 and buf[0] == buf[1] and _versions.current(
        ) < _versions.v2011:
            # pre-2011, windows with menus can have a strange name:
            # ex.  window1|window1|menu1
            buf = buf[:1]
        if not buf:
            return None
        return PyUI('|'.join(buf))

    getParent = parent

    def shortName(self):
        return unicode(self).split('|')[-1]

    def name(self):
        return unicode(self)

    def window(self):
        return Window(self.name().split('|')[0])

    delete = _factories.functionFactory('deleteUI', rename='delete')
    rename = _factories.functionFactory('renameUI', rename='rename')
    type = objectTypeUI

    @classmethod
    def exists(cls, name):
        return cls.__melcmd__(name, exists=True)

    if _versions.current() >= _versions.v2011:
        asQtObject = toQtControl