]> Creatis software - bbtk.git/commitdiff
*** empty log message ***
authorguigues <guigues>
Fri, 21 Mar 2008 14:59:39 +0000 (14:59 +0000)
committerguigues <guigues>
Fri, 21 Mar 2008 14:59:39 +0000 (14:59 +0000)
kernel/src/bbtkException.h
kernel/src/bbtkInterpreter.cxx
kernel/src/bbtkInterpreter.h
kernel/src/bbtkWxGUIHtmlBrowser.cxx
kernel/src/bbtkWxGUIHtmlBrowser.h
kernel/src/bbtkWxGUIScriptingInterface.cxx
kernel/src/bbtkWxGUIScriptingInterface.h
kernel/src/bbtkWxGUITextEditor.cxx
kernel/src/bbtkWxGUITextEditor.h

index 9c5c6ae45723c10543dff733af4a669487611e76..96e04a7c84da457dcd1abf2cf718d2f49606520a 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkException.h,v $
   Language:  C++
-  Date:      $Date: 2008/01/22 15:02:00 $
-  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
@@ -46,10 +46,10 @@ namespace bbtk
   {
   public:
     Exception(const std::string& object,
-             const std::string& file,
+             const std::string& source_file,
              const std::string& message) throw()
       : mObject(object),
-       mFile(file),
+       mSourceFile(source_file),
        mMessage(message)
     {}
     ~Exception() throw() {}
@@ -59,15 +59,15 @@ namespace bbtk
       int lev = bbtk::MessageManager::GetMessageLevel("Error");
       if (lev > 0) {
        std::cerr << "* OBJECT : " <<mObject<<std::endl;
-       std::cerr << "* FILE   : " <<mFile<<std::endl;
+       std::cerr << "* FILE   : " <<mSourceFile<<std::endl;
       }
     }
     const std::string& GetObject() const { return mObject; }
-    const std::string& GetFile() const { return mFile; }
+    const std::string& GetSourceFile() const { return mSourceFile; }
     const std::string& GetMessage() const { return mMessage; }
   private:
     std::string mObject;
-    std::string mFile;
+    std::string mSourceFile;
     std::string mMessage;
   };
 
index 82edfcd775c46d173dc99d500d29f9d0492dfcf0..544729156a10cb88e6d430f6a174648a5194c666 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.cxx,v $ $
   Language:  C++
-  Date:      $Date: 2008/03/21 11:44:37 $
-  Version:   $Revision: 1.51 $
+  Date:      $Date: 2008/03/21 14:59:39 $
+  Version:   $Revision: 1.52 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -296,6 +296,143 @@ bufferNb =0;
   //=======================================================================
 
 
