00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00048 #ifdef _USE_WXWIDGETS_
00049
00050 #include <iostream>
00051 #include "bbtkWxGUIConsole.h"
00052 #include "bbtkWxBlackBox.h"
00053 #include "bbtkConfigurationFile.h"
00054 #include "bbtkWxStreamRedirector.h"
00055
00056
00057 #include "icons/cc_run.xpm"
00058
00059 namespace bbtk
00060 {
00061
00062 enum
00063 {
00064 ID_Menu_Quit = 1,
00065 ID_Menu_About,
00066 ID_Menu_EditConfig,
00067 ID_Menu_CreatePackage,
00068 ID_Menu_CreateBlackBox,
00069 ID_Menu_ShowImageGraph,
00070 ID_Menu_ShowHTMLDoc,
00071 ID_Menu_CreateIndex,
00072 ID_Button_Run
00073 };
00074
00075
00076
00077 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
00078 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
00079 {
00080
00081 m_mgr.SetManagedWindow(this);
00082
00083 mInterpreter = bbtk::Interpreter::New();
00084 mInterpreter->SetUser(this);
00085 mInterpreter->SetCommandLine(true);
00086 mInterpreter->SetThrow(false);
00087
00088
00089 wxInitAllImageHandlers();
00090
00091 wxMenu *menuFile = new wxMenu;
00092 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
00093
00094 wxMenu *menuAbout = new wxMenu;
00095 menuAbout->Append( ID_Menu_About, _T("&About...") );
00096
00097 wxMenu *menuTools = new wxMenu;
00098 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
00099 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
00100 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
00101 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
00102 menuTools->Append( ID_Menu_ShowHTMLDoc, _T("Show &HTML documentation") );
00103 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
00104
00105
00106 wxMenuBar *menuBar = new wxMenuBar;
00107 menuBar->Append( menuFile, _T("&File") );
00108 menuBar->Append( menuTools, _T("&Tools") );
00109 menuBar->Append( menuAbout, _T("About") );
00110
00111 SetMenuBar( menuBar );
00112
00113 CreateStatusBar();
00114 SetStatusText( _T("Welcome to bbi !") );
00115
00116
00117
00118
00119
00120
00121
00122
00123 mwxNotebook = new wxAuiNotebook(this,
00124 -1,
00125 wxPoint(0, 0),
00126 wxSize(500,500),
00127 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
00128
00129 mwxPageCommand = new wxPanel(mwxNotebook,-1);
00130 mwxPageHelp = new wxPanel(mwxNotebook,-1);
00131
00132
00133 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
00134
00135 mwxPageCommand->SetAutoLayout(true);
00136 mwxPageCommand->SetSizer(cmdsizer);
00137 cmdsizer->Fit(mwxPageCommand);
00138 cmdsizer->SetSizeHints(mwxPageCommand);
00139
00140 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
00141
00142 mwxPageHelp->SetAutoLayout(true);
00143 mwxPageHelp->SetSizer(helpsizer);
00144 helpsizer->Fit(mwxPageHelp);
00145 helpsizer->SetSizeHints(mwxPageHelp);
00146
00147 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
00148
00149 wxSize(200,0));
00150
00151
00152 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
00153
00154 wxBitmap bmp_run(cc_run_xpm);
00155 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);
00156 helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
00157
00158
00159
00160
00161 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
00162
00163 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
00164
00165 mWxGUICommand->SetFocus();
00166
00167 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
00168 cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
00169
00170
00171
00172
00173 bbtk::Wx::SetTopWindow(this);
00174
00175
00176
00177
00178 bbtkAddWxSignalObserver(WxGUIConsole::OnWxSignal);
00179
00180
00181
00182
00183
00184 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
00185 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
00186 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
00187 m_mgr.Update();
00188
00189 SetAutoLayout(true);
00190 Layout();
00191
00192
00193 }
00194
00195
00196
00197 WxGUIConsole::~WxGUIConsole()
00198 {
00199 m_mgr.UnInit();
00200 }
00201
00202
00203
00204 void WxGUIConsole::OnClose(wxCloseEvent& event)
00205 {
00206 bbtkDebugMessage("widget",9,"bbi::OnClose()"<<std::endl);
00207
00208
00209 wxWindowList& list = GetChildren();
00210 wxWindowList::iterator iter;
00211 for (iter = list.begin(); iter != list.end(); ++iter)
00212 {
00213 (*iter)->Close();
00214 }
00215 this->Destroy();
00216 }
00217
00218
00219
00220 void WxGUIConsole::OnWxSignal()
00221 {
00222 if ((!bbtk::Wx::IsSomeWindowAlive())&&(!IsShown()))
00223 {
00224 bbtkDebugMessage("wx",2," --> bbtk top window destroyed and WxGUIConsole not shown => destructing"<<std::endl);
00225
00226
00227
00228
00229
00230
00231
00232
00233 Close();
00234 }
00235 }
00236
00237
00238
00239 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
00240 {
00241 std::string s("> ");
00242 s += command + "\n";
00243 mWxGUIOutputMessages->Print(s,wxRED);
00244
00245 if ( mInterpreter->InterpretLine( command ) ==
00246 Interpreter::Interpreter_QUIT )
00247 {
00248 Close(true);
00249 }
00250 }
00251
00252
00253
00255 bool WxGUIConsole::InterpretFile( const std::string& filename)
00256 {
00257 if ( mInterpreter->InterpretFile(filename) ==
00258 Interpreter::Interpreter_ERROR )
00259 {
00260 return false;
00261 }
00262 return true;
00263 }
00264
00265
00266
00267 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
00268 {
00269
00270 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();
00271 size_t s = filename.length();
00272
00273 Interpreter::Pointer I = Interpreter::New();
00274
00275 if ((s>3) && (filename[s-1]=='s')
00276 && (filename[s-2]=='b')
00277 && (filename[s-3]=='b')
00278 && (filename[s-4]=='.'))
00279 {
00280 std::string tmp("Executing ");
00281 tmp += filename;
00282 SetStatusText(std2wx(tmp));
00283 I->InterpretFile(filename);
00284 }
00285 else
00286 {
00287 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
00288 }
00289
00290 }
00291
00292
00293
00294 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
00295 {
00296 Close(true);
00297 }
00298
00299
00300
00301
00302 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
00303 {
00304 m_mgr.Update();
00305 Refresh();
00306 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
00307 _T("About ..."), wxOK | wxICON_INFORMATION,
00308 this);
00309 }
00310
00311
00312
00313
00314 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
00315 {
00316 std::string commandStr;
00317 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
00318 #ifdef WIN32
00319 commandStr = "notepad.exe ";
00320 #else
00321 commandStr = "gedit ";
00322 #endif
00323 commandStr = commandStr + configFile;
00324 std::cout << "system: " << commandStr << std::endl;
00325 system ( commandStr.c_str() );
00326 }
00327
00328
00329
00330
00331 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
00332 {
00333 std::string command("toolsbbtk/appli/GUICreatePackage");
00334
00335 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00336 Interpreter::Pointer I = Interpreter::New();
00337 I->InterpretFile(command);
00338 }
00339
00340
00341
00342
00343 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
00344 {
00345 std::string command("toolsbbtk/appli/GUICreateBlackBox");
00346 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00347 Interpreter::Pointer I = Interpreter::New();
00348 I->InterpretFile(command);
00349 }
00350
00351
00352
00353 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
00354 {
00355 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
00356
00357 #if defined(WIN32)
00358 std::string strappli="start ";
00359 #else
00360 std::string strappli="gnome-open ";
00361 #endif
00362 std::string strcommand0 = "cd \"" + default_temp_dir+"/temp_dir/" +"\"";
00363 std::string strcommand1 = strappli + "workspace_workspacePrototype.png";
00364 std::string strcommand = strcommand0 + " && " + strcommand1;
00365 std::cout << "system: " << strcommand << std::endl;
00366 system ( strcommand.c_str() );
00367
00368 }
00369
00370
00371
00372 void WxGUIConsole::OnMenuShowHTMLDoc(wxCommandEvent& WXUNUSED(event))
00373 {
00374 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
00375
00376 #if defined(WIN32)
00377 std::string strappli="start ";
00378 #else
00379 std::string strappli="gnome-open ";
00380 #endif
00381 std::string strcommand0 = "cd \"" + doc_path+"\"";
00382 std::string strcommand1 = strappli + "index.html";
00383 std::string strcommand = strcommand0 + " && " + strcommand1;
00384 std::cout << "system: " << strcommand << std::endl;
00385 system ( strcommand.c_str() );
00386
00387 }
00388
00389
00390
00391
00392
00393 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
00394 {
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409 std::string bin_path = ConfigurationFile::GetInstance().Get_bin_path();
00410 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
00411 std::string bbdoc_path = doc_path+"/bbdoc";
00412 std::string make_index_path = "\"" + bbdoc_path+"/make-index.bbs\"";
00413
00414 std::string strcommand0 = "cd "+bbdoc_path+" && mkdir tmp && cd tmp";
00415
00416 std::string strcommand1 = "cd "+bbdoc_path+"/tmp";
00417 std::string strcommand2 = "\""+bin_path+"/bbi\" -N "+make_index_path;
00418 #ifdef WIN32
00419 std::string strcommand3 = "move index*.html ../.";
00420 #else
00421 std::string strcommand3 = "mv index*.html ../.";
00422 #endif
00423
00424 std::string strcommand = strcommand1 +" && "+
00425 strcommand2 +" && "+
00426 strcommand3;
00427
00428 std::cout << "system: " << strcommand0 << std::endl;
00429 std::cout << "system: " << strcommand << std::endl;
00430
00431 system ( strcommand0.c_str() );
00432 system ( strcommand.c_str() );
00433 }
00434
00435
00436
00437
00438 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
00439 {
00440 std::string s(page);
00441
00442 if (mWxGUIHtmlBrowser->GoTo(s))
00443 {
00444
00445 mwxNotebook->SetSelection(1);
00446 }
00447 else
00448 {
00449
00450 }
00451 }
00452
00453
00454
00455
00456
00457 bool WxGUIConsole::Show(bool show)
00458 {
00459
00460 return wxFrame::Show(show);
00461 }
00462
00463
00464
00465 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
00466 EVT_CLOSE( WxGUIConsole::OnClose)
00467 EVT_MENU(ID_Menu_Quit , WxGUIConsole::OnMenuQuit)
00468 EVT_MENU(ID_Menu_About , WxGUIConsole::OnMenuAbout)
00469 EVT_MENU(ID_Menu_EditConfig , WxGUIConsole::OnMenuEditConfig)
00470 EVT_MENU(ID_Menu_CreatePackage , WxGUIConsole::OnMenuCreatePackage)
00471 EVT_MENU(ID_Menu_CreateBlackBox , WxGUIConsole::OnMenuCreateBlackBox)
00472 EVT_MENU(ID_Menu_ShowImageGraph , WxGUIConsole::OnMenuShowImageGraph)
00473 EVT_MENU(ID_Menu_ShowHTMLDoc , WxGUIConsole::OnMenuShowHTMLDoc)
00474 EVT_MENU(ID_Menu_CreateIndex , WxGUIConsole::OnMenuCreateIndex)
00475 EVT_BUTTON(ID_Button_Run , WxGUIConsole::OnButtonRun )
00476 END_EVENT_TABLE()
00477
00478
00479 }
00480
00481
00482 #endif //_USE_WXWIDGETS_