1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/05/14 12:32:26 $
7 Version: $Revision: 1.9 $
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 = bbtk::Interpreter::New();
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();
142 mwxNotebook = new wxAuiNotebook(this,
148 | wxAUI_NB_TAB_EXTERNAL_MOVE
149 //| wxAUI_NB_WINDOWLIST_BUTTON
150 //|wxAUI_NB_SCROLL_BUTTONS
151 // | wxAUI_NB_CLOSE_BUTTON
152 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
153 //| wxAUI_NB_CLOSE_ON_ALL_TABS
157 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
158 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
160 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
162 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
164 m_mgr.AddPane(mwxNotebook,
165 wxAuiPaneInfo().Name(wxT("nb"))
166 .CaptionVisible(false)
167 .MinimizeButton(false)
168 .MaximizeButton(false)
170 // .MinSize(wxSize(100,100))
175 m_mgr.AddPane(mWxGUITextEditor,
176 wxAuiPaneInfo().Name(wxT("editor_content"))
177 .Caption(wxT("Files"))
178 .MinimizeButton(true)
179 .MaximizeButton(true)
181 .MinSize(wxSize(100,100))
184 m_mgr.AddPane(mWxGUIHtmlBrowser,
185 wxAuiPaneInfo().Name(wxT("browser_content"))
186 .Caption(wxT("Help"))
187 .MinimizeButton(true)
188 .MaximizeButton(true)
190 .MinSize(wxSize(200,100))
193 m_mgr.AddPane(mWxGUIOutputMessages,
194 wxAuiPaneInfo().Name(wxT("messages_content"))
195 .Caption(wxT("Messages"))
196 .MinimizeButton(true)
197 .MaximizeButton(true)
199 .MinSize(wxSize(100,100))
201 m_mgr.AddPane(mWxGUICommand,
202 wxAuiPaneInfo().Name(wxT("command_content"))
203 .Caption(wxT("Command"))
204 .MinimizeButton(true)
205 .MaximizeButton(true)
208 .MinSize(wxSize(100,100))
211 // m_mgr.AddPane(mwxButtonRun,
212 // wxAuiPaneInfo().Name(wxT("button_run_content")));
214 // Creates the parent window of all bbtk windows as a child of this
215 Wx::CreateTopWindow(this);
216 // Add the method OnWxSignal as a Wx::Signal observer
217 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
219 //.PaneBorder(false));
224 mwxNotebook->SetSelection(1);
225 mWxGUIHtmlBrowser->GoHome();
229 //================================================================
231 //================================================================
232 WxGUIScriptingInterface::~WxGUIScriptingInterface()
236 //================================================================
238 //================================================================
239 void WxGUIScriptingInterface::Open(const std::string& filename)
241 mWxGUITextEditor->Open(filename);
243 //================================================================
245 #define CATCH_MACRO \
246 catch (QuitException e) \
248 std::cout << "* quit exception caught"<<std::endl; \
250 catch (InterpreterError e) \
252 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
253 if (e.IsInScriptFile()) \
254 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
255 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
256 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
258 std::cerr << "* Exception thrown : "<<std::endl; \
259 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
260 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
264 //================================================================
265 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
269 mWxGUIOutputMessages->Print(s,wxRED);
273 mInterpreter->InterpretLine( command );
277 //================================================================
279 //================================================================
280 /// Runs the interpretation of a file
281 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
285 mInterpreter->InterpretFile(filename);
290 //================================================================
292 //================================================================
293 void WxGUIScriptingInterface::WxGUITextEditorRun()
295 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
296 std::stringstream* buf = new std::stringstream;
297 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
300 std::cout << "RUN"<<std::endl;
301 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
302 mInterpreter->InterpretBuffer(buf);
303 std::cout << "EO RUN"<<std::endl;
306 std::cout << "EO RUN 3"<<std::endl;
308 //================================================================
310 //================================================================
311 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
313 if (!mWxGUITextEditor->CloseAllPages()) return;
316 //================================================================
319 //================================================================
320 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
324 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
325 _T("About ..."), wxOK | wxICON_INFORMATION,
328 //================================================================
331 //================================================================
332 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
334 std::string commandStr;
335 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
337 commandStr = "notepad.exe ";
339 commandStr = "gedit ";
341 commandStr = commandStr + configFile;
342 // std::cout << "system: " << commandStr << std::endl;
343 system ( commandStr.c_str() );
345 //================================================================
348 //================================================================
349 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
352 std::string command("toolsbbtk/appli/CreatePackage");
353 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
355 Interpreter::Pointer I = Interpreter::New();
356 I->InterpretFile(command);
359 //================================================================
362 //================================================================
363 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
365 std::string command("toolsbbtk/appli/CreateBlackBox");
366 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
368 Interpreter::Pointer I = Interpreter::New();
369 I->InterpretFile(command);
371 //================================================================
373 //================================================================
374 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
376 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
379 std::string strappli="start ";
381 std::string strappli="gnome-open ";
383 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
384 // std::cout << "system: " << strcommand << std::endl;
385 system ( strcommand.c_str() );
388 //================================================================
391 //================================================================
392 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
394 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
395 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
397 Interpreter::Pointer I = Interpreter::New();
399 I->InterpretLine( "exec freeze");
400 I->InterpretLine( "include *");
401 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
402 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
403 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
404 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
407 //================================================================
410 //================================================================
411 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
414 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
415 if (mWxGUIHtmlBrowser->GoTo(s))
417 //EED mwxNotebook->ChangeSelection(1);
418 // mwxNotebook->SetSelection(1);
422 // std::cout << "ERROR html"<<std::endl;
425 //================================================================
427 //================================================================
428 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
430 size_t s = target.length();
431 if ((s>3) && (target[s-1]=='s')
432 && (target[s-2]=='b')
433 && (target[s-3]=='b')
434 && (target[s-4]=='.'))
436 mWxGUITextEditor->Open(target);
437 mwxNotebook->SetSelection(0);
438 mWxGUITextEditor->SetFocus();
443 //================================================================
445 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
448 bool checked = event.IsChecked();
449 bool shown = m_mgr.GetPane(w).IsShown();
450 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
453 m_mgr.GetPane(w).Show(checked);
459 //================================================================
460 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
462 OnMenuWindowsCheck(event,mWxGUITextEditor);
464 //================================================================
466 //================================================================
467 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
469 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
471 //================================================================
473 //================================================================
474 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
476 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
478 //================================================================
480 //================================================================
481 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
483 OnMenuWindowsCheck(event,mWxGUICommand);
485 //================================================================
487 //================================================================
488 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
490 // TO DO : Save it into ConfigurationFile
491 // m_mgr.SavePerspective();
493 //================================================================
496 //================================================================
497 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
499 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
502 //================================================================
505 //================================================================
506 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
507 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
508 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
509 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
510 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
511 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
512 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
513 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
514 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
515 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
516 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
517 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
518 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
519 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
521 //================================================================
526 #endif //_USE_WXWIDGETS_