增加脚本中心的功能
This commit is contained in:
parent
4bf81c4753
commit
7b11230a5c
|
@ -40,7 +40,9 @@ SOURCES += \
|
|||
linebar.cpp \
|
||||
replacebar.cpp \
|
||||
aboutsoftwaredialog.cpp \
|
||||
sponsordialog.cpp
|
||||
sponsordialog.cpp \
|
||||
scriptmanager.cpp \
|
||||
scriptcenterwindow.cpp
|
||||
|
||||
HEADERS += \
|
||||
winghexpy.h \
|
||||
|
@ -88,12 +90,15 @@ HEADERS += \
|
|||
linebar.h \
|
||||
replacebar.h \
|
||||
aboutsoftwaredialog.h \
|
||||
sponsordialog.h
|
||||
sponsordialog.h \
|
||||
scriptmanager.h \
|
||||
scriptcenterwindow.h
|
||||
|
||||
DISTFILES += WingHexPy.json \
|
||||
img/infotable.png \
|
||||
img/infotree.png \
|
||||
img/infotxt.png
|
||||
img/infotxt.png \
|
||||
img/pydb.png
|
||||
|
||||
TRANSLATIONS += \
|
||||
$$PWD/WingHexPy.ts
|
||||
|
|
BIN
WingHexPy.qm
BIN
WingHexPy.qm
Binary file not shown.
85
WingHexPy.ts
85
WingHexPy.ts
|
@ -85,6 +85,42 @@
|
|||
<translation>全部替换</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ScriptCenterWindow</name>
|
||||
<message>
|
||||
<location filename="scriptcenterwindow.cpp" line="8"/>
|
||||
<source>ScriptCenter</source>
|
||||
<translation>脚本中心</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="scriptcenterwindow.cpp" line="29"/>
|
||||
<source>Name</source>
|
||||
<translation>名称</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="scriptcenterwindow.cpp" line="31"/>
|
||||
<source>Author</source>
|
||||
<translation>作者</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="scriptcenterwindow.cpp" line="33"/>
|
||||
<source>License</source>
|
||||
<translation>协议</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="scriptcenterwindow.cpp" line="41"/>
|
||||
<source>Catagory</source>
|
||||
<translation>类别</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ScriptManager</name>
|
||||
<message>
|
||||
<location filename="scriptmanager.cpp" line="72"/>
|
||||
<source>NoScript</source>
|
||||
<translation>暂无脚本</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>ScriptWindow</name>
|
||||
<message>
|
||||
|
@ -327,73 +363,84 @@
|
|||
<context>
|
||||
<name>WingHexPy</name>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="30"/>
|
||||
<location filename="winghexpy.cpp" line="134"/>
|
||||
<location filename="winghexpy.cpp" line="44"/>
|
||||
<location filename="winghexpy.cpp" line="174"/>
|
||||
<source>WingHexPy</source>
|
||||
<translation>WingHexPy</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="32"/>
|
||||
<location filename="winghexpy.cpp" line="46"/>
|
||||
<source>ScriptEditor</source>
|
||||
<translation>脚本编辑器</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="34"/>
|
||||
<location filename="winghexpy.cpp" line="64"/>
|
||||
<location filename="winghexpy.cpp" line="48"/>
|
||||
<location filename="winghexpy.cpp" line="104"/>
|
||||
<source>Run File</source>
|
||||
<translation>从文件执行</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="40"/>
|
||||
<location filename="winghexpy.cpp" line="50"/>
|
||||
<location filename="winghexpy.cpp" line="92"/>
|
||||
<source>Database</source>
|
||||
<translation>脚本库</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="55"/>
|
||||
<source>Script</source>
|
||||
<translation>脚本</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="63"/>
|
||||
<source>Console</source>
|
||||
<translation>控制台</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="43"/>
|
||||
<location filename="winghexpy.cpp" line="71"/>
|
||||
<location filename="winghexpy.cpp" line="66"/>
|
||||
<location filename="winghexpy.cpp" line="111"/>
|
||||
<source>InfoList</source>
|
||||
<translation>信息列表</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="46"/>
|
||||
<location filename="winghexpy.cpp" line="85"/>
|
||||
<location filename="winghexpy.cpp" line="70"/>
|
||||
<location filename="winghexpy.cpp" line="125"/>
|
||||
<source>InfoTree</source>
|
||||
<translation>树信息列表</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="49"/>
|
||||
<location filename="winghexpy.cpp" line="78"/>
|
||||
<location filename="winghexpy.cpp" line="73"/>
|
||||
<location filename="winghexpy.cpp" line="118"/>
|
||||
<source>InfoTable</source>
|
||||
<translation>信息表格</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="53"/>
|
||||
<location filename="winghexpy.cpp" line="92"/>
|
||||
<location filename="winghexpy.cpp" line="77"/>
|
||||
<location filename="winghexpy.cpp" line="132"/>
|
||||
<source>InfoTxt</source>
|
||||
<translation>信息文本浏览</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="61"/>
|
||||
<location filename="winghexpy.cpp" line="85"/>
|
||||
<source>ScriptWindow</source>
|
||||
<translation>脚本窗口</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="100"/>
|
||||
<location filename="winghexpy.cpp" line="140"/>
|
||||
<source>About</source>
|
||||
<translation>关于</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="107"/>
|
||||
<location filename="winghexpy.cpp" line="147"/>
|
||||
<source>Sponsor</source>
|
||||
<translation>赞助</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="115"/>
|
||||
<location filename="winghexpy.cpp" line="155"/>
|
||||
<source>ChooseFile</source>
|
||||
<translation>选择文件</translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="winghexpy.cpp" line="139"/>
|
||||
<location filename="winghexpy.cpp" line="179"/>
|
||||
<source>A useful plugin for python3.7 support.</source>
|
||||
<translation>一个十分有用的 Python 3.7 的支持插件。</translation>
|
||||
</message>
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 6.5 KiB |
Binary file not shown.
After Width: | Height: | Size: 19 KiB |
|
@ -38,5 +38,7 @@
|
|||
<file>img/unsaved.png</file>
|
||||
<file>img/saved.png</file>
|
||||
<file>img/readonly.png</file>
|
||||
<file>img/pydb.png</file>
|
||||
<file>img/py.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#include "scriptcenterwindow.h"
|
||||
#include <DTextBrowser>
|
||||
#include <DTreeWidget>
|
||||
#include <QHBoxLayout>
|
||||
|
||||
ScriptCenterWindow::ScriptCenterWindow(DMainWindow *parent) : DDialog(parent) {
|
||||
setMinimumSize(700, 500);
|
||||
setWindowTitle(tr("ScriptCenter"));
|
||||
auto w = new QWidget(this);
|
||||
auto layout = new QHBoxLayout(w);
|
||||
auto tree = new QTreeWidget(this);
|
||||
tree->setHeaderHidden(true);
|
||||
m = ScriptManager::instance();
|
||||
m->loadTreeWidget(tree);
|
||||
layout->addWidget(tree);
|
||||
auto txt = new QTextBrowser(this);
|
||||
layout->addWidget(txt);
|
||||
addContent(w);
|
||||
|
||||
connect(tree, &QTreeWidget::itemSelectionChanged, this, [=] {
|
||||
auto s = tree->selectedItems();
|
||||
if (s.count()) {
|
||||
auto si = s.first();
|
||||
auto meta = si->data(0, Qt::UserRole).value<ScriptMeta>();
|
||||
if (meta.name.length()) {
|
||||
txt->setMarkdown(QString("**%1** : %2\n\n**%3** : %4\n\n"
|
||||
"**%5** : %6\n\n**%7** : %8\n\n"
|
||||
"**%9** : %10\n\n")
|
||||
.arg(tr("Name"))
|
||||
.arg(meta.name)
|
||||
.arg(tr("Author"))
|
||||
.arg(meta.author)
|
||||
.arg(tr("License"))
|
||||
.arg(meta.license)
|
||||
.arg("Version")
|
||||
.arg(meta.version)
|
||||
.arg("Commnet")
|
||||
.arg(meta.commnet));
|
||||
} else {
|
||||
txt->setMarkdown(
|
||||
QString("**%1** : %2\n\n").arg(tr("Catagory")).arg(si->text(0)));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef SCRIPTCENTERWINDOW_H
|
||||
#define SCRIPTCENTERWINDOW_H
|
||||
|
||||
#include "scriptmanager.h"
|
||||
#include <DDialog>
|
||||
#include <DMainWindow>
|
||||
#include <QObject>
|
||||
|
||||
DWIDGET_USE_NAMESPACE
|
||||
|
||||
class ScriptCenterWindow : public DDialog {
|
||||
Q_OBJECT
|
||||
public:
|
||||
ScriptCenterWindow(DMainWindow *parent = nullptr);
|
||||
|
||||
private:
|
||||
ScriptManager *m;
|
||||
};
|
||||
|
||||
#endif // SCRIPTCENTERWINDOW_H
|
|
@ -0,0 +1,109 @@
|
|||
#include "scriptmanager.h"
|
||||
#include <QDir>
|
||||
#include <QJsonArray>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
ScriptManager *ScriptManager::m_instance = nullptr;
|
||||
|
||||
ScriptManager *ScriptManager::instance() {
|
||||
if (m_instance == nullptr)
|
||||
m_instance = new ScriptManager;
|
||||
return m_instance;
|
||||
}
|
||||
|
||||
ScriptManager::ScriptManager(QObject *parent) : QObject(parent) {
|
||||
auto dir = PLUGINDIR + "/winghexpys";
|
||||
QDir pdir(dir);
|
||||
pdir.setFilter(QDir::Filter::Dirs);
|
||||
auto fdirs = pdir.entryInfoList();
|
||||
for (auto folder : fdirs) {
|
||||
auto na = folder.fileName();
|
||||
if (na == "." || na == "..")
|
||||
continue;
|
||||
QDir jdir(folder.filePath());
|
||||
QList<ScriptMeta> m;
|
||||
jdir.setNameFilters({"*.json"});
|
||||
auto jsons = jdir.entryInfoList();
|
||||
if (!jsons.count())
|
||||
continue;
|
||||
for (auto j : jsons) {
|
||||
QFile f(j.absoluteFilePath());
|
||||
QJsonParseError err;
|
||||
if (!f.open(QFile::ReadOnly))
|
||||
continue;
|
||||
QJsonDocument doc = QJsonDocument::fromJson(f.readAll(), &err);
|
||||
f.close();
|
||||
if (err.error != QJsonParseError::NoError)
|
||||
continue;
|
||||
auto jobj = doc.object();
|
||||
auto n = j.fileName();
|
||||
ScriptMeta meta;
|
||||
auto p = n.lastIndexOf('.');
|
||||
meta.name = n.left(p);
|
||||
meta.filename = folder.absoluteFilePath() + "/" + meta.name + ".py";
|
||||
auto t = jobj.value("author");
|
||||
if (!t.isUndefined() && t.isString()) {
|
||||
meta.author = t.toString();
|
||||
}
|
||||
t = jobj.value("license");
|
||||
if (!t.isUndefined() && t.isString()) {
|
||||
meta.license = t.toString();
|
||||
} else {
|
||||
meta.license = "Unlicense";
|
||||
}
|
||||
t = jobj.value("commnet");
|
||||
if (!t.isUndefined() && t.isString()) {
|
||||
meta.commnet = t.toString();
|
||||
}
|
||||
t = jobj.value("version");
|
||||
meta.version = uint(t.toInt());
|
||||
m.push_back(meta);
|
||||
}
|
||||
m_metas.insert(folder.fileName(), m);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::loadMenu(QMenu *menu) {
|
||||
if (!menu)
|
||||
return;
|
||||
if (!m_metas.count()) {
|
||||
auto a = new QAction(tr("NoScript"));
|
||||
a->setEnabled(false);
|
||||
menu->addAction(a);
|
||||
return;
|
||||
}
|
||||
auto ke = m_metas.keyValueEnd();
|
||||
auto k = m_metas.keyValueBegin();
|
||||
for (; k != ke; k++) {
|
||||
auto i = new QMenu;
|
||||
auto n = *k;
|
||||
i->setTitle(n.first);
|
||||
for (auto mitem : n.second) {
|
||||
QAction *a;
|
||||
PluginMenuAddItemLamba(i, mitem.name, [=] {
|
||||
PlgInterface::instance()->RunPyFile(mitem.filename);
|
||||
});
|
||||
}
|
||||
menu->addMenu(i);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptManager::loadTreeWidget(QTreeWidget *tree) {
|
||||
if (!tree)
|
||||
return;
|
||||
tree->clear();
|
||||
auto ke = m_metas.keyValueEnd();
|
||||
auto k = m_metas.keyValueBegin();
|
||||
for (; k != ke; k++) {
|
||||
auto n = *k;
|
||||
auto p = new QTreeWidgetItem(tree, {k->first});
|
||||
p->setIcon(0, QIcon(":/img/pydb.png"));
|
||||
for (auto mitem : n.second) {
|
||||
auto i = new QTreeWidgetItem(p, {mitem.name});
|
||||
i->setIcon(0, QIcon(":/img/py.png"));
|
||||
i->setData(0, Qt::UserRole, QVariant::fromValue(mitem));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
#ifndef SCRIPTMANAGER_H
|
||||
#define SCRIPTMANAGER_H
|
||||
|
||||
#include "../WingHexExplorer/wing-hex-explorer.sourcecode/WingHexExplorer/plugin/iwingplugin.h"
|
||||
#include "plginterface.h"
|
||||
#include <QMap>
|
||||
#include <QObject>
|
||||
|
||||
struct ScriptMeta {
|
||||
QString name;
|
||||
QString filename;
|
||||
QString author;
|
||||
QString license;
|
||||
QString commnet;
|
||||
uint version;
|
||||
};
|
||||
|
||||
Q_DECLARE_METATYPE(ScriptMeta)
|
||||
|
||||
class ScriptManager : public QObject {
|
||||
Q_OBJECT
|
||||
public:
|
||||
static ScriptManager *instance();
|
||||
void loadMenu(QMenu *menu);
|
||||
void loadTreeWidget(QTreeWidget *tree);
|
||||
static ScriptManager *m_instance;
|
||||
|
||||
private:
|
||||
ScriptManager(QObject *parent = nullptr);
|
||||
QMap<QString, QList<ScriptMeta>> m_metas;
|
||||
};
|
||||
|
||||
#endif // SCRIPTMANAGER_H
|
|
@ -1,5 +1,6 @@
|
|||
#include "winghexpy.h"
|
||||
#include "aboutsoftwaredialog.h"
|
||||
#include "scriptcenterwindow.h"
|
||||
#include "scriptwindow.h"
|
||||
#include "sponsordialog.h"
|
||||
#include <QApplication>
|
||||
|
@ -38,12 +39,23 @@ bool WingHexPy::init(QList<WingPluginInfo> loadedplugin) {
|
|||
}
|
||||
connect(plgint, &PlgInterface::log, this, &WingHexPy::log);
|
||||
|
||||
smanager = ScriptManager::instance();
|
||||
|
||||
PluginMenuInitBegin(menu, tr("WingHexPy")) {
|
||||
menu->setIcon(ICONRES("icon"));
|
||||
PluginMenuAddItemIconLamba(menu, tr("ScriptEditor"), ICONRES("pys"),
|
||||
[=] { ScriptWindow::instance()->show(); });
|
||||
PluginMenuAddItemIconAction(menu, tr("Run File"), ICONRES("runf"),
|
||||
WingHexPy::runPyFile);
|
||||
PluginMenuAddItemIconLamba(menu, tr("Database"), ICONRES("pydb"), [=] {
|
||||
ScriptCenterWindow d;
|
||||
d.exec();
|
||||
});
|
||||
auto m = new QMenu;
|
||||
m->setTitle(tr("Script"));
|
||||
m->setIcon(ICONRES("py"));
|
||||
smanager->loadMenu(m);
|
||||
menu->addMenu(m);
|
||||
}
|
||||
PluginMenuInitEnd();
|
||||
|
||||
|
@ -71,6 +83,22 @@ bool WingHexPy::init(QList<WingPluginInfo> loadedplugin) {
|
|||
PluginToolBarAddLamba(
|
||||
tb, ICONRES("pys"), [=] { ScriptWindow::instance()->show(); },
|
||||
tr("ScriptWindow"));
|
||||
PluginToolBarAddLamba(
|
||||
tb, ICONRES("pydb"),
|
||||
[=] {
|
||||
ScriptCenterWindow d;
|
||||
d.exec();
|
||||
},
|
||||
tr("Database"));
|
||||
|
||||
auto m = new QMenu;
|
||||
smanager->loadMenu(m);
|
||||
auto tbtn = new QToolButton;
|
||||
tbtn->setIcon(ICONRES("py"));
|
||||
tbtn->setMenu(m);
|
||||
tbtn->setPopupMode(QToolButton::ToolButtonPopupMode::InstantPopup);
|
||||
tb->addWidget(tbtn);
|
||||
|
||||
tb->addSeparator();
|
||||
PluginToolBarAddAction(tb, ICONRES("runf"), WingHexPy::runPyFile,
|
||||
tr("Run File"));
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "../WingHexExplorer/wing-hex-explorer.sourcecode/WingHexExplorer/plugin/iwingplugin.h"
|
||||
#include "PythonQt/gui/PythonQtScriptingConsole.h"
|
||||
#include "plginterface.h"
|
||||
#include "scriptmanager.h"
|
||||
#include <Python.h>
|
||||
#include <QListWidget>
|
||||
#include <QTableWidget>
|
||||
|
@ -49,6 +50,7 @@ private:
|
|||
QToolBar *tb;
|
||||
QDockWidget *dw;
|
||||
PythonQtScriptingConsole *txt;
|
||||
ScriptManager *smanager;
|
||||
|
||||
private:
|
||||
QDockWidget *dlist, *dtree, *dtable, *dtxt;
|
||||
|
|
Loading…
Reference in New Issue