mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-19 03:16:10 +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();
|
||||
installEventFilter(mainWindow);
|
||||
|
||||
@ -161,9 +163,6 @@ CutterApplication::CutterApplication(int &argc, char **argv) : QApplication(argc
|
||||
mainWindow->openNewFile(options, analLevelSpecified);
|
||||
}
|
||||
|
||||
// Load plugins
|
||||
loadPlugins();
|
||||
|
||||
#ifdef CUTTER_APPVEYOR_R2DEC
|
||||
qputenv("R2DEC_HOME", "radare2\\lib\\plugins\\r2dec-js");
|
||||
#endif
|
||||
|
@ -80,10 +80,23 @@ CutterDockWidget* CutterPythonPlugin::setupInterface(MainWindow *main, QAction *
|
||||
PyObject *pWidget = nullptr;
|
||||
Python()->restoreThread();
|
||||
pWidget = PyObject_CallMethod(pInstance, "setupInterface", nullptr);
|
||||
|
||||
if (!pWidget) {
|
||||
qWarning() << "Error in setupInterface().";
|
||||
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();
|
||||
|
||||
return nullptr;
|
||||
|
@ -1,6 +1,7 @@
|
||||
import cutter
|
||||
from cutter_plugin import CutterPlugin
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
import shiboken2
|
||||
|
||||
class CutterSamplePlugin(CutterPlugin):
|
||||
def setupPlugin(self):
|
||||
@ -12,11 +13,17 @@ class CutterSamplePlugin(CutterPlugin):
|
||||
|
||||
def setupInterface(self):
|
||||
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.setObjectName("FancyDockWidgetFromCoolPlugin")
|
||||
dock_widget.setWindowTitle('Test Widget')
|
||||
print(main_window, dock_widget)
|
||||
return dock_widget
|
||||
ptr = shiboken2.getCppPointer(dock_widget)[0]
|
||||
print(ptr)
|
||||
return ptr
|
||||
|
||||
|
||||
# Instantiate our plugin
|
||||
|
Loading…
Reference in New Issue
Block a user