]> Creatis software - bbtk.git/commitdiff
wxColorDialogButton
authorEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 13 Feb 2008 15:09:34 +0000 (15:09 +0000)
committerEduardo Davila <Eduardo.Davila@creatis.insa-lyon.fr>
Wed, 13 Feb 2008 15:09:34 +0000 (15:09 +0000)
packages/wx/bbs/appli/testButtonExecBlackBox.bbs [deleted file]
packages/wx/src/bbwxButtonExecBlackBox.cxx [deleted file]
packages/wx/src/bbwxButtonExecBlackBox.h [deleted file]
packages/wx/src/bbwxColourDialogButton.cxx [new file with mode: 0644]
packages/wx/src/bbwxColourDialogButton.h [new file with mode: 0644]
packages/wx/src/bbwxSlider.cxx
packages/wx/src/bbwxSlider.h

diff --git a/packages/wx/bbs/appli/testButtonExecBlackBox.bbs b/packages/wx/bbs/appli/testButtonExecBlackBox.bbs
deleted file mode 100644 (file)
index c9b1671..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-description "Simple test of wx::ButtonExecBlackBox widget"
-author "eduardo.davila@creatis.insa-lyon.fr"
-category "test;widget"
-
-load wx
-new Slider slider
-new ButtonExecBlackBox button
-  set button.In "slider"
-  set button.Label "Run"
-
-exec button
-
diff --git a/packages/wx/src/bbwxButtonExecBlackBox.cxx b/packages/wx/src/bbwxButtonExecBlackBox.cxx
deleted file mode 100644 (file)
index 9951196..0000000
+++ /dev/null
@@ -1,158 +0,0 @@
-/*=========================================================================
-                                                                                
-  Program:   bbtk
-  Module:    $RCSfile: bbwxButtonExecBlackBox.cxx,v $
-  Language:  C++
-  Date:      $Date: 2008/02/12 10:31:58 $
-  Version:   $Revision: 1.1 $
-                                                                                
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 
-  l'Image). All rights reserved. See Doc/License.txt or
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
-                                                                                
-     This software is distributed WITHOUT ANY WARRANTY; without even
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
-     PURPOSE.  See the above copyright notices for more information.
-                                                                                
-=========================================================================*/
-/**
- *  \file 
- *  \brief 
- */
-
-
-#ifdef _USE_WXWIDGETS_
-
-
-#include "bbwxButtonExecBlackBox.h"
-#include "bbwxPackage.h"
-#include "bbtkInterpreter.h"
-
-
-
-namespace bbwx
-{
-  BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ButtonExecBlackBox);
-  
-  ButtonExecBlackBoxWidget::ButtonExecBlackBoxWidget(ButtonExecBlackBox* box,
-                                                    wxWindow *parent, 
-                                                    wxString title)
-    :wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
-    mBox(box)
-  { 
-    
-    wxPanel *panel     = this;
-
-    mwxButton = new wxButton( panel, -1, title);
-    Connect( mwxButton->GetId(),  
-            wxEVT_COMMAND_BUTTON_CLICKED , 
-            (wxObjectEventFunction) 
-            (void (wxPanel::*)(wxEvent&))
-             &ButtonExecBlackBoxWidget::OnButton ); 
-
-    wxFlexGridSizer *sizer     = new wxFlexGridSizer(1);
-    sizer->Add( mwxButton,1,wxGROW ); 
-    sizer->AddGrowableCol(0);
-    
-    panel->SetSizer(sizer);
-    panel->SetAutoLayout(true);
-    panel->Layout();
-    
-  }
-
-
-  ButtonExecBlackBoxWidget::~ButtonExecBlackBoxWidget()
-  {
-  }
-  
-
-  void ButtonExecBlackBoxWidget::OnButton( wxEvent& )
-  {
-    std::string 
-      commandstr("exec "
-                +mBox->bbGetInputIn());
-    bool insideComment = false; // for multiline comment
-    bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr,
-                                                          insideComment );
-    mBox->bbSignalOutputModification();
-  }
-  
-  
-  
-  
-  void ButtonExecBlackBoxWidget::SetLabel(wxString title)
-  {
-    mwxButton->SetLabel(title);
-  }
-
-
-
-  void ButtonExecBlackBoxWidget::SetColour(wxColour color)
-  {
-    mwxButton->SetBackgroundColour(color);
-  }
-
-
-
-  //--------------------------------------------------------------------------
-  //-------------------------------------------------------------------------
-  // WxBlackBox implementation
-  //--------------------------------------------------------------------------
-  //--------------------------------------------------------------------------
-
-  BBTK_USER_BLACK_BOX_IMPLEMENTATION(ButtonExecBlackBox,bbtk::WxBlackBox);
-
-       void ButtonExecBlackBox::bbUserConstructor() 
-       { 
-               bbSetInputIn("CURRENT");
-               bbSetInputLabel("");
-               std::vector<double> lstColour;
-               lstColour.push_back(-1);
-               lstColour.push_back(-1);
-               lstColour.push_back(-1);
-       }
-
-
-  void ButtonExecBlackBox::Process() 
-  { 
-    mWidget->SetLabel( wxString( bbGetInputLabel().c_str() , wxConvUTF8 ) );
-
-    
-  /*  
-       if  ( (bbGetInputColour()[0]==-1) && (bbGetInputColour()[1]==-1) &&(bbGetInputColour()[1]==-1) )
-       {
-                         wxwidget->SetColour( wxwidget->GetParent()->GetBeckgroundColor() );
-       } else {
-         int r=(int) (255*bbGetInputColour()[0]);
-         int g=(int) (255*bbGetInputColour()[1]);
-         int b=(int) (255*bbGetInputColour()[2]);
-         wxwidget->SetColour( wxColour(r,g,b) );
-       }
-*/
-//    wxwidget->Update(); 
-//    bbSetOutput###( 0 ); 
-  } 
-   
-  /** 
-   * \brief  Create wxWidget .  
-   * 
-   * 
-   */  
-  void ButtonExecBlackBox::CreateWidget()
-  { 
-    bbtkDebugMessageInc("Core",9,"ButtonExecBlackBox::bbCreateWxWindow("<<parent<<")"<<std::endl); 
-    mWidget =  new ButtonExecBlackBoxWidget(this, 
-                               bbGetWxParent(), 
-                               wxString( bbGetInputLabel().c_str() , wxConvUTF8 )  
-                                                                       );
-    bbtkDebugDecTab("Core",9); 
-    bbSetOutputWidget( mWidget );
-  } 
-    
-}  //namespace bbwx 
-#endif  // _USE_WXWIDGETS_ 
diff --git a/packages/wx/src/bbwxButtonExecBlackBox.h b/packages/wx/src/bbwxButtonExecBlackBox.h
deleted file mode 100644 (file)
index 93bc21a..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-/*========================================================================= 
-                                                                                 
-  Program:   bbtk 
-  Module:    $RCSfile: bbwxButtonExecBlackBox.h,v $ 
-  Language:  C++ 
-  Date:      $Date: 2008/02/12 10:31:58 $ 
-  Version:   $Revision: 1.1 $ 
-                                                                                 
-  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 
-  l'Image). All rights reserved. See Doc/License.txt or 
-  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details. 
-                                                                                 
-     This software is distributed WITHOUT ANY WARRANTY; without even 
-     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
-     PURPOSE.  See the above copyright notices for more information. 
-                                                                                 
-=========================================================================*//** 
-/**
- * \file 
- * \brief Short description in one line
- * 
- * Long description which 
- * can span multiple lines
-*/
-
-/**
- * \class bbwx::Slider
- * \brief 
-
- * \class bbwx::SliderWidget
- * \brief 
- */
-
-
-#ifdef _USE_WXWIDGETS_
-// Prevents multiple inclusions : use symbols of the form
-// __FILENAME_INCLUDED__ 
-// where FILENAME must be replaced by the actual file name
-#ifndef __bbwxButtonExecBlackBox_h_INCLUDED_H__ 
-#define __bbwxButtonExecBlackBox_h_INCLUDED_H__ 
-// Include wxBlackBox definition
-#include "bbtkWxBlackBox.h" 
-// Namespace of the package "wx" is "bbwx" 
-// Namespace associated to packages should be of the form :
-// bbPACKAGENAME
-namespace bbwx 
-{ 
-//--------------------------------------------------------------------------
-// Forward declaration of the box
-  class ButtonExecBlackBox;
-  
-  //--------------------------------------------------------------------------
-  // The widget created by the box 
-  class ButtonExecBlackBoxWidget : public wxPanel
-  {
-  public:
-       /// Ctor with the two first params the parent window and the creator box
-       /// which must be passed to the WxBlackBoxWidget constructor.
-       /// The other params initialize the widget 
-    ButtonExecBlackBoxWidget(ButtonExecBlackBox* box,
-                            wxWindow *parent, 
-                            wxString title);
-    ~ButtonExecBlackBoxWidget();
-    /// Events callbacks
-    void OnButton( wxEvent& );
-    
-    // Accessors
-    void SetLabel(wxString title);
-    void SetColour(wxColour color);
-       
-  private:
-       ButtonExecBlackBox              *mBox;
-    wxButton                           *mwxButton;
-  }; 
-   
-  //--------------------------------------------------------------------------
-  //--------------------------------------------------------------------------
-  //--------------------------------------------------------------------------
-
-  class /*BBTK_EXPORT*/ ButtonExecBlackBox : public bbtk::WxBlackBox 
-  {     
-    BBTK_USER_BLACK_BOX_INTERFACE(ButtonExecBlackBox,bbtk::WxBlackBox); 
-    BBTK_DECLARE_INPUT(In, std::string );      
-    BBTK_DECLARE_INPUT(Label, std::string ); 
-    BBTK_DECLARE_INPUT(Colour, std::vector<double> );  
-    //    BBTK_DECLARE_OUTPUT(Out,int); 
-    BBTK_CREATE_WIDGET(CreateWidget);
-    BBTK_PROCESS(Process); 
-    void Process();
-    void CreateWidget();
-
-  protected:
-    virtual void bbUserConstructor();
-
-  private:
-         ButtonExecBlackBoxWidget *mWidget;      
-  }; 
-  
-  //================================================================= 
-  // UserBlackBox description 
-  BBTK_BEGIN_DESCRIBE_BLACK_BOX(ButtonExecBlackBox,bbtk::WxBlackBox); 
-  BBTK_NAME("ButtonExecBlackBox"); 
-  BBTK_AUTHOR("eduardo.davila@creatis.insa-lyon.fr"); 
-  // Already inserted for any WxBlackBox  BBTK_CATEGORY("widget");
-  BBTK_DESCRIPTION("Button widget (Execute a BlackBox)"); 
-
-  typedef std::vector<double> vectorcolour;
-
-  BBTK_INPUT(ButtonExecBlackBox,In,"Name of the Black Box to be executed",std::string);   
-  BBTK_INPUT(ButtonExecBlackBox,Label,"Label of the button",std::string); 
-  BBTK_INPUT(ButtonExecBlackBox,Colour,"Colour of the button (-1 -1 -1  Background)",vectorcolour); 
-  //   BBTK_OUTPUT(ButtonExecBlackBox,Out,"..Out..",int); 
-  BBTK_END_DESCRIBE_BLACK_BOX(ButtonExecBlackBox); 
-  //================================================================= 
-}//namespace  bbwx 
-#endif  // __bbwxButtonExecBlackBox_h_INCLUDED_H__ 
-#endif //_USE_WXWIDGETS_ 
diff --git a/packages/wx/src/bbwxColourDialogButton.cxx b/packages/wx/src/bbwxColourDialogButton.cxx
new file mode 100644 (file)
index 0000000..5e4154c
--- /dev/null
@@ -0,0 +1,150 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbwxColourDialogButton.cxx,v $
+  Language:  C++
+  Date:      $Date: 2008/02/13 15:09:37 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*/
+/**
+ * \file 
+ * \brief Short description in one line
+ *
+ * Long 
+ * description
+ *  
+ */
+
+#ifdef _USE_WXWIDGETS_
+
+#include "bbwxColourDialogButton.h"
+#include "bbwxPackage.h"
+
+
+namespace bbwx
+{
+  
+
+//-------------------------------------------------------------------------
+wxColourPickerCtrlWidget::wxColourPickerCtrlWidget(    ColourDialogButton* box, 
+                                                                                                       wxWindow *parent, 
+                                                                                                       unsigned char  cr,
+                                                                                                       unsigned char  cg,
+                                                                                                       unsigned char  cb
+                                                                                                       )
+  :   wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
+         mBox(box)
+{
+    bbtkDebugMessage("Process",9,"=> wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
+
+    wxPanel * panel = this;
+    picker = new wxColourPickerCtrl(panel,-1,
+                                       wxColour(cr,cg,cb),
+                                       wxDefaultPosition,
+                                       wxDefaultSize,
+                                       wxCLRP_USE_TEXTCTRL
+                               );
+    picker->SetPickerCtrlGrowable(false);
+    picker->SetTextCtrlGrowable(false);
+    
+    Connect ( picker->GetId(),
+             wxEVT_COMMAND_COLOURPICKER_CHANGED,
+             wxColourPickerEventHandler( wxColourPickerCtrlWidget::OnColorChange ) );
+    
+    bbtkDebugMessage("Process",9,"<= wxColourPickerCtrlWidget::wxColourPickerCtrlWidget"<<std::endl);
+    wxFlexGridSizer *sizer = new wxFlexGridSizer(10);
+       sizer -> AddGrowableRow(0);
+       sizer -> Add( picker,1,wxGROW );                
+       panel -> SetSizer(sizer);
+  }
+
+wxColourPickerCtrlWidget::~wxColourPickerCtrlWidget()
+{
+}
+
+
+//---------------------------------------------------------------------
+void wxColourPickerCtrlWidget::OnColorChange(wxColourPickerEvent& e)
+{
+       UpdateBox();
+}
+
+
+//---------------------------------------------------------------------
+void wxColourPickerCtrlWidget::UpdateBox()
+{
+    char col[100];
+    wxColour c = picker->GetColour();
+    sprintf(col,"%f %f %f",c.Red()/255.,c.Green()/255.,c.Blue()/255.);
+
+    //    std::cout << col << std::endl;
+
+    ColourDialogButton* b = (ColourDialogButton*)mBox;
+    b->bbSetOutputOut( col );
+    b->bbSignalOutputModification("Out");
+}
+
+  //--------------------------------------------------------------------------
+  //-------------------------------------------------------------------------
+  // WxBlackBox implementation
+  //--------------------------------------------------------------------------
+  //--------------------------------------------------------------------------
+
+  //--------------------------------------------------------------------------
+  
+  BBTK_USER_BLACK_BOX_IMPLEMENTATION(ColourDialogButton,bbtk::WxBlackBox);
+  BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ColourDialogButton);
+  
+  void ColourDialogButton::bbUserConstructor() 
+  { 
+    bbSetInputIn("1 1 1");
+  }
+  
+  
+  void ColourDialogButton::Process() 
+  { 
+    bbtkDebugMessageInc("Process",9,"ColourDialogButton::Process()"<<std::endl);
+      pickerWidget->UpdateBox();
+    bbtkDebugDecTab("Process",9);
+  }
+  
+
+  /**
+   * \brief  Create wxWidget . 
+   *
+   *
+   */ 
+  void ColourDialogButton::CreateWidget()
+  {
+    bbtkDebugMessage("Process",9,"=> ColourDialogButton::CreateWidget("
+                       <<parent<<")"<<std::endl);
+    
+    float r,g,b;
+    sscanf( bbGetInputIn().c_str(), "%f %f %f", &r, &g ,&b);
+    unsigned char cr,cg,cb;
+    cr = (unsigned char)(255.*r);
+    cg = (unsigned char)(255.*g);
+    cb = (unsigned char)(255.*b);
+
+    pickerWidget = new wxColourPickerCtrlWidget(this, bbGetWxParent() , cr , cg , cb );    
+    
+    bbtkDebugMessage("Process",9,"<= ColourDialogButton::CreateWidget("
+                    <<parent<<")"<<std::endl);
+
+    bbSetOutputWidget( pickerWidget );
+  }
+
+
+}  //namespace bbwx
+
+#endif  // _USE_WXWIDGETS_
+
diff --git a/packages/wx/src/bbwxColourDialogButton.h b/packages/wx/src/bbwxColourDialogButton.h
new file mode 100644 (file)
index 0000000..75fb6d4
--- /dev/null
@@ -0,0 +1,116 @@
+/*=========================================================================
+                                                                                
+  Program:   bbtk
+  Module:    $RCSfile: bbwxColourDialogButton.h,v $
+  Language:  C++
+  Date:      $Date: 2008/02/13 15:09:37 $
+  Version:   $Revision: 1.1 $
+                                                                                
+  Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
+  l'Image). All rights reserved. See Doc/License.txt or
+  http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
+                                                                                
+     This software is distributed WITHOUT ANY WARRANTY; without even
+     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+     PURPOSE.  See the above copyright notices for more information.
+                                                                                
+=========================================================================*//**
+/**
+ * \file 
+ * \brief Short description in one line
+ * 
+ * Long description which 
+ * can span multiple lines
+*/
+
+/**
+ * \class bbwx::Slider
+ * \brief 
+
+ * \class bbwx::SliderWidget
+ * \brief 
+ */
+
+#ifdef _USE_WXWIDGETS_
+
+// Prevents multiple inclusions : use symbols of the form
+// __FILENAME_INCLUDED__ 
+// where FILENAME must be replaced by the actual file name
+#ifndef __bbwxColourDialogButton_h_INCLUDED_H__
+#define __bbwxColourDialogButton_h_INCLUDED_H__
+
+// Include wxBlackBox definition
+#include "bbtkWxBlackBox.h"
+
+#include <wx/clrpicker.h>
+
+// Namespace of the package "wx" is "bbwx" 
+// Namespace associated to packages should be of the form :
+// bbPACKAGENAME
+namespace bbwx
+{
+
+class ColourDialogButton;
+
+class wxColourPickerCtrlWidget :public wxPanel
+{
+
+public:
+       wxColourPickerCtrlWidget(       ColourDialogButton* box, 
+                                                               wxWindow *parent, 
+                                                               unsigned char  cr,
+                                                               unsigned char  cg,
+                                                               unsigned char  cb  );
+
+       ~wxColourPickerCtrlWidget();
+       void OnColorChange(wxColourPickerEvent& e);
+       void UpdateBox();
+private:
+       wxColourPickerCtrl *picker; 
+       ColourDialogButton *mBox;
+};
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+//------------------------------------------------------------------------
+
+
+
+
+//------------------------------------------------------------------------
+// The black box
+  class /*BBTK_EXPORT*/ ColourDialogButton : public bbtk::WxBlackBox
+  {    
+    BBTK_USER_BLACK_BOX_INTERFACE(ColourDialogButton,bbtk::WxBlackBox);
+    BBTK_DECLARE_INPUT(In,std::string);
+    BBTK_DECLARE_OUTPUT(Out,std::string);
+    BBTK_PROCESS(Process);
+    BBTK_CREATE_WIDGET(CreateWidget);
+    void Process();
+    void CreateWidget();
+
+  protected:
+    virtual void bbUserConstructor();
+  private:
+         wxColourPickerCtrlWidget* pickerWidget;
+  };
+   
+  //=================================================================
+  // UserBlackBox description
+  BBTK_BEGIN_DESCRIBE_BLACK_BOX(ColourDialogButton,bbtk::WxBlackBox);
+  BBTK_NAME("ColourDialogButton");
+  BBTK_AUTHOR("laurent.guigues@creatis.insa-lyon.fr");
+  // Already inserted for any WxBlackBox  BBTK_CATEGORY("widget");
+  BBTK_DESCRIPTION("A button which displays a colour picker dialog when clicked");
+  BBTK_INPUT(ColourDialogButton,In,"Initial colour",std::string);
+  BBTK_OUTPUT(ColourDialogButton,Out,"Colour choosen in format '[0,1] [0,1] [0,1]'",std::string);
+  BBTK_END_DESCRIBE_BLACK_BOX(ColourDialogButton);
+  //=================================================================
+  
+  
+}//namespace  bbwx
+
+#endif  // __bbwxColourDialogButton_h_INCLUDED_H__
+
+#endif //_USE_WXWIDGETS_
index fda48f4155037ea441c321a06fb66d885056e243..3017b5ef0a27565123b16197d0067659fda94e45 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxSlider.cxx,v $
   Language:  C++
