1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
5 Date: $Date: 2009/05/28 08:12:06 $
6 Version: $Revision: 1.16 $
7 =========================================================================*/
9 /* ---------------------------------------------------------------------
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
14 * This software is governed by the CeCILL-B license under French law and
15 * abiding by the rules of distribution of free software. You can use,
16 * modify and/ or redistribute the software under the terms of the CeCILL-B
17 * license as circulated by CEA, CNRS and INRIA at the following URL
18 * http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
19 * or in the file LICENSE.txt.
21 * As a counterpart to the access to the source code and rights to copy,
22 * modify and redistribute granted by the license, users are provided only
23 * with a limited warranty and the software's author, the holder of the
24 * economic rights, and the successive licensors have only limited
27 * The fact that you are presently reading this means that you have had
28 * knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */
33 * \brief Short description in one line
35 * Long description which
36 * can span multiple lines
48 #ifdef _USE_WXWIDGETS_
51 #include "bbtkWxGUIConsole.h"
52 #include "bbtkWxBlackBox.h"
53 #include "bbtkConfigurationFile.h"
54 #include "bbtkWxStreamRedirector.h"
57 #include "icons/cc_run.xpm"
67 ID_Menu_CreatePackage,
68 ID_Menu_CreateBlackBox,
69 ID_Menu_ShowImageGraph,
76 //================================================================
77 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
78 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
80 // m_mgr = new wxAuiManager(this);
81 m_mgr.SetManagedWindow(this);
83 mInterpreter = bbtk::Interpreter::New();
84 mInterpreter->SetUser(this);
85 mInterpreter->SetCommandLine(true);
86 mInterpreter->SetThrow(false);
89 wxInitAllImageHandlers();
91 wxMenu *menuFile = new wxMenu;
92 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
94 wxMenu *menuAbout = new wxMenu;
95 menuAbout->Append( ID_Menu_About, _T("&About...") );
97 wxMenu *menuTools = new wxMenu;
98 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
99 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
100 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
101 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
102 menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
103 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
106 wxMenuBar *menuBar = new wxMenuBar;
107 menuBar->Append( menuFile, _T("&File") );
108 menuBar->Append( menuTools, _T("&Tools") );
109 menuBar->Append( menuAbout, _T("About") );
111 SetMenuBar( menuBar );
114 SetStatusText( _T("Welcome to bbi !") );
119 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
121 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
122 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
123 mwxNotebook = new wxAuiNotebook(this,
127 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
129 mwxPageCommand = new wxPanel(mwxNotebook,-1);
130 mwxPageHelp = new wxPanel(mwxNotebook,-1);
133 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
135 mwxPageCommand->SetAutoLayout(true);
136 mwxPageCommand->SetSizer(cmdsizer);
137 cmdsizer->Fit(mwxPageCommand);
138 cmdsizer->SetSizeHints(mwxPageCommand);
140 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
142 mwxPageHelp->SetAutoLayout(true);
143 mwxPageHelp->SetSizer(helpsizer);
144 helpsizer->Fit(mwxPageHelp);
145 helpsizer->SetSizeHints(mwxPageHelp);
147 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
148 //EED wxSize(1200,0));
151 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
152 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
153 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
154 wxBitmap bmp_run(cc_run_xpm);
155 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
156 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
161 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
163 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
165 mWxGUICommand->SetFocus();
167 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
168 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
171 // Set the parent window of all bbtk windows as a child of this
172 // bbtk::Wx::SetTopWindowParent(this);
173 bbtk::Wx::SetTopWindow(this);
174 // Top Window Auto Destroys when no more black box window alive
175 // : this is the default
176 // bbtk::Wx::SetAutoDestroyTopWindow(true);
177 // Add the method OnWxSignal as a Wx::Signal observer
178 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
182 //EED SetSizer(sizer);
184 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
185 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
186 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
194 //================================================================
196 //================================================================
197 WxGUIConsole::~WxGUIConsole()
201 //================================================================
203 //================================================================
204 void WxGUIConsole::OnClose(wxCloseEvent& event)
206 bbtkDebugMessage("widget",9,"bbi::OnClose()"<<std::endl);
207 //Wx::SetWindowsHaveBeenDestroyedByParent();
208 //mInterpreter.reset();
209 wxWindowList& list = GetChildren();
210 wxWindowList::iterator iter;
211 for (iter = list.begin(); iter != list.end(); ++iter)
217 //================================================================
219 //================================================================
220 void WxGUIConsole::OnWxSignal()
222 if ((!bbtk::Wx::IsSomeWindowAlive())&&(!IsShown()))
224 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
226 wxWindowList& list = GetChildren();
227 wxWindowList::iterator iter;
228 for (iter = list.begin(); iter != list.end(); ++iter)
236 //================================================================
238 //================================================================
239 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
243 mWxGUIOutputMessages->Print(s,wxRED);
245 if ( mInterpreter->InterpretLine( command ) ==
246 Interpreter::Interpreter_QUIT )
251 //================================================================
253 //================================================================
254 /// Runs the interpretation of a file
255 bool WxGUIConsole::InterpretFile( const std::string& filename)
257 if ( mInterpreter->InterpretFile(filename) ==
258 Interpreter::Interpreter_ERROR )
264 //================================================================
266 //================================================================
267 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
269 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
270 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
271 size_t s = filename.length();
273 Interpreter::Pointer I = Interpreter::New();
275 if ((s>3) && (filename[s-1]=='s')
276 && (filename[s-2]=='b')
277 && (filename[s-3]=='b')
278 && (filename[s-4]=='.'))
280 std::string tmp("Executing ");
282 SetStatusText(std2wx(tmp));
283 I->InterpretFile(filename);
287 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
291 //================================================================
293 //================================================================
294 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
298 //================================================================
301 //================================================================
302 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
306 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
307 _T("About ..."), wxOK | wxICON_INFORMATION,
310 //================================================================
313 //================================================================
314 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
316 std::string commandStr;
317 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
319 commandStr = "notepad.exe ";
321 commandStr = "gedit ";
323 commandStr = commandStr + configFile;
324 std::cout << "system: " << commandStr << std::endl;
325 system ( commandStr.c_str() );
327 //================================================================
330 //================================================================
331 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
333 std::string command("toolsbbtk/appli/GUICreatePackage");
335 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
336 Interpreter::Pointer I = Interpreter::New();
337 I->InterpretFile(command);
339 //================================================================
342 //================================================================
343 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
345 std::string command("toolsbbtk/appli/GUICreateBlackBox");
346 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
347 Interpreter::Pointer I = Interpreter::New();
348 I->InterpretFile(command);
350 //================================================================
352 //================================================================
353 void WxGUIConsole::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 strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
363 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
364 std::string strcommand = strcommand0 + " && " + strcommand1;
365 std::cout << "system: " << strcommand << std::endl;
366 system ( strcommand.c_str() );
369 //================================================================
371 //================================================================
372 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
374 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
377 std::string strappli="start ";
379 std::string strappli="gnome-open ";
381 std::string strcommand0 = "cd \"" + doc_path+"\"";
382 std::string strcommand1 = strappli + "index.html";
383 std::string strcommand = strcommand0 + " && " + strcommand1;
384 std::cout << "system: " << strcommand << std::endl;
385 system ( strcommand.c_str() );
388 //================================================================
392 //================================================================
393 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
396 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
397 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
398 Interpreter* I = new Interpreter;
399 I->InterpretLine( "exec freeze");
400 I->InterpretLine( "include *");
401 I->InterpretLine( "help packages");
402 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
403 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
404 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
405 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
409 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
410 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
411 std::string bbdoc_path = doc_path+"/bbdoc";
412 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
414 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
416 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
417 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
419 std::string strcommand3 = "move index*.html ../.";
421 std::string strcommand3 = "mv index*.html ../.";
424 std::string strcommand = strcommand1 +" && "+
428 std::cout << "system: " << strcommand0 << std::endl;
429 std::cout << "system: " << strcommand << std::endl;
431 system ( strcommand0.c_str() );
432 system ( strcommand.c_str() );
434 //================================================================
437 //================================================================
438 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
441 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
442 if (mWxGUIHtmlBrowser->GoTo(s))
444 //EED mwxNotebook->ChangeSelection(1);
445 mwxNotebook->SetSelection(1);
449 // std::cout << "ERROR html"<<std::endl;
452 //================================================================
454 //================================================================
455 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
457 bool WxGUIConsole::Show(bool show)
459 // bbtk::Wx::SetAutoDestroyTopWindow(!show);
460 return wxFrame::Show(show);
462 //================================================================
464 //================================================================
465 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
466 EVT_CLOSE( WxGUIConsole::OnClose)
467 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
468 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
469 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
470 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
471 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
472 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
473 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
474 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
475 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
477 //================================================================
482 #endif //_USE_WXWIDGETS_