+  InterpreterError::InterpreterError( const std::string& message,
+                                     bool in_script_file,
+                                     const std::string& script_file,
+                                     int script_line 
+                                     )
+    : Exception("Interpreter",0,message),
+      mInScriptFile(in_script_file),
+      mScriptFile(script_file),
+      mScriptLine(script_line)
+  {
+  }
+  InterpreterError::InterpreterError( const Exception& excep,
+                     bool in_script_file,
+                     const std::string& script_file,
+                     int script_line 
+                     )
+    : Exception(excep),
+      mInScriptFile(in_script_file),
+      mScriptFile(script_file),
+      mScriptLine(script_line)
+  {
+  }
+  //=======================================================================
+  void Interpreter::CatchBbtkException( const bbtk::Exception& e )
+  {
+    if (mThrow) 
+      {
+       bool in_script = false;
+       std::string file("");
+       int line = 0;
+       if (mFileName.size()) {
+         std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+         if (fs!=0) in_script = true;    
+         file = mFileName.back();
+         line = mLine.back();
+       }    
+       throw InterpreterError(e,in_script,file,line);
+      }
+    else
+      {
+       std::stringstream mess;
+       mess << "* ERROR : "<<e.GetMessage()<<std::endl;
+       if (mFileName.size()) {
+         mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+         mess << "* LINE  : "<<mLine.back()<<std::endl;
+       }    
+       std::cerr << mess.str();
+      }
+  }
+  //=======================================================================
+  
+  //=======================================================================
+  void Interpreter::CatchStdException( const std::exception& e )
+  {  
+    if (mThrow) 
+      {
+       bool in_script = false;
+       std::string file("");
+       int line = 0;
+       if (mFileName.size()) {
+         std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+         if (fs!=0) in_script = true;    
+         file = mFileName.back();
+         line = mLine.back();
+       }    
+       throw InterpreterError(e.what(),in_script,file,line);
+      }
+    else
+      {
+       std::stringstream mess;
+       mess << "* ERROR : "<<e.what()<<std::endl;
+       if (mFileName.size()) {
+         mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+         mess << "* LINE  : "<<mLine.back()<<std::endl;
+       }    
+       std::cerr << mess.str();
+      }
+  }
+  //=======================================================================
+
+  //=======================================================================
+  void Interpreter::CatchUnknownException()
+  {
+    if (mThrow) 
+      {
+       bool in_script = false;
+       std::string file("");
+       int line = 0;
+       if (mFileName.size()) {
+         std::ifstream* fs = dynamic_cast<std::ifstream*>(mFile.back());
+         if (fs!=0) in_script = true;    
+         file = mFileName.back();
+         line = mLine.back();
+       }    
+       throw InterpreterError("Unknown exception caught",
+                                  in_script,file,line);
+      }
+    else
+      {
+       std::stringstream mess;
+       mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)" 
+            << std::endl;
+       if (mFileName.size()) {
+         mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
+         mess << "* LINE  : "<<mLine.back()<<std::endl;
+       }    
+       std::cerr << mess.str();
+      }
+  }
+  //=======================================================================
+
+  //=======================================================================
+
+#define CATCH_MACRO                            \
+  catch (QuitException e)                      \
+    {                                          \
+      status = Interpreter_QUIT;               \
+      if (mThrow) throw QuitException();       \
+    }                                          \
+  catch (bbtk::Exception e)                    \
+    {                                          \
+      status = Interpreter_ERROR;              \
+      CatchBbtkException(e);                   \
+    }                                          \
+  catch (std::exception& e)                    \
+    {                                          \
+      status = Interpreter_ERROR;              \
+      CatchStdException(e);                    \
+    }                                          \
+  catch (...)                                  \
+    {                                          \
+      status = Interpreter_ERROR;              \
+      CatchUnknownException();                 \
+    }                                          
+  //=======================================================================
+   
+
   //=======================================================================
   /**
    *  
@@ -309,7 +446,6 @@ bufferNb =0;
 
     ExitStatus status = Interpreter_OK;
 
-  
     try 
     {
       SwitchToFile(filename);
@@ -334,55 +470,7 @@ bufferNb =0;
        CloseCurrentFile();
       }
     }
-    catch (QuitException e) 
-    {
-      status = Interpreter_QUIT;
-      if (mThrow) throw QuitException();
-    }
-    catch (bbtk::Exception e) 
-    {
-      std::stringstream mess;
-      mess << "* ERROR : "<<e.GetMessage()<<std::endl;
-      if (mFileName.size()) {
-         mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-         mess << "* LINE  : "<<mLine.back()<<std::endl;
-      }    
-      status = Interpreter_ERROR;
-      if (mThrow) 
-       throw bbtk::Exception("Interpreter","",mess.str());
-      else
-       std::cerr << mess.str();
-
-    }
-    catch (std::exception& e) 
-    {
-       std::stringstream mess;
-       mess << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
-       if (mFileName.size()) {
-          mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-          mess << "* LINE  : "<<mLine.back()<<std::endl;
-       }  
-      status = Interpreter_ERROR;
-      if (mThrow) 
-       throw bbtk::Exception("Interpreter","",mess.str());
-      else
-       std::cerr << mess.str();  
-    }  
-    catch (...)
-      {
-        std::stringstream mess;
-       mess << "* UNDEFINED ERROR (not a bbtk nor a std exception)"
-            <<std::endl;
-       if (mFileName.size()) {
-          mess << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-          mess << "* LINE  : "<<mLine.back()<<std::endl;
-       }    
-       status = Interpreter_ERROR;
-       if (mThrow) 
-         throw bbtk::Exception("Interpreter","",mess.str());
-       else
-         std::cerr << mess.str();   
-      }
+    CATCH_MACRO;
     
     CloseAllFiles();
     bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretFile(\""<<filename<<"\")"<<std::endl);
@@ -434,41 +522,7 @@ bufferNb =0;
        CloseCurrentFile();
       }
     }
-    catch (QuitException e) 
-      { 
-       status = Interpreter_QUIT;
-      }
-    catch (bbtk::Exception e) 
-      {
-       std::cerr << "* ERROR : "<<e.GetMessage()<<std::endl;
-       if (mFileName.size()) 
-         {
-           std::cerr << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-           std::cerr << "* LINE  : "<<mLine.back()<<std::endl;
-         }    
-       status = Interpreter_ERROR;
-      }
-    catch (std::exception& e) 
-      {
-       std::cerr << "* ERROR : "<<e.what()<<" (not in bbtk)"<<std::endl;
-       if (mFileName.size()) 
-         {
-           std::cerr << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-           std::cerr << "* LINE  : "<<mLine.back()<<std::endl;
-         }    
-       status = Interpreter_ERROR;
-    }  
-    catch (...)
-      {
-       std::cerr 
-         << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
-       if (mFileName.size()) 
-         {
-           std::cerr << "* FILE  : \""<<mFileName.back()<<"\""<<std::endl;
-           std::cerr << "* LINE  : "<<mLine.back()<<std::endl;
-         }    
-       status = Interpreter_ERROR;
-      }
+    CATCH_MACRO;
     
     CloseAllFiles();
     bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretBuffer()"<<std::endl);
@@ -492,7 +546,9 @@ bufferNb =0;
       bool insideComment = false;
       InterpretLine(line, insideComment);
     }
-    catch (QuitException e) 
+    CATCH_MACRO;
+    /*
+   catch (QuitException e) 
       { 
       status = Interpreter_QUIT;
       }
@@ -512,7 +568,7 @@ bufferNb =0;
          << "* UNDEFINED ERROR (not a bbtk nor a std exception)"<<std::endl;
        status = Interpreter_ERROR;
       }
-    
+    */
 
     bbtkDebugMessage("Interpreter",9,"EO Interpreter::InterpretLine()"
                     <<std::endl);
