1 /*=========================================================================
3 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
5 Date: $Date: 2008/10/17 08:18:15 $
6 Version: $Revision: 1.15 $
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 // Top Window Auto Destroys when no more black box window alive
174 // : this is the default
175 // bbtk::Wx::SetAutoDestroyTopWindow(true);
176 // Add the method OnWxSignal as a Wx::Signal observer
177 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
181 //EED SetSizer(sizer);
183 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
184 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
185 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
193 //================================================================
195 //================================================================
196 WxGUIConsole::~WxGUIConsole()
200 //================================================================
202 //================================================================
203 void WxGUIConsole::OnWxSignal()
205 if ((!Wx::TopWindowExists())&&(!IsShown()))
207 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
211 //================================================================
213 //================================================================
214 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
218 mWxGUIOutputMessages->Print(s,wxRED);
220 if ( mInterpreter->InterpretLine( command ) ==
221 Interpreter::Interpreter_QUIT )
226 //================================================================
228 //================================================================
229 /// Runs the interpretation of a file
230 bool WxGUIConsole::InterpretFile( const std::string& filename)
232 if ( mInterpreter->InterpretFile(filename) ==
233 Interpreter::Interpreter_ERROR )
239 //================================================================
241 //================================================================
242 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
244 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
245 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
246 size_t s = filename.length();
248 Interpreter::Pointer I = Interpreter::New();
250 if ((s>3) && (filename[s-1]=='s')
251 && (filename[s-2]=='b')
252 && (filename[s-3]=='b')
253 && (filename[s-4]=='.'))
255 std::string tmp("Executing ");
257 SetStatusText(std2wx(tmp));
258 I->InterpretFile(filename);
262 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
266 //================================================================
268 //================================================================
269 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
273 //================================================================
276 //================================================================
277 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
281 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
282 _T("About ..."), wxOK | wxICON_INFORMATION,
285 //================================================================
288 //================================================================
289 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
291 std::string commandStr;
292 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
294 commandStr = "notepad.exe ";
296 commandStr = "gedit ";
298 commandStr = commandStr + configFile;
299 std::cout << "system: " << commandStr << std::endl;
300 system ( commandStr.c_str() );
302 //================================================================
305 //================================================================
306 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
308 std::string command("toolsbbtk/appli/GUICreatePackage");
310 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
311 Interpreter::Pointer I = Interpreter::New();
312 I->InterpretFile(command);
314 //================================================================
317 //================================================================
318 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
320 std::string command("toolsbbtk/appli/GUICreateBlackBox");
321 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
322 Interpreter::Pointer I = Interpreter::New();
323 I->InterpretFile(command);
325 //================================================================
327 //================================================================
328 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
330 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
333 std::string strappli="start ";
335 std::string strappli="gnome-open ";
337 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
338 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
339 std::string strcommand = strcommand0 + " && " + strcommand1;
340 std::cout << "system: " << strcommand << std::endl;
341 system ( strcommand.c_str() );
344 //================================================================
346 //================================================================
347 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
349 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
352 std::string strappli="start ";
354 std::string strappli="gnome-open ";
356 std::string strcommand0 = "cd \"" + doc_path+"\"";
357 std::string strcommand1 = strappli + "index.html";
358 std::string strcommand = strcommand0 + " && " + strcommand1;
359 std::cout << "system: " << strcommand << std::endl;
360 system ( strcommand.c_str() );
363 //================================================================
367 //================================================================
368 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
371 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
372 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
373 Interpreter* I = new Interpreter;
374 I->InterpretLine( "exec freeze");
375 I->InterpretLine( "include *");
376 I->InterpretLine( "help packages");
377 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
378 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
379 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
380 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
384 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
385 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
386 std::string bbdoc_path = doc_path+"/bbdoc";
387 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
389 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
391 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
392 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
394 std::string strcommand3 = "move index*.html ../.";
396 std::string strcommand3 = "mv index*.html ../.";
399 std::string strcommand = strcommand1 +" && "+
403 std::cout << "system: " << strcommand0 << std::endl;
404 std::cout << "system: " << strcommand << std::endl;
406 system ( strcommand0.c_str() );
407 system ( strcommand.c_str() );
409 //================================================================
412 //================================================================
413 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
416 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
417 if (mWxGUIHtmlBrowser->GoTo(s))
419 //EED mwxNotebook->ChangeSelection(1);
420 mwxNotebook->SetSelection(1);
424 // std::cout << "ERROR html"<<std::endl;
427 //================================================================
429 //================================================================
430 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
431 bool WxGUIConsole::Show(bool show)
433 bbtk::Wx::SetAutoDestroyTopWindow(!show);
434 return wxFrame::Show(show);
436 //================================================================
438 //================================================================
439 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
440 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
441 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
442 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
443 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
444 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
445 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
446 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
447 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
448 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
450 //================================================================
455 #endif //_USE_WXWIDGETS_