1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/09/10 09:25:19 $
7 Version: $Revision: 1.17 $
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"
40 #include "bbtkUtilities.h"
43 //#include "icons/cc_run.xpm"
53 ID_Menu_CreatePackage,
54 ID_Menu_CreateBlackBox,
55 ID_Menu_ShowImageGraph,
57 ID_Menu_Windows_Files,
59 ID_Menu_Windows_Messages,
60 ID_Menu_Windows_Command,
62 ID_Menu_Windows_PackageBrowser
67 //================================================================
68 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
69 : wxFrame((wxFrame *)parent, -1, _T("bbStudio"),
70 wxDefaultPosition, wxSize(1200,800) )
72 // m_mgr = new wxAuiManager(this);
73 m_mgr.SetManagedWindow(this);
75 mInterpreter = bbtk::Interpreter::New();
76 mInterpreter->SetUser(this);
77 mInterpreter->SetCommandLine(true);
78 mInterpreter->SetThrow(true);
82 wxInitAllImageHandlers();
84 wxMenu *menuFile = new wxMenu;
85 menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
86 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
88 wxMenu *menuAbout = new wxMenu;
89 menuAbout->Append( ID_Menu_About, _T("&About...") );
91 wxMenu *menuTools = new wxMenu;
92 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
93 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
94 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
95 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
97 wxMenu *menuWindows = new wxMenu;
98 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
99 _T("Show 'files' panel") )->Check();
100 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
101 _T("Show 'help' panel") )->Check();
102 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
103 _T("Show 'messages' panel") )->Check();
104 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
105 _T("Show 'command' panel") )->Check();
106 menuWindows->AppendSeparator();
107 menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Launch Package &Browser") );
109 // menuWindows->AppendSeparator();
110 // menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
112 wxMenu *menuOptions = new wxMenu;
113 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
114 _T("Reset before running") );
115 mwxMenuItemReset->Check();
117 wxMenuBar *menuBar = new wxMenuBar;
118 menuBar->Append( menuFile, _T("&File") );
119 menuBar->Append( menuTools, _T("&Tools") );
120 menuBar->Append( menuOptions, _T("&Options") );
121 menuBar->Append( menuWindows, _T("&Windows") );
122 menuBar->Append( menuAbout, _T("About") );
124 SetMenuBar( menuBar );
129 SetStatusText( _T("Welcome to bbStudio !") );
132 // Panes (Files, Messages, Help, Command)
133 mWxGUITextEditor = new WxGUITextEditor(this,this);
134 mWxGUITextEditor->SetFileNameFilter("*.bbs");
136 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
138 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
140 mWxGUICommand = new WxGUICommand(this,this);
142 mWxGUICommand->SetFocus();
147 mwxNotebook = new wxAuiNotebook(this,
153 | wxAUI_NB_TAB_EXTERNAL_MOVE
154 //| wxAUI_NB_WINDOWLIST_BUTTON
155 //|wxAUI_NB_SCROLL_BUTTONS
156 // | wxAUI_NB_CLOSE_BUTTON
157 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
158 //| wxAUI_NB_CLOSE_ON_ALL_TABS
162 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
163 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
165 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
167 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
170 m_mgr.AddPane(mwxNotebook,
171 wxAuiPaneInfo().Name(wxT("nb"))
172 .CaptionVisible(false)
173 .MinimizeButton(false)
174 .MaximizeButton(false)
176 // .MinSize(wxSize(100,100))
181 m_mgr.AddPane(mWxGUITextEditor,
182 wxAuiPaneInfo().Name(wxT("editor_content"))
183 .Caption(wxT("Files"))
184 .MinimizeButton(true)
185 .MaximizeButton(true)
187 .MinSize(wxSize(100,100))
190 m_mgr.AddPane(mWxGUIHtmlBrowser,
191 wxAuiPaneInfo().Name(wxT("browser_content"))
192 .Caption(wxT("Help"))
193 .MinimizeButton(true)
194 .MaximizeButton(true)
197 .MinSize(wxSize(400,100))
200 m_mgr.AddPane(mWxGUIOutputMessages,
201 wxAuiPaneInfo().Name(wxT("messages_content"))
202 .Caption(wxT("Messages"))
203 .MinimizeButton(true)
204 .MaximizeButton(true)
206 .MinSize(wxSize(100,100))
208 m_mgr.AddPane(mWxGUICommand,
209 wxAuiPaneInfo().Name(wxT("command_content"))
210 .Caption(wxT("Command"))
211 .MinimizeButton(true)
212 .MaximizeButton(true)
215 .MinSize(wxSize(100,100))
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));
225 // Load the interface appearance saved on last closing
228 // Done in LoadPerspective
233 // mwxNotebook->SetSelection(1);
234 mWxGUIHtmlBrowser->GoHome();
237 // LoadPerspective();
240 //================================================================
242 //================================================================
243 WxGUIScriptingInterface::~WxGUIScriptingInterface()
248 //================================================================
250 //================================================================
251 void WxGUIScriptingInterface::Open(const std::string& filename)
253 mWxGUITextEditor->Open(filename);
255 //================================================================
257 #define CATCH_MACRO \
258 catch (QuitException e) \
260 std::cout << "* quit exception caught"<<std::endl; \
262 catch (InterpreterError e) \
264 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
265 if (e.IsInScriptFile()) \
266 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
267 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
268 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
270 std::cerr << "* Exception thrown : "<<std::endl; \
271 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
272 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
276 //================================================================
277 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
281 mWxGUIOutputMessages->Print(s,wxRED);
285 mInterpreter->InterpretLine( command );
289 //================================================================
291 //================================================================
292 /// Runs the interpretation of a file
293 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
297 mInterpreter->InterpretFile(filename);
302 //================================================================
304 //================================================================
305 void WxGUIScriptingInterface::WxGUITextEditorRun()
307 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
308 std::stringstream* buf = new std::stringstream;
309 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
312 // std::cout << "RUN"<<std::endl;
313 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
314 mInterpreter->InterpretBuffer(buf);
315 // std::cout << "EO RUN"<<std::endl;
318 // std::cout << "EO RUN 3"<<std::endl;
320 //================================================================
322 //================================================================
323 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
325 if (!mWxGUITextEditor->CloseAllPages()) return;
328 //================================================================
331 //================================================================
332 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
336 wxMessageBox(_T(" bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
337 _T("About ..."), wxOK | wxICON_INFORMATION,
340 //================================================================
343 //================================================================
344 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
346 std::string configFile =
347 ConfigurationFile::GetInstance().Get_config_xml_full_path();
350 //================================================================
352 //================================================================
353 void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
356 WxGUIPackageBrowser2Window *helpbrowser = new
357 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
362 WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
363 browser->IncludeAll();
366 // mwxNotebook->AddPage(browser,_T("Package Browser"),true);
369 m_mgr.AddPane(browser,
370 wxAuiPaneInfo().Name(wxT("package_brower"))
371 .Caption(wxT("Package browser"))
372 .MinimizeButton(true)
373 .MaximizeButton(true)
376 .MinSize(wxSize(100,100))
381 //================================================================
385 //================================================================
386 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
389 std::string command("toolsbbtk/appli/GUICreatePackage");
390 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
392 Interpreter::Pointer I = Interpreter::New();
393 I->InterpretFile(command);
396 //================================================================
399 //================================================================
400 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
402 std::string command("toolsbbtk/appli/GUICreateBlackBox");
403 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
405 Interpreter::Pointer I = Interpreter::New();
406 I->InterpretFile(command);
408 //================================================================
410 //================================================================
411 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
413 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
416 std::string strappli="start ";
418 std::string strappli="gnome-open ";
420 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
421 // std::cout << "system: " << strcommand << std::endl;
422 system ( strcommand.c_str() );
425 //================================================================
428 //================================================================
429 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
431 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
432 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
434 Interpreter::Pointer I = Interpreter::New();
436 I->InterpretLine( "config");
437 I->InterpretLine( "message echo 2");
438 I->InterpretLine( "exec freeze");
439 I->InterpretLine( "include *");
440 I->InterpretLine( "help packages");
441 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
442 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
443 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
444 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
447 //================================================================
450 //================================================================
451 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
454 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
455 if (mWxGUIHtmlBrowser->GoTo(s))
457 //EED mwxNotebook->ChangeSelection(1);
458 // mwxNotebook->SetSelection(1);
462 // std::cout << "ERROR html"<<std::endl;
465 //================================================================
467 //================================================================
468 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
470 size_t s = target.length();
471 if ((s>3) && (target[s-1]=='s')
472 && (target[s-2]=='b')
473 && (target[s-3]=='b')
474 && (target[s-4]=='.'))
476 mWxGUITextEditor->Open(target);
478 mwxNotebook->SetSelection(0);
480 mWxGUITextEditor->SetFocus();
485 //================================================================
487 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
490 bool checked = event.IsChecked();
491 bool shown = m_mgr.GetPane(w).IsShown();
492 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
495 m_mgr.GetPane(w).Show(checked);
501 //================================================================
502 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
504 OnMenuWindowsCheck(event,mWxGUITextEditor);
506 //================================================================
508 //================================================================
509 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
511 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
513 //================================================================
515 //================================================================
516 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
518 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
520 //================================================================
522 //================================================================
523 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
525 OnMenuWindowsCheck(event,mWxGUICommand);
527 //================================================================
529 //================================================================
530 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
534 //================================================================
536 //================================================================
537 void WxGUIScriptingInterface::SavePerspective()
539 // std::cout << "Saving configuration..."<<std::endl;
540 std::string conf = wx2std(m_mgr.SavePerspective());
541 std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
543 f.open(fname.c_str(), std::ios::out );
544 f << conf << std::endl;
549 f << w << " " << h << std::endl;
553 //================================================================
555 //================================================================
556 void WxGUIScriptingInterface::LoadPerspective()
559 Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
560 if ( Utilities::FileExists( fname ))
562 // std::cout << "Loading configuration..."<<std::endl;
565 f.open(fname.c_str());
575 // std::cout << conf << std::endl;
578 m_mgr.LoadPerspective(std2wx(conf));
585 //================================================================
587 //================================================================
588 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
590 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
592 // OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
594 //================================================================
597 //================================================================
598 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
599 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
600 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
601 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
602 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
603 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
604 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
605 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
606 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
607 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
608 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
609 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
610 EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
611 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
612 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
613 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
615 //================================================================
620 #endif //_USE_WXWIDGETS_