1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
6 Date: $Date: 2008/04/23 14:49:28 $
7 Version: $Revision: 1.8 $
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,
60 //================================================================
61 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
62 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
64 // m_mgr = new wxAuiManager(this);
65 m_mgr.SetManagedWindow(this);
67 mInterpreter = bbtk::Interpreter::New();
68 mInterpreter->SetUser(this);
69 mInterpreter->SetCommandLine(true);
70 mInterpreter->SetThrow(false);
73 wxInitAllImageHandlers();
75 wxMenu *menuFile = new wxMenu;
76 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
78 wxMenu *menuAbout = new wxMenu;
79 menuAbout->Append( ID_Menu_About, _T("&About...") );
81 wxMenu *menuTools = new wxMenu;
82 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
83 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
84 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
85 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
86 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
89 wxMenuBar *menuBar = new wxMenuBar;
90 menuBar->Append( menuFile, _T("&File") );
91 menuBar->Append( menuTools, _T("&Tools") );
92 menuBar->Append( menuAbout, _T("About") );
94 SetMenuBar( menuBar );
97 SetStatusText( _T("Welcome to bbi !") );
102 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
104 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
105 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
106 mwxNotebook = new wxAuiNotebook(this,
110 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
112 mwxPageCommand = new wxPanel(mwxNotebook,-1);
113 mwxPageHelp = new wxPanel(mwxNotebook,-1);
116 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
118 mwxPageCommand->SetAutoLayout(true);
119 mwxPageCommand->SetSizer(cmdsizer);
120 cmdsizer->Fit(mwxPageCommand);
121 cmdsizer->SetSizeHints(mwxPageCommand);
123 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
125 mwxPageHelp->SetAutoLayout(true);
126 mwxPageHelp->SetSizer(helpsizer);
127 helpsizer->Fit(mwxPageHelp);
128 helpsizer->SetSizeHints(mwxPageHelp);
130 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
131 //EED wxSize(1200,0));
134 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
135 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
136 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
137 wxBitmap bmp_run(cc_run_xpm);
138 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
139 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
144 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
146 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
148 mWxGUICommand->SetFocus();
150 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
151 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
154 // Creates and sets the parent window of all bbtk windows
156 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
158 Wx::SetTopWindow(top);
160 Wx::CreateInvisibleTopWindow(this);
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 //================================================================
185 //================================================================
186 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
190 mWxGUIOutputMessages->Print(s,wxRED);
192 if ( mInterpreter->InterpretLine( command ) ==
193 Interpreter::Interpreter_QUIT )
198 //================================================================
200 //================================================================
201 /// Runs the interpretation of a file
202 bool WxGUIConsole::InterpretFile( const std::string& filename)
204 if ( mInterpreter->InterpretFile(filename) ==
205 Interpreter::Interpreter_ERROR )
211 //================================================================
213 //================================================================
214 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
216 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
217 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
218 size_t s = filename.length();
220 Interpreter::Pointer I = Interpreter::New();
222 if ((s>3) && (filename[s-1]=='s')
223 && (filename[s-2]=='b')
224 && (filename[s-3]=='b')
225 && (filename[s-4]=='.'))
227 std::string tmp("Executing ");
229 SetStatusText(std2wx(tmp));
230 I->InterpretFile(filename);
234 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
238 //================================================================
240 //================================================================
241 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
245 //================================================================
248 //================================================================
249 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
253 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
254 _T("About ..."), wxOK | wxICON_INFORMATION,
257 //================================================================
260 //================================================================
261 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
263 std::string commandStr;
264 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
266 commandStr = "notepad.exe ";
268 commandStr = "gedit ";
270 commandStr = commandStr + configFile;
271 std::cout << "system: " << commandStr << std::endl;
272 system ( commandStr.c_str() );
274 //================================================================
277 //================================================================
278 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
280 std::string command("toolsbbtk/appli/CreatePackage");
282 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
283 Interpreter::Pointer I = Interpreter::New();
284 I->InterpretFile(command);
286 //================================================================
289 //================================================================
290 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
292 std::string command("toolsbbtk/appli/CreateBlackBox");
293 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
294 Interpreter::Pointer I = Interpreter::New();
295 I->InterpretFile(command);
297 //================================================================
299 //================================================================
300 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
302 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
305 std::string strappli="start ";
307 std::string strappli="gnome-open ";
309 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
310 std::cout << "system: " << strcommand << std::endl;
311 system ( strcommand.c_str() );
314 //================================================================
317 //================================================================
318 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
321 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
322 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
323 Interpreter* I = new Interpreter;
324 I->InterpretLine( "exec freeze");
325 I->InterpretLine( "include *");
326 I->InterpretLine( "help packages");
327 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
328 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
329 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
330 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
334 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
335 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
336 std::string bbdoc_path = doc_path+"/bbdoc";
337 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
339 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
341 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
342 std::string strcommand2 = "\""+bin_path+"/bbi\" -n "+make_index_path;
344 std::string strcommand3 = "move index*.html ../.";
346 std::string strcommand3 = "mv index*.html ../.";
349 std::string strcommand = strcommand1 +" && "+
353 std::cout << "system: " << strcommand0 << std::endl;
354 std::cout << "system: " << strcommand << std::endl;
356 system ( strcommand0.c_str() );
357 system ( strcommand.c_str() );
359 //================================================================
362 //================================================================
363 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
366 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
367 if (mWxGUIHtmlBrowser->GoTo(s))
369 //EED mwxNotebook->ChangeSelection(1);
370 mwxNotebook->SetSelection(1);
374 // std::cout << "ERROR html"<<std::endl;
377 //================================================================
380 //================================================================
381 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
382 EVT_MENU(ID_Menu_Quit, WxGUIConsole::OnMenuQuit)
383 EVT_MENU(ID_Menu_About, WxGUIConsole::OnMenuAbout)
384 EVT_MENU(ID_Menu_EditConfig, WxGUIConsole::OnMenuEditConfig)
385 EVT_MENU(ID_Menu_CreatePackage, WxGUIConsole::OnMenuCreatePackage)
386 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIConsole::OnMenuCreateBlackBox)
387 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIConsole::OnMenuShowImageGraph)
388 EVT_MENU(ID_Menu_CreateIndex, WxGUIConsole::OnMenuCreateIndex)
389 EVT_BUTTON(ID_Button_Run, WxGUIConsole::OnButtonRun )
391 //================================================================
396 #endif //_USE_WXWIDGETS_