1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/03/25 10:31:18 $
7 Version: $Revision: 1.3 $
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,
56 ID_Menu_Windows_Files,
58 ID_Menu_Windows_Messages,
59 ID_Menu_Windows_Command,
65 //================================================================
66 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size)
67 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
69 // m_mgr = new wxAuiManager(this);
70 m_mgr.SetManagedWindow(this);
72 mInterpreter = new bbtk::Interpreter();
73 mInterpreter->SetUser(this);
74 mInterpreter->SetCommandLine(true);
77 wxInitAllImageHandlers();
79 wxMenu *menuFile = new wxMenu;
80 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
82 wxMenu *menuAbout = new wxMenu;
83 menuAbout->Append( ID_Menu_About, _T("&About...") );
85 wxMenu *menuTools = new wxMenu;
86 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
87 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
88 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
89 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
90 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
92 wxMenu *menuWindows = new wxMenu;
93 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
94 _T("Show 'files' panel") )->Check();
95 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
96 _T("Show 'help' panel") )->Check();
97 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
98 _T("Show 'messages' panel") )->Check();
99 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
100 _T("Show 'command' panel") )->Check();
102 menuWindows->AppendSeparator();
103 menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
105 wxMenuBar *menuBar = new wxMenuBar;
106 menuBar->Append( menuFile, _T("&File") );
107 menuBar->Append( menuTools, _T("&Tools") );
108 menuBar->Append( menuWindows, _T("&Windows") );
109 menuBar->Append( menuAbout, _T("About") );
111 SetMenuBar( menuBar );
114 SetStatusText( _T("Welcome to bbi !") );
117 mWxGUITextEditor = new WxGUITextEditor(this,this);
118 mWxGUITextEditor->SetFileNameFilter("*.bbs");
120 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
123 wxBitmap bmp_run(cc_run_xpm);
124 mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
127 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
129 mWxGUICommand = new WxGUICommand(this,this);
131 mWxGUICommand->SetFocus();
133 // Creates and sets the parent window of all bbtk windows
134 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
136 Wx::SetTopWindow(top);
140 m_mgr.AddPane(mWxGUITextEditor,
141 wxAuiPaneInfo().Name(wxT("editor_content"))
142 .Caption(wxT("Files"))
143 .MinimizeButton(true)
144 .MaximizeButton(true)
146 .MinSize(wxSize(100,100))
148 m_mgr.AddPane(mWxGUIHtmlBrowser,
149 wxAuiPaneInfo().Name(wxT("browser_content"))
150 .Caption(wxT("Help"))
151 .MinimizeButton(true)
152 .MaximizeButton(true)
154 .MinSize(wxSize(100,100))
156 m_mgr.AddPane(mWxGUIOutputMessages,
157 wxAuiPaneInfo().Name(wxT("messages_content"))
158 .Caption(wxT("Messages"))
159 .MinimizeButton(true)
160 .MaximizeButton(true)
162 .MinSize(wxSize(100,100))
164 m_mgr.AddPane(mWxGUICommand,
165 wxAuiPaneInfo().Name(wxT("command_content"))
166 .Caption(wxT("Command"))
167 .MinimizeButton(true)
168 .MaximizeButton(true)
171 .MinSize(wxSize(100,100))
173 // m_mgr.AddPane(mwxButtonRun,
174 // wxAuiPaneInfo().Name(wxT("button_run_content")));
177 //.PaneBorder(false));
185 //================================================================
187 //================================================================
188 WxGUIScriptingInterface::~WxGUIScriptingInterface()
192 //================================================================
194 //================================================================
195 void WxGUIScriptingInterface::Open(const std::string& filename)
197 mWxGUITextEditor->Open(filename);
199 //================================================================
201 //================================================================
202 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
206 mWxGUIOutputMessages->Print(s,wxRED);
208 if ( mInterpreter->InterpretLine( command ) ==
209 Interpreter::Interpreter_QUIT )
214 //================================================================
216 //================================================================
217 /// Runs the interpretation of a file
218 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
220 if ( mInterpreter->InterpretFile(filename) ==
221 Interpreter::Interpreter_ERROR )
227 //================================================================
229 //================================================================
230 void WxGUIScriptingInterface::WxGUITextEditorRun()
232 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
233 std::stringstream* buf = new std::stringstream;
234 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
236 mInterpreter->SetThrow(true);
239 mInterpreter->InterpretBuffer(buf);
241 catch (InterpreterError e)
243 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl;
244 if (e.IsInScriptFile())
245 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl;
246 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl;
247 int lev = bbtk::MessageManager::GetMessageLevel("Error");
249 std::cerr << "* Exception thrown : "<<std::endl;
250 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl;
251 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl;
255 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
256 std::string filename = mWxGUITextEditor->GetCurrentPage();//wx2std(temp);
257 size_t s = filename.length();
259 Interpreter* I = new Interpreter;
261 if ((s>3) && (filename[s-1]=='s')
262 && (filename[s-2]=='b')
263 && (filename[s-3]=='b')
264 && (filename[s-4]=='.'))
266 std::string tmp("Executing ");
268 SetStatusText(std2wx(tmp));
269 I->InterpretFile(filename);
273 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
279 //================================================================
281 //================================================================
282 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
286 //================================================================
289 //================================================================
290 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
294 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
295 _T("About ..."), wxOK | wxICON_INFORMATION,
298 //================================================================
301 //================================================================
302 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
304 std::string commandStr;
305 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
307 commandStr = "notepad.exe ";
309 commandStr = "gedit ";
311 commandStr = commandStr + configFile;
312 std::cout << "system: " << commandStr << std::endl;
313 system ( commandStr.c_str() );
315 //================================================================
318 //================================================================
319 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
321 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 01 \n");
322 std::string command("toolsbbtk/appli/CreatePackage");
323 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 02 \n");
325 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
326 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 03 \n");
327 Interpreter* I = new Interpreter;
328 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 04 \n");
329 I->InterpretFile(command);
330 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 05 \n");
332 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
334 //================================================================
337 //================================================================
338 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
340 std::string command("toolsbbtk/appli/CreateBlackBox");
341 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
342 Interpreter* I = new Interpreter;
343 I->InterpretFile(command);
346 //================================================================
348 //================================================================
349 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
351 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
354 std::string strappli="start ";
356 std::string strappli="gnome-open ";
358 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
359 std::cout << "system: " << strcommand << std::endl;
360 system ( strcommand.c_str() );
363 //================================================================
366 //================================================================
367 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
369 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
370 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
371 Interpreter* I = new Interpreter;
373 //EED std::cout << "bbi: include "<<filepath<<std::endl;
374 //EED I->InterpretFile( filepath );
376 I->InterpretLine( "exec freeze");
377 I->InterpretLine( "include *");
378 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
379 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
380 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
381 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
385 //================================================================
388 //================================================================
389 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
392 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
393 if (mWxGUIHtmlBrowser->GoTo(s))
395 //EED mwxNotebook->ChangeSelection(1);
396 // mwxNotebook->SetSelection(1);
400 // std::cout << "ERROR html"<<std::endl;
403 //================================================================
405 //================================================================
406 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
408 std::cout << "OnLink"<<std::endl;
409 size_t s = target.length();
410 if ((s>3) && (target[s-1]=='s')
411 && (target[s-2]=='b')
412 && (target[s-3]=='b')
413 && (target[s-4]=='.'))
415 mWxGUITextEditor->Open(target);
420 //================================================================
422 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
425 bool checked = event.IsChecked();
426 bool shown = m_mgr.GetPane(w).IsShown();
427 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
430 m_mgr.GetPane(w).Show(checked);
436 //================================================================
437 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
439 OnMenuWindowsCheck(event,mWxGUITextEditor);
441 //================================================================
443 //================================================================
444 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
446 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
448 //================================================================
450 //================================================================
451 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
453 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
455 //================================================================
457 //================================================================
458 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
460 OnMenuWindowsCheck(event,mWxGUICommand);
462 //================================================================
464 //================================================================
465 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
467 // TO DO : Save it into ConfigurationFile
468 // m_mgr.SavePerspective();
470 //================================================================
473 //================================================================
474 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
476 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
479 //================================================================
482 //================================================================
483 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
484 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
485 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
486 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
487 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
488 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
489 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
490 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
491 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
492 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
493 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
494 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
495 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
496 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
498 //================================================================
503 #endif //_USE_WXWIDGETS_