1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
6 Date: $Date: 2008/07/24 14:37:06 $
7 Version: $Revision: 1.14 $
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 // Set the parent window of all bbtk windows as a child of this
157 bbtk::Wx::SetTopWindowParent(this);
158 // Top Window Auto Destroys when no more black box window alive
159 // : this is the default
160 // bbtk::Wx::SetAutoDestroyTopWindow(true);
161 // Add the method OnWxSignal as a Wx::Signal observer
162 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
166 //EED SetSizer(sizer);
168 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
169 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
170 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
178 //================================================================
180 //================================================================
181 WxGUIConsole::~WxGUIConsole()
185 //================================================================
187 //================================================================
188 void WxGUIConsole::OnWxSignal()
190 if ((!Wx::TopWindowExists())&&(!IsShown()))
192 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
196 //================================================================
198 //================================================================
199 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
203 mWxGUIOutputMessages->Print(s,wxRED);
205 if ( mInterpreter->InterpretLine( command ) ==
206 Interpreter::Interpreter_QUIT )
211 //================================================================
213 //================================================================
214 /// Runs the interpretation of a file
215 bool WxGUIConsole::InterpretFile( const std::string& filename)
217 if ( mInterpreter->InterpretFile(filename) ==
218 Interpreter::Interpreter_ERROR )
224 //================================================================
226 //================================================================
227 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
229 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
230 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
231 size_t s = filename.length();
233 Interpreter::Pointer I = Interpreter::New();
235 if ((s>3) && (filename[s-1]=='s')
236 && (filename[s-2]=='b')
237 && (filename[s-3]=='b')
238 && (filename[s-4]=='.'))
240 std::string tmp("Executing ");
242 SetStatusText(std2wx(tmp));
243 I->InterpretFile(filename);
247 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
251 //================================================================
253 //================================================================
254 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
258 //================================================================
261 //================================================================
262 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
266 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
267 _T("About ..."), wxOK | wxICON_INFORMATION,
270 //================================================================
273 //================================================================
274 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
276 std::string commandStr;
277 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
279 commandStr = "notepad.exe ";
281 commandStr = "gedit ";
283 commandStr = commandStr + configFile;
284 std::cout << "system: " << commandStr << std::endl;
285 system ( commandStr.c_str() );
287 //================================================================
290 //================================================================
291 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
293 std::string command("toolsbbtk/appli/GUICreatePackage");
295 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
296 Interpreter::Pointer I = Interpreter::New();
297 I->InterpretFile(command);
299 //================================================================
302 //================================================================
303 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
305 std::string command("toolsbbtk/appli/GUICreateBlackBox");
306 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
307 Interpreter::Pointer I = Interpreter::New();
308 I->InterpretFile(command);
310 //================================================================
312 //================================================================
313 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
315 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
318 std::string strappli="start ";
320 std::string strappli="gnome-open ";
322 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
323 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
324 std::string strcommand = strcommand0 + " && " + strcommand1;
325 std::cout << "system: " << strcommand << std::endl;
326 system ( strcommand.c_str() );
329 //================================================================
331 //================================================================
332 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
334 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
337 std::string strappli="start ";
339 std::string strappli="gnome-open ";
341 std::string strcommand0 = "cd \"" + doc_path+"\"";
342 std::string strcommand1 = strappli + "index.html";
343 std::string strcommand = strcommand0 + " && " + strcommand1;
344 std::cout << "system: " << strcommand << std::endl;
345 system ( strcommand.c_str() );
348 //================================================================
352 //================================================================
353 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
356 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
357 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
358 Interpreter* I = new Interpreter;
359 I->InterpretLine( "exec freeze");
360 I->InterpretLine( "include *");
361 I->InterpretLine( "help packages");
362 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
363 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
364 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
365 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
369 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
370 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
371 std::string bbdoc_path = doc_path+"/bbdoc";
372 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
374 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
376 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
377 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
379 std::string strcommand3 = "move index*.html ../.";
381 std::string strcommand3 = "mv index*.html ../.";
384 std::string strcommand = strcommand1 +" && "+
388 std::cout << "system: " << strcommand0 << std::endl;
389 std::cout << "system: " << strcommand << std::endl;
391 system ( strcommand0.c_str() );
392 system ( strcommand.c_str() );
394 //================================================================
397 //================================================================
398 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
401 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
402 if (mWxGUIHtmlBrowser->GoTo(s))
404 //EED mwxNotebook->ChangeSelection(1);
405 mwxNotebook->SetSelection(1);
409 // std::cout << "ERROR html"<<std::endl;
412 //================================================================
414 //================================================================
415 // Overloaded Show method to handle bbtk::Wx::TopWindow auto-destruction
416 bool WxGUIConsole::Show(bool show)
418 bbtk::Wx::SetAutoDestroyTopWindow(!show);
419 return wxFrame::Show(show);
421 //================================================================
423 //================================================================
424 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
425 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
426 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
427 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
428 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
429 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
430 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
431 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
432 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
433 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
435 //================================================================
440 #endif //_USE_WXWIDGETS_