2 # ---------------------------------------------------------------------
4 # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
6 # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7 # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8 # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
10 # This software is governed by the CeCILL-B license under French law and
11 # abiding by the rules of distribution of free software. You can use,
12 # modify and/ or redistribute the software under the terms of the CeCILL-B
13 # license as circulated by CEA, CNRS and INRIA at the following URL
14 # http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15 # or in the file LICENSE.txt.
17 # As a counterpart to the access to the source code and rights to copy,
18 # modify and redistribute granted by the license, users are provided only
19 # with a limited warranty and the software's author, the holder of the
20 # economic rights, and the successive licensors have only limited
23 # The fact that you are presently reading this means that you have had
24 # knowledge of the CeCILL-B license and that you accept its terms.
25 # ------------------------------------------------------------------------ */
28 /*=========================================================================
30 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
32 Date: $Date: 2012/11/16 08:49:01 $
33 Version: $Revision: 1.18 $
34 =========================================================================*/
40 * \brief Short description in one line
42 * Long description which
43 * can span multiple lines
55 #ifdef _USE_WXWIDGETS_
58 #include "bbtkWxGUIConsole.h"
59 #include "bbtkWxBlackBox.h"
60 #include "bbtkConfigurationFile.h"
61 #include "bbtkWxStreamRedirector.h"
64 #include "icons/cc_run.xpm"
74 ID_Menu_CreatePackage,
75 ID_Menu_CreateBlackBox,
76 ID_Menu_ShowImageGraph,
83 //================================================================
84 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
85 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
87 // m_mgr = new wxAuiManager(this);
88 m_mgr.SetManagedWindow(this);
90 mInterpreter = bbtk::Interpreter::New();
91 mInterpreter->SetUser(this);
92 mInterpreter->SetCommandLine(true);
93 mInterpreter->SetThrow(false);
96 wxInitAllImageHandlers();
98 wxMenu *menuFile = new wxMenu;
99 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
101 wxMenu *menuAbout = new wxMenu;
102 menuAbout->Append( ID_Menu_About, _T("&About...") );
104 wxMenu *menuTools = new wxMenu;
105 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
106 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
107 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
108 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
109 menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
110 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
113 wxMenuBar *menuBar = new wxMenuBar;
114 menuBar->Append( menuFile, _T("&File") );
115 menuBar->Append( menuTools, _T("&Tools") );
116 menuBar->Append( menuAbout, _T("About") );
118 SetMenuBar( menuBar );
121 SetStatusText( _T("Welcome to bbi !") );
126 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
128 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
129 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
130 mwxNotebook = new wxAuiNotebook(this,
134 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
136 mwxPageCommand = new wxPanel(mwxNotebook,-1);
137 mwxPageHelp = new wxPanel(mwxNotebook,-1);
140 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
142 mwxPageCommand->SetAutoLayout(true);
143 mwxPageCommand->SetSizer(cmdsizer);
144 cmdsizer->Fit(mwxPageCommand);
145 cmdsizer->SetSizeHints(mwxPageCommand);
147 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
149 mwxPageHelp->SetAutoLayout(true);
150 mwxPageHelp->SetSizer(helpsizer);
151 helpsizer->Fit(mwxPageHelp);
152 helpsizer->SetSizeHints(mwxPageHelp);
154 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
155 //EED wxSize(1200,0));
158 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
159 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
160 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
161 wxBitmap bmp_run(cc_run_xpm);
162 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
163 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
168 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
170 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
172 mWxGUICommand->SetFocus();
174 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
175 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
178 // Set the parent window of all bbtk windows as a child of this
179 // bbtk::Wx::SetTopWindowParent(this);
180 bbtk::Wx::SetTopWindow(this);
181 // Top Window Auto Destroys when no more black box window alive
182 // : this is the default
183 // bbtk::Wx::SetAutoDestroyTopWindow(true);
184 // Add the method OnWxSignal as a Wx::Signal observer
185 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
189 //EED SetSizer(sizer);
191 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
192 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
193 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
201 //================================================================
203 //================================================================
204 WxGUIConsole::~WxGUIConsole()
208 //================================================================
210 //================================================================
211 void WxGUIConsole::OnClose(wxCloseEvent& event)
213 bbtkDebugMessage("widget",9,"bbi::OnClose()"<<std::endl);
214 //Wx::SetWindowsHaveBeenDestroyedByParent();
215 //mInterpreter.reset();
216 wxWindowList& list = GetChildren();
217 wxWindowList::iterator iter;
218 for (iter = list.begin(); iter != list.end(); ++iter)
224 //================================================================
226 //================================================================
227 void WxGUIConsole::OnWxSignal()
229 if ((!bbtk::Wx::IsSomeWindowAlive())&&(!IsShown()))
231 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
233 wxWindowList& list = GetChildren();
234 wxWindowList::iterator iter;
235 for (iter = list.begin(); iter != list.end(); ++iter)
243 //================================================================
245 //================================================================
246 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
250 mWxGUIOutputMessages->Print(s,wxRED);
252 if ( mInterpreter->InterpretLine( command ) ==
253 Interpreter::Interpreter_QUIT )
258 //================================================================
260 //================================================================
261 /// Runs the interpretation of a file
262 bool WxGUIConsole::InterpretFile( const std::string& filename)
264 if ( mInterpreter->InterpretFile(filename) ==
265 Interpreter::Interpreter_ERROR )
271 //================================================================
273 //================================================================
274 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
276 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
277 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
278 size_t s = filename.length();
280 Interpreter::Pointer I = Interpreter::New();
282 if ((s>3) && (filename[s-1]=='s')
283 && (filename[s-2]=='b')
284 && (filename[s-3]=='b')
285 && (filename[s-4]=='.'))
287 std::string tmp("Executing ");
289 SetStatusText(std2wx(tmp));
290 I->InterpretFile(filename);
294 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
298 //================================================================
300 //================================================================
301 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
305 //================================================================
308 //================================================================
309 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
313 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS 2008"),
314 _T("About ..."), wxOK | wxICON_INFORMATION,
317 //================================================================
320 //================================================================
321 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
323 std::string commandStr;
324 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
326 commandStr = "notepad.exe ";
328 commandStr = "gedit ";
330 commandStr = commandStr + configFile;
331 std::cout << "system: " << commandStr << std::endl;
332 system ( commandStr.c_str() );
334 //================================================================
337 //================================================================
338 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
340 std::string command("toolsbbtk/appli/GUICreatePackage");
342 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
343 Interpreter::Pointer I = Interpreter::New();
344 I->InterpretFile(command);
346 //================================================================
349 //================================================================
350 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
352 std::string command("toolsbbtk/appli/GUICreateBlackBox");
353 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
354 Interpreter::Pointer I = Interpreter::New();
355 I->InterpretFile(command);
357 //================================================================
359 //================================================================
360 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
362 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
365 std::string strappli="start ";
367 std::string strappli="gnome-open ";
369 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
370 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
371 std::string strcommand = strcommand0 + " && " + strcommand1;
372 std::cout << "system: " << strcommand << std::endl;
373 system ( strcommand.c_str() );
376 //================================================================
378 //================================================================
379 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
381 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
384 std::string strappli="start ";
386 std::string strappli="gnome-open ";
388 std::string strcommand0 = "cd \"" + doc_path+"\"";
389 std::string strcommand1 = strappli + "index.html";
390 std::string strcommand = strcommand0 + " && " + strcommand1;
391 std::cout << "system: " << strcommand << std::endl;
392 system ( strcommand.c_str() );
395 //================================================================
399 //================================================================
400 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
403 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
404 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
405 Interpreter* I = new Interpreter;
406 I->InterpretLine( "exec freeze");
407 I->InterpretLine( "include *");
408 I->InterpretLine( "help packages");
409 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
410 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
411 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
412 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
416 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
417 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
418 std::string bbdoc_path = doc_path+"/bbdoc";
419 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
421 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
423 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
424 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
426 std::string strcommand3 = "move index*.html ../.";
428 std::string strcommand3 = "mv index*.html ../.";
431 std::string strcommand = strcommand1 +" && "+
435 std::cout << "system: " << strcommand0 << std::endl;
436 std::cout << "system: " << strcommand << std::endl;
438 system ( strcommand0.c_str() );
439 system ( strcommand.c_str() );
441 //================================================================
444 //================================================================
445 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
448 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
449 if (mWxGUIHtmlBrowser->GoTo(s))
451 //EED mwxNotebook->ChangeSelection(1);
452 mwxNotebook->SetSelection(1);
456 // std::cout << "ERROR html"<<std::endl;
459 //================================================================
461 //================================================================
462 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
464 bool WxGUIConsole::Show(bool show)
466 // bbtk::Wx::SetAutoDestroyTopWindow(!show);
467 return wxFrame::Show(show);
469 //================================================================
471 //================================================================
472 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
473 EVT_CLOSE( WxGUIConsole::OnClose)
474 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
475 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
476 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
477 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
478 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
479 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
480 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
481 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
482 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
484 //================================================================
489 #endif //_USE_WXWIDGETS_