1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/04/25 07:33:17 $
7 Version: $Revision: 1.8 $
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 m_mgr.AddPane(mWxGUITextEditor,
158 wxAuiPaneInfo().Name(wxT("editor_content"))
159 .Caption(wxT("Files"))
160 .MinimizeButton(true)
161 .MaximizeButton(true)
163 .MinSize(wxSize(100,100))
166 m_mgr.AddPane(mWxGUIHtmlBrowser,
167 wxAuiPaneInfo().Name(wxT("browser_content"))
168 .Caption(wxT("Help"))
169 .MinimizeButton(true)
170 .MaximizeButton(true)
172 .MinSize(wxSize(200,100))
175 m_mgr.AddPane(mWxGUIOutputMessages,
176 wxAuiPaneInfo().Name(wxT("messages_content"))
177 .Caption(wxT("Messages"))
178 .MinimizeButton(true)
179 .MaximizeButton(true)
181 .MinSize(wxSize(100,100))
183 m_mgr.AddPane(mWxGUICommand,
184 wxAuiPaneInfo().Name(wxT("command_content"))
185 .Caption(wxT("Command"))
186 .MinimizeButton(true)
187 .MaximizeButton(true)
190 .MinSize(wxSize(100,100))
192 // m_mgr.AddPane(mwxButtonRun,
193 // wxAuiPaneInfo().Name(wxT("button_run_content")));
195 // Creates the parent window of all bbtk windows as a child of this
196 Wx::CreateTopWindow(this);
197 // Add the method OnWxSignal as a Wx::Signal observer
198 //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
200 //.PaneBorder(false));
208 //================================================================
210 //================================================================
211 WxGUIScriptingInterface::~WxGUIScriptingInterface()
215 //================================================================
217 //================================================================
218 void WxGUIScriptingInterface::Open(const std::string& filename)
220 mWxGUITextEditor->Open(filename);
222 //================================================================
224 #define CATCH_MACRO \
225 catch (QuitException e) \
227 std::cout << "* quit exception caught"<<std::endl; \
229 catch (InterpreterError e) \
231 std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; \
232 if (e.IsInScriptFile()) \
233 std::cerr << "* FILE : '"<<e.GetScriptFile()<<"'"<<std::endl; \
234 std::cerr << "* LINE : "<<e.GetScriptLine()<<std::endl; \
235 int lev = bbtk::MessageManager::GetMessageLevel("Error"); \
237 std::cerr << "* Exception thrown : "<<std::endl; \
238 std::cerr << "* OBJECT : " <<e.GetObject()<<std::endl; \
239 std::cerr << "* FILE : " <<e.GetSourceFile()<<std::endl; \
243 //================================================================
244 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
248 mWxGUIOutputMessages->Print(s,wxRED);
252 mInterpreter->InterpretLine( command );
256 //================================================================
258 //================================================================
259 /// Runs the interpretation of a file
260 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
264 mInterpreter->InterpretFile(filename);
269 //================================================================
271 //================================================================
272 void WxGUIScriptingInterface::WxGUITextEditorRun()
274 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
275 std::stringstream* buf = new std::stringstream;
276 (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
279 std::cout << "RUN"<<std::endl;
280 if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
281 mInterpreter->InterpretBuffer(buf);
282 std::cout << "EO RUN"<<std::endl;
285 std::cout << "EO RUN 3"<<std::endl;
287 //================================================================
289 //================================================================
290 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
292 if (!mWxGUITextEditor->CloseAllPages()) return;
295 //================================================================
298 //================================================================
299 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
303 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
304 _T("About ..."), wxOK | wxICON_INFORMATION,
307 //================================================================
310 //================================================================
311 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
313 std::string commandStr;
314 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
316 commandStr = "notepad.exe ";
318 commandStr = "gedit ";
320 commandStr = commandStr + configFile;
321 // std::cout << "system: " << commandStr << std::endl;
322 system ( commandStr.c_str() );
324 //================================================================
327 //================================================================
328 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
331 std::string command("toolsbbtk/appli/CreatePackage");
332 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
334 Interpreter::Pointer I = Interpreter::New();
335 I->InterpretFile(command);
338 //================================================================
341 //================================================================
342 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
344 std::string command("toolsbbtk/appli/CreateBlackBox");
345 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
347 Interpreter::Pointer I = Interpreter::New();
348 I->InterpretFile(command);
350 //================================================================
352 //================================================================
353 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
355 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
358 std::string strappli="start ";
360 std::string strappli="gnome-open ";
362 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
363 // std::cout << "system: " << strcommand << std::endl;
364 system ( strcommand.c_str() );
367 //================================================================
370 //================================================================
371 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
373 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
374 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
376 Interpreter::Pointer I = Interpreter::New();
378 I->InterpretLine( "exec freeze");
379 I->InterpretLine( "include *");
380 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
381 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
382 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
383 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
386 //================================================================
389 //================================================================
390 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
393 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
394 if (mWxGUIHtmlBrowser->GoTo(s))
396 //EED mwxNotebook->ChangeSelection(1);
397 // mwxNotebook->SetSelection(1);
401 // std::cout << "ERROR html"<<std::endl;
404 //================================================================
406 //================================================================
407 bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
409 size_t s = target.length();
410 if ((s>3) && (target[s-1]=='s')
411 && (target[s-2]=='b')
412 && (target[s-3]=='b')
413 && (target[s-4]=='.'))
415 mWxGUITextEditor->Open(target);
420 //================================================================
422 void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event,
425 bool checked = event.IsChecked();
426 bool shown = m_mgr.GetPane(w).IsShown();
427 // std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
430 m_mgr.GetPane(w).Show(checked);
436 //================================================================
437 void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
439 OnMenuWindowsCheck(event,mWxGUITextEditor);
441 //================================================================
443 //================================================================
444 void WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
446 OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
448 //================================================================
450 //================================================================
451 void WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
453 OnMenuWindowsCheck(event,mWxGUIOutputMessages);
455 //================================================================
457 //================================================================
458 void WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
460 OnMenuWindowsCheck(event,mWxGUICommand);
462 //================================================================
464 //================================================================
465 void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
467 // TO DO : Save it into ConfigurationFile
468 // m_mgr.SavePerspective();
470 //================================================================
473 //================================================================
474 void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
476 std::cout << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
479 //================================================================
482 //================================================================
483 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
484 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
485 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
486 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
487 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
488 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
489 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
490 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
491 EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
492 EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
493 EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
494 EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
495 EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
496 // EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
498 //================================================================
503 #endif //_USE_WXWIDGETS_