mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-21 12:26:11 +00:00
Find MainWindow in Python
Return Pointer from setupInterface() in Python Plugin Load plugins before creating MainWindow
This commit is contained in:
parent
7798021f03
commit
1f3315d020
@ -119,6 +119,8 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
loadPlugins();
|
||||||
|
|
||||||
mainWindow = new MainWindow();
|
mainWindow = new MainWindow();
|
||||||
installEventFilter(mainWindow);
|
installEventFilter(mainWindow);
|
||||||
|
|
||||||
@ -161,9 +163,6 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
|||||||
mainWindow->openNewFile(options, analLevelSpecified);
|
mainWindow->openNewFile(options, analLevelSpecified);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load plugins
|
|
||||||
loadPlugins();
|
|
||||||
|
|
||||||
#ifdef CUTTER_APPVEYOR_R2DEC
|
#ifdef CUTTER_APPVEYOR_R2DEC
|
||||||
qputenv("R2DEC_HOME", "radare2\\lib\\plugins\\r2dec-js");
|
qputenv("R2DEC_HOME", "radare2\\lib\\plugins\\r2dec-js");
|
||||||
#endif
|
#endif
|
||||||
|
@ -80,10 +80,23 @@ CutterDockWidget* CutterPythonPlugin::setupInterface(MainWindow *main, QAction *
|
|||||||
PyObject *pWidget = nullptr;
|
PyObject *pWidget = nullptr;
|
||||||
Python()->restoreThread();
|
Python()->restoreThread();
|
||||||
pWidget = PyObject_CallMethod(pInstance, "setupInterface", nullptr);
|
pWidget = PyObject_CallMethod(pInstance, "setupInterface", nullptr);
|
||||||
|
|
||||||
if (!pWidget) {
|
if (!pWidget) {
|
||||||
qWarning() << "Error in setupInterface().";
|
qWarning() << "Error in setupInterface().";
|
||||||
PyErr_Print();
|
PyErr_Print();
|
||||||
|
Python()->saveThread();
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!PyLong_Check(pWidget)) {
|
||||||
|
qWarning() << "Value returned by setupInterface() is not PyLong.";
|
||||||
|
Python()->saveThread();
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto dockWidget = reinterpret_cast<QDockWidget *>(PyLong_AsLong(pWidget));
|
||||||
|
printf("plugin gave me this: %s\n", dockWidget->objectName().toLocal8Bit().constData());
|
||||||
|
|
||||||
Python()->saveThread();
|
Python()->saveThread();
|
||||||
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import cutter
|
import cutter
|
||||||
from cutter_plugin import CutterPlugin
|
from cutter_plugin import CutterPlugin
|
||||||
from PySide2 import QtCore, QtWidgets
|
from PySide2 import QtCore, QtWidgets
|
||||||
|
import shiboken2
|
||||||
|
|
||||||
class CutterSamplePlugin(CutterPlugin):
|
class CutterSamplePlugin(CutterPlugin):
|
||||||
def setupPlugin(self):
|
def setupPlugin(self):
|
||||||
@ -12,11 +13,17 @@ class CutterSamplePlugin(CutterPlugin):
|
|||||||
|
|
||||||
def setupInterface(self):
|
def setupInterface(self):
|
||||||
print('Creating the dock widget...')
|
print('Creating the dock widget...')
|
||||||
main_window = self.app.findChild('MainWindow')
|
main_window = None
|
||||||
|
for widget in QtWidgets.QApplication.topLevelWidgets():
|
||||||
|
if widget.objectName() == "MainWindow":
|
||||||
|
main_window = widget
|
||||||
dock_widget = QtWidgets.QDockWidget(main_window)
|
dock_widget = QtWidgets.QDockWidget(main_window)
|
||||||
|
dock_widget.setObjectName("FancyDockWidgetFromCoolPlugin")
|
||||||
dock_widget.setWindowTitle('Test Widget')
|
dock_widget.setWindowTitle('Test Widget')
|
||||||
print(main_window, dock_widget)
|
print(main_window, dock_widget)
|
||||||
return dock_widget
|
ptr = shiboken2.getCppPointer(dock_widget)[0]
|
||||||
|
print(ptr)
|
||||||
|
return ptr
|
||||||
|
|
||||||
|
|
||||||
# Instantiate our plugin
|
# Instantiate our plugin
|
||||||
|
Loading…
Reference in New Issue
Block a user