@@ -28,9 +28,9 @@ PythonConsole::PythonConsole(HWND hNotepad) :
2828 m_nppData (new NppData)
2929{
3030}
31- /*
31+ /*
3232//lint -e1554 Direct pointer copy of member 'name' within copy constructor: 'PythonConsole::PythonConsole(const PythonConsole &)')
33- // We indeed copy pointers, and it's okay. These are not allocated within the
33+ // We indeed copy pointers, and it's okay. These are not allocated within the
3434// scope of this class but rather passed in and copied anyway.
3535PythonConsole::PythonConsole(const PythonConsole& other) :
3636 PyProducerConsumer<std::string>(other),
@@ -56,7 +56,6 @@ PythonConsole::~PythonConsole()
5656 {
5757 delete mp_consoleDlg;
5858 delete m_nppData;
59-
6059 }
6160 catch (...)
6261 {
@@ -92,27 +91,27 @@ void PythonConsole::initPython(PythonHandler *pythonHandler)
9291 try
9392 {
9493 mp_mainThreadState = pythonHandler->getMainThreadState ();
95-
96- GILLock gilLock;
94+
95+ GILLock gilLock;
9796
9897 boost::python::object main_module (boost::python::handle<>(boost::python::borrowed (PyImport_AddModule (" __main__" ))));
9998 boost::python::object main_namespace = main_module.attr (" __dict__" );
100-
99+
101100 // import code
102101 boost::python::object code = boost::python::import (" code" );
103102 main_namespace[" code" ] = code;
104103
105104 // import __main__
106105 main_namespace[" __main__" ] = main_namespace;
107-
106+
108107 // get ref to code.InteractiveConsole().push()
109108 m_console = eval (" code.InteractiveConsole(__main__)" , main_namespace, main_namespace);
110109 m_pushFunc = m_console.attr (" push" );
111110
112111 m_sys = main_namespace[" sys" ];
113-
114-
115- }
112+
113+
114+ }
116115 catch (...)
117116 {
118117 PyErr_Print ();
@@ -146,7 +145,7 @@ void PythonConsole::showDialog()
146145 assert (mp_consoleDlg);
147146 if (mp_consoleDlg)
148147 {
149- GILRelease release;
148+ GILRelease release;
150149 mp_consoleDlg->doDialog ();
151150 }
152151}
@@ -156,7 +155,7 @@ void PythonConsole::hideDialog()
156155 assert (mp_consoleDlg);
157156 if (mp_consoleDlg)
158157 {
159- GILRelease release;
158+ GILRelease release;
160159 mp_consoleDlg->hide ();
161160 }
162161}
@@ -166,8 +165,8 @@ void PythonConsole::message(const char *msg)
166165 assert (mp_consoleDlg);
167166 if (mp_consoleDlg)
168167 {
169- GILRelease release;
170- mp_consoleDlg->writeCmdText (strlen (msg), msg);
168+ GILRelease release;
169+ mp_consoleDlg->writeCmdText (strlen (msg), msg);
171170 }
172171}
173172
@@ -176,7 +175,7 @@ void PythonConsole::clear()
176175 assert (mp_consoleDlg);
177176 if (mp_consoleDlg)
178177 {
179- GILRelease release;
178+ GILRelease release;
180179 mp_consoleDlg->clearText ();
181180 }
182181}
@@ -191,12 +190,12 @@ void PythonConsole::writeText(boost::python::object text)
191190 assert (mp_consoleDlg);
192191 if (mp_consoleDlg)
193192 {
194- if (PyUnicode_Check (text.ptr ()))
193+ if (PyUnicode_Check (text.ptr ()))
195194 {
196195
197196
198- std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
199- GILRelease release;
197+ std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
198+ GILRelease release;
200199 if (m_runStatementExecuted)
201200 {
202201 mp_consoleDlg->writeColoredText (textToWrite.size (), textToWrite.c_str ());
@@ -208,8 +207,8 @@ void PythonConsole::writeText(boost::python::object text)
208207 }
209208 else
210209 {
211- std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()), _len (text));
212- GILRelease release;
210+ std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()), _len (text));
211+ GILRelease release;
213212 if (m_runStatementExecuted)
214213 {
215214 mp_consoleDlg->writeColoredText (textToWrite.size (), textToWrite.c_str ());
@@ -231,15 +230,15 @@ void PythonConsole::writeError(boost::python::object text)
231230 {
232231
233232
234- std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
235- GILRelease release;
236- mp_consoleDlg->writeError (textToWrite.size (), textToWrite.c_str ());
233+ std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
234+ GILRelease release;
235+ mp_consoleDlg->writeError (textToWrite.size (), textToWrite.c_str ());
237236 }
238237 else
239238 {
240- std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
241- GILRelease release;
242- mp_consoleDlg->writeError (textToWrite.size (),textToWrite.c_str ());
239+ std::string textToWrite ((const char *)boost::python::extract<const char *>(text.attr (" __str__" )()));
240+ GILRelease release;
241+ mp_consoleDlg->writeError (textToWrite.size (),textToWrite.c_str ());
243242 }
244243 }
245244}
@@ -248,7 +247,7 @@ void PythonConsole::stopStatement()
248247{
249248 DWORD threadID;
250249 CreateThread (NULL , 0 , (LPTHREAD_START_ROUTINE)PythonConsole::stopStatementWorker, this , 0 , &threadID);
251-
250+
252251}
253252
254253DWORD PythonConsole::runCommand (boost::python::str text, boost::python::object pyStdout, boost::python::object pyStderr)
@@ -267,9 +266,9 @@ void PythonConsole::runStatement(const char *statement)
267266 mp_consoleDlg->runEnabled (false );
268267 }
269268
270- // Console statements executed whilst a script is in progress MUST run on a separate
269+ // Console statements executed whilst a script is in progress MUST run on a separate
271270 // thread. Otherwise, we wait for the GIL, no problem, except that that blocks the UI thread
272- // so if the script happens to be sending a message to scintilla (likely), then
271+ // so if the script happens to be sending a message to scintilla (likely), then
273272 // it will deadlock.
274273 // PyProducerConsumer used here to keep one thread running the actual statements
275274
@@ -326,10 +325,10 @@ void PythonConsole::consume(std::shared_ptr<std::string> statement)
326325
327326void PythonConsole::stopStatementWorker (PythonConsole *console)
328327{
329- GILLock gilLock;
330-
328+ GILLock gilLock;
329+
331330 PyThreadState_SetAsyncExc ((long )console->getConsumerThreadID (), PyExc_KeyboardInterrupt);
332-
331+
333332}
334333
335334void export_console ()
@@ -345,6 +344,7 @@ void export_console()
345344 .def (" run" , &PythonConsole::runCommand, " Runs a command on the console" )
346345 .def (" run" , &PythonConsole::runCommandNoStderr, " Runs a command on the console" )
347346 .def (" run" , &PythonConsole::runCommandNoStdout, " Runs a command on the console" )
347+ .def (" getScintillaHwnd" , &PythonConsole::getScintillaHwndPython, " Provide HWnd for scintilla of console" )
348348 .add_static_property (" encoding" , &PythonConsole::getEncoding)
349349 .add_property (" editor" , &PythonConsole::getScintillaWrapper);
350350 // lint +e1793
0 commit comments