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