Beispiel #1
0
def importFromStandardOrCustomDirectories(directories, defaultFormatter,
                                          customFormatter, moduleName):
    """Return imported module

    Arguments:
        directories: the directories for search in. this is got by
            gatherCustomModuleDirectories
        defaultFormatter: this represents module structure for default
            module. for example "mgear.core.shifter.component.{}"
        customFormatter:  this represents module structure for custom
            module. for example "{0}.{1}"

    Returns:
        module: imported module

    """
    # Import module and get class
    try:
        module_name = defaultFormatter.format(moduleName)
        module = __import__(module_name, globals(), locals(), ["*"], -1)

    except ImportError:
        moduleBasePath = getModuleBasePath(directories, moduleName)
        module_name = customFormatter.format(moduleName)
        if pm.dirmap(cd=moduleBasePath) not in sys.path:
            sys.path.append(pm.dirmap(cd=moduleBasePath))
        module = __import__(module_name, globals(), locals(), ["*"], -1)

    return module
Beispiel #2
0
    def updateTabs(self):
        self.tabs.clear()
        defPath = os.environ.get("MGEAR_SYNOPTIC_PATH", None)

        tab_names = pm.ls(self.model_list.currentText())[0].getAttr("synoptic").split(",")

        for i, tab_name in enumerate(tab_names):
            try:
                if tab_name:
                    if not defPath or not os.path.isdir(defPath):
                        print "Loading default mGear synoptics"
                        module_name = "mgear.maya.synoptic.tabs."+tab_name
                    else:
                        print "Loading Project mGear synoptics"
                        sys.path.append(pm.dirmap(cd=project_synModule))
                        module_name = tab_name
                    module = __import__(module_name, globals(), locals(), ["*"], -1)
                    print tab_name
                    print module_name
                    SynopticTab = getattr(module , "SynopticTab")

                    tab = SynopticTab()
                    self.tabs.insertTab(i, tab, tab_name)
                else:
                    pm.displayWarning("No synoptic tabs for %s"%self.model_list.currentText())
            except:
                pm.displayError("Synoptic tab: %s Loading fail"%tab_name)