X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/979a73474cf18beb6fa4104dd89dade05ce98c4b..2839804c3530db6756d2eb4a081a442ad8b2f773:/samples/exec/exec.cpp diff --git a/samples/exec/exec.cpp b/samples/exec/exec.cpp index ee51fbdf74..a979d505ab 100644 --- a/samples/exec/exec.cpp +++ b/samples/exec/exec.cpp @@ -121,7 +121,7 @@ public: void OnAbout(wxCommandEvent& event); // polling output of async processes - void OnTimer(wxTimerEvent& event); + void OnIdleTimer(wxTimerEvent& event); void OnIdle(wxIdleEvent& event); // for MyPipedProcess @@ -131,6 +131,9 @@ public: // for MyProcess void OnAsyncTermination(MyProcess *process); + // timer updating a counter in the background + void OnBgTimer(wxTimerEvent& event); + private: void ShowOutput(const wxString& cmd, const wxArrayString& output, @@ -173,6 +176,10 @@ private: // the idle event wake up timer wxTimer m_timerIdleWakeUp; + // a background timer allowing to easily check visually whether the + // messages are processed or not + wxTimer m_timerBg; + // any class wishing to process wxWidgets events must use this macro DECLARE_EVENT_TABLE() }; @@ -293,6 +300,10 @@ private: // IDs for the controls and the menu commands enum { + // timer ids + Exec_TimerIdle = 10, + Exec_TimerBg, + // menu items Exec_Quit = 100, Exec_Kill, @@ -311,7 +322,7 @@ enum Exec_DDERequest, Exec_Redirect, Exec_Pipe, - Exec_About = 300, + Exec_About = wxID_ABOUT, // control ids Exec_Btn_Send = 1000, @@ -358,7 +369,8 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_IDLE(MyFrame::OnIdle) - EVT_TIMER(wxID_ANY, MyFrame::OnTimer) + EVT_TIMER(Exec_TimerIdle, MyFrame::OnIdleTimer) + EVT_TIMER(Exec_TimerBg, MyFrame::OnBgTimer) END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyPipeFrame, wxFrame) @@ -420,7 +432,8 @@ bool MyApp::OnInit() // frame constructor MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) : wxFrame((wxFrame *)NULL, wxID_ANY, title, pos, size), - m_timerIdleWakeUp(this) + m_timerIdleWakeUp(this, Exec_TimerIdle), + m_timerBg(this, Exec_TimerBg) { m_pidLast = 0; @@ -494,9 +507,11 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) #if wxUSE_STATUSBAR // create a status bar just for fun (by default with 1 pane only) - CreateStatusBar(); + CreateStatusBar(2); SetStatusText(_T("Welcome to wxWidgets exec sample!")); #endif // wxUSE_STATUSBAR + + m_timerBg.Start(1000); } MyFrame::~MyFrame() @@ -612,9 +627,13 @@ void MyFrame::OnKill(wxCommandEvent& WXUNUSED(event)) if ( sig == 0 ) { if ( wxProcess::Exists(pid) ) + { wxLogStatus(_T("Process %ld is running."), pid); + } else + { wxLogStatus(_T("No process with pid = %ld."), pid); + } } else // not SIGNONE { @@ -879,7 +898,7 @@ static bool AskUserForFileName() wxString filename; #if wxUSE_FILEDLG - filename = wxLoadFileSelector(_T("any file"), wxEmptyString, gs_lastFile); + filename = wxLoadFileSelector(_T("any"), wxEmptyString, gs_lastFile); #else // !wxUSE_FILEDLG filename = wxGetTextFromUser(_T("Enter the file name"), _T("exec sample"), gs_lastFile); @@ -950,7 +969,9 @@ void MyFrame::OnOpenURL(wxCommandEvent& WXUNUSED(event)) s_url = filename; if ( !wxLaunchDefaultBrowser(s_url) ) + { wxLogError(_T("Failed to open URL \"%s\""), s_url.c_str()); + } } // ---------------------------------------------------------------------------- @@ -1054,11 +1075,17 @@ void MyFrame::OnIdle(wxIdleEvent& event) } } -void MyFrame::OnTimer(wxTimerEvent& WXUNUSED(event)) +void MyFrame::OnIdleTimer(wxTimerEvent& WXUNUSED(event)) { wxWakeUpIdle(); } +void MyFrame::OnBgTimer(wxTimerEvent& WXUNUSED(event)) +{ + static unsigned long s_ticks = 0; + SetStatusText(wxString::Format("%lu ticks", s_ticks++), 1); +} + void MyFrame::OnProcessTerminated(MyPipedProcess *process) { RemovePipedProcess(process);