1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIConsole.cxx,v $
6 Date: $Date: 2008/03/20 09:51:29 $
7 Version: $Revision: 1.1 $
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_
36 #include "bbtkWxGUIConsole.h"
37 #include "bbtkWxBlackBox.h"
38 #include "bbtkConfigurationFile.h"
39 #include "bbtkWxStreamRedirector.h"
42 #include "icons/cc_run.xpm"
52 ID_Menu_CreatePackage,
53 ID_Menu_CreateBlackBox,
54 ID_Menu_ShowImageGraph,
60 //================================================================
61 WxGUIConsole::WxGUIConsole( wxWindow *parent, wxString title, wxSize size)
62 : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
64 // m_mgr = new wxAuiManager(this);
65 m_mgr.SetManagedWindow(this);
67 mInterpreter = new bbtk::Interpreter();
68 mInterpreter->SetUser(this);
69 mInterpreter->SetCommandLine(true);
72 wxInitAllImageHandlers();
74 wxMenu *menuFile = new wxMenu;
75 menuFile->Append( ID_Menu_Quit, _T("&Quit") );
77 wxMenu *menuAbout = new wxMenu;
78 menuAbout->Append( ID_Menu_About, _T("&About...") );
80 wxMenu *menuTools = new wxMenu;
81 menuTools->Append( ID_Menu_EditConfig, _T("&Edit bbtk config") );
82 menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
83 menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &blackbox") );
84 menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last image graph") );
85 menuTools->Append( ID_Menu_CreateIndex, _T("&Generate index") );
88 wxMenuBar *menuBar = new wxMenuBar;
89 menuBar->Append( menuFile, _T("&File") );
90 menuBar->Append( menuTools, _T("&Tools") );
91 menuBar->Append( menuAbout, _T("About") );
93 SetMenuBar( menuBar );
96 SetStatusText( _T("Welcome to bbi !") );
101 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
103 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
104 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
105 mwxNotebook = new wxAuiNotebook(this,
109 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
111 mwxPageCommand = new wxPanel(mwxNotebook,-1);
112 mwxPageHelp = new wxPanel(mwxNotebook,-1);
115 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
117 mwxPageCommand->SetAutoLayout(true);
118 mwxPageCommand->SetSizer(cmdsizer);
119 cmdsizer->Fit(mwxPageCommand);
120 cmdsizer->SetSizeHints(mwxPageCommand);
122 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
124 mwxPageHelp->SetAutoLayout(true);
125 mwxPageHelp->SetSizer(helpsizer);
126 helpsizer->Fit(mwxPageHelp);
127 helpsizer->SetSizeHints(mwxPageHelp);
129 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(mwxPageHelp,
130 //EED wxSize(1200,0));
133 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
134 helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxBOTTOM );
135 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
136 wxBitmap bmp_run(cc_run_xpm);
137 mwxButtonRun = new wxBitmapButton( mwxPageHelp,ID_Button_Run,bmp_run);//_T("Run") );
138 helpsizer->Add( mwxButtonRun );
143 mWxGUIOutputMessages = new WxGUIOutputMessages(mwxPageCommand);
145 mWxGUICommand = new WxGUICommand(mwxPageCommand,this);
147 mWxGUICommand->SetFocus();
149 cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 10);
150 cmdsizer->Add (mWxGUICommand, 1, wxALL | wxGROW, 10);
153 // Creates and sets the parent window of all bbtk windows
154 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
156 Wx::SetTopWindow(top);
160 //EED SetSizer(sizer);
162 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
163 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
164 m_mgr.AddPane(mwxNotebook, wxAuiPaneInfo().Name(wxT("notebook_content")).CenterPane().PaneBorder(false));
172 //================================================================
174 //================================================================
175 WxGUIConsole::~WxGUIConsole()
179 //================================================================
182 //================================================================
183 void WxGUIConsole::WxGUICommandEnter(const std::string& command)
187 mWxGUIOutputMessages->Print(s,wxRED);
189 if ( mInterpreter->InterpretLine( command ) ==
195 //================================================================
197 //================================================================
198 /// Runs the interpretation of a file
199 bool WxGUIConsole::InterpretFile( const std::string& filename)
201 if ( mInterpreter->InterpretFile(filename) ==
208 //================================================================
210 //================================================================
211 void WxGUIConsole::OnButtonRun(wxCommandEvent& WXUNUSED(event))
213 std::string filename = wx2std(mWxGUIHtmlBrowser->GetCurrentPage());
214 size_t s = filename.length();
216 Interpreter* I = new Interpreter;
218 if ((s>3) && (filename[s-1]=='s')
219 && (filename[s-2]=='b')
220 && (filename[s-3]=='b')
221 && (filename[s-4]=='.'))
223 SetStatusText(_T("Executing ")+filename);
224 I->InterpretFile(filename);
228 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
233 //================================================================
235 //================================================================
236 void WxGUIConsole::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
240 //================================================================
243 //================================================================
244 void WxGUIConsole::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
248 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
249 _T("About ..."), wxOK | wxICON_INFORMATION,
252 //================================================================
255 //================================================================
256 void WxGUIConsole::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
258 std::string commandStr;
259 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
261 commandStr = "notepad.exe ";
263 commandStr = "gedit ";
265 commandStr = commandStr + configFile;
266 std::cout << "system: " << commandStr << std::endl;
267 system ( commandStr.c_str() );
269 //================================================================
272 //================================================================
273 void WxGUIConsole::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
275 printf("EED WxGUIConsole::OnMenuCreatePackage 01 \n");
276 std::string command("toolsbbtk/appli/CreatePackage");
277 printf("EED WxGUIConsole::OnMenuCreatePackage 02 \n");
279 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
280 printf("EED WxGUIConsole::OnMenuCreatePackage 03 \n");
281 Interpreter* I = new Interpreter;
282 printf("EED WxGUIConsole::OnMenuCreatePackage 04 \n");
283 I->InterpretFile(command);
284 printf("EED WxGUIConsole::OnMenuCreatePackage 05 \n");
286 printf("EED WxGUIConsole::OnMenuCreatePackage 06 \n");
288 //================================================================
291 //================================================================
292 void WxGUIConsole::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
294 std::string command("toolsbbtk/appli/CreateBlackBox");
295 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
296 Interpreter* I = new Interpreter;
297 I->InterpretFile(command);
300 //================================================================
302 //================================================================
303 void WxGUIConsole::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
305 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
308 std::string strappli="start ";
310 std::string strappli="gnome-open ";
312 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
313 std::cout << "system: " << strcommand << std::endl;
314 system ( strcommand.c_str() );
317 //================================================================
320 //================================================================
321 void WxGUIConsole::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
323 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
324 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
325 Interpreter* I = new Interpreter;
327 //EED std::cout << "bbi: include "<<filepath<<std::endl;
328 //EED I->InterpretFile( filepath );
330 I->InterpretLine( "exec freeze");
331 I->InterpretLine( "include *");
332 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
333 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
334 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
335 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
339 //================================================================
342 //================================================================
343 void WxGUIConsole::InterpreterUserViewHtmlPage(const std::string& page)
346 // std::cout << "WxGUIConsole::ShowHtmlPage('"<<page<<"')"<<std::endl;
347 if (mWxGUIHtmlBrowser->GoTo(s))
349 //EED mwxNotebook->ChangeSelection(1);
350 mwxNotebook->SetSelection(1);
354 // std::cout << "ERROR html"<<std::endl;
357 //================================================================
360 //================================================================
361 BEGIN_EVENT_TABLE(WxGUIConsole, wxFrame)
362 EVT_MENU(ID_Menu_Quit, WxGUIConsole::OnMenuQuit)
363 EVT_MENU(ID_Menu_About, WxGUIConsole::OnMenuAbout)
364 EVT_MENU(ID_Menu_EditConfig, WxGUIConsole::OnMenuEditConfig)
365 EVT_MENU(ID_Menu_CreatePackage, WxGUIConsole::OnMenuCreatePackage)
366 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIConsole::OnMenuCreateBlackBox)
367 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIConsole::OnMenuShowImageGraph)
368 EVT_MENU(ID_Menu_CreateIndex, WxGUIConsole::OnMenuCreateIndex)
369 EVT_BUTTON(ID_Button_Run, WxGUIConsole::OnButtonRun )
371 //================================================================
376 #endif //_USE_WXWIDGETS_