1 /*=========================================================================
4 Module: $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
6 Date: $Date: 2008/03/21 11:46:41 $
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 "bbtkWxGUIScriptingInterface.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 WxGUIScriptingInterface::WxGUIScriptingInterface( 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 !") );
100 m_mgr.AddPane(CreateSizeReportCtrl(), wxAuiPaneInfo().
101 Name(wxT("test4")).Caption(wxT("Pane Caption")).
108 // wxFlexGridSizer *sizer = new wxFlexGridSizer(1);
110 //EED wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
111 // mwxNotebook = new wxNotebook(this,-1,wxDefaultPosition, wxDefaultSize, 0);
113 mwxNotebook = new wxAuiNotebook(this,
117 wxAUI_NB_TAB_SPLIT | wxAUI_NB_TAB_EXTERNAL_MOVE | wxNO_BORDER);
119 mwxPageCommand = new wxPanel(mwxNotebook,-1);
120 mwxPageHelp = new wxPanel(mwxNotebook,-1);
123 wxBoxSizer *cmdsizer = new wxBoxSizer(wxVERTICAL);
125 mwxPageCommand->SetAutoLayout(true);
126 mwxPageCommand->SetSizer(cmdsizer);
127 cmdsizer->Fit(mwxPageCommand);
128 cmdsizer->SetSizeHints(mwxPageCommand);
130 wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
132 mwxPageHelp->SetAutoLayout(true);
133 mwxPageHelp->SetSizer(helpsizer);
134 helpsizer->Fit(mwxPageHelp);
135 helpsizer->SetSizeHints(mwxPageHelp);
137 mWxGUITextEditor = new WxGUITextEditor(this);
138 mWxGUITextEditor->SetFileNameFilter("*.bbs");
140 mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this, //mwxPageHelp,
141 //EED wxSize(1200,0));
144 // mWxGUIHtmlBrowser->SetSize(wxSize(800,1000));
145 // helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5 );
146 // helpsizer->Add ( new wxButton(mwxPageHelp,-1,"perro"), 0, wxEXPAND );
148 wxBitmap bmp_run(cc_run_xpm);
149 mwxButtonRun = new wxBitmapButton( this, ID_Button_Run,bmp_run);//_T("Run") );
150 // helpsizer->Add( mwxButtonRun, 0, wxALL, 5 );
155 mWxGUIOutputMessages = new WxGUIOutputMessages(this);
157 mWxGUICommand = new WxGUICommand(this,this);
159 // mWxGUICommand->SetFocus();
161 // cmdsizer->Add (mWxGUIOutputMessages, 1, wxALL | wxGROW, 5);
162 // cmdsizer->Add (mWxGUICommand, 0, wxALL | wxGROW, 5);
165 // Creates and sets the parent window of all bbtk windows
166 wxWindow* top = new wxPanel(this,-1);//,_T("top"));
168 Wx::SetTopWindow(top);
172 //EED SetSizer(sizer);
174 mwxNotebook->AddPage( mwxPageCommand, _T("Command"));
175 mwxNotebook->AddPage( mwxPageHelp, _T("Help"));
178 m_mgr.AddPane(mWxGUITextEditor,
179 wxAuiPaneInfo().Name(wxT("editor_content"))
181 m_mgr.AddPane(mWxGUIOutputMessages,
182 wxAuiPaneInfo().Name(wxT("messages_content"))
183 .Caption(wxT("Messages"))
185 m_mgr.AddPane(mWxGUIHtmlBrowser,
186 wxAuiPaneInfo().Name(wxT("browser_content"))
188 m_mgr.AddPane(mWxGUICommand,
189 wxAuiPaneInfo().Name(wxT("command_content"))
191 m_mgr.AddPane(mwxButtonRun,
192 wxAuiPaneInfo().Name(wxT("button_run_content")));
195 //.PaneBorder(false));
203 //================================================================
205 //================================================================
206 WxGUIScriptingInterface::~WxGUIScriptingInterface()
210 //================================================================
212 //================================================================
213 void WxGUIScriptingInterface::Open(const std::string& filename)
215 mWxGUITextEditor->Open(filename);
217 //================================================================
219 //================================================================
220 void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
224 mWxGUIOutputMessages->Print(s,wxRED);
226 if ( mInterpreter->InterpretLine( command ) ==
232 //================================================================
234 //================================================================
235 /// Runs the interpretation of a file
236 bool WxGUIScriptingInterface::InterpretFile( const std::string& filename)
238 if ( mInterpreter->InterpretFile(filename) ==
245 //================================================================
247 //================================================================
248 void WxGUIScriptingInterface::OnButtonRun(wxCommandEvent& WXUNUSED(event))
250 wxString per = m_mgr.SavePerspective();
251 std::cout << per<< std::endl;
253 // wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
254 std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();//wx2std(temp);
255 size_t s = filename.length();
257 Interpreter* I = new Interpreter;
259 if ((s>3) && (filename[s-1]=='s')
260 && (filename[s-2]=='b')
261 && (filename[s-3]=='b')
262 && (filename[s-4]=='.'))
264 std::string tmp("Executing ");
266 SetStatusText(std2wx(tmp));
267 I->InterpretFile(filename);
271 SetStatusText(_T("The current page is not a bbs file : cannot execute it"));
276 //================================================================
278 //================================================================
279 void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
283 //================================================================
286 //================================================================
287 void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
291 wxMessageBox(_T(" bbi\nThe Black Box Toolkit interpreter\n(c) CREATIS-LRMN 2008"),
292 _T("About ..."), wxOK | wxICON_INFORMATION,
295 //================================================================
298 //================================================================
299 void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
301 std::string commandStr;
302 std::string configFile = ConfigurationFile::GetInstance().Get_config_xml_full_path();
304 commandStr = "notepad.exe ";
306 commandStr = "gedit ";
308 commandStr = commandStr + configFile;
309 std::cout << "system: " << commandStr << std::endl;
310 system ( commandStr.c_str() );
312 //================================================================
315 //================================================================
316 void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
318 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 01 \n");
319 std::string command("toolsbbtk/appli/CreatePackage");
320 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 02 \n");
322 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
323 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 03 \n");
324 Interpreter* I = new Interpreter;
325 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 04 \n");
326 I->InterpretFile(command);
327 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 05 \n");
329 printf("EED WxGUIScriptingInterface::OnMenuCreatePackage 06 \n");
331 //================================================================
334 //================================================================
335 void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
337 std::string command("toolsbbtk/appli/CreateBlackBox");
338 bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
339 Interpreter* I = new Interpreter;
340 I->InterpretFile(command);
343 //================================================================
345 //================================================================
346 void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
348 std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
351 std::string strappli="start ";
353 std::string strappli="gnome-open ";
355 std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
356 std::cout << "system: " << strcommand << std::endl;
357 system ( strcommand.c_str() );
360 //================================================================
363 //================================================================
364 void WxGUIScriptingInterface::OnMenuCreateIndex(wxCommandEvent& WXUNUSED(event))
366 std::string doc_path = ConfigurationFile::GetInstance().Get_doc_path();
367 std::string filepath = doc_path+"/bbdoc/make-index.bbs";
368 Interpreter* I = new Interpreter;
370 //EED std::cout << "bbi: include "<<filepath<<std::endl;
371 //EED I->InterpretFile( filepath );
373 I->InterpretLine( "exec freeze");
374 I->InterpretLine( "include *");
375 I->InterpretLine( "index "+doc_path+"/bbdoc/index-alpha.html Initials");
376 I->InterpretLine( "index "+doc_path+"/bbdoc/index-package.html Packages");
377 I->InterpretLine( "index "+doc_path+"/bbdoc/index-category.html Categories");
378 I->InterpretLine( "index "+doc_path+"/bbdoc/index-adaptors.html Adaptors");
382 //================================================================
385 //================================================================
386 void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
389 // std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
390 if (mWxGUIHtmlBrowser->GoTo(s))
392 //EED mwxNotebook->ChangeSelection(1);
393 mwxNotebook->SetSelection(1);
397 // std::cout << "ERROR html"<<std::endl;
400 //================================================================
403 //================================================================
404 BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
405 EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
406 EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
407 EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
408 EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
409 EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
410 EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
411 EVT_MENU(ID_Menu_CreateIndex, WxGUIScriptingInterface::OnMenuCreateIndex)
412 EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
414 //================================================================
419 #endif //_USE_WXWIDGETS_