-  Date:      $Date: 2008/02/12 20:08:12 $
-  Version:   $Revision: 1.7 $
+  Date:      $Date: 2008/02/13 15:09:37 $
+  Version:   $Revision: 1.8 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
  *  
  */
 
-
 #ifdef _USE_WXWIDGETS_
 
-
-
 #include "bbwxSlider.h"
 #include "bbwxPackage.h"
 #include "bbtkUtilities.h"
 
-
-
-
 namespace bbwx
 {
   
@@ -225,8 +219,6 @@ namespace bbwx
     RefreshLabels();  
     // Insert the sizer in the main panel and refresh the layout
     panel->SetSizer(sizer);
-    //   panel->SetAutoLayout(true);
-    //    panel->Layout();
   }
   //-------------------------------------------------------------------------
   
index cac5a7309981254c7fb994aef8d21899b8450547..5d4d445831b95b192fbbef288e092f8f59742402 100644 (file)
@@ -3,8 +3,8 @@
   Program:   bbtk
   Module:    $RCSfile: bbwxSlider.h,v $
   Language:  C++
-  Date:      $Date: 2008/02/12 10:31:58 $
-  Version:   $Revision: 1.8 $
+  Date:      $Date: 2008/02/13 15:09:38 $
+  Version:   $Revision: 1.9 $
                                                                                 
   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
   l'Image). All rights reserved. See Doc/License.txt or
  * \brief 
  */
 
-
 #ifdef _USE_WXWIDGETS_
 
-
 // Prevents multiple inclusions : use symbols of the form
 // __FILENAME_INCLUDED__ 
 // where FILENAME must be replaced by the actual file name