]> Creatis software - bbtk.git/blob - packages/wx/src/bbwxButtonExecBlackBox.cxx
9951196ba429e5b779ce8f8862c31ddfb806a41a
[bbtk.git] / packages / wx / src / bbwxButtonExecBlackBox.cxx
1 /*=========================================================================
2                                                                                 
3   Program:   bbtk
4   Module:    $RCSfile: bbwxButtonExecBlackBox.cxx,v $
5   Language:  C++
6   Date:      $Date: 2008/02/12 10:31:58 $
7   Version:   $Revision: 1.1 $
8                                                                                 
9   Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de 
10   l'Image). All rights reserved. See Doc/License.txt or
11   http://www.creatis.insa-lyon.fr/Public/bbtk/License.html for details.
12                                                                                 
13      This software is distributed WITHOUT ANY WARRANTY; without even
14      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15      PURPOSE.  See the above copyright notices for more information.
16                                                                                 
17 =========================================================================*/
18 /**
19  *  \file 
20  *  \brief 
21  */
22
23
24 #ifdef _USE_WXWIDGETS_
25
26
27 #include "bbwxButtonExecBlackBox.h"
28 #include "bbwxPackage.h"
29 #include "bbtkInterpreter.h"
30
31
32
33 namespace bbwx
34 {
35   BBTK_ADD_BLACK_BOX_TO_PACKAGE(wx,ButtonExecBlackBox);
36   
37   ButtonExecBlackBoxWidget::ButtonExecBlackBoxWidget(ButtonExecBlackBox* box,
38                                                      wxWindow *parent, 
39                                                      wxString title)
40     :wxPanel( parent, -1, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL),
41     mBox(box)
42   { 
43     
44     wxPanel *panel      = this;
45
46     mwxButton = new wxButton( panel, -1, title);
47     Connect( mwxButton->GetId(),  
48              wxEVT_COMMAND_BUTTON_CLICKED , 
49              (wxObjectEventFunction) 
50              (void (wxPanel::*)(wxEvent&))
51               &ButtonExecBlackBoxWidget::OnButton ); 
52
53     wxFlexGridSizer *sizer      = new wxFlexGridSizer(1);
54     sizer->Add( mwxButton,1,wxGROW ); 
55     sizer->AddGrowableCol(0);
56     
57     panel->SetSizer(sizer);
58     panel->SetAutoLayout(true);
59     panel->Layout();
60     
61   }
62
63
64   ButtonExecBlackBoxWidget::~ButtonExecBlackBoxWidget()
65   {
66   }
67   
68
69   void ButtonExecBlackBoxWidget::OnButton( wxEvent& )
70   {
71     std::string 
72       commandstr("exec "
73                  +mBox->bbGetInputIn());
74     bool insideComment = false; // for multiline comment
75     bbtk::Interpreter::mGlobalInterpreter->InterpretLine( commandstr,
76                                                           insideComment );
77     mBox->bbSignalOutputModification();
78   }
79   
80   
81   
82   
83   void ButtonExecBlackBoxWidget::SetLabel(wxString title)
84   {
85     mwxButton->SetLabel(title);
86   }
87
88
89
90   void ButtonExecBlackBoxWidget::SetColour(wxColour color)
91   {
92     mwxButton->SetBackgroundColour(color);
93   }
94
95
96
97   //--------------------------------------------------------------------------
98   //-------------------------------------------------------------------------
99   // WxBlackBox implementation
100   //--------------------------------------------------------------------------
101   //--------------------------------------------------------------------------
102
103   BBTK_USER_BLACK_BOX_IMPLEMENTATION(ButtonExecBlackBox,bbtk::WxBlackBox);
104
105         void ButtonExecBlackBox::bbUserConstructor() 
106         { 
107                 bbSetInputIn("CURRENT");
108                 bbSetInputLabel("");
109                 std::vector<double> lstColour;
110                 lstColour.push_back(-1);
111                 lstColour.push_back(-1);
112                 lstColour.push_back(-1);
113         }
114
115
116   void ButtonExecBlackBox::Process() 
117   { 
118     mWidget->SetLabel( wxString( bbGetInputLabel().c_str() , wxConvUTF8 ) );
119
120     
121   /*  
122         if  ( (bbGetInputColour()[0]==-1) && (bbGetInputColour()[1]==-1) &&(bbGetInputColour()[1]==-1) )
123         {
124                           wxwidget->SetColour( wxwidget->GetParent()->GetBeckgroundColor() );
125         } else {
126           int r=(int) (255*bbGetInputColour()[0]);
127           int g=(int) (255*bbGetInputColour()[1]);
128           int b=(int) (255*bbGetInputColour()[2]);
129           wxwidget->SetColour( wxColour(r,g,b) );
130         }
131 */
132 //    wxwidget->Update(); 
133 //    bbSetOutput###( 0 ); 
134   } 
135    
136  
137   /** 
138    * \brief  Create wxWidget .  
139    * 
140    * 
141    */  
142   void ButtonExecBlackBox::CreateWidget()
143   { 
144     bbtkDebugMessageInc("Core",9,"ButtonExecBlackBox::bbCreateWxWindow("<<parent<<")"<<std::endl); 
145     mWidget =  new ButtonExecBlackBoxWidget(this, 
146                                 bbGetWxParent(), 
147                                 wxString( bbGetInputLabel().c_str() , wxConvUTF8 )  
148                                                                         );
149     bbtkDebugDecTab("Core",9); 
150     bbSetOutputWidget( mWidget );
151   } 
152  
153     
154  
155 }  //namespace bbwx 
156  
157 #endif  // _USE_WXWIDGETS_ 
158