mirror of
https://github.com/rizinorg/cutter.git
synced 2024-12-20 03:46:11 +00:00
Cleaned a bit and added a widget example
This commit is contained in:
parent
74a201ecba
commit
da3e1fad29
@ -278,7 +278,7 @@ void MainWindow::initUI()
|
||||
/* Setup plugins interfaces */
|
||||
QList<CutterPlugin *> plugins = core->getCutterPlugins();
|
||||
for (auto plugin : plugins) {
|
||||
CutterDockWidget *pluginDock = plugin->setupInterface(this);
|
||||
QDockWidget *pluginDock = plugin->setupInterface(this);
|
||||
if (pluginDock) {
|
||||
tabifyDockWidget(dashboardDock, pluginDock);
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ class CutterPlugin
|
||||
public:
|
||||
virtual ~CutterPlugin() {}
|
||||
virtual void setupPlugin(CutterCore *core) = 0;
|
||||
virtual CutterDockWidget* setupInterface(MainWindow *main, QAction *action = nullptr) = 0;
|
||||
virtual QDockWidget *setupInterface(MainWindow *main, QAction *action = nullptr) = 0;
|
||||
|
||||
QString name;
|
||||
QString description;
|
||||
|
@ -93,7 +93,7 @@ QString CutterPythonPlugin::getAttributeFromPython(const char *attribute)
|
||||
return result;
|
||||
}
|
||||
|
||||
CutterDockWidget* CutterPythonPlugin::setupInterface(MainWindow *main, QAction *action)
|
||||
QDockWidget *CutterPythonPlugin::setupInterface(MainWindow *main, QAction *action)
|
||||
{
|
||||
Q_UNUSED(main)
|
||||
Q_UNUSED(action)
|
||||
@ -116,9 +116,13 @@ CutterDockWidget* CutterPythonPlugin::setupInterface(MainWindow *main, QAction *
|
||||
}
|
||||
|
||||
auto dockWidget = reinterpret_cast<QDockWidget *>(PyLong_AsLong(pWidget));
|
||||
printf("plugin gave me this: %s\n", dockWidget->objectName().toLocal8Bit().constData());
|
||||
if (!dockWidget) {
|
||||
qWarning() << "Cannot instantiate QDockWidget.";
|
||||
Python()->saveThread();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Python()->saveThread();
|
||||
|
||||
return nullptr;
|
||||
return dockWidget;
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public:
|
||||
CutterPythonPlugin(PyObject* pluginModule);
|
||||
~CutterPythonPlugin();
|
||||
void setupPlugin(CutterCore *core);
|
||||
CutterDockWidget* setupInterface(MainWindow *main, QAction *action);
|
||||
QDockWidget *setupInterface(MainWindow *main, QAction *action);
|
||||
|
||||
private:
|
||||
PyObject *pluginModule = nullptr;
|
||||
|
@ -1,31 +1,51 @@
|
||||
import cutter
|
||||
from cutter_plugin import CutterPlugin
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
import shiboken2
|
||||
from PySide2 import QtWidgets
|
||||
from PySide2.QtCore import QObject, SIGNAL, Qt
|
||||
from PySide2.QtGui import QFont
|
||||
|
||||
|
||||
class CutterSamplePlugin(CutterPlugin):
|
||||
name = "SamplePlugin"
|
||||
description = "A sample plugin written in python."
|
||||
version = "1.0"
|
||||
author = "xarkes"
|
||||
|
||||
def setupPlugin(self):
|
||||
self.app = QtCore.QCoreApplication.instance()
|
||||
author = "xarkes and thestr4ng3r :-P"
|
||||
|
||||
def setupInterface(self):
|
||||
print('Creating the dock widget...')
|
||||
main_window = None
|
||||
for widget in QtWidgets.QApplication.topLevelWidgets():
|
||||
if widget.objectName() == "MainWindow":
|
||||
main_window = widget
|
||||
dock_widget = QtWidgets.QDockWidget(main_window)
|
||||
super().setupInterface()
|
||||
|
||||
# Create dock widget and content widget
|
||||
dock_widget = QtWidgets.QDockWidget(self.main)
|
||||
dock_widget.setObjectName("FancyDockWidgetFromCoolPlugin")
|
||||
dock_widget.setWindowTitle('Test Widget')
|
||||
print(main_window, dock_widget)
|
||||
ptr = shiboken2.getCppPointer(dock_widget)[0]
|
||||
print(ptr)
|
||||
return ptr
|
||||
dock_widget.setWindowTitle("Test Widget")
|
||||
content = QtWidgets.QWidget()
|
||||
dock_widget.setWidget(content)
|
||||
|
||||
# Create layout and label
|
||||
layout = QtWidgets.QVBoxLayout(dock_widget)
|
||||
content.setLayout(layout)
|
||||
self.text = QtWidgets.QLabel(content)
|
||||
self.text.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
|
||||
layout.addWidget(self.text)
|
||||
|
||||
button = QtWidgets.QPushButton(content)
|
||||
button.setText("Want a fortune?")
|
||||
button.setSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
|
||||
button.setMaximumHeight(50)
|
||||
button.setMaximumWidth(200)
|
||||
layout.addWidget(button)
|
||||
layout.setAlignment(button, Qt.AlignHCenter)
|
||||
|
||||
# TODO How to access CutterCore::seekChanged?
|
||||
# QObject.connect(cutter.core() ?, cutter.???)
|
||||
QObject.connect(button, SIGNAL("clicked()"), self.on_button_clicked)
|
||||
|
||||
return self.makeCppPointer(dock_widget)
|
||||
|
||||
|
||||
def on_button_clicked(self):
|
||||
res = cutter.cmd("?E `fo`")
|
||||
self.text.setText(res)
|
||||
|
||||
|
||||
# Instantiate our plugin
|
||||
|
@ -1,17 +1,25 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from PySide2 import QtCore, QtWidgets
|
||||
import shiboken2
|
||||
|
||||
|
||||
class CutterPlugin(ABC):
|
||||
class CutterPlugin(object):
|
||||
name = ''
|
||||
description = ''
|
||||
version = ''
|
||||
author = ''
|
||||
|
||||
@abstractmethod
|
||||
def setupPlugin(self):
|
||||
pass
|
||||
self.app = QtCore.QCoreApplication.instance()
|
||||
|
||||
@abstractmethod
|
||||
def setupInterface(self):
|
||||
pass
|
||||
for widget in QtWidgets.QApplication.topLevelWidgets():
|
||||
if widget.objectName() == "MainWindow":
|
||||
self.main = widget
|
||||
break
|
||||
|
||||
def makeCppPointer(self, widget):
|
||||
ptr = shiboken2.getCppPointer(widget)[0]
|
||||
return ptr
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user