4 Star 15 Fork 8

羽云工作室/WingHexPy
暂停

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
plginterface.cpp 4.03 KB
一键复制 编辑 原始数据 按行查看 历史
wingsummer 提交于 2023-07-07 21:04 +08:00 . update
#include "plginterface.h"
#include "PythonQt/PythonQtCppWrapperFactory.h"
#include "PythonQt/PythonQt_QtAll.h"
#include "iwingpluginstructwrapper.h"
#include <QKeySequence>
#include <QListWidgetItem>
#include <QShortcut>
#include <QTemporaryFile>
PlgInterface *PlgInterface::m_instace = nullptr;
bool PlgInterface::init() {
PythonQt::init(PythonQt::IgnoreSiteModule | PythonQt::RedirectStdOut);
PythonQt_QtAll::init();
auto py = PythonQt::self();
py->registerClass(&QListWidget::staticMetaObject, "QtGui");
py->registerClass(&QTableWidget::staticMetaObject, "QtGui");
py->registerClass(&QTreeWidget::staticMetaObject, "QtGui");
py->registerClass(&QTextBrowser::staticMetaObject, "QtGui");
py->registerCPPClass("plgreader", nullptr, "wingplg",
PythonQtCreateObject<WingPlugin::Reader>);
py->registerCPPClass("plgcontroller", nullptr, "wingplg",
PythonQtCreateObject<WingPlugin::Controller>);
py->registerCPPClass("plgservice", nullptr, "wingplg",
PythonQtCreateObject<PlgService>);
py->addDecorators(new IWingPluginStructWrapper());
qRegisterMetaType<HexPosition>("HexPosition");
qRegisterMetaType<BookMark>("BookMark");
qRegisterMetaType<ErrFile>("ErrFile");
qRegisterMetaType<FindResult>("FindResult");
qRegisterMetaType<HexMetadataAbsoluteItem>("HexMetadataAbsoluteItem");
qRegisterMetaType<HexMetadataItem>("HexMetadataItem");
qRegisterMetaType<HexLineMetadata>("HexLineMetadata");
mainContext = PythonQt::self()->getMainModule();
mainContext.addObject("reader", &plg->reader);
mainContext.addObject("controller", &plg->controller);
mainContext.addObject("service", new PlgService(this));
mainContext.evalScript("from PythonQt import *");
console = new PythonQtScriptingConsole(nullptr, mainContext);
m_instace = this;
auto shortcut = new QShortcut(
QKeySequence(Qt::KeyboardModifier::ControlModifier | Qt::Key_L), console);
connect(shortcut, &QShortcut::activated, this, [=] { console->clear(); });
return true;
}
void PlgInterface::initInfo(QListWidget *infolist, QTreeWidget *infotree,
QTableWidget *infotable, QTextBrowser *infotxt) {
mainContext.addObject("infotree", infotree);
mainContext.addObject("infotable", infotable);
mainContext.addObject("infolist", infolist);
mainContext.addObject("infotxt", infotxt);
}
PythonQtScriptingConsole *PlgInterface::getScriptingConsole() {
return console;
}
bool PlgInterface::RunPyFile(const QString &filename) {
if (mutex.tryLock()) {
auto cur = console->textCursor();
cur.movePosition(QTextCursor::End);
console->setTextCursor(cur);
console->insertPlainText(filename);
mainContext.evalFile(filename);
console->appendCommandPrompt();
if (plg->hasControl())
plg->requestRelease();
mutex.unlock();
return true;
}
return false;
}
bool PlgInterface::requestControl(int timeout) {
return plg->requestControl(timeout);
}
bool PlgInterface::requestRelease() { return plg->requestRelease(); }
bool PlgInterface::hasControl() { return plg->hasControl(); }
void PlgInterface::toast(const QIcon &icon, const QString &message) {
plg->toast(icon, message);
}
void PlgInterface::logWarn(const QString &message) { plg->warn(message); }
void PlgInterface::logError(const QString &message) { plg->error(message); }
void PlgInterface::logInfo(const QString &message) { plg->info(message); }
void PlgInterface::logDebug(const QString &message) { plg->debug(message); }
bool PlgInterface::RunPyText(const QString &content) {
if (mutex.tryLock()) {
auto cur = console->textCursor();
cur.movePosition(QTextCursor::End);
console->setTextCursor(cur);
console->insertPlainText(tr("[ExcuteFromScriptWindow]"));
mainContext.evalScript(content);
console->appendCommandPrompt();
if (plg->hasControl())
plg->requestRelease();
mutex.unlock();
return true;
}
return false;
}
PlgInterface::PlgInterface(IWingPlugin *parent) : QObject(parent) {
plg = parent;
}
PlgInterface *PlgInterface::instance() { return m_instace; }
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/wing-cloud/wing-hex-py.git
git@gitee.com:wing-cloud/wing-hex-py.git
wing-cloud
wing-hex-py
WingHexPy
master

搜索帮助