Commit d30fd10b authored by Stas Korobeynikov's avatar Stas Korobeynikov

add event

parent 609a279e
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma implementation "asyncprocess.h"
#endif
#include "wx/wxprec.h" #include "wx/wxprec.h"
#include "stdio.h" #include "stdio.h"
...@@ -12,10 +8,14 @@ ...@@ -12,10 +8,14 @@
#include "asyncprocess.h" #include "asyncprocess.h"
DEFINE_LOCAL_EVENT_TYPE(wxEVT_PROCESS_STDOUT);
IMPLEMENT_DYNAMIC_CLASS(AsyncProcess, wxProcess) IMPLEMENT_DYNAMIC_CLASS(AsyncProcess, wxProcess)
AsyncProcess::AsyncProcess() : wxProcess(), wxThreadHelper() { AsyncProcess::AsyncProcess(): m_pEvtHandler(NULL) {
}
AsyncProcess::AsyncProcess(wxEvtHandler *evtHandler) : wxProcess(), wxThreadHelper(), m_pEvtHandler(evtHandler) {
Redirect(); Redirect();
} }
...@@ -33,6 +33,12 @@ wxThread::ExitCode AsyncProcess::Entry() { ...@@ -33,6 +33,12 @@ wxThread::ExitCode AsyncProcess::Entry() {
while (IsInputAvailable()) { while (IsInputAvailable()) {
char c = GetInputStream()->GetC(); char c = GetInputStream()->GetC();
printf("%c", c); printf("%c", c);
if(c == '\n') {
wxCommandEvent event(wxEVT_PROCESS_STDOUT, wxID_ANY);
event.SetString("String compleate\n");
event.SetClientData(this);
m_pEvtHandler->AddPendingEvent(event);
}
} }
} }
} }
......
...@@ -5,21 +5,22 @@ ...@@ -5,21 +5,22 @@
#include <wx/process.h> #include <wx/process.h>
#include <wx/thread.h> #include <wx/thread.h>
#if defined(__GNUG__) && !defined(__APPLE__) DECLARE_LOCAL_EVENT_TYPE(wxEVT_PROCESS_STDOUT, -3);
#pragma interface "AsyncProcess.cpp"
#endif
class AsyncProcess : public wxProcess , public wxThreadHelper { class AsyncProcess : public wxProcess , public wxThreadHelper {
DECLARE_DYNAMIC_CLASS(AsyncProcess) DECLARE_DYNAMIC_CLASS(AsyncProcess)
public: public:
AsyncProcess(); AsyncProcess();
AsyncProcess(wxEvtHandler *m_pEvtHandler);
void start(); void start();
virtual ~AsyncProcess(); virtual ~AsyncProcess();
private:
virtual wxThread::ExitCode Entry(); virtual wxThread::ExitCode Entry();
virtual void OnTerminate(int pid, int status); virtual void OnTerminate(int pid, int status);
wxEvtHandler *m_pEvtHandler;
}; };
#endif #endif
\ No newline at end of file
...@@ -10,13 +10,13 @@ ...@@ -10,13 +10,13 @@
IMPLEMENT_APP(OpennxTestEvent) IMPLEMENT_APP(OpennxTestEvent)
BEGIN_EVENT_TABLE(OpennxTestEvent, wxEvtHandler) BEGIN_EVENT_TABLE(OpennxTestEvent, wxEvtHandler)
EVT_COMMAND(wxID_ANY, wxEVT_PROCESS_STDOUT, OpennxTestEvent::OnOutReceived )
END_EVENT_TABLE(); END_EVENT_TABLE();
// This is executed upon startup, like 'main()' in non-wxWidgets programs. // This is executed upon startup, like 'main()' in non-wxWidgets programs.
bool OpennxTestEvent::OnInit() bool OpennxTestEvent::OnInit()
{ {
AsyncProcess* ap = new AsyncProcess(); AsyncProcess* ap = new AsyncProcess(this);
wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Test opennx event")); wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Test opennx event"));
frame->CreateStatusBar(); frame->CreateStatusBar();
frame->SetStatusText(_T("Test opennx event")); frame->SetStatusText(_T("Test opennx event"));
...@@ -27,3 +27,7 @@ bool OpennxTestEvent::OnInit() ...@@ -27,3 +27,7 @@ bool OpennxTestEvent::OnInit()
return true; return true;
} }
void OpennxTestEvent::OnOutReceived(wxCommandEvent &event) {
printf("event received");
}
\ No newline at end of file
...@@ -6,6 +6,7 @@ class OpennxTestEvent : public wxApp ...@@ -6,6 +6,7 @@ class OpennxTestEvent : public wxApp
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
public: public:
virtual bool OnInit(); virtual bool OnInit();
void OnOutReceived(wxCommandEvent &event);
}; };
DECLARE_APP(OpennxTestEvent) DECLARE_APP(OpennxTestEvent)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment