mirror of
https://github.com/rizinorg/cutter.git
synced 2025-02-20 13:46:06 +00:00
Get Python Plugin Metadata
This commit is contained in:
parent
1f3315d020
commit
b9c859bc0c
@ -3,7 +3,7 @@
|
||||
|
||||
#include "CutterPythonPlugin.h"
|
||||
|
||||
CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
||||
CutterPythonPlugin::CutterPythonPlugin(PyObject *pluginModule)
|
||||
{
|
||||
this->pluginModule = pluginModule;
|
||||
|
||||
@ -14,7 +14,28 @@ CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
||||
pInstance = PyObject_GetAttrString(pluginModule, "plugin");
|
||||
if (!pInstance) {
|
||||
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()
|
||||
|
@ -3,12 +3,14 @@ from cutter_plugin import CutterPlugin
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
import shiboken2
|
||||
|
||||
|
||||
class CutterSamplePlugin(CutterPlugin):
|
||||
name = "SamplePlugin"
|
||||
description = "A sample plugin written in python."
|
||||
version = "1.0"
|
||||
author = "xarkes"
|
||||
|
||||
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()
|
||||
|
||||
def setupInterface(self):
|
||||
@ -28,4 +30,3 @@ class CutterSamplePlugin(CutterPlugin):
|
||||
|
||||
# Instantiate our plugin
|
||||
plugin = CutterSamplePlugin()
|
||||
|
||||
|
@ -1,11 +1,11 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class CutterPlugin(ABC):
|
||||
name = ''
|
||||
description = ''
|
||||
version = ''
|
||||
author = ''
|
||||
app = None
|
||||
|
||||
@abstractmethod
|
||||
def setupPlugin(self):
|
||||
|
Loading…
Reference in New Issue
Block a user