mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-22 06:33:46 +00:00
Get Python Plugin Metadata
This commit is contained in:
parent
1f3315d020
commit
b9c859bc0c
@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
#include "CutterPythonPlugin.h"
|
#include "CutterPythonPlugin.h"
|
||||||
|
|
||||||
CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
CutterPythonPlugin::CutterPythonPlugin(PyObject *pluginModule)
|
||||||
{
|
{
|
||||||
this->pluginModule = pluginModule;
|
this->pluginModule = pluginModule;
|
||||||
|
|
||||||
@ -14,7 +14,28 @@ CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
|||||||
pInstance = PyObject_GetAttrString(pluginModule, "plugin");
|
pInstance = PyObject_GetAttrString(pluginModule, "plugin");
|
||||||
if (!pInstance) {
|
if (!pInstance) {
|
||||||
qWarning() << "Cannot find plugin instance.";
|
qWarning() << "Cannot find plugin instance.";
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto getStringAttr = [this](const char *attrName) -> QString {
|
||||||
|
if (!PyObject_HasAttrString(pInstance, attrName)) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
PyObject *attr = PyObject_GetAttrString(pInstance, attrName);
|
||||||
|
if (!attr) {
|
||||||
|
PyErr_Print();
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
if (!PyUnicode_Check(attr)) {
|
||||||
|
return QString();
|
||||||
|
}
|
||||||
|
return QString::fromUtf8(PyUnicode_AsUTF8(attr));
|
||||||
|
};
|
||||||
|
|
||||||
|
name = getStringAttr("name");
|
||||||
|
description = getStringAttr("description");
|
||||||
|
version = getStringAttr("version");
|
||||||
|
author = getStringAttr("author");
|
||||||
}
|
}
|
||||||
|
|
||||||
CutterPythonPlugin::~CutterPythonPlugin()
|
CutterPythonPlugin::~CutterPythonPlugin()
|
||||||
|
@ -3,12 +3,14 @@ from cutter_plugin import CutterPlugin
|
|||||||
from PySide2 import QtCore, QtWidgets
|
from PySide2 import QtCore, QtWidgets
|
||||||
import shiboken2
|
import shiboken2
|
||||||
|
|
||||||
|
|
||||||
class CutterSamplePlugin(CutterPlugin):
|
class CutterSamplePlugin(CutterPlugin):
|
||||||
|
name = "SamplePlugin"
|
||||||
|
description = "A sample plugin written in python."
|
||||||
|
version = "1.0"
|
||||||
|
author = "xarkes"
|
||||||
|
|
||||||
def setupPlugin(self):
|
def setupPlugin(self):
|
||||||
self.name = 'SamplePlugin'
|
|
||||||
self.description = 'A sample plugin written in python.'
|
|
||||||
self.version = '1.0'
|
|
||||||
self.author = 'xarkes'
|
|
||||||
self.app = QtCore.QCoreApplication.instance()
|
self.app = QtCore.QCoreApplication.instance()
|
||||||
|
|
||||||
def setupInterface(self):
|
def setupInterface(self):
|
||||||
@ -28,4 +30,3 @@ class CutterSamplePlugin(CutterPlugin):
|
|||||||
|
|
||||||
# Instantiate our plugin
|
# Instantiate our plugin
|
||||||
plugin = CutterSamplePlugin()
|
plugin = CutterSamplePlugin()
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
|
||||||
class CutterPlugin(ABC):
|
class CutterPlugin(ABC):
|
||||||
name = ''
|
name = ''
|
||||||
description = ''
|
description = ''
|
||||||
version = ''
|
version = ''
|
||||||
author = ''
|
author = ''
|
||||||
app = None
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def setupPlugin(self):
|
def setupPlugin(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user