1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/03/21 14:59:39 $
7 Version: $Revision: 1.2 $
9 Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
10 l'Image). All rights reserved. See Doc/License.txt or
11 http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notices for more information.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
36 #include "bbtkWxGUIScriptingInterface.h"
37 #include "bbtkWxBlackBox.h"
38 #include "bbtkConfigurationFile.h"
39 #include "bbtkWxStreamRedirector.h"
42 #include "icons/cc_run.xpm"
52 ID_Menu_CreatePackage,
53 ID_Menu_CreateBlackBox,
54 ID_Menu_ShowImageGraph,
60 //================================================================
61 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size)
62 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
64 // m_mgr = new wxAuiManager(this);
65 m_mgr.SetManagedWindow(this);
67 mInterpreter = new bbtk::Interpreter();
68 mInterpreter->SetUser(this);
69 mInterpreter->SetCommandLine(true);
72 wxInitAllImageHandlers();
74 wxMenu *menuFile = new wxMenu;
75 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
77 wxMenu *menuAbout = new wxMenu;
78 menuAbout->Append( ID_Menu_About, _T("&About...") );
80 wxMenu *menuTools = new wxMenu;
81 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
82 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
83 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
84 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
85 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
88 wxMenuBar *menuBar = new wxMenuBar;
89 menuBar->Append( menuFile, _T("&File") );
90 menuBar->Append( menuTools, _T("&Tools") );
91 menuBar->Append( menuAbout, _T("About") );
93 SetMenuBar( menuBar );
96 SetStatusText( _T("Welcome to bbi !") );
99 mWxGUITextEditor = new WxGUITextEditor(this,this);
100 mWxGUITextEditor->SetFileNameFilter("*.bbs");
102 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
105 wxBitmap bmp_run(cc_run_xpm);
106 mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
109 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
111 mWxGUICommand = new WxGUICommand(this,this);
113 mWxGUICommand->SetFocus();
115 // Creates and sets the parent window of all bbtk windows
116 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
118 Wx::SetTopWindow(top);
122 m_mgr.AddPane(mWxGUITextEditor,
123 wxAuiPaneInfo().Name(wxT("editor_content"))
124 .Caption(wxT("Files"))
125 .MinimizeButton(true)
126 .MaximizeButton(true)
129 m_mgr.AddPane(mWxGUIHtmlBrowser,
130 wxAuiPaneInfo().Name(wxT("browser_content"))
131 .Caption(wxT("Help"))
132 .MinimizeButton(true)
133 .MaximizeButton(true)
136 m_mgr.AddPane(mWxGUIOutputMessages,
137 wxAuiPaneInfo().Name(wxT("messages_content"))
138 .Caption(wxT("Messages"))
139 .MinimizeButton(true)
140 .MaximizeButton(true)
143 m_mgr.AddPane(mWxGUICommand,
144 wxAuiPaneInfo().Name(wxT("command_content"))
145 .Caption(wxT("Command"))
146 .MinimizeButton(true)
147 .MaximizeButton(true)
151 // m_mgr.AddPane(mwxButtonRun,
152 // wxAuiPaneInfo().Name(wxT("button_run_content")));
155 //.PaneBorder(false));
163 //================================================================
165 //================================================================
166 WxGUIScriptingInterface::~WxGUIScriptingInterface()
170 //================================================================
172 //================================================================
173 void WxGUIScriptingInterface::Open(const std::string& filename)
175 mWxGUITextEditor->Open(filename);
177 //================================================================
179 //================================================================
180 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
184 mWxGUIOutputMessages->Print(s,wxRED);
186 if ( mInterpreter->InterpretLine( command ) ==
187 Interpreter::Interpreter_QUIT )
192 //================================================================
194 //================================================================
195 /// Runs the interpretation of a file
196 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
198 if ( mInterpreter->InterpretFile(filename) ==
199 Interpreter::Interpreter_ERROR )
205 //================================================================
207 //================================================================
208 void WxGUIScriptingInterface::WxGUITextEditorRun()
210 // wxString per = m_mgr.SavePerspective();
211 // std::cout << per<< std::endl;
213 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
214 std::stringstream* buf = new std::stringstream;
215 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
217 mInterpreter->SetThrow(true);
220 mInterpreter->InterpretBuffer(buf);
222 catch (InterpreterError e)
224 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl;
225 if (e.IsInScriptFile())
226 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl;
227 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl;
228 int lev = bbtk::MessageManager::GetMessageLevel("Error");
230 std::cerr << "* Exception thrown : "<<std::endl;
231 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl;
232 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl;
236 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
237 std::string filename = mWxGUITextEditor->GetCurrentPage();//wx2std(temp);
238 size_t s = filename.length();
240 Interpreter* I = new Interpreter;
242 if ((s>3) && (filename[s-1]=='s')
243 && (filename[s-2]=='b')
244 && (filename[s-3]=='b')
245 && (filename[s-4]=='.'))
247 std::string tmp("Executing ");
249 SetStatusText(std2wx(tmp));
250 I->InterpretFile(filename);
254 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
260 //================================================================
262 //================================================================
263 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
267 //================================================================
270 //================================================================
271 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
275 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
276 _T("About ..."), wxOK | wxICON_INFORMATION,
279 //================================================================
282 //================================================================
283 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
285 std::string commandStr;
286 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
288 commandStr = "notepad.exe ";
290 commandStr = "gedit ";
292 commandStr = commandStr + configFile;
293 std::cout << "system: " << commandStr << std::endl;
294 system ( commandStr.c_str() );
296 //================================================================
299 //================================================================
300 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
302 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 01 \n");
303 std::string command("toolsbbtk/appli/CreatePackage");
304 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 02 \n");
306 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
307 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 03 \n");
308 Interpreter* I = new Interpreter;
309 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 04 \n");
310 I->InterpretFile(command);
311 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 05 \n");
313 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
315 //================================================================
318 //================================================================
319 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
321 std::string command("toolsbbtk/appli/CreateBlackBox");
322 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
323 Interpreter* I = new Interpreter;
324 I->InterpretFile(command);
327 //================================================================
329 //================================================================
330 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
332 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
335 std::string strappli="start ";
337 std::string strappli="gnome-open ";
339 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
340 std::cout << "system: " << strcommand << std::endl;
341 system ( strcommand.c_str() );
344 //================================================================
347 //================================================================
348 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
350 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
351 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
352 Interpreter* I = new Interpreter;
354 //EED std::cout << "bbi: include "<<filepath<<std::endl;
355 //EED I->InterpretFile( filepath );
357 I->InterpretLine( "exec freeze");
358 I->InterpretLine( "include *");
359 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
360 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
361 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
362 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
366 //================================================================
369 //================================================================
370 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
373 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
374 if (mWxGUIHtmlBrowser->GoTo(s))
376 //EED mwxNotebook->ChangeSelection(1);
377 // mwxNotebook->SetSelection(1);
381 // std::cout << "ERROR html"<<std::endl;
384 //================================================================
386 //================================================================
387 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
389 std::cout << "OnLink"<<std::endl;
390 size_t s = target.length();
391 if ((s>3) && (target[s-1]=='s')
392 && (target[s-2]=='b')
393 && (target[s-3]=='b')
394 && (target[s-4]=='.'))
396 mWxGUITextEditor->Open(target);
401 //================================================================
403 //================================================================
404 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
405 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
406 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
407 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
408 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
409 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
410 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
411 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
412 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
414 //================================================================
419 #endif //_USE_WXWIDGETS_