bbtkWxGUICommand.cxx

Go to the documentation of this file.
00001 /*=========================================================================                                                                               
00002   Program:   bbtk
00003   Module:    $RCSfile: bbtkWxGUICommand.cxx,v $
00004   Language:  C++
00005   Date:      $Date: 2008/10/17 08:18:15 $
00006   Version:   $Revision: 1.8 $
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 
00047 #ifdef _USE_WXWIDGETS_
00048 
00049 #include "bbtkWxGUICommand.h"
00050 #include "bbtkMessageManager.h"
00051 #include "bbtkConfigurationFile.h"
00052 #include "bbtkWxGUIPackageBrowser2.h" 
00053 
00054 namespace bbtk
00055 {
00056   //================================================================  
00057   BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
00058     EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
00059     EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
00060     EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
00061     EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
00062     EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
00063     EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
00064     EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
00065     EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
00066     EVT_BUTTON(WxGUICommand::ID_Btn_PackageBrowser, WxGUICommand::OnBtnPackageBrowser)
00067    END_EVENT_TABLE()
00068   //================================================================
00069 
00070 
00071   WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
00072     : wxPanel(parent,-1),
00073       mUser(user)
00074   {
00075     wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
00076     
00077     mwxTextCommand = 
00078       new wxComboBox(this,
00079                      ID_Text_Command,
00080                      _T(""),
00081                      wxDefaultPosition,
00082                      wxDefaultSize,
00083                      0, NULL,
00084                      wxTE_PROCESS_ENTER
00085                      //             | wxTE_PROCESS_TAB 
00086                      //             | wxWANTS_CHARS 
00087                      //             //|  wxTAB_TRAVERSAL
00088                      );
00089     
00090     wxButton *btnGo     = new wxButton(this,ID_Btn_Go,_T("Go"));          
00091     
00092     wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
00093     sizerCommand->AddGrowableCol(0);
00094     sizerCommand->Add(mwxTextCommand,1,wxGROW);
00095     sizerCommand->Add(btnGo);
00096     
00097     sizer->Add(sizerCommand,0,wxGROW);
00098 
00099     wxBoxSizer *btnsSizer       = new wxBoxSizer(wxHORIZONTAL);
00100     
00101     wxButton *btnInclude                = new wxButton(this,ID_Btn_Include              ,_T("include")                  );
00102     wxButton *btnReset                  = new wxButton(this,ID_Btn_Reset                ,_T("reset")                    );
00103     wxButton *btnConfig                 = new wxButton(this,ID_Btn_Config               ,_T("config")                   );
00104     wxButton *btnGraphS                 = new wxButton(this,ID_Btn_GraphS               ,_T("graph (simple)")   );
00105     wxButton *btnGraphD                 = new wxButton(this,ID_Btn_GraphD               ,_T("graph (detailed)") );
00106     wxButton *btnHelp                   = new wxButton(this,ID_Btn_Help                 ,_T("help")                             );
00107     wxButton *btnPackageBrowser    = new wxButton(this,ID_Btn_PackageBrowser    ,_T("Start Package Browser")     );
00108     
00109     btnsSizer->Add( btnInclude          );
00110     btnsSizer->Add( btnReset            );
00111     btnsSizer->Add( btnConfig           );
00112     btnsSizer->Add( btnGraphS           );
00113     btnsSizer->Add( btnGraphD           );
00114     btnsSizer->Add( btnHelp             );
00115     btnsSizer->Add( btnPackageBrowser   );
00116     
00117     sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
00118 
00119     SetSizer(sizer);
00120     
00121     SetAutoLayout(true);
00122     Layout();
00123   }
00124 
00125   WxGUICommand::~WxGUICommand()
00126   {
00127   }
00128     
00129   void WxGUICommand::OnBtnGo(wxCommandEvent& event)
00130   {
00131     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
00132     SendCommand(wx2std(mwxTextCommand->GetValue()));
00133   }
00134   
00135   void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
00136   {
00137     bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
00138     SendCommand(wx2std(mwxTextCommand->GetValue()));
00139   }
00140   
00141   void WxGUICommand::SendCommand(const std::string& command)
00142   {
00143     if (command.length()==0) return;
00144 
00145     mwxTextCommand->SetValue(_T(""));
00146     mwxTextCommand->Append(std2wx(command));
00147     if (mUser) mUser->WxGUICommandEnter(command);
00148   }
00149 
00150 
00151   void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
00152   {
00153     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
00154 
00155     std::string default_doc_dir = 
00156       ConfigurationFile::GetInstance().Get_default_temp_dir();
00157     std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
00158     wxString defaultDir(stdDir.c_str(), wxConvUTF8);
00159 
00160     wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
00161     if (dialog.ShowModal() == wxID_OK)
00162      {
00163        // std::string command(_T("include "));
00164        // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
00165        std::string command("include ");
00166        command = command + "\"" + wx2std(dialog.GetPath()) + "\"";
00167        SendCommand(command);
00168      }
00169   }
00170 
00171   void WxGUICommand::OnBtnReset(wxCommandEvent& event)
00172   {
00173     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
00174     SendCommand("reset");
00175   }
00176 
00177   void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
00178   {
00179     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
00180     SendCommand("config");
00181   }
00182   
00183   void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
00184   {
00185     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
00186     SendCommand("graph");
00187   }
00188   
00189   void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
00190   {
00191     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
00192     SendCommand("graph . 1");
00193   }
00194 
00195   void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
00196   {
00197     bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
00198     SendCommand("help");
00199   }
00200 
00201   void WxGUICommand::OnBtnPackageBrowser(wxCommandEvent& event)
00202   {
00203         wxBusyCursor wait;
00204         WxGUIPackageBrowser2Window *helpbrowser = new
00205         WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
00206         helpbrowser->Show();
00207   }
00208   
00209 } // namespace bbtk
00210 
00211 #endif //  _USE_WXWIDGETS_

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