mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 16:47:26 +00:00
Test setupInterface
This commit is contained in:
parent
9c2de3e23d
commit
650823409d
@ -279,9 +279,11 @@ void MainWindow::initUI()
|
|||||||
QList<CutterPlugin *> plugins = core->getCutterPlugins();
|
QList<CutterPlugin *> plugins = core->getCutterPlugins();
|
||||||
for (auto plugin : plugins) {
|
for (auto plugin : plugins) {
|
||||||
CutterDockWidget *pluginDock = plugin->setupInterface(this);
|
CutterDockWidget *pluginDock = plugin->setupInterface(this);
|
||||||
|
if (pluginDock) {
|
||||||
tabifyDockWidget(dashboardDock, pluginDock);
|
tabifyDockWidget(dashboardDock, pluginDock);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::toggleOverview(bool visibility, GraphWidget *targetGraph)
|
void MainWindow::toggleOverview(bool visibility, GraphWidget *targetGraph)
|
||||||
{
|
{
|
||||||
|
@ -6,30 +6,26 @@
|
|||||||
CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
CutterPythonPlugin::CutterPythonPlugin(PyObject* pluginModule)
|
||||||
{
|
{
|
||||||
this->pluginModule = pluginModule;
|
this->pluginModule = pluginModule;
|
||||||
|
|
||||||
|
if (!pluginModule) {
|
||||||
|
qWarning() << "Could not find plugin module.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
pInstance = PyObject_GetAttrString(pluginModule, "plugin");
|
||||||
|
if (!pInstance) {
|
||||||
|
qWarning() << "Cannot find plugin instance.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CutterPythonPlugin::setupPlugin(CutterCore *core)
|
void CutterPythonPlugin::setupPlugin(CutterCore *core)
|
||||||
{
|
{
|
||||||
Q_UNUSED(core)
|
Q_UNUSED(core)
|
||||||
|
|
||||||
if (!pluginModule) {
|
|
||||||
qWarning() << "Could not find plugin module.";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Python()->restoreThread();
|
Python()->restoreThread();
|
||||||
PyObject *pInstance = PyObject_GetAttrString(pluginModule, "plugin");
|
|
||||||
if (!pInstance) {
|
|
||||||
qWarning() << "Cannot find plugin instance.";
|
|
||||||
Python()->saveThread();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check setupPlugin method exists
|
// Check setupPlugin method exists
|
||||||
PyObject *setupPlugin = PyObject_GetAttrString(pInstance, "setupPlugin");
|
PyObject *setupPlugin = PyObject_GetAttrString(pInstance, "setupPlugin");
|
||||||
if (!setupPlugin) {
|
if (!setupPlugin) {
|
||||||
qWarning() << "Cannot find setupPlugin method.";
|
qWarning() << "Cannot find setupPlugin method.";
|
||||||
Py_DECREF(pInstance);
|
|
||||||
Python()->saveThread();
|
Python()->saveThread();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -39,24 +35,22 @@ void CutterPythonPlugin::setupPlugin(CutterCore *core)
|
|||||||
PyObject *result = PyObject_CallMethod(pInstance, "setupPlugin", nullptr);
|
PyObject *result = PyObject_CallMethod(pInstance, "setupPlugin", nullptr);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
qWarning() << "Error in setupPlugin().";
|
qWarning() << "Error in setupPlugin().";
|
||||||
Py_DECREF(pInstance);
|
|
||||||
Python()->saveThread();
|
Python()->saveThread();
|
||||||
}
|
}
|
||||||
Py_DECREF(result);
|
Py_DECREF(result);
|
||||||
|
|
||||||
this->name = getAttributeFromPython(pInstance, "name");
|
this->name = getAttributeFromPython("name");
|
||||||
this->description = getAttributeFromPython(pInstance, "description");
|
this->description = getAttributeFromPython("description");
|
||||||
this->version = getAttributeFromPython(pInstance, "version");
|
this->version = getAttributeFromPython("version");
|
||||||
this->author = getAttributeFromPython(pInstance, "author");
|
this->author = getAttributeFromPython("author");
|
||||||
|
|
||||||
Py_DECREF(pInstance);
|
|
||||||
Python()->saveThread();
|
Python()->saveThread();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString CutterPythonPlugin::getAttributeFromPython(PyObject *object, const char *attribute)
|
QString CutterPythonPlugin::getAttributeFromPython(const char *attribute)
|
||||||
{
|
{
|
||||||
QString result;
|
QString result;
|
||||||
PyObject *pName = PyObject_GetAttrString(object, attribute);
|
PyObject *pName = PyObject_GetAttrString(pInstance, attribute);
|
||||||
if (pName) {
|
if (pName) {
|
||||||
result = QString(PyUnicode_AsUTF8(pName));
|
result = QString(PyUnicode_AsUTF8(pName));
|
||||||
}
|
}
|
||||||
@ -70,5 +64,12 @@ CutterDockWidget* CutterPythonPlugin::setupInterface(MainWindow *main, QAction *
|
|||||||
Q_UNUSED(main)
|
Q_UNUSED(main)
|
||||||
Q_UNUSED(action)
|
Q_UNUSED(action)
|
||||||
|
|
||||||
|
PyObject *pWidget = nullptr;
|
||||||
|
Python()->restoreThread();
|
||||||
|
pWidget = PyObject_CallMethod(pInstance, "setupInterface", nullptr);
|
||||||
|
Python()->saveThread();
|
||||||
|
|
||||||
|
qDebug() << "Here is the widget: " << pWidget;
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,9 @@ public:
|
|||||||
CutterDockWidget* setupInterface(MainWindow *main, QAction *action);
|
CutterDockWidget* setupInterface(MainWindow *main, QAction *action);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PyObject *pluginModule;
|
PyObject *pluginModule = nullptr;
|
||||||
QString getAttributeFromPython(PyObject *object, const char *attribute);
|
PyObject *pInstance = nullptr;
|
||||||
|
QString getAttributeFromPython(const char *attribute);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CUTTERPYTHONPLUGIN_H
|
#endif // CUTTERPYTHONPLUGIN_H
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import cutter
|
import cutter
|
||||||
from cutter_plugin import CutterPlugin
|
from cutter_plugin import CutterPlugin
|
||||||
|
from PySide2 import QtCore, QtWidgets
|
||||||
|
|
||||||
class CutterSamplePlugin(CutterPlugin):
|
class CutterSamplePlugin(CutterPlugin):
|
||||||
def setupPlugin(self):
|
def setupPlugin(self):
|
||||||
@ -7,9 +8,17 @@ class CutterSamplePlugin(CutterPlugin):
|
|||||||
self.description = 'A sample plugin written in python.'
|
self.description = 'A sample plugin written in python.'
|
||||||
self.version = '1.0'
|
self.version = '1.0'
|
||||||
self.author = 'xarkes'
|
self.author = 'xarkes'
|
||||||
|
self.app = QtCore.QCoreApplication.instance()
|
||||||
|
|
||||||
def setupInterface(self, main, action):
|
def setupInterface(self):
|
||||||
print('TODO')
|
for _ in range(200):
|
||||||
|
print('FUCK', end='')
|
||||||
|
main_window = self.app.findChild('MainWindow')
|
||||||
|
dock_widget = QtWidgets.QDockWidget(main_window)
|
||||||
|
dock_widget.setWindowTitle('Test Widget!!!')
|
||||||
|
for _ in range(200):
|
||||||
|
print(main_window, dock_widget)
|
||||||
|
return dock_widget
|
||||||
|
|
||||||
|
|
||||||
# Instantiate our plugin
|
# Instantiate our plugin
|
||||||
|
@ -5,13 +5,13 @@ class CutterPlugin(ABC):
|
|||||||
description = ''
|
description = ''
|
||||||
version = ''
|
version = ''
|
||||||
author = ''
|
author = ''
|
||||||
core = None
|
app = None
|
||||||
dockable = None
|
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def setupPlugin(self):
|
def setupPlugin(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def setupInterface(self, main, action):
|
def setupInterface(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user