1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/10/02 13:21:11 $
7 Version: $Revision: 1.20 $
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"
42 #include <wx/tipwin.h>
44 //#include "icons/cc_run.xpm"
54 ID_Menu_CreatePackage,
55 ID_Menu_CreateBlackBox,
56 ID_Menu_ShowImageGraph,
58 ID_Menu_Windows_Files,
60 ID_Menu_Windows_Messages,
61 ID_Menu_Windows_Command,
63 ID_Menu_Windows_PackageBrowser
68 //================================================================
69 WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
70 : wxFrame((wxFrame *)parent, -1, _T("bbStudio"),
71 wxDefaultPosition, wxSize(1200,800) )
73 // m_mgr = new wxAuiManager(this);
74 m_mgr.SetManagedWindow(this);
76 mInterpreter = bbtk::Interpreter::New();
77 mInterpreter->SetUser(this);
78 mInterpreter->SetCommandLine(true);
79 mInterpreter->SetThrow(true);
83 wxInitAllImageHandlers();
85 wxMenu *menuFile = new wxMenu;
86 menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
87 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
89 wxMenu *menuAbout = new wxMenu;
90 menuAbout->Append( ID_Menu_About, _T("&About...") );
92 wxMenu *menuTools = new wxMenu;
93 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
94 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
95 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
96 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
98 wxMenu *menuWindows = new wxMenu;
99 menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
100 _T("Show 'files' panel") )->Check();
101 menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
102 _T("Show 'help' panel") )->Check();
103 menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
104 _T("Show 'messages' panel") )->Check();
105 menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
106 _T("Show 'command' panel") )->Check();
107 menuWindows->AppendSeparator();
108 menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Launch Package &Browser") );
110 // menuWindows->AppendSeparator();
111 // menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
113 wxMenu *menuOptions = new wxMenu;
114 mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
115 _T("Reset before running") );
116 mwxMenuItemReset->Check();
118 wxMenuBar *menuBar = new wxMenuBar;
119 menuBar->Append( menuFile, _T("&File") );
120 menuBar->Append( menuTools, _T("&Tools") );
121 menuBar->Append( menuOptions, _T("&Options") );
122 menuBar->Append( menuWindows, _T("&Windows") );
123 menuBar->Append( menuAbout, _T("About") );
125 SetMenuBar( menuBar );
130 SetStatusText( _T("Welcome to bbStudio !") );
133 // Panes (Files, Messages, Help, Command)
134 mWxGUITextEditor = new WxGUITextEditor(this,this);
135 mWxGUITextEditor->SetFileNameFilter("*.bbs");
137 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
139 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
141 mWxGUICommand = new WxGUICommand(this,this);
143 mWxGUICommand->SetFocus();
148 mwxNotebook = new wxAuiNotebook(this,
154 | wxAUI_NB_TAB_EXTERNAL_MOVE
155 //| wxAUI_NB_WINDOWLIST_BUTTON
156 //|wxAUI_NB_SCROLL_BUTTONS
157 // | wxAUI_NB_CLOSE_BUTTON
158 //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
159 //| wxAUI_NB_CLOSE_ON_ALL_TABS
163 mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
164 mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
166 mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
168 mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
171 m_mgr.AddPane(mwxNotebook,
172 wxAuiPaneInfo().Name(wxT("nb"))
173 .CaptionVisible(false)
174 .MinimizeButton(false)
175 .MaximizeButton(false)
177 // .MinSize(wxSize(100,100))
182 m_mgr.AddPane(mWxGUITextEditor,
183 wxAuiPaneInfo().Name(wxT("editor_content"))
184 .Caption(wxT("Files"))
185 .MinimizeButton(true)
186 .MaximizeButton(true)
188 .MinSize(wxSize(100,100))
191 m_mgr.AddPane(mWxGUIHtmlBrowser,
192 wxAuiPaneInfo().Name(wxT("browser_content"))
193 .Caption(wxT("Help"))
194 .MinimizeButton(true)
195 .MaximizeButton(true)
198 .MinSize(wxSize(400,100))
201 m_mgr.AddPane(mWxGUIOutputMessages,
202 wxAuiPaneInfo().Name(wxT("messages_content"))
203 .Caption(wxT("Messages"))
204 .MinimizeButton(true)
205 .MaximizeButton(true)
207 .MinSize(wxSize(100,100))
209 m_mgr.AddPane(mWxGUICommand,
210 wxAuiPaneInfo().Name(wxT("command_content"))
211 .Caption(wxT("Command"))
212 .MinimizeButton(true)
213 .MaximizeButton(true)
216 .MinSize(wxSize(100,100))
220 // parent window of all bbtk windows will be a child of this
221 Wx::SetTopWindowParent(this);
222 // Add the method OnWxSignal as a Wx::Signal observer
223 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
225 //.PaneBorder(false));
226 // Load the interface appearance saved on last closing
229 // Done in LoadPerspective
234 // mwxNotebook->SetSelection(1);
235 mWxGUIHtmlBrowser->GoHome();
238 // LoadPerspective();
241 wxTipWindow* tip = new wxTipWindow(this,
242 _T("\n Welcome to bbStudio !\n\n To run a demo or example:\n 1. click on the 'Demos' or 'Examples' link\n 2. select a demo or example\n 3. click on the '[source]' link : the source file is loaded in bbStudio\n 4. click on the 'Run' button (the arrow at the bottom right of the source file) \n"),1000);
243 tip->CenterOnParent();
246 //================================================================
248 //================================================================
249 WxGUIScriptingInterface::~WxGUIScriptingInterface()
254 //================================================================
256 //================================================================
257 void WxGUIScriptingInterface::Open(const std::string& filename)
259 mWxGUITextEditor->Open(filename);
261 //================================================================
263 #define CATCH_MACRO \
264 catch (QuitException e) \
266 std::cout << "* quit exception caught"<<std::endl; \
268 catch (InterpreterError e) \
270 std::cerr << "* IERROR : "<<e.GetErrorMessage()<<std::endl; \
271 if (e.IsInScriptFile()) \
272 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
273 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
274 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
276 std::cerr << "* Exception thrown : "<<std::endl; \
277 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
278 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
282 //================================================================
283 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
287 mWxGUIOutputMessages->Print(s,wxRED);
291 mInterpreter->InterpretLine( command );
295 //================================================================
297 //================================================================
298 /// Runs the interpretation of a file
299 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
303 mInterpreter->InterpretFile(filename);
308 //================================================================
310 //================================================================
311 void WxGUIScriptingInterface::WxGUITextEditorRun()
313 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
314 std::stringstream* buf = new std::stringstream;
315 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
318 // std::cout << "RUN"<<std::endl;
319 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
320 mInterpreter->InterpretBuffer(buf);
321 // std::cout << "EO RUN"<<std::endl;
324 // std::cout << "EO RUN 3"<<std::endl;
326 //================================================================
328 //================================================================
329 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
331 if (!mWxGUITextEditor->CloseAllPages()) return;
334 //================================================================
337 //================================================================
338 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
342 wxMessageBox(_T(" bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
343 _T("About ..."), wxOK | wxICON_INFORMATION,
346 //================================================================
349 //================================================================
350 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
352 std::string configFile =
353 ConfigurationFile::GetInstance().Get_config_xml_full_path();
356 //================================================================
358 //================================================================
359 void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
362 WxGUIPackageBrowser2Window *helpbrowser = new
363 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
368 WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
369 browser->IncludeAll();
372 // mwxNotebook->AddPage(browser,_T("Package Browser"),true);
375 m_mgr.AddPane(browser,
376 wxAuiPaneInfo().Name(wxT("package_brower"))
377 .Caption(wxT("Package browser"))
378 .MinimizeButton(true)
379 .MaximizeButton(true)
382 .MinSize(wxSize(100,100))
387 //================================================================
391 //================================================================
392 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
395 std::string command("toolsbbtk/appli/GUICreatePackage");
396 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
398 Interpreter::Pointer I = Interpreter::New();
399 I->InterpretFile(command);
402 //================================================================
405 //================================================================
406 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
408 std::string command("toolsbbtk/appli/GUICreateBlackBox");
409 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
411 Interpreter::Pointer I = Interpreter::New();
412 I->InterpretFile(command);
414 //================================================================
416 //================================================================
417 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
419 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
422 std::string strappli="start ";
424 std::string strappli="gnome-open ";
426 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
427 // std::cout << "system: " << strcommand << std::endl;
428 system ( strcommand.c_str() );
431 //================================================================
434 //================================================================
435 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
437 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
438 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
440 Interpreter::Pointer I = Interpreter::New();
442 I->InterpretLine( "config");
443 I->InterpretLine( "message echo 2");
444 I->InterpretLine( "exec freeze");
445 I->InterpretLine( "include *");
446 I->InterpretLine( "help packages");
447 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
448 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
449 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
450 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
453 //================================================================
456 //================================================================
457 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
460 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
461 if (mWxGUIHtmlBrowser->GoTo(s))
463 //EED mwxNotebook->ChangeSelection(1);
464 // mwxNotebook->SetSelection(1);
468 // std::cout << "ERROR html"<<std::endl;
471 //================================================================
473 //================================================================
474 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
476 size_t s = target.length();
477 if ((s>3) && (target[s-1]=='s')
478 && (target[s-2]=='b')
479 && (target[s-3]=='b')
480 && (target[s-4]=='.'))
482 mWxGUITextEditor->Open(target);
484 mwxNotebook->SetSelection(0);
486 mWxGUITextEditor->SetFocus();
491 //================================================================
493 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
496 bool checked = event.IsChecked();
497 bool shown = m_mgr.GetPane(w).IsShown();
498 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
501 m_mgr.GetPane(w).Show(checked);
507 //================================================================
508 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
510 OnMenuWindowsCheck(event,mWxGUITextEditor);
512 //================================================================
514 //================================================================
515 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
517 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
519 //================================================================
521 //================================================================
522 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
524 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
526 //================================================================
528 //================================================================
529 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
531 OnMenuWindowsCheck(event,mWxGUICommand);
533 //================================================================
535 //================================================================
536 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
540 //================================================================
542 //================================================================
543 void WxGUIScriptingInterface::SavePerspective()
545 // std::cout << "Saving configuration..."<<std::endl;
546 std::string conf = wx2std(m_mgr.SavePerspective());
547 std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
549 f.open(fname.c_str(), std::ios::out );
550 f << conf << std::endl;
553 // GetPosition(&x,&y);
554 // f << x << " " << y << std::endl;
560 f << w << " " << h << std::endl;
564 //================================================================
566 //================================================================
567 void WxGUIScriptingInterface::LoadPerspective()
570 Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
571 if ( Utilities::FileExists( fname ))
573 // std::cout << "Loading configuration..."<<std::endl;
576 f.open(fname.c_str());
588 // std::cout << conf << std::endl;
592 m_mgr.LoadPerspective(std2wx(conf));
599 //================================================================
601 //================================================================
602 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
604 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
606 // OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
608 //================================================================
611 //================================================================
612 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
613 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
614 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
615 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
616 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
617 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
618 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
619 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
620 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
621 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
622 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
623 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
624 EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
625 EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
626 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
627 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
629 //================================================================
634 #endif //_USE_WXWIDGETS_