forked from bruderstein/PythonScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPythonConsole.h
More file actions
104 lines (80 loc) · 2.84 KB
/
PythonConsole.h
File metadata and controls
104 lines (80 loc) · 2.84 KB
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
101
102
103
104
#ifndef _PYTHONCONSOLE_H
#define _PYTHONCONSOLE_H
#ifndef _CONSOLEINTERFACE_H
#include "ConsoleInterface.h"
#endif
#ifndef _PYPRODUCER_H
#include "PyProducerConsumer.h"
#endif
class PythonHandler;
class ScintillaWrapper;
class ConsoleDialog;
struct RunStatementArgs;
struct NppData;
class PythonConsole : public NppPythonScript::PyProducerConsumer<std::string>, public ConsoleInterface
{
public:
PythonConsole(HWND hNotepad);
~PythonConsole();
void init(HINSTANCE hInst, NppData& nppData);
void initPython(PythonHandler *pythonHandler);
void showDialog();
// Show console but fire a message to get it created on the right thread.
void pythonShowDialog();
void hideDialog();
void message(const char *msg);
void writeText(boost::python::object text);
void writeError(boost::python::object text);
void clear();
void stopScript();
/* Console Interface members */
void runStatement(const char *statement);
void stopStatement();
void setPrompt(const char *prompt);
void openFile(const char *filename, int lineNumber);
/* ConsoleInterface end */
static void stopStatementWorker(PythonConsole *console);
bool runStatementWorker(const char *statement);
long runCommand(boost::python::str text, boost::python::object pyStdout, boost::python::object pyStderr);
long runCommandNoStderr(boost::python::str text, boost::python::object pyStdout)
{
boost::python::object sys_module( (boost::python::handle<>(PyImport_ImportModule("sys"))) );
boost::python::object sys_namespace = sys_module.attr("__dict__");
return runCommand(text, pyStdout, sys_namespace["stderr"]);
}
long runCommandNoStdout(boost::python::str text)
{
boost::python::object sys_module( (boost::python::handle<>(PyImport_ImportModule("sys"))) );
boost::python::object sys_namespace = sys_module.attr("__dict__");
boost::python::object npp_module( (boost::python::handle<>(PyImport_ImportModule("Npp"))) );
boost::python::object npp_namespace = npp_module.attr("__dict__");
return runCommand(text, npp_namespace["console"], sys_namespace["stderr"]);
}
HWND getScintillaHwnd();
ScintillaWrapper* mp_scintillaWrapper;
protected:
virtual void consume(const std::shared_ptr<std::string>& statement);
virtual void queueComplete();
private:
PythonConsole(); // default constructor disabled
ConsoleDialog *mp_consoleDlg;
boost::python::object m_console;
boost::python::object m_pushFunc;
boost::python::object m_sys;
PythonHandler* mp_python;
PyThreadState* mp_mainThreadState;
HANDLE m_statementRunning;
HANDLE m_hThread;
HWND m_hNotepad;
bool m_consumerStarted;
NppData* m_nppData;
};
void export_console();
void importConsole(PythonConsole *console);
struct RunStatementArgs
{
char *statement;
HANDLE statementRunning;
PythonConsole *console;
};
#endif