bbtkWxGUIScriptingInterface.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/21 14:38:31 $
00006   Version:   $Revision: 1.31 $
00007 =========================================================================*/
00008 
00009 /* ---------------------------------------------------------------------
00010 
00011 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
00012 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
00013 *
00014 *  This software is governed by the CeCILL-B license under French law and 
00015 *  abiding by the rules of distribution of free software. You can  use, 
00016 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
00017 *  license as circulated by CEA, CNRS and INRIA at the following URL 
00018 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
00019 *  or in the file LICENSE.txt.
00020 *
00021 *  As a counterpart to the access to the source code and  rights to copy,
00022 *  modify and redistribute granted by the license, users are provided only
00023 *  with a limited warranty  and the software's author,  the holder of the
00024 *  economic rights,  and the successive licensors  have only  limited
00025 *  liability. 
00026 *
00027 *  The fact that you are presently reading this means that you have had
00028 *  knowledge of the CeCILL-B license and that you accept its terms.
00029 * ------------------------------------------------------------------------ */                                                                         
00030    
00031 
00048 #ifdef _USE_WXWIDGETS_
00049 
00050 #include <iostream>     
00051 #include "bbtkWxGUIScriptingInterface.h"
00052 #include "bbtkWxBlackBox.h"
00053 #include "bbtkConfigurationFile.h"
00054 #include "bbtkWxStreamRedirector.h"
00055 #include "bbtkUtilities.h"
00056 
00057 #include <wx/tipwin.h>
00058 
00059 //#include "icons/cc_run.xpm"
00060 
00061 namespace bbtk
00062 {
00063 
00064     enum
00065     {
00066       ID_Menu_Quit = 1,
00067       ID_Menu_About,
00068       ID_Menu_EditConfig,
00069       ID_Menu_CreatePackage,
00070       ID_Menu_CreateBlackBox,
00071       ID_Menu_ShowImageGraph,
00072       ID_Menu_RegeneratePackageDoc,
00073       ID_Menu_RegenerateBoxesLists,
00074       ID_Menu_RegenerateAll,
00075       ID_Menu_PlugPackage,
00076       ID_Menu_Windows_Files,
00077       ID_Menu_Windows_Help,
00078       ID_Menu_Windows_Messages,
00079       ID_Menu_Windows_Command,
00080       ID_Menu_Windows_Save,
00081       ID_Menu_Windows_PackageBrowser
00082       //      ID_Button_Run
00083     };
00084     
00085   
00086   //================================================================
00087   WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
00088     : wxFrame((wxFrame *)parent, -1, _T("bbStudio"), 
00089               wxDefaultPosition, wxSize(1200,800) )
00090   {     
00091     //    m_mgr = new wxAuiManager(this);
00092     m_mgr.SetManagedWindow(this);
00093     
00094     mInterpreter = bbtk::Interpreter::New();
00095     mInterpreter->SetUser(this);
00096     mInterpreter->SetCommandLine(true);
00097     mInterpreter->SetThrow(true);
00098     
00099     //==============
00100     // Menu
00101     wxInitAllImageHandlers();
00102     
00103     wxMenu *menuFile = new wxMenu;
00104     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
00105     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
00106     
00107     wxMenu *menuAbout = new wxMenu;
00108     menuAbout->Append( ID_Menu_About, _T("&About...") );
00109 
00110     wxMenu *menuTools = new wxMenu;
00111     menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
00112     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
00113     menuTools->Append( ID_Menu_PlugPackage, _T("&Plug package") );
00114     menuTools->AppendSeparator();
00115     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
00116     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
00117     menuTools->Append( ID_Menu_RegenerateAll,_T("Regenerate &all") );
00118     menuTools->AppendSeparator();
00119     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
00120 
00121     wxMenu *menuWindows = new wxMenu;
00122     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
00123                                  _T("Show 'files' panel") )->Check();
00124     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
00125                                  _T("Show 'help' panel") )->Check();
00126     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
00127                                  _T("Show 'messages' panel") )->Check();
00128     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
00129                                  _T("Show 'command' panel") )->Check();
00130     menuWindows->AppendSeparator();
00131     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
00132     
00133     //    menuWindows->AppendSeparator();
00134     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
00135 
00136     wxMenu *menuOptions = new wxMenu;
00137     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
00138                                                     _T("Reset before running") );
00139     mwxMenuItemReset->Check();
00140 
00141     wxMenuBar *menuBar = new wxMenuBar;
00142     menuBar->Append( menuFile, _T("&File") );
00143     menuBar->Append( menuTools, _T("&Tools") );
00144     menuBar->Append( menuOptions, _T("&Options") );
00145     menuBar->Append( menuWindows, _T("&Windows") );
00146     menuBar->Append( menuAbout, _T("About") );
00147     
00148     SetMenuBar( menuBar );
00149     
00150     //=== 
00151     // Status bar
00152     CreateStatusBar();
00153     SetStatusText( _T("Welcome to bbStudio !") );
00154     
00155     //===
00156     // Panes (Files, Messages, Help, Command)
00157     mWxGUITextEditor = new WxGUITextEditor(this,this);
00158     mWxGUITextEditor->SetFileNameFilter("*.bbs");
00159         
00160     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
00161 
00162     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
00163 
00164     mWxGUICommand = new WxGUICommand(this,this);
00165    
00166     mWxGUICommand->SetFocus();
00167 
00168  
00169 #if NOTEBOOK
00170 
00171     mwxNotebook = new wxAuiNotebook(this,  
00172                                     -1,
00173                                     wxPoint(0, 0),
00174                                     wxSize(500,500),
00175                                     wxAUI_NB_TAB_SPLIT 
00176                                     | wxAUI_NB_TAB_MOVE
00177                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
00178                                     //| wxAUI_NB_WINDOWLIST_BUTTON
00179                                     //|wxAUI_NB_SCROLL_BUTTONS
00180                                     // | wxAUI_NB_CLOSE_BUTTON 
00181                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
00182                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
00183                                     | wxNO_BORDER);
00184   
00185 
00186     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
00187     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
00188 
00189     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
00190 
00191     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
00192 
00193 
00194     m_mgr.AddPane(mwxNotebook,
00195                   wxAuiPaneInfo().Name(wxT("nb"))
00196                   .CaptionVisible(false)
00197                   .MinimizeButton(false)
00198                   .MaximizeButton(false)
00199                   .Center()
00200                   //              .MinSize(wxSize(100,100))
00201                   );   
00202 #else 
00203 
00204     //
00205     m_mgr.AddPane(mWxGUITextEditor,
00206                   wxAuiPaneInfo().Name(wxT("editor_content"))
00207                   .Caption(wxT("Files"))
00208                   .MinimizeButton(true)
00209                   .MaximizeButton(true)
00210                   .Center()
00211                   .MinSize(wxSize(100,100))
00212                   );   
00213   
00214     m_mgr.AddPane(mWxGUIHtmlBrowser,
00215                   wxAuiPaneInfo().Name(wxT("browser_content"))
00216                   .Caption(wxT("Help"))
00217                   .MinimizeButton(true)
00218                   .MaximizeButton(true)
00219                   .Right()
00220                   .Layer(2)
00221                   .MinSize(wxSize(400,100))
00222                   );
00223 
00224     m_mgr.AddPane(mWxGUIOutputMessages,
00225                   wxAuiPaneInfo().Name(wxT("messages_content"))
00226                   .Caption(wxT("Messages"))
00227                   .MinimizeButton(true)
00228                   .MaximizeButton(true)
00229                   .Bottom()
00230                   .MinSize(wxSize(100,100))
00231                   );
00232     m_mgr.AddPane(mWxGUICommand,
00233                   wxAuiPaneInfo().Name(wxT("command_content"))
00234                   .Caption(wxT("Command"))
00235                   .MinimizeButton(true)
00236                   .MaximizeButton(true)
00237                   .Bottom()
00238                   .Layer(1)
00239                   .MinSize(wxSize(100,100))
00240                   );     
00241 #endif
00242 
00243     // parent window of all bbtk windows will be a child of this
00244     Wx::SetTopWindowParent(this);
00245     // Add the method OnWxSignal as a Wx::Signal observer 
00246     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
00247 
00248     //.PaneBorder(false)); 
00249     // Load the interface appearance saved on last closing
00250     LoadPerspective();
00251 
00252     // Done in LoadPerspective
00253     //    m_mgr.Update();
00254         
00255     SetAutoLayout(true);
00256     Layout();
00257     //    mwxNotebook->SetSelection(1);
00258     mWxGUIHtmlBrowser->GoHome();
00259 //    Refresh();
00260     m_mgr.Update();
00261     //   LoadPerspective();
00262 
00263 
00264     wxTipWindow* tip = new wxTipWindow(this,
00265                                        _T("\n                  Welcome to bbStudio !\n\n   To run a demo or example:\n     1. click on the 'Demos' or 'Examples' link\n     2. select a demo or example\n     3. click on the '[source]' link : the source file is loaded in bbStudio\n     4. click on the 'Run' button (the arrow at the bottom right of the source file)   \n"),1000);
00266     tip->CenterOnParent();
00267     tip->Show();
00268   }
00269   //================================================================
00270 
00271  //================================================================
00272   WxGUIScriptingInterface::~WxGUIScriptingInterface()
00273   {
00274     SavePerspective();
00275     m_mgr.UnInit();
00276   }
00277   //================================================================
00278 
00279   //================================================================
00280   void WxGUIScriptingInterface::Open(const std::string& filename)
00281   {
00282     mWxGUITextEditor->Open(filename);
00283   }
00284   //================================================================
00285   
00286 #define CATCH_MACRO                                                     \
00287   catch (QuitException e)                                               \
00288     {                                                                   \
00289       std::cout << "* quit exception caught"<<std::endl;                \
00290     }                                                                   \
00291   catch (InterpreterError e)                                            \
00292     {                                                                   \
00293       std::cerr << "* IERROR : "<<e.GetErrorMessage()<<std::endl;               \
00294       if (e.IsInScriptFile())                                           \
00295         std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
00296       std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
00297       int lev = bbtk::MessageManager::GetMessageLevel("Error");         \
00298       if (lev > 0) {                                                    \
00299         std::cerr << "* Exception thrown : "<<std::endl;                \
00300         std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;         \
00301         std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl;     \
00302       }                                                                 \
00303     }
00304   
00305   //================================================================
00306   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
00307   {
00308     std::string s("> ");
00309     s += command + "\n";
00310     mWxGUIOutputMessages->Print(s,wxRED);
00311     
00312     try
00313       {
00314         mInterpreter->InterpretLine( command );
00315       }
00316     CATCH_MACRO;
00317   }
00318   //================================================================
00319   
00320   //================================================================
00322   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
00323   { 
00324     try
00325       {
00326         mInterpreter->InterpretFile(filename);
00327       }
00328     CATCH_MACRO;
00329     return true;
00330   }
00331   //================================================================
00332  
00333   //================================================================
00334   void WxGUIScriptingInterface::WxGUITextEditorRun()
00335   {
00336     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
00337     std::stringstream* buf = new std::stringstream;
00338     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
00339     try 
00340       {
00341         //      std::cout << "RUN"<<std::endl;
00342         if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
00343         mInterpreter->InterpretBuffer(buf);
00344         //      std::cout << "EO RUN"<<std::endl;
00345       }
00346     CATCH_MACRO;
00347     //    std::cout << "EO RUN 3"<<std::endl;
00348   }
00349   //================================================================  
00350 
00351   //================================================================
00352   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
00353   {
00354     if (!mWxGUITextEditor->CloseAllPages()) return;
00355     Close(true);
00356   }
00357   //================================================================
00358 
00359 
00360   //================================================================
00361   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
00362   {
00363     m_mgr.Update();
00364         Refresh();
00365     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
00366                  _T("About ..."), wxOK | wxICON_INFORMATION,
00367                  this);
00368   }
00369   //================================================================
00370 
00371 
00372   //================================================================
00373   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
00374   {
00375     std::string configFile = 
00376       ConfigurationFile::GetInstance().Get_config_xml_full_path();
00377     Open(configFile);
00378   }
00379   //================================================================
00380 
00381   //================================================================
00382   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
00383   {
00384     wxBusyCursor wait;
00385     WxGUIPackageBrowser2Window *helpbrowser = new
00386       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
00387     helpbrowser->Show();
00388     
00389     /*
00390     wxBusyCursor wait;
00391     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
00392     browser->IncludeAll();
00393     */
00394 #if NOTEBOOK
00395     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
00396 #else
00397      /*
00398      m_mgr.AddPane(browser,
00399                    wxAuiPaneInfo().Name(wxT("package_brower"))
00400                    .Caption(wxT("Package browser"))
00401                    .MinimizeButton(true)
00402                    .MaximizeButton(true)
00403                    .Bottom()
00404                    .Position(1)
00405                    .MinSize(wxSize(100,100))
00406                    );     
00407      */
00408 #endif
00409   }
00410   //================================================================
00411 
00412 
00413 
00414   //================================================================
00415   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
00416   {
00417 /*
00418     std::string command("toolsbbtk/appli/GUICreatePackage");
00419     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00420   
00421         Interpreter::Pointer I = Interpreter::New();    
00422     I->InterpretFile(command);
00423 */
00424     std::string command("reset");
00425         mWxGUICommand->SendCommand(command);
00426     command = "include toolsbbtk/appli/GUICreatePackage";
00427     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00428         mWxGUICommand->SendCommand(command);
00429 
00430   }
00431   //================================================================
00432 
00433 
00434   //================================================================
00435   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
00436   {
00437           /*
00438     std::string command("toolsbbtk/appli/GUICreateBlackBox");
00439     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00440     
00441     Interpreter::Pointer I = Interpreter::New();    
00442     I->InterpretFile(command);
00443 */
00444     std::string command("reset");
00445         mWxGUICommand->SendCommand(command);
00446     command = "include toolsbbtk/appli/GUICreateBlackBox";
00447     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
00448         mWxGUICommand->SendCommand(command);
00449   }
00450   //================================================================
00451   
00452   //================================================================
00453   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
00454   {
00455     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
00456 
00457 #if defined(WIN32)
00458     std::string strappli="start ";
00459 #else
00460     std::string strappli="gnome-open ";
00461 #endif
00462     std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
00463     //  std::cout << "system: " << strcommand << std::endl;
00464     system ( strcommand.c_str() );
00465 
00466   }
00467   //================================================================
00468 
00469   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
00470   {
00471             std::string command;
00472 #if defined(WIN32)
00473         command = "\"";
00474 #endif
00475         command += ConfigurationFile::GetInstance().Get_bin_path();
00476     command += ConfigurationFile::GetInstance().Get_file_separator();
00477     command += "bbRegeneratePackageDoc";
00478 #if defined(WIN32)
00479         command += "\"";
00480 #endif
00481         command += " " + pack + " -q";
00482     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00483     
00484 
00485     if ( ! system ( command.c_str() ) )
00486       {
00487         wxMessageBox(_T("Done !"),_T("Regenerate package '")+std2wx(pack)+_T("' doc"),
00488                      wxOK | wxICON_INFORMATION);
00489       }
00490     else 
00491       {
00492         wxString err(_T("An error occured while running '"));
00493         err +=  bbtk::std2wx(command) + _T("'");
00494         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
00495       }
00496   }
00497 
00498 
00499   //================================================================
00500   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
00501   {
00502     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
00503                                       _T("Regenerate package doc"),
00504                                       _T(""));
00505     if (name.IsEmpty()) return;
00506     std::string pack = bbtk::wx2std(name);
00507     
00508         DoRegeneratePackageDoc(pack);
00509   }
00510   //================================================================
00511 
00512 
00513   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
00514   {
00515     std::string command;
00516 #if defined(WIN32)
00517         command = "\"";
00518 #endif
00519     command += ConfigurationFile::GetInstance().Get_bin_path();
00520     command += ConfigurationFile::GetInstance().Get_file_separator();
00521     command += "bbRegenerateBoxesLists";
00522 #if defined(WIN32)
00523         command += "\"";
00524 #endif
00525         command += " -q";
00526         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
00527 
00528         if ( ! system ( command.c_str() ) )
00529     {
00530        wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
00531                     wxOK | wxICON_INFORMATION);
00532      }
00533    else 
00534      {
00535        wxString err(_T("An error occured while running '"));
00536        err +=  bbtk::std2wx(command) + _T("'");
00537        wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
00538      }
00539   }
00540 
00541   //================================================================
00542   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
00543   {
00544         DoRegenerateBoxesLists();
00545   }
00546   //================================================================
00547 
00548   //================================================================
00549   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
00550   {
00551         
00552     DoRegeneratePackageDoc("-a");       
00553         DoRegenerateBoxesLists();
00554   }
00555   //================================================================
00556 
00557  
00558   //================================================================
00559   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
00560   {
00561     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
00562     wxDirDialog* FD = 
00563       new wxDirDialog( 0, 
00564                        _T("Select package directory"),
00565                        _T(""),
00566                        style);
00567     
00568     if (FD->ShowModal()==wxID_OK)
00569       {
00570         std::string path = wx2std (FD->GetPath()) ;
00571         std::string fname = path + "/bbtkPackage"; 
00572         if ( ! Utilities::FileExists( fname ) )
00573           {
00574             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
00575             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
00576             return;
00577           }
00578         
00579         std::ifstream f;
00580         f.open(fname.c_str());
00581         std::string pname;
00582         f >> pname;
00583         f.close();
00584         
00585         
00586         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
00587         
00588         DoRegeneratePackageDoc(pname);
00589         DoRegenerateBoxesLists();
00590 
00591           }     
00592   }
00593   //================================================================
00594 
00595   //================================================================
00596   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
00597   {
00598     std::string s(page);
00599     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
00600     if (mWxGUIHtmlBrowser->GoTo(s)) 
00601       {
00602 //EED   mwxNotebook->ChangeSelection(1);
00603 //      mwxNotebook->SetSelection(1);
00604       }
00605     else 
00606       {
00607          // std::cout << "ERROR html"<<std::endl;
00608       }
00609   } 
00610   //================================================================  
00611   
00612   //================================================================  
00613   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
00614   {
00615     size_t s = target.length();
00616     if ((s>3) && (target[s-1]=='s')
00617         && (target[s-2]=='b')
00618         && (target[s-3]=='b')
00619         && (target[s-4]=='.'))
00620       {
00621         mWxGUITextEditor->Open(target);
00622 #if NOTEBOOK
00623         mwxNotebook->SetSelection(0);
00624 #endif
00625         mWxGUITextEditor->SetFocus();
00626         return false;
00627       }
00628     return true;
00629   }
00630   //================================================================  
00631 
00632   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
00633                                                     wxWindow* w)
00634   {
00635     bool checked = event.IsChecked();
00636     bool shown = m_mgr.GetPane(w).IsShown();
00637     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
00638     if (checked ^ shown) 
00639       {
00640         m_mgr.GetPane(w).Show(checked);
00641         m_mgr.Update();
00642       }
00643   }
00644 
00645 
00646   //================================================================  
00647   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
00648   {
00649     OnMenuWindowsCheck(event,mWxGUITextEditor);
00650   }
00651   //================================================================  
00652 
00653   //================================================================  
00654   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
00655   {
00656     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
00657   }
00658   //================================================================  
00659 
00660   //================================================================  
00661   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
00662   {
00663     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
00664   }
00665   //================================================================  
00666 
00667   //================================================================  
00668   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
00669   {
00670     OnMenuWindowsCheck(event,mWxGUICommand);
00671   }
00672   //================================================================  
00673 
00674   //================================================================  
00675   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
00676   {
00677     SavePerspective();
00678   }
00679   //================================================================  
00680 
00681   //================================================================  
00682   void WxGUIScriptingInterface::SavePerspective()
00683   {
00684     //    std::cout  << "Saving configuration..."<<std::endl;
00685     std::string conf = wx2std(m_mgr.SavePerspective());
00686     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
00687     std::ofstream f;
00688     f.open(fname.c_str(), std::ios::out );
00689     f << conf << std::endl;
00690 
00691     //    int x,y;
00692     //    GetPosition(&x,&y);
00693     //    f << x << "  " << y << std::endl;
00694 
00695 
00696     int w,h;
00697     GetSize(&w,&h);
00698 
00699     f << w << " " << h << std::endl;
00700 
00701     f.close();
00702   }
00703   //================================================================  
00704 
00705   //================================================================  
00706   void WxGUIScriptingInterface::LoadPerspective()
00707   {
00708     std::string fname = 
00709       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
00710     if ( Utilities::FileExists( fname ))
00711       {
00712         //      std::cout  << "Loading configuration..."<<std::endl;
00713 
00714         std::ifstream f;
00715         f.open(fname.c_str());
00716         std::string conf;
00717         f >> conf;
00718 
00719         //      int x,y;
00720         //      f >> x >> y ;
00721 
00722         int w,h;
00723         f >> w >> h ;
00724 
00725         f.close();
00726         
00727         //      std::cout << conf << std::endl;
00728 
00729         //      Move(x,y);
00730         SetSize(w,h);
00731         m_mgr.LoadPerspective(std2wx(conf));
00732       }
00733     else 
00734       {
00735         m_mgr.Update();
00736       }
00737   }
00738   //================================================================  
00739 
00740   //================================================================  
00741   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
00742   {
00743     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
00744     // TO DO : Uncheck 
00745     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
00746   }
00747   //================================================================  
00748 
00749   
00750   //================================================================  
00751   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
00752     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
00753     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
00754     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
00755     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
00756     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
00757     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
00758     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
00759     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
00760     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
00761     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
00762     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
00763     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
00764     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
00765     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
00766     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
00767     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
00768     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
00769   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
00770     END_EVENT_TABLE()
00771   //================================================================
00772 
00773 } // namespace bbtk
00774 
00775 
00776 #endif //_USE_WXWIDGETS_

Generated on Wed Nov 12 11:37:08 2008 for BBTK by  doxygen 1.5.6