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 "stdio.h"
......@@ -12,10 +8,14 @@
#include "asyncprocess.h"
DEFINE_LOCAL_EVENT_TYPE(wxEVT_PROCESS_STDOUT);
IMPLEMENT_DYNAMIC_CLASS(AsyncProcess, wxProcess)
AsyncProcess::AsyncProcess() : wxProcess(), wxThreadHelper() {
AsyncProcess::AsyncProcess(): m_pEvtHandler(NULL) {
}
AsyncProcess::AsyncProcess(wxEvtHandler *evtHandler) : wxProcess(), wxThreadHelper(), m_pEvtHandler(evtHandler) {
Redirect();
}
......@@ -33,6 +33,12 @@ wxThread::ExitCode AsyncProcess::Entry() {
while (IsInputAvailable()) {
char c = GetInputStream()->GetC();
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 @@
#include <wx/process.h>
#include <wx/thread.h>
#if defined(__GNUG__) && !defined(__APPLE__)
#pragma interface "AsyncProcess.cpp"
#endif
DECLARE_LOCAL_EVENT_TYPE(wxEVT_PROCESS_STDOUT, -3);
class AsyncProcess : public wxProcess , public wxThreadHelper {
DECLARE_DYNAMIC_CLASS(AsyncProcess)
public:
AsyncProcess();
AsyncProcess();
AsyncProcess(wxEvtHandler *m_pEvtHandler);
void start();
virtual ~AsyncProcess();
private:
virtual wxThread::ExitCode Entry();
virtual void OnTerminate(int pid, int status);
wxEvtHandler *m_pEvtHandler;
};
#endif
\ No newline at end of file
......@@ -10,13 +10,13 @@
IMPLEMENT_APP(OpennxTestEvent)
BEGIN_EVENT_TABLE(OpennxTestEvent, wxEvtHandler)
EVT_COMMAND(wxID_ANY, wxEVT_PROCESS_STDOUT, OpennxTestEvent::OnOutReceived )
END_EVENT_TABLE();
// This is executed upon startup, like 'main()' in non-wxWidgets programs.
bool OpennxTestEvent::OnInit()
{
AsyncProcess* ap = new AsyncProcess();
AsyncProcess* ap = new AsyncProcess(this);
wxFrame *frame = new wxFrame((wxFrame*) NULL, -1, _T("Test opennx event"));
frame->CreateStatusBar();
frame->SetStatusText(_T("Test opennx event"));
......@@ -26,4 +26,8 @@ bool OpennxTestEvent::OnInit()
ap->start();
return true;
}
void OpennxTestEvent::OnOutReceived(wxCommandEvent &event) {
printf("event received");
}
\ No newline at end of file
......@@ -6,6 +6,7 @@ class OpennxTestEvent : public wxApp
DECLARE_EVENT_TABLE();
public:
virtual bool OnInit();
void OnOutReceived(wxCommandEvent &event);
};
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