-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplginterface.h
100 lines (83 loc) · 2.86 KB
/
plginterface.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#ifndef PLGINTERFACE_H
#define PLGINTERFACE_H
#define PY_SSIZE_T_CLEAN
#include "../WingHexExplorer/WingHexExplorer/plugin/iwingplugin.h"
#include "PythonQt/PythonQt.h"
#include "PythonQt/gui/PythonQtScriptingConsole.h"
#include <QApplication>
#include <QClipboard>
#include <QListWidget>
#include <QMutex>
#include <QObject>
#include <QTableWidget>
#include <QTextBrowser>
#include <QTreeWidget>
#define INFOLOG(msg) "<font color=\"green\">" + msg + "</font>"
#define ERRLOG(msg) "<font color=\"red\">" + msg + "</font>"
#define WARNLOG(msg) "<font color=\"gold\">" + msg + "</font>"
#define WingHexPyVersion 5
class PlgInterface : public QObject {
Q_OBJECT
public:
explicit PlgInterface(IWingPlugin *parent);
signals:
void log(QString message);
public:
bool init();
void initInfo(QListWidget *infolist, QTreeWidget *infotree,
QTableWidget *infotable, QTextBrowser *infotxt);
PythonQtScriptingConsole *getScriptingConsole();
bool RunPyFile(const QString &filename);
bool RunPyText(const QString &content);
bool requestControl(int timeout = 1500);
bool requestRelease();
bool hasControl();
void toast(const QIcon &icon, const QString &message);
void logWarn(const QString &message);
void logError(const QString &message);
void logInfo(const QString &message);
void logDebug(const QString &message);
static PlgInterface *instance();
private slots:
private:
IWingPlugin *plg;
PythonQtObjectPtr mainContext;
PythonQtScriptingConsole *console;
QMutex mutex;
private:
static PlgInterface *m_instace;
};
class PlgService : public QObject {
Q_OBJECT
public:
PlgService() {}
PlgService(PlgInterface *parent) : inter(parent) {}
public slots:
bool requestControl(int timeout = 1500) {
return inter->requestControl(timeout);
}
bool requestRelease() { return inter->requestRelease(); }
bool hasControl() { return inter->hasControl(); }
void toast(const QIcon &icon, const QString &message) {
inter->toast(icon, message);
}
void toast(const QString &message) {
inter->toast(QIcon(":/WingHexPy/img/icon.png"), message);
}
void logWarn(const QString &message) { inter->logWarn(message); }
void logError(const QString &message) { inter->logError(message); }
void logInfo(const QString &message) { inter->logInfo(message); }
void logDebug(const QString &message) { inter->logDebug(message); }
void print(QString message) { inter->log(message); }
void errPrint(QString message) { inter->log(ERRLOG(message)); }
void infoPrint(QString message) { inter->log(INFOLOG(message)); }
void warnPrint(QString message) { inter->log(WARNLOG(message)); }
void copy2Clipboard(QString content) {
QApplication::clipboard()->setText(content);
}
QString getClipboardText() { return QApplication::clipboard()->text(); }
int version() { return WingHexPyVersion; }
private:
PlgInterface *inter;
};
#endif // PLGINTERFACE_H