1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/07/24 14:37:06 $
7 Version: $Revision: 1.15 $
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,
61 ID_Menu_Windows_PackageBrowser
66 //================================================================
67 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size)
68 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
70 // m_mgr = new wxAuiManager(this);
71 m_mgr.SetManagedWindow(this);
73 mInterpreter = bbtk::Interpreter::New();
74 mInterpreter->SetUser(this);
75 mInterpreter->SetCommandLine(true);
76 mInterpreter->SetThrow(true);
79 wxInitAllImageHandlers();
81 wxMenu *menuFile = new wxMenu;
82 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
84 wxMenu *menuAbout = new wxMenu;
85 menuAbout->Append( ID_Menu_About, _T("&About...") );
87 wxMenu *menuTools = new wxMenu;
88 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
89 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
90 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
91 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
92 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
94 wxMenu *menuWindows = new wxMenu;
95 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
96 _T("Show 'files' panel") )->Check();
97 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
98 _T("Show 'help' panel") )->Check();
99 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
100 _T("Show 'messages' panel") )->Check();
101 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
102 _T("Show 'command' panel") )->Check();
103 menuWindows->AppendSeparator();
104 menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Show Package &Browser") );
106 menuWindows->AppendSeparator();
107 menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
109 wxMenu *menuOptions = new wxMenu;
110 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
111 _T("Reset before running") );
112 mwxMenuItemReset->Check();
114 wxMenuBar *menuBar = new wxMenuBar;
115 menuBar->Append( menuFile, _T("&File") );
116 menuBar->Append( menuTools, _T("&Tools") );
117 menuBar->Append( menuOptions, _T("&Options") );
118 menuBar->Append( menuWindows, _T("&Windows") );
119 menuBar->Append( menuAbout, _T("About") );
121 SetMenuBar( menuBar );
124 SetStatusText( _T("Welcome to bbStudio !") );
127 mWxGUITextEditor = new WxGUITextEditor(this,this);
128 mWxGUITextEditor->SetFileNameFilter("*.bbs");
130 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
134 wxBitmap bmp_run(cc_run_xpm);
135 mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
138 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
140 mWxGUICommand = new WxGUICommand(this,this);
142 mWxGUICommand->SetFocus();
146 mwxNotebook = new wxAuiNotebook(this,
152 | wxAUI_NB_TAB_EXTERNAL_MOVE
153 //| wxAUI_NB_WINDOWLIST_BUTTON
154 //|wxAUI_NB_SCROLL_BUTTONS
155 // | wxAUI_NB_CLOSE_BUTTON
156 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
157 //| wxAUI_NB_CLOSE_ON_ALL_TABS
161 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
162 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
164 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
166 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
169 m_mgr.AddPane(mwxNotebook,
170 wxAuiPaneInfo().Name(wxT("nb"))
171 .CaptionVisible(false)
172 .MinimizeButton(false)
173 .MaximizeButton(false)
175 // .MinSize(wxSize(100,100))
180 m_mgr.AddPane(mWxGUITextEditor,
181 wxAuiPaneInfo().Name(wxT("editor_content"))
182 .Caption(wxT("Files"))
183 .MinimizeButton(true)
184 .MaximizeButton(true)
186 .MinSize(wxSize(100,100))
189 m_mgr.AddPane(mWxGUIHtmlBrowser,
190 wxAuiPaneInfo().Name(wxT("browser_content"))
191 .Caption(wxT("Help"))
192 .MinimizeButton(true)
193 .MaximizeButton(true)
195 .MinSize(wxSize(200,100))
198 m_mgr.AddPane(mWxGUIOutputMessages,
199 wxAuiPaneInfo().Name(wxT("messages_content"))
200 .Caption(wxT("Messages"))
201 .MinimizeButton(true)
202 .MaximizeButton(true)
204 .MinSize(wxSize(100,100))
206 m_mgr.AddPane(mWxGUICommand,
207 wxAuiPaneInfo().Name(wxT("command_content"))
208 .Caption(wxT("Command"))
209 .MinimizeButton(true)
210 .MaximizeButton(true)
213 .MinSize(wxSize(100,100))
216 // m_mgr.AddPane(mwxButtonRun,
217 // wxAuiPaneInfo().Name(wxT("button_run_content")));
219 // parent window of all bbtk windows will be a child of this
220 Wx::SetTopWindowParent(this);
221 // Add the method OnWxSignal as a Wx::Signal observer
222 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
224 //.PaneBorder(false));
229 mwxNotebook->SetSelection(1);
230 mWxGUIHtmlBrowser->GoHome();
234 //================================================================
236 //================================================================
237 WxGUIScriptingInterface::~WxGUIScriptingInterface()
241 //================================================================
243 //================================================================
244 void WxGUIScriptingInterface::Open(const std::string& filename)
246 mWxGUITextEditor->Open(filename);
248 //================================================================
250 #define CATCH_MACRO \
251 catch (QuitException e) \
253 std::cout << "* quit exception caught"<<std::endl; \
255 catch (InterpreterError e) \
257 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
258 if (e.IsInScriptFile()) \
259 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
260 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
261 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
263 std::cerr << "* Exception thrown : "<<std::endl; \
264 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
265 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
269 //================================================================
270 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
274 mWxGUIOutputMessages->Print(s,wxRED);
278 mInterpreter->InterpretLine( command );
282 //================================================================
284 //================================================================
285 /// Runs the interpretation of a file
286 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
290 mInterpreter->InterpretFile(filename);
295 //================================================================
297 //================================================================
298 void WxGUIScriptingInterface::WxGUITextEditorRun()
300 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
301 std::stringstream* buf = new std::stringstream;
302 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
305 // std::cout << "RUN"<<std::endl;
306 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
307 mInterpreter->InterpretBuffer(buf);
308 // std::cout << "EO RUN"<<std::endl;
311 // std::cout << "EO RUN 3"<<std::endl;
313 //================================================================
315 //================================================================
316 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
318 if (!mWxGUITextEditor->CloseAllPages()) return;
321 //================================================================
324 //================================================================
325 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
329 wxMessageBox(_T(" bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
330 _T("About ..."), wxOK | wxICON_INFORMATION,
333 //================================================================
336 //================================================================
337 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
339 std::string commandStr;
340 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
342 commandStr = "notepad.exe ";
344 commandStr = "gedit ";
346 commandStr = commandStr + configFile;
347 // std::cout << "system: " << commandStr << std::endl;
348 system ( commandStr.c_str() );
350 //================================================================
352 //================================================================
353 void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
356 WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
357 browser->IncludeAll();
358 mwxNotebook->AddPage(browser,_T("Package Browser"),true);
360 //================================================================
364 //================================================================
365 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
368 std::string command("toolsbbtk/appli/GUICreatePackage");
369 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
371 Interpreter::Pointer I = Interpreter::New();
372 I->InterpretFile(command);
375 //================================================================
378 //================================================================
379 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
381 std::string command("toolsbbtk/appli/GUICreateBlackBox");
382 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
384 Interpreter::Pointer I = Interpreter::New();
385 I->InterpretFile(command);
387 //================================================================
389 //================================================================
390 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
392 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
395 std::string strappli="start ";
397 std::string strappli="gnome-open ";
399 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
400 // std::cout << "system: " << strcommand << std::endl;
401 system ( strcommand.c_str() );
404 //================================================================
407 //================================================================
408 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
410 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
411 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
413 Interpreter::Pointer I = Interpreter::New();
415 I->InterpretLine( "exec freeze");
416 I->InterpretLine( "include *");
417 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
418 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
419 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
420 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
423 //================================================================
426 //================================================================
427 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
430 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
431 if (mWxGUIHtmlBrowser->GoTo(s))
433 //EED mwxNotebook->ChangeSelection(1);
434 // mwxNotebook->SetSelection(1);
438 // std::cout << "ERROR html"<<std::endl;
441 //================================================================
443 //================================================================
444 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
446 size_t s = target.length();
447 if ((s>3) && (target[s-1]=='s')
448 && (target[s-2]=='b')
449 && (target[s-3]=='b')
450 && (target[s-4]=='.'))
452 mWxGUITextEditor->Open(target);
453 mwxNotebook->SetSelection(0);
454 mWxGUITextEditor->SetFocus();
459 //================================================================
461 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
464 bool checked = event.IsChecked();
465 bool shown = m_mgr.GetPane(w).IsShown();
466 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
469 m_mgr.GetPane(w).Show(checked);
475 //================================================================
476 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
478 OnMenuWindowsCheck(event,mWxGUITextEditor);
480 //================================================================
482 //================================================================
483 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
485 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
487 //================================================================
489 //================================================================
490 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
492 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
494 //================================================================
496 //================================================================
497 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
499 OnMenuWindowsCheck(event,mWxGUICommand);
501 //================================================================
503 //================================================================
504 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
506 // TO DO : Save it into ConfigurationFile
507 // m_mgr.SavePerspective();
509 //================================================================
512 //================================================================
513 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
515 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
518 //================================================================
521 //================================================================
522 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
523 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
524 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
525 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
526 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
527 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
528 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
529 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
530 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
531 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
532 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
533 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
534 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
535 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
536 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
538 //================================================================
543 #endif //_USE_WXWIDGETS_