-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathPythonHandler.h
More file actions
119 lines (85 loc) · 2.92 KB
/
PythonHandler.h
File metadata and controls
119 lines (85 loc) · 2.92 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#ifndef _PYTHONHANDLER_H
#define _PYTHONHANDLER_H
#ifndef _PYPRODUCER_H
#include "PyProducerConsumer.h"
#endif
// Forward def
struct SCNotification;
namespace NppPythonScript
{
class ScintillaWrapper;
class NotepadPlusWrapper;
class PythonConsole;
struct RunScriptArgs;
struct RunScriptArgs
{
public:
RunScriptArgs(
const TCHAR* filename,
PyThreadState *threadState,
bool synchronous,
HANDLE completedEvent,
bool isStatement
):
m_filename(filename?filename:_T("")),
m_threadState(threadState),
m_synchronous(synchronous),
m_completedEvent(completedEvent),
m_isStatement(isStatement)
{
}
tstring m_filename;
PyThreadState *m_threadState;
bool m_synchronous;
HANDLE m_completedEvent;
bool m_isStatement;
private:
RunScriptArgs(); // default constructor disabled
};
class PythonHandler : public PyProducerConsumer<RunScriptArgs>
{
public:
PythonHandler::PythonHandler(TCHAR *pluginsDir, TCHAR *configDir, HINSTANCE hInst, HWND nppHandle, HWND scintilla1Handle, HWND scintilla2Handle, boost::shared_ptr<PythonConsole> pythonConsole);
~PythonHandler();
bool runScript(const TCHAR *filename, bool synchronous = false, bool allowQueuing = false, HANDLE completedEvent = NULL, bool isStatement = false);
bool runScript(const tstring& filename, bool synchronous = false, bool allowQueuing = false, HANDLE completedEvent = NULL, bool isStatement = false);
void runScriptWorker(const std::shared_ptr<RunScriptArgs>& args);
void notify(SCNotification *notifyCode);
void initPython();
void runStartupScripts();
void stopScript();
PyThreadState* getMainThreadState() { return mp_mainThreadState; };
DWORD getExecutingThreadID() { return getConsumerThreadID(); };
protected:
void consume(std::shared_ptr<RunScriptArgs> args);
boost::shared_ptr<ScintillaWrapper> createScintillaWrapper();
boost::shared_ptr<NotepadPlusWrapper> createNotepadPlusWrapper();
virtual void queueComplete();
// Handles
HWND m_nppHandle;
HWND m_scintilla1Handle;
HWND m_scintilla2Handle;
private:
PythonHandler() = delete; // default constructor disabled
PythonHandler(const PythonHandler&) = delete; // copy constructor disabled
PythonHandler& operator = (const PythonHandler&) = delete; // Disable assignment operator disabled
// Private methods
void initModules();
void initSysArgv();
static void stopScriptWorker(PythonHandler *handler);
bool containsExtendedChars(char *s);
// Private member vars
HINSTANCE m_hInst;
tstring m_machineBaseDir;
tstring m_userBaseDir;
boost::shared_ptr<ScintillaWrapper> mp_scintilla;
boost::shared_ptr<ScintillaWrapper> mp_scintilla1;
boost::shared_ptr<ScintillaWrapper> mp_scintilla2;
boost::shared_ptr<NotepadPlusWrapper> mp_notepad;
boost::shared_ptr<PythonConsole> mp_console;
int m_currentView;
PyThreadState *mp_mainThreadState;
bool m_consumerStarted;
};
}
#endif