]> Creatis software - bbtk.git/blobdiff - kernel/src/bbtkWxGUIScriptingInterface.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
index 9952d89991724e99721f2e112e581a30a7fded09..8654ed2ce0acfefb380a8ebbe2871b6ca026034d 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/21 11:46:41 $
-  Version:   $Revision: 1.1 $
+  Date:      $Date: 2008/03/21 14:59:39 $
+  Version:   $Revision: 1.2 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -95,101 +95,61 @@ namespace bbtk
     CreateStatusBar();
     SetStatusText( _T("Welcome to bbi !") );
     
-
-    /*
-    m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
-                  Name(wxT("test4")).Caption(wxT("Pane Caption")).
-                  Left());
-    */
-
-   //==============
-    // Notebook
-    
-    //    wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
-    
-//EED    wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
-//    mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
-/*
-    mwxNotebook = new wxAuiNotebook(this,  
-                                    -1,
-                                    wxPoint(0, 0),
-                                    wxSize(500,500),
-                                    wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
-    
-    mwxPageCommand = new wxPanel(mwxNotebook,-1);        
-    mwxPageHelp = new wxPanel(mwxNotebook,-1);    
-    
-    
-    wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
-    
-    mwxPageCommand->SetAutoLayout(true);    
-    mwxPageCommand->SetSizer(cmdsizer);
-    cmdsizer->Fit(mwxPageCommand);
-    cmdsizer->SetSizeHints(mwxPageCommand);
-
-    wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
-    
-    mwxPageHelp->SetAutoLayout(true);    
-    mwxPageHelp->SetSizer(helpsizer);
-    helpsizer->Fit(mwxPageHelp);
-    helpsizer->SetSizeHints(mwxPageHelp);
-*/ 
-    mWxGUITextEditor = new WxGUITextEditor(this);
+    //
+    mWxGUITextEditor = new WxGUITextEditor(this,this);
     mWxGUITextEditor->SetFileNameFilter("*.bbs");
 
-      mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this, //mwxPageHelp,
-                                            //EED                                wxSize(1200,0));
-                                            wxSize(200,0));
-
-    //    mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
-    //   helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
-    //    helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0,  wxEXPAND  );
-    
-    wxBitmap bmp_run(cc_run_xpm);
-    mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run")  );
-    // helpsizer->Add( mwxButtonRun, 0, wxALL, 5  );
+    mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
 
+    /*    
+         wxBitmap bmp_run(cc_run_xpm);
+         mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run")  );
+    */
   
-    //==============
-    // Command page 
     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
 
     mWxGUICommand = new WxGUICommand(this,this);
    
-    //    mWxGUICommand->SetFocus();
-
-    //    cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
-    //    cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
+    mWxGUICommand->SetFocus();
 
-        
     // Creates and sets the parent window of all bbtk windows
     wxWindow* top = new wxPanel(this,-1);//,_T("top"));
     top->Hide();
     Wx::SetTopWindow(top);
     
 
-    // Layout
-//EED    SetSizer(sizer);
-/*
-    mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
-    mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
-*/
-
+    //
     m_mgr.AddPane(mWxGUITextEditor,
                  wxAuiPaneInfo().Name(wxT("editor_content"))
-                 .Top());     
+                 .Caption(wxT("Files"))
+                 .MinimizeButton(true)
+                 .MaximizeButton(true)
+                 .Center()
+                 );     
+    m_mgr.AddPane(mWxGUIHtmlBrowser,
+                 wxAuiPaneInfo().Name(wxT("browser_content"))
+                 .Caption(wxT("Help"))
+                 .MinimizeButton(true)
+                 .MaximizeButton(true)
+                 .Right()
+                 );
     m_mgr.AddPane(mWxGUIOutputMessages,
                  wxAuiPaneInfo().Name(wxT("messages_content"))
                  .Caption(wxT("Messages"))
-                 .Center());     
-    m_mgr.AddPane(mWxGUIHtmlBrowser,
-                 wxAuiPaneInfo().Name(wxT("browser_content"))
-                 .Right());     
+                 .MinimizeButton(true)
+                 .MaximizeButton(true)
+                 .Bottom()
+                 );
     m_mgr.AddPane(mWxGUICommand,
                  wxAuiPaneInfo().Name(wxT("command_content"))
-                 .Bottom());     
-    m_mgr.AddPane(mwxButtonRun,
-                 wxAuiPaneInfo().Name(wxT("button_run_content")));     
+                 .Caption(wxT("Command"))
+                 .MinimizeButton(true)
+                 .MaximizeButton(true)
+                 .Bottom()
+                 .Position(1)
+);     
+    //    m_mgr.AddPane(mwxButtonRun,
+    //           wxAuiPaneInfo().Name(wxT("button_run_content")));     
 
 
 //.PaneBorder(false)); 
