1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/03/25 15:47:54 $
7 Version: $Revision: 1.4 $
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);
75 mInterpreter->SetThrow(true);
78 wxInitAllImageHandlers();
80 wxMenu *menuFile = new wxMenu;
81 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
83 wxMenu *menuAbout = new wxMenu;
84 menuAbout->Append( ID_Menu_About, _T("&About...") );
86 wxMenu *menuTools = new wxMenu;
87 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
88 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
89 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
90 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
91 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
93 wxMenu *menuWindows = new wxMenu;
94 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
95 _T("Show 'files' panel") )->Check();
96 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
97 _T("Show 'help' panel") )->Check();
98 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
99 _T("Show 'messages' panel") )->Check();
100 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
101 _T("Show 'command' panel") )->Check();
103 menuWindows->AppendSeparator();
104 menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
106 wxMenu *menuOptions = new wxMenu;
107 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
108 _T("Reset before running") );
109 mwxMenuItemReset->Check();
111 wxMenuBar *menuBar = new wxMenuBar;
112 menuBar->Append( menuFile, _T("&File") );
113 menuBar->Append( menuTools, _T("&Tools") );
114 menuBar->Append( menuOptions, _T("&Options") );
115 menuBar->Append( menuWindows, _T("&Windows") );
116 menuBar->Append( menuAbout, _T("About") );
118 SetMenuBar( menuBar );
121 SetStatusText( _T("Welcome to bbi !") );
124 mWxGUITextEditor = new WxGUITextEditor(this,this);
125 mWxGUITextEditor->SetFileNameFilter("*.bbs");
127 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
130 wxBitmap bmp_run(cc_run_xpm);
131 mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
134 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
136 mWxGUICommand = new WxGUICommand(this,this);
138 mWxGUICommand->SetFocus();
140 // Creates and sets the parent window of all bbtk windows
141 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
143 Wx::SetTopWindow(top);
147 m_mgr.AddPane(mWxGUITextEditor,
148 wxAuiPaneInfo().Name(wxT("editor_content"))
149 .Caption(wxT("Files"))
150 .MinimizeButton(true)
151 .MaximizeButton(true)
153 .MinSize(wxSize(100,100))
155 m_mgr.AddPane(mWxGUIHtmlBrowser,
156 wxAuiPaneInfo().Name(wxT("browser_content"))
157 .Caption(wxT("Help"))
158 .MinimizeButton(true)
159 .MaximizeButton(true)
161 .MinSize(wxSize(100,100))
163 m_mgr.AddPane(mWxGUIOutputMessages,
164 wxAuiPaneInfo().Name(wxT("messages_content"))
165 .Caption(wxT("Messages"))
166 .MinimizeButton(true)
167 .MaximizeButton(true)
169 .MinSize(wxSize(100,100))
171 m_mgr.AddPane(mWxGUICommand,
172 wxAuiPaneInfo().Name(wxT("command_content"))
173 .Caption(wxT("Command"))
174 .MinimizeButton(true)
175 .MaximizeButton(true)
178 .MinSize(wxSize(100,100))
180 // m_mgr.AddPane(mwxButtonRun,
181 // wxAuiPaneInfo().Name(wxT("button_run_content")));
184 //.PaneBorder(false));
192 //================================================================
194 //================================================================
195 WxGUIScriptingInterface::~WxGUIScriptingInterface()
199 //================================================================
201 //================================================================
202 void WxGUIScriptingInterface::Open(const std::string& filename)
204 mWxGUITextEditor->Open(filename);
206 //================================================================
208 #define CATCH_MACRO \
209 catch (InterpreterError e) \
211 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
212 if (e.IsInScriptFile()) \
213 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
214 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
215 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
217 std::cerr << "* Exception thrown : "<<std::endl; \
218 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
219 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
223 //================================================================
224 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
228 mWxGUIOutputMessages->Print(s,wxRED);
232 mInterpreter->InterpretLine( command );
236 //================================================================
238 //================================================================
239 /// Runs the interpretation of a file
240 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
244 mInterpreter->InterpretFile(filename);
249 //================================================================
251 //================================================================
252 void WxGUIScriptingInterface::WxGUITextEditorRun()
254 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
255 std::stringstream* buf = new std::stringstream;
256 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
259 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
260 mInterpreter->InterpretBuffer(buf);
264 //================================================================
266 //================================================================
267 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
269 if (!mWxGUITextEditor->CloseAllPages()) return;
272 //================================================================
275 //================================================================
276 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
280 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
281 _T("About ..."), wxOK | wxICON_INFORMATION,
284 //================================================================
287 //================================================================
288 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
290 std::string commandStr;
291 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
293 commandStr = "notepad.exe ";
295 commandStr = "gedit ";
297 commandStr = commandStr + configFile;
298 std::cout << "system: " << commandStr << std::endl;
299 system ( commandStr.c_str() );
301 //================================================================
304 //================================================================
305 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
307 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 01 \n");
308 std::string command("toolsbbtk/appli/CreatePackage");
309 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 02 \n");
311 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
312 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 03 \n");
313 Interpreter* I = new Interpreter;
314 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 04 \n");
315 I->InterpretFile(command);
316 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 05 \n");
318 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
320 //================================================================
323 //================================================================
324 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
326 std::string command("toolsbbtk/appli/CreateBlackBox");
327 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
328 Interpreter* I = new Interpreter;
329 I->InterpretFile(command);
332 //================================================================
334 //================================================================
335 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
337 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
340 std::string strappli="start ";
342 std::string strappli="gnome-open ";
344 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
345 std::cout << "system: " << strcommand << std::endl;
346 system ( strcommand.c_str() );
349 //================================================================
352 //================================================================
353 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
355 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
356 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
357 Interpreter* I = new Interpreter;
359 //EED std::cout << "bbi: include "<<filepath<<std::endl;
360 //EED I->InterpretFile( filepath );
362 I->InterpretLine( "exec freeze");
363 I->InterpretLine( "include *");
364 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
365 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
366 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
367 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
371 //================================================================
374 //================================================================
375 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
378 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
379 if (mWxGUIHtmlBrowser->GoTo(s))
381 //EED mwxNotebook->ChangeSelection(1);
382 // mwxNotebook->SetSelection(1);
386 // std::cout << "ERROR html"<<std::endl;
389 //================================================================
391 //================================================================
392 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
394 std::cout << "OnLink"<<std::endl;
395 size_t s = target.length();
396 if ((s>3) && (target[s-1]=='s')
397 && (target[s-2]=='b')
398 && (target[s-3]=='b')
399 && (target[s-4]=='.'))
401 mWxGUITextEditor->Open(target);
406 //================================================================
408 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
411 bool checked = event.IsChecked();
412 bool shown = m_mgr.GetPane(w).IsShown();
413 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
416 m_mgr.GetPane(w).Show(checked);
422 //================================================================
423 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
425 OnMenuWindowsCheck(event,mWxGUITextEditor);
427 //================================================================
429 //================================================================
430 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
432 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
434 //================================================================
436 //================================================================
437 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
439 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
441 //================================================================
443 //================================================================
444 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
446 OnMenuWindowsCheck(event,mWxGUICommand);
448 //================================================================
450 //================================================================
451 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
453 // TO DO : Save it into ConfigurationFile
454 // m_mgr.SavePerspective();
456 //================================================================
459 //================================================================
460 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
462 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
465 //================================================================
468 //================================================================
469 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
470 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
471 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
472 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
473 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
474 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
475 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
476 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
477 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
478 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
479 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
480 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
481 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
482 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
484 //================================================================
489 #endif //_USE_WXWIDGETS_