@@ -1176,6 +1232,7 @@ void Interpreter::SwitchToStream( std::stringstream* stream )
     mFileName.push_back(fullPathScriptName);
     mIncludeFileName.push_back(includeScriptName);
     mLine.push_back(0);
+
     return;
   }
 
index 93fad6de074a72a0df994e9f2281ba1415f0afba..c53e76b4acba1d5fc297bb976a67398c554040b3 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkInterpreter.h,v $ $
   Language:  C++
-  Date:      $Date: 2008/03/21 11:44:37 $
-  Version:   $Revision: 1.19 $
+  Date:      $Date: 2008/03/21 14:59:39 $
+  Version:   $Revision: 1.20 $
 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -53,6 +53,33 @@ namespace bbtk
 
   };
 
+  ///
+  class BBTK_EXPORT InterpreterError : public Exception
+  {
+  public:
+    InterpreterError( const std::string& message,
+                     bool in_script_file,
+                     const std::string& script_file,
+                     int script_line 
+                     );
+    InterpreterError( const Exception& excep,
+                     bool in_script_file,
+                     const std::string& script_file,
+                     int script_line 
+                     );
+    ~InterpreterError() throw() {}
+
+    bool IsInScriptFile() const { return mInScriptFile; }
+    const std::string& GetScriptFile() const { return mScriptFile; }
+    int GetScriptLine() const { return mScriptLine; }
+  private:
+    bool mInScriptFile;
+    std::string mScriptFile;
+    int mScriptLine;
+  };
+
+
+  /// 
   class BBTK_EXPORT Interpreter
   {
 
@@ -231,6 +258,11 @@ namespace bbtk
     void LoadScript( std::string fullPathScriptName,
                     std::string includeScriptName);
 
+    /// 
+    void CatchBbtkException( const bbtk::Exception& e );
+    void CatchStdException( const std::exception& e );
+    void CatchUnknownException();
+
   private:
 
     //==================================================================
index abc4835e484acf84178adc03529c096e4f753a27..4cfe254f3e6a9752f4d4144f81cfe4ee4cfd2bb1 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIHtmlBrowser.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/03/20 15:27:57 $
-  Version:   $Revision: 1.2 $
+  Date:      $Date: 2008/03/21 14:59:39 $
+  Version:   $Revision: 1.3 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
@@ -88,10 +88,11 @@ namespace bbtk
 
 
   //========================================================================
-    WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size )
+    WxGUIHtmlBrowser::WxGUIHtmlBrowser ( wxWindow *parent, wxSize size,
+                                        WxGUIHtmlBrowserUser* user)
       : 
