[Scummvm-cvs-logs] SF.net SVN: scummvm:[41939] tools/branches/gsoc2009-gui/gui

Remere at users.sourceforge.net Remere at users.sourceforge.net
Mon Jun 29 02:59:53 CEST 2009


Revision: 41939
          http://scummvm.svn.sourceforge.net/scummvm/?rev=41939&view=rev
Author:   Remere
Date:     2009-06-29 00:59:53 +0000 (Mon, 29 Jun 2009)

Log Message:
-----------
*Semi-working process page, some jagged edges yet, but it works in the simple case.

Modified Paths:
--------------
    tools/branches/gsoc2009-gui/gui/main.cpp
    tools/branches/gsoc2009-gui/gui/main.h
    tools/branches/gsoc2009-gui/gui/pages.cpp
    tools/branches/gsoc2009-gui/gui/pages.h

Modified: tools/branches/gsoc2009-gui/gui/main.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.cpp	2009-06-28 22:20:28 UTC (rev 41938)
+++ tools/branches/gsoc2009-gui/gui/main.cpp	2009-06-29 00:59:53 UTC (rev 41939)
@@ -53,6 +53,7 @@
 }
 
 BEGIN_EVENT_TABLE(ScummToolsFrame, wxFrame)
+	EVT_IDLE(ScummToolsFrame::onIdle)
 END_EVENT_TABLE()
 
 ScummToolsFrame::ScummToolsFrame(const wxString &title, const wxPoint &pos, const wxSize& size)
@@ -150,6 +151,15 @@
 	_buttons->setPage(_pages.back(), newPanel);
 }
 
+void ScummToolsFrame::onIdle(wxIdleEvent &evt) {
+	if(_pages.back()->onIdle(dynamic_cast<wxPanel *>(_wizardpane->FindWindow(wxT("Wizard Page"))))) {
+		// We want more!
+		evt.RequestMore(true);
+	}
+}
+
+//
+
 BEGIN_EVENT_TABLE(WizardButtons, wxPanel)
 	EVT_BUTTON(ID_NEXT, WizardButtons::onClickNext)
 	EVT_BUTTON(ID_PREV, WizardButtons::onClickPrevious)
@@ -157,7 +167,7 @@
 END_EVENT_TABLE()
 
 WizardButtons::WizardButtons(wxWindow *parent, wxStaticText *linetext)
-	: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("Wizard Button Panel")),
+	: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE, wxT("WizardButtonPanel")),
 	  _linetext(linetext),
 	  _currentPage(NULL)
 {

Modified: tools/branches/gsoc2009-gui/gui/main.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/main.h	2009-06-28 22:20:28 UTC (rev 41938)
+++ tools/branches/gsoc2009-gui/gui/main.h	2009-06-29 00:59:53 UTC (rev 41939)
@@ -73,6 +73,11 @@
 	void switchToPreviousPage() {
 		switchPage(NULL, true);}
 
+	/**
+	 * Handle wx OnIdle events
+	 */
+	void onIdle(wxIdleEvent &evt);
+
 	/** The state of the wizard so far */
 	Configuration _configuration;
 

Modified: tools/branches/gsoc2009-gui/gui/pages.cpp
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.cpp	2009-06-28 22:20:28 UTC (rev 41938)
+++ tools/branches/gsoc2009-gui/gui/pages.cpp	2009-06-29 00:59:53 UTC (rev 41939)
@@ -31,11 +31,16 @@
 #endif
 
 #include <wx/filepicker.h>
+#include <wx/file.h>
 
 #include "main.h"
 #include "pages.h"
 #include "tools.h"
 
+
+BEGIN_EVENT_TABLE(WizardPage, wxEvtHandler)
+END_EVENT_TABLE()
+
 WizardPage::WizardPage(ScummToolsFrame *frame)
 	: _topframe(frame),
 		_configuration(frame->_configuration)
@@ -84,6 +89,10 @@
 void WizardPage::save(wxWindow *panel) {
 }
 
+bool WizardPage::onIdle(wxPanel *panel) {
+	return false;
+}
+
 // Introduction page
 
 IntroPage::IntroPage(ScummToolsFrame* frame)
@@ -818,8 +827,15 @@
 
 // Page to choose ANY tool to use
 
+BEGIN_EVENT_TABLE(ProcessPage, WizardPage)
+	EVT_END_PROCESS(wxID_ANY, ProcessPage::onTerminate)
+END_EVENT_TABLE()
+
 ProcessPage::ProcessPage(ScummToolsFrame* frame)
-	: WizardPage(frame)
+	: WizardPage(frame),
+	  _finished(false),
+	  _success(false),
+	  _process(NULL)
 {
 }
 
@@ -833,7 +849,7 @@
 	sizer->Add(new wxStaticText(panel, wxID_ANY, wxT("Processing data...")), wxSizerFlags().Expand().Border(wxLEFT, 20));
 	
 	wxTextCtrl *outwin = new wxTextCtrl(panel, wxID_ANY, wxT(""), wxDefaultPosition, wxDefaultSize, 
-		wxTE_MULTILINE | wxTE_READONLY, wxDefaultValidator, wxT("OutputText"));
+		wxTE_MULTILINE | wxTE_READONLY, wxDefaultValidator, wxT("OutputWindow"));
 	outwin->Enable(false);
 	sizer->Add(outwin, wxSizerFlags(1).Expand().Border(wxALL, 10));
 
