1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/09/10 07:25:23 $
7 Version: $Revision: 1.16 $
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, wxString title, wxSize size)
69 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
71 // m_mgr = new wxAuiManager(this);
72 m_mgr.SetManagedWindow(this);
74 mInterpreter = bbtk::Interpreter::New();
75 mInterpreter->SetUser(this);
76 mInterpreter->SetCommandLine(true);
77 mInterpreter->SetThrow(true);
81 wxInitAllImageHandlers();
83 wxMenu *menuFile = new wxMenu;
84 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
86 wxMenu *menuAbout = new wxMenu;
87 menuAbout->Append( ID_Menu_About, _T("&About...") );
89 wxMenu *menuTools = new wxMenu;
90 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
91 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
92 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
93 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
94 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
96 wxMenu *menuWindows = new wxMenu;
97 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
98 _T("Show 'files' panel") )->Check();
99 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
100 _T("Show 'help' panel") )->Check();
101 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
102 _T("Show 'messages' panel") )->Check();
103 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
104 _T("Show 'command' panel") )->Check();
105 menuWindows->AppendSeparator();
106 menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Launch Package &Browser") );
108 // menuWindows->AppendSeparator();
109 // menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
111 wxMenu *menuOptions = new wxMenu;
112 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
113 _T("Reset before running") );
114 mwxMenuItemReset->Check();
116 wxMenuBar *menuBar = new wxMenuBar;
117 menuBar->Append( menuFile, _T("&File") );
118 menuBar->Append( menuTools, _T("&Tools") );
119 menuBar->Append( menuOptions, _T("&Options") );
120 menuBar->Append( menuWindows, _T("&Windows") );
121 menuBar->Append( menuAbout, _T("About") );
123 SetMenuBar( menuBar );
126 SetStatusText( _T("Welcome to bbStudio !") );
129 mWxGUITextEditor = new WxGUITextEditor(this,this);
130 mWxGUITextEditor->SetFileNameFilter("*.bbs");
132 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
134 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
136 mWxGUICommand = new WxGUICommand(this,this);
138 mWxGUICommand->SetFocus();
143 mwxNotebook = new wxAuiNotebook(this,
149 | wxAUI_NB_TAB_EXTERNAL_MOVE
150 //| wxAUI_NB_WINDOWLIST_BUTTON
151 //|wxAUI_NB_SCROLL_BUTTONS
152 // | wxAUI_NB_CLOSE_BUTTON
153 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
154 //| wxAUI_NB_CLOSE_ON_ALL_TABS
158 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
159 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
161 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
163 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
166 m_mgr.AddPane(mwxNotebook,
167 wxAuiPaneInfo().Name(wxT("nb"))
168 .CaptionVisible(false)
169 .MinimizeButton(false)
170 .MaximizeButton(false)
172 // .MinSize(wxSize(100,100))
177 m_mgr.AddPane(mWxGUITextEditor,
178 wxAuiPaneInfo().Name(wxT("editor_content"))
179 .Caption(wxT("Files"))
180 .MinimizeButton(true)
181 .MaximizeButton(true)
183 .MinSize(wxSize(100,100))
186 m_mgr.AddPane(mWxGUIHtmlBrowser,
187 wxAuiPaneInfo().Name(wxT("browser_content"))
188 .Caption(wxT("Help"))
189 .MinimizeButton(true)
190 .MaximizeButton(true)
192 .MinSize(wxSize(200,100))
195 m_mgr.AddPane(mWxGUIOutputMessages,
196 wxAuiPaneInfo().Name(wxT("messages_content"))
197 .Caption(wxT("Messages"))
198 .MinimizeButton(true)
199 .MaximizeButton(true)
201 .MinSize(wxSize(100,100))
203 m_mgr.AddPane(mWxGUICommand,
204 wxAuiPaneInfo().Name(wxT("command_content"))
205 .Caption(wxT("Command"))
206 .MinimizeButton(true)
207 .MaximizeButton(true)
210 .MinSize(wxSize(100,100))
214 // parent window of all bbtk windows will be a child of this
215 Wx::SetTopWindowParent(this);
216 // Add the method OnWxSignal as a Wx::Signal observer
217 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
219 //.PaneBorder(false));
226 // mwxNotebook->SetSelection(1);
227 mWxGUIHtmlBrowser->GoHome();
230 // LoadPerspective();
233 //================================================================
235 //================================================================
236 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 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( "exec freeze");
437 I->InterpretLine( "include *");
438 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
439 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
440 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
441 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
444 //================================================================
447 //================================================================
448 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
451 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
452 if (mWxGUIHtmlBrowser->GoTo(s))
454 //EED mwxNotebook->ChangeSelection(1);
455 // mwxNotebook->SetSelection(1);
459 // std::cout << "ERROR html"<<std::endl;
462 //================================================================
464 //================================================================
465 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
467 size_t s = target.length();
468 if ((s>3) && (target[s-1]=='s')
469 && (target[s-2]=='b')
470 && (target[s-3]=='b')
471 && (target[s-4]=='.'))
473 mWxGUITextEditor->Open(target);
475 mwxNotebook->SetSelection(0);
477 mWxGUITextEditor->SetFocus();
482 //================================================================
484 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
487 bool checked = event.IsChecked();
488 bool shown = m_mgr.GetPane(w).IsShown();
489 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
492 m_mgr.GetPane(w).Show(checked);
498 //================================================================
499 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
501 OnMenuWindowsCheck(event,mWxGUITextEditor);
503 //================================================================
505 //================================================================
506 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
508 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
510 //================================================================
512 //================================================================
513 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
515 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
517 //================================================================
519 //================================================================
520 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
522 OnMenuWindowsCheck(event,mWxGUICommand);
524 //================================================================
526 //================================================================
527 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
531 //================================================================
533 //================================================================
534 void WxGUIScriptingInterface::SavePerspective()
536 // std::cout << "Saving configuration..."<<std::endl;
537 std::string conf = wx2std(m_mgr.SavePerspective());
538 std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
540 f.open(fname.c_str(), std::ios::out );
541 f << conf << std::endl;
546 f << w << " " << h << std::endl;
550 //================================================================
552 //================================================================
553 void WxGUIScriptingInterface::LoadPerspective()
556 Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
557 if ( Utilities::FileExists( fname ))
559 // std::cout << "Loading configuration..."<<std::endl;
562 f.open(fname.c_str());
572 // std::cout << conf << std::endl;
575 m_mgr.LoadPerspective(std2wx(conf));
582 //================================================================
584 //================================================================
585 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
587 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
590 //================================================================
593 //================================================================
594 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
595 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
596 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
597 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
598 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
599 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
600 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
601 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
602 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
603 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
604 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
605 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
606 EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
607 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
608 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
609 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
611 //================================================================
616 #endif //_USE_WXWIDGETS_