-      wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL)
-                                      // ,      mWxGUIConsole(0)
+      wxPanel ( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
+      mUser(user)
 
   {
     wxPanel* panel = this;
@@ -292,11 +293,24 @@ namespace bbtk
 
   //========================================================================
   void WxGUIHtmlBrowser::OnLinkClicked(wxHtmlLinkEvent& e)
-  {
-    mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
+  { 
+    std::cout << "BrOnLink"<<std::endl; 
+  
+    bool go = true;
+    if (mUser) 
+      {
+       wxString file = wxPathOnly(mwxURL->GetValue());
+       file += std2wx(ConfigurationFile::GetInstance().Get_file_separator());
+       file += e.GetLinkInfo().GetHref();
+       go = mUser->WxGUIHtmlBrowserUserOnLinkClicked( wx2std( file ) );
+      }
+    if (go) 
+      {
+       mwxHtmlWindow->LoadPage( e.GetLinkInfo().GetHref() );
        UpdateURL();
-    mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
-  }
+      }
+    //    mwxHtmlWindow->LoadPage( mwxURL->GetValue() );
+   }
   //========================================================================
 
 
index 885dad03481f2aada0ca11c2447042269c1e7136..bf8b99cede07b26c698561bf8591c69419085013 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIHtmlBrowser.h,v $
   Language:  C++
-  Date:      $Date: 2008/03/20 09:51:29 $
-  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
@@ -65,15 +65,18 @@ namespace bbtk
 
   };
 
-  /*
+  
   /// Abstract class which defines the callbacks invoked by WxGUIHtmlBrowser
   class WxGUIHtmlBrowserUser 
   {
   public :
     WxGUIHtmlBrowserUser() {}
     ~WxGUIHtmlBrowserUser() {}
+    
+    virtual bool WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target) 
+    { return true; }
   };
-  */
+  
  
 
   // class WxGUIConsole;
@@ -82,8 +85,8 @@ namespace bbtk
   class WxGUIHtmlBrowser : public wxPanel
   {
   public:
-    WxGUIHtmlBrowser ( wxWindow *parent, wxSize size ); 
-    //                WxGUIHtmlBrowserUser* = 0 );
+    WxGUIHtmlBrowser ( wxWindow *parent, wxSize size, 
+                      WxGUIHtmlBrowserUser* = 0 );
  
     bool GoTo(std::string&);
     void GoHome();
@@ -111,7 +114,7 @@ namespace bbtk
     wxButton* mwxReloadButton;
     //    wxButton* mwxRunButton;
     
-    //  WxGUIHtmlBrowserUser* mUser;
+    WxGUIHtmlBrowserUser* mUser;
     
    // any class wishing to process wxWidgets events must use this macro
     DECLARE_EVENT_TABLE()  
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()
   //================================================================
 
index 251961ff185d59e58151bf643384ca472cfd217d..2f3327cec0cfe20310cbd91649b9aa9251661a45 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUIScriptingInterface.h,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
@@ -54,8 +54,10 @@ namespace bbtk
 
   /// A scripting interface window
   class BBTK_EXPORT WxGUIScriptingInterface : public wxFrame, 
-                                  public InterpreterUser,
-                                  public WxGUICommandUser
+                                             public InterpreterUser,
+                                             public WxGUICommandUser,
+                                             public WxGUITextEditorUser,
+                                             public WxGUIHtmlBrowserUser
   {
   public:
     WxGUIScriptingInterface( wxWindow *parent, wxString title, wxSize size);
@@ -96,7 +98,7 @@ namespace bbtk
     void OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event));
    
 
-    void OnButtonRun(wxCommandEvent& WXUNUSED(event));
+    // void OnButtonRun(wxCommandEvent& WXUNUSED(event));
 
     // Interpreter callbacks
     bool InterpreterUserHasOwnHtmlPageViewer() { return true; }
@@ -105,21 +107,26 @@ namespace bbtk
     // WxGUICommand callbacks
     void WxGUICommandEnter(const std::string&);
 
+    // WxGUITextEditor callbacks
+    void WxGUITextEditorRun();
+    
+    // WxGUIHtmlBrowser callbacks
+    bool WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target);
   private:
     wxAuiManager m_mgr;
     Interpreter* mInterpreter;
 
     
 //EED    wxNotebook* mwxNotebook;
