Menu

[0b4401]: / PythonScript / src / PythonConsole.h  Maximize  Restore  History

Download this file

102 lines (78 with data), 3.0 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
#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:
explicit PythonConsole(HWND hNotepad);
PythonConsole(const PythonConsole& other);
~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();
/* Console Interface members */
void runStatement(const char *statement);
void stopStatement();
void openFile(const char *filename, idx_t lineNumber);
/* ConsoleInterface end */
static void stopStatementWorker(PythonConsole *console);
DWORD runCommand(boost::python::str text, boost::python::object pyStdout, boost::python::object pyStderr);
DWORD 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"]);
}
DWORD 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& getScintillaWrapper() { return *mp_scintillaWrapper; }
ScintillaWrapper* mp_scintillaWrapper;
protected:
virtual void consume(const std::shared_ptr<std::string>& statement);
virtual void queueComplete();
private:
PythonConsole(); // default constructor disabled
PythonConsole& operator = (const PythonConsole&); // assignment operator disabled
ConsoleDialog *mp_consoleDlg;
boost::python::object m_console;
boost::python::object m_pushFunc;
boost::python::object m_sys;
PyThreadState* mp_mainThreadState;
HANDLE m_statementRunning;
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