Example #1
0
def Text(language):
    class Translation(Default):
        pass
    languagePath = os.path.join(eg.languagesDir, "%s.py" % language)
    try:
        eg.ExecFile(languagePath, {}, Translation.__dict__)
    except IOError:
        pass
    SetDefault(Translation, Default)
    return Translation
Example #2
0
 def __new__(mcs, name, bases, dct):
     defaultText = type.__new__(mcs, name, bases, dct)
     if len(bases):
         moduleName = dct["__module__"].split(".")[-1]
         translatedText = getattr(eg.text, moduleName, None)
         if translatedText is None:
             setattr(eg.text, moduleName, defaultText)
             return defaultText
         else:
             SetDefault(translatedText, defaultText)
             return translatedText
     return defaultText
    def FromModuleInfo(cls, moduleInfo):
        self = cls.__new__(cls)
        self.__dict__.update(moduleInfo.__dict__)
        pathname = join(self.path, "__init__.py")
        if not exists(pathname):
            eg.PrintError("File %s does not exist" % pathname)
            return None
        if self.path.startswith(eg.corePluginDir):
            moduleName = "eg.CorePluginModule." + self.pluginName
        else:
            moduleName = "eg.UserPluginModule." + self.pluginName
        try:
            if moduleName in sys.modules:
                module = sys.modules[moduleName]
            else:
                module = __import__(moduleName, None, None, [''])
        except:
            eg.PrintTraceback(
                eg.text.Error.pluginLoadError % self.path,
                1
            )
            raise eg.Exceptions.PluginLoadError()
        pluginCls = module.__pluginCls__
        self.module = module
        self.pluginCls = pluginCls

        englishText = pluginCls.text
        if englishText is None:
            englishText = ClassType("EmptyDefaultText", (), {})

        englishText.name = self.englishName
        englishText.description = self.englishDescription

        # TODO: the text class should be referenced by the GUID instead of
        #       pluginCls.__name__
        translatedText = getattr(eg.text.Plugin, pluginCls.__name__, None)
        if translatedText is None:
            setattr(eg.text.Plugin, pluginCls.__name__, englishText)
            text = englishText
        else:
            SetDefault(translatedText, englishText)
            text = translatedText

        pluginCls.text = text
        pluginCls.name = text.name
        pluginCls.description = text.description
        return self
Example #4
0
 def Translate(self, plugin, actionCls, actionClsName):
     defaultText = actionCls.text
     if defaultText is None:
         defaultText = ClassType(actionClsName, (), {})
     translatedText = getattr(plugin.text, actionClsName, None)
     if translatedText is None:
         translatedText = ClassType(actionClsName, (), {})
         setattr(plugin.text, actionClsName, translatedText)
     SetDefault(translatedText, defaultText)
     if not hasattr(translatedText, "name"):
         name = actionCls.name
         translatedText.name = actionClsName if name is None else name
     if not hasattr(translatedText, "description"):
         description = actionCls.description
         translatedText.description = (translatedText.name if
                                       description is None else description)
     return translatedText
Example #5
0
 def AddGroup(self, name, description=None, iconFile=None, identifier=None):
     """
     Create and add a new sub-group.
     """
     plugin = self.plugin
     if identifier is not None:
         description = name if description is None else description
         defaultText = ClassType(identifier, (), {
             "name": name,
             "description": description
         })
         translatedText = getattr(plugin.text, identifier, None)
         if translatedText is None:
             translatedText = ClassType(identifier, (), {})
             setattr(plugin.text, identifier, translatedText)
         SetDefault(translatedText, defaultText)
         name = translatedText.name
         description = translatedText.description
     group = ActionGroup(plugin, name, description, iconFile)
     self.items.append(group)
     return group