1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
6 Date: $Date: 2008/04/24 12:56:39 $
7 Version: $Revision: 1.10 $
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 "bbtkWxGUIConsole.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,
61 //================================================================
62 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
63 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
65 // m_mgr = new wxAuiManager(this);
66 m_mgr.SetManagedWindow(this);
68 mInterpreter = bbtk::Interpreter::New();
69 mInterpreter->SetUser(this);
70 mInterpreter->SetCommandLine(true);
71 mInterpreter->SetThrow(false);
74 wxInitAllImageHandlers();
76 wxMenu *menuFile = new wxMenu;
77 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
79 wxMenu *menuAbout = new wxMenu;
80 menuAbout->Append( ID_Menu_About, _T("&About...") );
82 wxMenu *menuTools = new wxMenu;
83 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
84 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
85 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
86 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
87 menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
88 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
91 wxMenuBar *menuBar = new wxMenuBar;
92 menuBar->Append( menuFile, _T("&File") );
93 menuBar->Append( menuTools, _T("&Tools") );
94 menuBar->Append( menuAbout, _T("About") );
96 SetMenuBar( menuBar );
99 SetStatusText( _T("Welcome to bbi !") );
104 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
106 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
107 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
108 mwxNotebook = new wxAuiNotebook(this,
112 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
114 mwxPageCommand = new wxPanel(mwxNotebook,-1);
115 mwxPageHelp = new wxPanel(mwxNotebook,-1);
118 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
120 mwxPageCommand->SetAutoLayout(true);
121 mwxPageCommand->SetSizer(cmdsizer);
122 cmdsizer->Fit(mwxPageCommand);
123 cmdsizer->SetSizeHints(mwxPageCommand);
125 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
127 mwxPageHelp->SetAutoLayout(true);
128 mwxPageHelp->SetSizer(helpsizer);
129 helpsizer->Fit(mwxPageHelp);
130 helpsizer->SetSizeHints(mwxPageHelp);
132 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
133 //EED wxSize(1200,0));
136 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
137 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
138 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
139 wxBitmap bmp_run(cc_run_xpm);
140 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
141 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
146 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
148 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
150 mWxGUICommand->SetFocus();
152 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
153 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
156 // Creates the parent window of all bbtk windows as a child of this
157 Wx::CreateTopWindow(this,true);
158 // Add the method OnWxSignal as a Wx::Signal observer
159 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
163 //EED SetSizer(sizer);
165 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
166 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
167 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
175 //================================================================
177 //================================================================
178 WxGUIConsole::~WxGUIConsole()
182 //================================================================
184 //================================================================
185 void WxGUIConsole::OnWxSignal()
187 if ((!Wx::TopWindowExists())&&(!IsShown()))
189 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
193 //================================================================
195 //================================================================
196 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
200 mWxGUIOutputMessages->Print(s,wxRED);
202 if ( mInterpreter->InterpretLine( command ) ==
203 Interpreter::Interpreter_QUIT )
208 //================================================================
210 //================================================================
211 /// Runs the interpretation of a file
212 bool WxGUIConsole::InterpretFile( const std::string& filename)
214 if ( mInterpreter->InterpretFile(filename) ==
215 Interpreter::Interpreter_ERROR )
221 //================================================================
223 //================================================================
224 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
226 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
227 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
228 size_t s = filename.length();
230 Interpreter::Pointer I = Interpreter::New();
232 if ((s>3) && (filename[s-1]=='s')
233 && (filename[s-2]=='b')
234 && (filename[s-3]=='b')
235 && (filename[s-4]=='.'))
237 std::string tmp("Executing ");
239 SetStatusText(std2wx(tmp));
240 I->InterpretFile(filename);
244 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
248 //================================================================
250 //================================================================
251 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
255 //================================================================
258 //================================================================
259 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
263 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
264 _T("About ..."), wxOK | wxICON_INFORMATION,
267 //================================================================
270 //================================================================
271 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
273 std::string commandStr;
274 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
276 commandStr = "notepad.exe ";
278 commandStr = "gedit ";
280 commandStr = commandStr + configFile;
281 std::cout << "system: " << commandStr << std::endl;
282 system ( commandStr.c_str() );
284 //================================================================
287 //================================================================
288 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
290 std::string command("toolsbbtk/appli/CreatePackage");
292 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
293 Interpreter::Pointer I = Interpreter::New();
294 I->InterpretFile(command);
296 //================================================================
299 //================================================================
300 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
302 std::string command("toolsbbtk/appli/CreateBlackBox");
303 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
304 Interpreter::Pointer I = Interpreter::New();
305 I->InterpretFile(command);
307 //================================================================
309 //================================================================
310 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
312 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
315 std::string strappli="start ";
317 std::string strappli="gnome-open ";
319 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
320 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
321 std::string strcommand = strcommand0 + " && " + strcommand1;
322 std::cout << "system: " << strcommand << std::endl;
323 system ( strcommand.c_str() );
326 //================================================================
328 //================================================================
329 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
331 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
334 std::string strappli="start ";
336 std::string strappli="gnome-open ";
338 std::string strcommand0 = "cd \"" + doc_path+"\"";
339 std::string strcommand1 = strappli + "index.html";
340 std::string strcommand = strcommand0 + " && " + strcommand1;
341 std::cout << "system: " << strcommand << std::endl;
342 system ( strcommand.c_str() );
345 //================================================================
349 //================================================================
350 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
353 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
354 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
355 Interpreter* I = new Interpreter;
356 I->InterpretLine( "exec freeze");
357 I->InterpretLine( "include *");
358 I->InterpretLine( "help packages");
359 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
360 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
361 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
362 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
366 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
367 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
368 std::string bbdoc_path = doc_path+"/bbdoc";
369 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
371 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
373 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
374 std::string strcommand2 = "\""+bin_path+"/bbi\" -n "+make_index_path;
376 std::string strcommand3 = "move index*.html ../.";
378 std::string strcommand3 = "mv index*.html ../.";
381 std::string strcommand = strcommand1 +" && "+
385 std::cout << "system: " << strcommand0 << std::endl;
386 std::cout << "system: " << strcommand << std::endl;
388 system ( strcommand0.c_str() );
389 system ( strcommand.c_str() );
391 //================================================================
394 //================================================================
395 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
398 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
399 if (mWxGUIHtmlBrowser->GoTo(s))
401 //EED mwxNotebook->ChangeSelection(1);
402 mwxNotebook->SetSelection(1);
406 // std::cout << "ERROR html"<<std::endl;
409 //================================================================
411 //================================================================
412 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
413 bool WxGUIConsole::Show(bool show)
415 Wx::AutoDestroyTopWindow(!show);
418 //================================================================
420 //================================================================
421 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
422 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
423 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
424 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
425 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
426 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
427 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
428 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
429 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
430 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
432 //================================================================
437 #endif //_USE_WXWIDGETS_