-    wxAuiNotebook* mwxNotebook;
-    wxPanel *mwxPageCommand, *mwxPageHelp;
+//    wxAuiNotebook* mwxNotebook;
+//    wxPanel *mwxPageCommand, *mwxPageHelp;
 
     WxGUICommand* mWxGUICommand;
     WxGUIOutputMessages* mWxGUIOutputMessages;
     WxGUIHtmlBrowser* mWxGUIHtmlBrowser;
     WxGUITextEditor* mWxGUITextEditor;
 
-    wxButton* mwxButtonRun;
+    //    wxButton* mwxButtonRun;
 
   public:
          
index 7de71068cb5abaf552737309a7d6c7bebbd4d0f3..e2f7fe46eada0f9f3346205ff88feac0f3089e44 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUITextEditor.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
@@ -96,42 +96,6 @@ namespace bbtk
   //================================================================
   
   
-  //================================================================
-  class WxGUITextEditorPage : public wxPanel
-  {
-  public:
-    WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
-    ~WxGUITextEditorPage();
-
-    void SetPageName(const std::string& name) { mName = name; }
-    const std::string& GetPageName() const { return mName; }
-
-    bool AskFilename() const { return mAskFilename; }
-
-    WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
-
-    void Load(const std::string& filename);
-    void Save(const std::string& filter);
-
-    bool IsModified() { return mwxInputText->IsModified(); }
-   
-  private:
-    WxGUITextEditor* mEditor;
-    WxTextCtrlGettingKeyEvents* mwxInputText;
-    wxTextAttr* mwxInputTextAttr;
-    std::string mName;
-    bool mAskFilename;
-
-    /*
-    enum
-    {
-      ID_InputText
-    };
-    */
-    //DECLARE_EVENT_TABLE();
-
-  } ;
-  //================================================================
 
   //================================================================  
   /*  BEGIN_EVENT_TABLE(WxGUITextEditorPage, wxPanel)
@@ -185,6 +149,13 @@ namespace bbtk
   }
   //================================================================
 
+  bool WxGUITextEditorPage::IsModified()
+   { return mwxInputText->IsModified(); }
+
+  std::string WxGUITextEditorPage::GetText()
+  {
+    return wx2std(GetTextCtrl()->GetValue());
+  }
 
   //================================================================
   void WxGUITextEditorPage::Load(const std::string& filename)
@@ -228,8 +199,10 @@ namespace bbtk
   //================================================================
   
   //================================================================
-  WxGUITextEditor::WxGUITextEditor( wxWindow *parent )
+  WxGUITextEditor::WxGUITextEditor( wxWindow *parent,
+                                   WxGUITextEditorUser* user )
     : wxPanel(parent, -1),
+      mUser(user),
       mFileNameFilter("*.*")
   {
     std::cout << "WxGUITextEditor::WxGUITextEditor"<<std::endl;
@@ -276,10 +249,10 @@ namespace bbtk
     mwxButtonSave = new wxBitmapButton( btnsCtrlPanel,ID_ButtonSave,bmp_save);//_T("Save")  );
     btnsSizer->Add( mwxButtonSave );
 
-    /*
     wxBitmap bmp_run(cc_run_xpm);
     mwxButtonRun = new wxBitmapButton( btnsCtrlPanel,ID_ButtonRun,bmp_run);//_T("Run")  );
     btnsSizer->Add( mwxButtonRun );
+    /*
     wxBitmap bmp_quit(cc_exit_xpm);
     mwxButtonQuit = new wxBitmapButton( btnsCtrlPanel,ID_ButtonQuit,bmp_quit);//_T("Quit")  );
     btnsSizer->Add( mwxButtonQuit );
@@ -435,14 +408,16 @@ namespace bbtk
     if (AskSave()) GetParent()->Close();
   }
   //================================================================  
-
+  */
 
   //================================================================  
   void WxGUITextEditor::OnButtonRun(wxCommandEvent& event) 
   { 
-    Run(); 
+    if (mUser!=0) mUser->WxGUITextEditorRun();
     FocusOnCurrentPage();
   }
