1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUICommand.cxx,v $
6 Date: $Date: 2008/06/26 06:50:05 $
7 Version: $Revision: 1.7 $
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.
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.
17 =========================================================================*//**
18 * \brief Short description in one line
20 * Long description which
21 * can span multiple lines
33 #ifdef _USE_WXWIDGETS_
35 #include "bbtkWxGUICommand.h"
36 #include "bbtkMessageManager.h"
37 #include "bbtkConfigurationFile.h"
38 #include "bbtkWxGUIPackageBrowser2.h"
42 //================================================================
43 BEGIN_EVENT_TABLE(WxGUICommand, wxPanel)
44 EVT_TEXT_ENTER(WxGUICommand::ID_Text_Command, WxGUICommand::OnCommandEnter)
45 EVT_BUTTON(WxGUICommand::ID_Btn_Go, WxGUICommand::OnBtnGo)
46 EVT_BUTTON(WxGUICommand::ID_Btn_Include, WxGUICommand::OnBtnInclude)
47 EVT_BUTTON(WxGUICommand::ID_Btn_Reset, WxGUICommand::OnBtnReset)
48 EVT_BUTTON(WxGUICommand::ID_Btn_Config, WxGUICommand::OnBtnConfig)
49 EVT_BUTTON(WxGUICommand::ID_Btn_GraphS, WxGUICommand::OnBtnGraphS)
50 EVT_BUTTON(WxGUICommand::ID_Btn_GraphD, WxGUICommand::OnBtnGraphD)
51 EVT_BUTTON(WxGUICommand::ID_Btn_Help, WxGUICommand::OnBtnHelp)
52 EVT_BUTTON(WxGUICommand::ID_Btn_PackageBrowser, WxGUICommand::OnBtnPackageBrowser)
54 //================================================================
57 WxGUICommand::WxGUICommand(wxWindow *parent, WxGUICommandUser* user)
61 wxBoxSizer *sizer = new wxBoxSizer(wxVERTICAL);
73 // //| wxTAB_TRAVERSAL
76 wxButton *btnGo = new wxButton(this,ID_Btn_Go,_T("Go"));
78 wxFlexGridSizer *sizerCommand= new wxFlexGridSizer(2);
79 sizerCommand->AddGrowableCol(0);
80 sizerCommand->Add(mwxTextCommand,1,wxGROW);
81 sizerCommand->Add(btnGo);
83 sizer->Add(sizerCommand,0,wxGROW);
85 wxBoxSizer *btnsSizer = new wxBoxSizer(wxHORIZONTAL);
87 wxButton *btnInclude = new wxButton(this,ID_Btn_Include ,_T("include") );
88 wxButton *btnReset = new wxButton(this,ID_Btn_Reset ,_T("reset") );
89 wxButton *btnConfig = new wxButton(this,ID_Btn_Config ,_T("config") );
90 wxButton *btnGraphS = new wxButton(this,ID_Btn_GraphS ,_T("graph (simple)") );
91 wxButton *btnGraphD = new wxButton(this,ID_Btn_GraphD ,_T("graph (detailed)") );
92 wxButton *btnHelp = new wxButton(this,ID_Btn_Help ,_T("help") );
93 wxButton *btnPackageBrowser = new wxButton(this,ID_Btn_PackageBrowser ,_T("Start Package Browser") );
95 btnsSizer->Add( btnInclude );
96 btnsSizer->Add( btnReset );
97 btnsSizer->Add( btnConfig );
98 btnsSizer->Add( btnGraphS );
99 btnsSizer->Add( btnGraphD );
100 btnsSizer->Add( btnHelp );
101 btnsSizer->Add( btnPackageBrowser );
103 sizer->Add(btnsSizer,0,wxTOP|wxGROW, 10 );
111 WxGUICommand::~WxGUICommand()
115 void WxGUICommand::OnBtnGo(wxCommandEvent& event)
117 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGo"<<std::endl);
118 SendCommand(wx2std(mwxTextCommand->GetValue()));
121 void WxGUICommand::OnCommandEnter(wxCommandEvent& event)
123 bbtkDebugMessage("gui",2,"WxGUICommand::OnCommandEnter"<<std::endl);
124 SendCommand(wx2std(mwxTextCommand->GetValue()));
127 void WxGUICommand::SendCommand(const std::string& command)
129 if (command.length()==0) return;
131 mwxTextCommand->SetValue(_T(""));
132 mwxTextCommand->Append(std2wx(command));
133 if (mUser) mUser->WxGUICommandEnter(command);
137 void WxGUICommand::OnBtnInclude(wxCommandEvent& event)
139 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnInclude"<<std::endl);
141 std::string default_doc_dir =
142 ConfigurationFile::GetInstance().Get_default_temp_dir();
143 std::string stdDir = default_doc_dir+"/share/bbtk/bbs";
144 wxString defaultDir(stdDir.c_str(), wxConvUTF8);
146 wxFileDialog dialog(this, _T("Include file"),defaultDir, _T(""), _T("*.bbs"), wxOPEN );
147 if (dialog.ShowModal() == wxID_OK)
149 // std::string command(_T("include "));
150 // std::string pathfilename = (const char *)(dialog.GetFilename().mb_str());
151 std::string command("include ");
152 command = command + "\"" + wx2std(dialog.GetPath()) + "\"";
153 SendCommand(command);
157 void WxGUICommand::OnBtnReset(wxCommandEvent& event)
159 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnReset"<<std::endl);
160 SendCommand("reset");
163 void WxGUICommand::OnBtnConfig(wxCommandEvent& event)
165 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnConfig"<<std::endl);
166 SendCommand("config");
169 void WxGUICommand::OnBtnGraphS(wxCommandEvent& event)
171 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphS"<<std::endl);
172 SendCommand("graph");
175 void WxGUICommand::OnBtnGraphD(wxCommandEvent& event)
177 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnGraphD"<<std::endl);
178 SendCommand("graph . 1");
181 void WxGUICommand::OnBtnHelp(wxCommandEvent& event)
183 bbtkDebugMessage("gui",2,"WxGUICommand::OnBtnHelp"<<std::endl);
187 void WxGUICommand::OnBtnPackageBrowser(wxCommandEvent& event)
190 WxGUIPackageBrowser2Window *helpbrowser = new
191 WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
197 #endif // _USE_WXWIDGETS_