示例#1
0
    def AddAction(
        self,
        actionCls,
        clsName=None,
        name=None,
        description=None,
        value=None,
        hidden=False
    ):
        if not issubclass(actionCls, eg.ActionBase):
            raise Exception("Actions must be subclasses of eg.ActionBase")
        if clsName is not None:
            actionCls = ClassType(
                clsName,
                (actionCls, ),
                dict(name=name, description=description, value=value),
            )
        plugin = self.plugin
        pluginInfo = plugin.info
        actionClsName = actionCls.__name__
        icon = pluginInfo.icon
        if actionCls.iconFile:
            try:
                path = join(pluginInfo.path, actionCls.iconFile + ".png")
                icon = eg.Icons.PathIcon(path)
            except:
                eg.PrintError(
                    "Error while loading icon file %s" % actionCls.iconFile
                )
        if icon == eg.Icons.PLUGIN_ICON:
            icon = eg.Icons.ACTION_ICON
        else:
            icon = eg.Icons.ActionSubIcon(icon)

        text = self.Translate(plugin, actionCls, actionClsName)
        actionCls = ClassType(
            actionClsName,
            (actionCls, ),
            dict(
                name=text.name,
                description=text.description,
                plugin=plugin,
                info=ActionInfo(icon),
                text=text,
                Exceptions=eg.Exceptions
            )
        )
        pluginInfo.actions[actionClsName] = actionCls
        actionCls.OnAddAction()
        if not hidden:
            self.items.append(actionCls)
        return actionCls