@@ -894,10 +910,83 @@
 }
 
 void ProcessPage::runProcess(wxTextCtrl *outwin) {
-	outwin->WriteText(createCommandLine());
+	wxString cli = createCommandLine();
+	outwin->WriteText(cli + wxT("\n"));
+
+	if(wxFile::Exists(_topframe->_configuration.selectedTool->getExecutable())) {
+		_process = new wxProcess(this);
+		bool success = wxExecute(cli, wxEXEC_ASYNC, _process) != 0;
+
+		if(!success) {
+			outwin->WriteText(wxT("Could not run process."));
+			return;
+		}
+
+		_process->Redirect();
+	} else {
+		_finished = true;
+		outwin->WriteText(wxT("Could not find executable file on the current path. Check that the executable for the selected tool is available and place in the correct directory."));
+	}
+
 }
 
+bool ProcessPage::onIdle(wxPanel *panel) {
+	if(_process) {
+		wxInputStream *stream = _process->GetInputStream();
+		wxTextCtrl *outwin = static_cast<wxTextCtrl *>(panel->FindWindowByName(wxT("OutputWindow")));
+
+		wxASSERT_MSG(stream, wxT("Could not bind input stream!"));
+
+		while(stream->CanRead()) {
+			wxFileOffset off = stream->GetLength();
+			if(off = wxInvalidOffset) {
+				return false;
+			}
+			char *buf = new char[(size_t)off];
+			stream->Read(buf, (size_t)off);
+			outwin->WriteText(wxString(buf, wxConvUTF8, (size_t)off));
+			delete[] buf;
+		}
+
+		return true;
+	}
+	return false;
+}
+
+void ProcessPage::onTerminate(wxProcessEvent &evt) {
+	// Ugly hack, should not find the panel this way...
+	wxWindow *panel = _topframe->FindWindowByName(wxT("WizardPage"));
+	wxTextCtrl *outwin = static_cast<wxTextCtrl *>(panel->FindWindowByName(wxT("OutputWindow")));
+
+	_success = evt.GetExitCode() == 0;
+	if(_success) {
+		outwin->WriteText(wxT("Subprocess exited sucessfully!"));
+	} else {
+		outwin->WriteText(wxT("Subprocess exited sucessfully!"));
+	}
+	_finished = true;
+
+	updateButtons(panel, static_cast<WizardButtons *>(_topframe->FindWindowByName(wxT("WizardButtonPanel"))));
+}
+
 /*
 void ProcessPage::onNext(wxWindow *panel) {
 	switchPage(new ChooseInOutPage(_topframe));
 }*/
+
+void ProcessPage::updateButtons(wxWindow *panel, WizardButtons *buttons) {
+	if(_success) {
+		buttons->enablePrevious(false);
+		buttons->enableNext(true);
+	} else if(_finished) {
+		buttons->enablePrevious(true);
+		buttons->enableNext(true);
+	} else {
+		buttons->enablePrevious(false);
+		buttons->enableNext(false);
+	}
+}
+
+
+
+	
\ No newline at end of file

Modified: tools/branches/gsoc2009-gui/gui/pages.h
===================================================================
--- tools/branches/gsoc2009-gui/gui/pages.h	2009-06-28 22:20:28 UTC (rev 41938)
+++ tools/branches/gsoc2009-gui/gui/pages.h	2009-06-29 00:59:53 UTC (rev 41939)
@@ -21,6 +21,7 @@
  */
 
 #include <wx/wx.h>
+#include <wx/process.h>
 
 #include "configuration.h"
 
@@ -101,6 +102,13 @@
 	 */
 	virtual void updateButtons(wxWindow *panel, WizardButtons *buttons);
 
+	/**
+	 * This handler is called when the application is idle, used to read output from the subprocess.
+	 *
+	 * @return false indicates that we do not want to receive more idle events.
+	 */
+	virtual bool onIdle(wxPanel *panel);
+
 protected:
 	/** 
 	 * This adds an offset (about 100px) to the left of the sizer to center the text somewhat, before adding it 
@@ -113,6 +121,8 @@
 
 	ScummToolsFrame* _topframe;
 	Configuration &_configuration;
+
+	DECLARE_EVENT_TABLE()
 };
 
 /**
@@ -292,12 +302,15 @@
 
 /**
  * Runs the subprocess and displays it's output to the user
- *
- * @todo Run the subprocess
+ * You really ought to only run one subprocess at the time, as
+ * this class keeps internal state.
  */
 
 class ProcessPage : public WizardPage
 {
+	bool _finished;
+	bool _success;
+	wxProcess *_process;
 public:
 	ProcessPage(ScummToolsFrame* frame);
 
@@ -306,7 +319,15 @@
 	wxString createCommandLine();
 	void runProcess(wxTextCtrl *outwin);
 
+	void onTerminate(wxProcessEvent &evt);
+
+	bool onIdle(wxPanel *panel);
+
 	//void onNext(wxWindow *panel);
 
+	void updateButtons(wxWindow *panel, WizardButtons *buttons);
+
 	void save(wxWindow *panel);
+
+	DECLARE_EVENT_TABLE()
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list