@@ -224,7 +184,7 @@ namespace bbtk
     mWxGUIOutputMessages->Print(s,wxRED);
 
     if (  mInterpreter->InterpretLine( command ) == 
-         Interpreter::QUIT )
+         Interpreter::Interpreter_QUIT )
       {
        Close(true); 
       }
@@ -236,7 +196,7 @@ namespace bbtk
   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
   { 
     if ( mInterpreter->InterpretFile(filename) ==
-        Interpreter::ERROR ) 
+        Interpreter::Interpreter_ERROR ) 
       {
        return false;
       }
@@ -245,13 +205,36 @@ namespace bbtk
   //================================================================
  
   //================================================================
-  void WxGUIScriptingInterface::OnButtonRun(wxCommandEvent& WXUNUSED(event))
+  void WxGUIScriptingInterface::WxGUITextEditorRun()
   {
-    wxString per = m_mgr.SavePerspective();
-    std::cout << per<< std::endl;
+    //    wxString per = m_mgr.SavePerspective();
+    //    std::cout << per<< std::endl;
+
+    //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
+    std::stringstream* buf = new std::stringstream;
+    (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
 
-//    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
-    std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
+    mInterpreter->SetThrow(true);
+    try 
+      {
+       mInterpreter->InterpretBuffer(buf);
+      }
+    catch (InterpreterError e)
+      {
+       std::cerr << "* IERROR : "<<e.GetMessage()<<std::endl; 
+       if (e.IsInScriptFile())  
+         std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl;
+       std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;
+       int lev = bbtk::MessageManager::GetMessageLevel("Error");
+       if (lev > 0) {
+         std::cerr << "* Exception thrown : "<<std::endl;
+         std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;
+         std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl;
+       }         
+      }
+    /*
+   //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
+    std::string filename = mWxGUITextEditor->GetCurrentPage();//wx2std(temp);
     size_t s = filename.length();
 
     Interpreter* I = new Interpreter;
@@ -272,6 +255,7 @@ namespace bbtk
       }
     
     delete I;
+    */
   }
   //================================================================  
 
@@ -390,7 +374,7 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
     if (mWxGUIHtmlBrowser->GoTo(s)) 
       {
 //EED  mwxNotebook->ChangeSelection(1);
-       mwxNotebook->SetSelection(1);
+//     mwxNotebook->SetSelection(1);
       }
     else 
       {
@@ -399,7 +383,23 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
   } 
   //================================================================  
   
-    
+  //================================================================  
+  bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
+  {
+    std::cout << "OnLink"<<std::endl; 
+    size_t s = target.length();
+    if ((s>3) && (target[s-1]=='s')
+       && (target[s-2]=='b')
+       && (target[s-3]=='b')
+       && (target[s-4]=='.'))
+      {
+       mWxGUITextEditor->Open(target);
+       return false;
+      }
+    return true;
+  }
+  //================================================================  
+
   //================================================================  
   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
@@ -409,7 +409,7 @@ printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
     EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
-    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
+  //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
     END_EVENT_TABLE()
   //================================================================