+
+  /*
   void WxGUITextEditor::Run()
   {
     std::cout << "-------------- RUN ---------------"<<std::endl;
@@ -552,7 +527,7 @@ namespace bbtk
     EVT_BUTTON(WxGUITextEditor::ID_ButtonNew, WxGUITextEditor::OnButtonNew)
     EVT_BUTTON(WxGUITextEditor::ID_ButtonOpen, WxGUITextEditor::OnButtonOpen)
     EVT_BUTTON(WxGUITextEditor::ID_ButtonSave, WxGUITextEditor::OnButtonSave)
-  //    EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun)
+    EVT_BUTTON(WxGUITextEditor::ID_ButtonRun, WxGUITextEditor::OnButtonRun)
   //    EVT_BUTTON(WxGUITextEditor::ID_ButtonQuit, WxGUITextEditor::OnButtonQuit)
     EVT_AUINOTEBOOK_PAGE_CLOSE(wxID_ANY, WxGUITextEditor::OnPageClose)
     END_EVENT_TABLE()
index 77f712671cc86a2d941eadd1eeca97c1b6e4d6ff..0f08e15c7b09d2c5aa3ee2bb5e3fce3fa3c06325 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbtkWxGUITextEditor.h,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
@@ -49,13 +49,65 @@ namespace bbtk
 {
 
   class WxTextCtrlGettingKeyEvents;
-  class WxGUITextEditorPage;
+  class WxGUITextEditor;
+
+  /// Abstract class which defines the callbacks invoked by WxGUITextEditor
+  class BBTK_EXPORT WxGUITextEditorUser
+  {
+  public:
+    WxGUITextEditorUser() {}
+    ~WxGUITextEditorUser() {}
+    /// Callback invoked when the 'run' button is pressed
+    virtual void WxGUITextEditorRun() {}
+  };
+
+  //================================================================
+  class WxGUITextEditorPage : public wxPanel
+  {
+  public:
+    WxGUITextEditorPage(wxWindow* parent, WxGUITextEditor* editor);
+    ~WxGUITextEditorPage();
+
+    void SetPageName(const std::string& name) { mName = name; }
+    const std::string& GetPageName() const { return mName; }
+
+    bool AskFilename() const { return mAskFilename; }
+
+    WxTextCtrlGettingKeyEvents* GetTextCtrl() { return mwxInputText; }
+
+    void Load(const std::string& filename);
+    void Save(const std::string& filter);
 
-  /// A bbs editor panel
+    bool IsModified(); //{ return mwxInputText->IsModified(); }
+   
+    std::string GetText();
+
+  private:
+    WxGUITextEditor* mEditor;
+    WxTextCtrlGettingKeyEvents* mwxInputText;
+    wxTextAttr* mwxInputTextAttr;
+    std::string mName;
+    bool mAskFilename;
+
+    /*
+    enum
+    {
+      ID_InputText
+    };
+    */
+    //DECLARE_EVENT_TABLE();
+
+  } ;
+  //================================================================
+
+
+
+  /// A text editor panel
   class BBTK_EXPORT WxGUITextEditor : public wxPanel
   {
   public:
-    WxGUITextEditor( wxWindow *parent );
+    WxGUITextEditor( wxWindow *parent, WxGUITextEditorUser* user = 0 );
     ~WxGUITextEditor();
 
     void OnKeyDown(wxKeyEvent& event);
@@ -64,7 +116,7 @@ namespace bbtk
     void OnButtonNew(wxCommandEvent& event);
     void OnButtonOpen(wxCommandEvent& event);
     void OnButtonSave(wxCommandEvent& event);
-    //    void OnButtonRun(wxCommandEvent& event);
+    void OnButtonRun(wxCommandEvent& event);
     //    void OnButtonQuit(wxCommandEvent& event);
     void OnPageClose(wxAuiNotebookEvent& evt);
 
@@ -72,7 +124,7 @@ namespace bbtk
     void Open();
     void Open(const std::string& filename);
     void Save();
-    //    void Run();
+    //   void Run();
     //    void Quit();
 
     void HighlightSyntax();
@@ -86,6 +138,8 @@ namespace bbtk
     { mFileNameFilter = filter; }
 
   private:
+    WxGUITextEditorUser* mUser;
+
     wxAuiManager m_mgr;
     wxAuiNotebook* mwxNotebook;
  
@@ -95,7 +149,7 @@ namespace bbtk
     wxButton *  mwxButtonNew; 
     wxButton *  mwxButtonOpen; 
     wxButton *  mwxButtonSave; 
-    //    wxButton *  mwxButtonRun; 
+    wxButton *  mwxButtonRun; 
     //    wxButton *  mwxButtonQuit; 
     wxStaticText* mwxPosition;
 
@@ -107,8 +161,8 @@ namespace bbtk
     {
       ID_ButtonNew,
       ID_ButtonOpen,
-      ID_ButtonSave
-      //      ID_ButtonRun,
+      ID_ButtonSave,
+      ID_ButtonRun
       //      ID_ButtonQuit
     };