Program: bbtk
Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
Language: C++
- Date: $Date: 2008/03/25 10:31:18 $
- Version: $Revision: 1.3 $
+ Date: $Date: 2008/03/25 15:47:54 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
mInterpreter = new bbtk::Interpreter();
mInterpreter->SetUser(this);
mInterpreter->SetCommandLine(true);
+ mInterpreter->SetThrow(true);
//==============
// Menu
wxInitAllImageHandlers();
menuWindows->AppendSeparator();
menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
+ wxMenu *menuOptions = new wxMenu;
+ mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
+ _T("Reset before running") );
+ mwxMenuItemReset->Check();
+
wxMenuBar *menuBar = new wxMenuBar;
menuBar->Append( menuFile, _T("&File") );
menuBar->Append( menuTools, _T("&Tools") );
+ menuBar->Append( menuOptions, _T("&Options") );
menuBar->Append( menuWindows, _T("&Windows") );
menuBar->Append( menuAbout, _T("About") );
mWxGUITextEditor->Open(filename);
}
//================================================================
-
+
+#define CATCH_MACRO \
+ catch (InterpreterError e) \
+ { \
+ std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
+ if (e.IsInScriptFile()) \
+ std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
+ std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
+ int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
+ if (lev > 0) { \
+ std::cerr << "* Exception thrown : "<<std::endl; \
+ std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
+ std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
+ } \
+ }
+
//================================================================
void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
{
std::string s("> ");
s += command + "\n";
mWxGUIOutputMessages->Print(s,wxRED);
-
- if ( mInterpreter->InterpretLine( command ) ==
- Interpreter::Interpreter_QUIT )
+
+ try
{
- Close(true);
+ mInterpreter->InterpretLine( command );
}
+ CATCH_MACRO;
}
//================================================================
-
+
//================================================================
/// Runs the interpretation of a file
bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
{
- if ( mInterpreter->InterpretFile(filename) ==
- Interpreter::Interpreter_ERROR )
+ try
{
- return false;
+ mInterpreter->InterpretFile(filename);
}
+ CATCH_MACRO;
return true;
}
//================================================================
// wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
std::stringstream* buf = new std::stringstream;
(*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
-
- mInterpreter->SetThrow(true);
try
{
+ if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
mInterpreter->InterpretBuffer(buf);
}
- catch (InterpreterError e)
- {
- std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl;
- if (e.IsInScriptFile())
- std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl;
- std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl;
- int lev = bbtk::MessageManager::GetMessageLevel("Error");
- if (lev > 0) {
- std::cerr << "* Exception thrown : "<<std::endl;
- std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl;
- std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl;
- }
- }
- /*
- // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
- std::string filename = mWxGUITextEditor->GetCurrentPage();//wx2std(temp);
- size_t s = filename.length();
-
- Interpreter* I = new Interpreter;
-
- if ((s>3) && (filename[s-1]=='s')
- && (filename[s-2]=='b')
- && (filename[s-3]=='b')
- && (filename[s-4]=='.'))
- {
- std::string tmp("Executing ");
- tmp += filename;
- SetStatusText(std2wx(tmp));
- I->InterpretFile(filename);
- }
- else
- {
- SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
- }
-
- delete I;
- */
+ CATCH_MACRO
}
//================================================================
//================================================================
void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
{
+ if (!mWxGUITextEditor->CloseAllPages()) return;
Close(true);
}
//================================================================