]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIScriptingInterface.cxx
*** empty log message ***
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/12/15 09:04:47 $
6   Version:   $Revision: 1.32 $
7 =========================================================================*/
8
9 /* ---------------------------------------------------------------------
10
11 * Copyright (c) CREATIS-LRMN (Centre de Recherche en Imagerie Medicale)
12 * Authors : Eduardo Davila, Laurent Guigues, Jean-Pierre Roux
13 *
14 *  This software is governed by the CeCILL-B license under French law and 
15 *  abiding by the rules of distribution of free software. You can  use, 
16 *  modify and/ or redistribute the software under the terms of the CeCILL-B 
17 *  license as circulated by CEA, CNRS and INRIA at the following URL 
18 *  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html 
19 *  or in the file LICENSE.txt.
20 *
21 *  As a counterpart to the access to the source code and  rights to copy,
22 *  modify and redistribute granted by the license, users are provided only
23 *  with a limited warranty  and the software's author,  the holder of the
24 *  economic rights,  and the successive licensors  have only  limited
25 *  liability. 
26 *
27 *  The fact that you are presently reading this means that you have had
28 *  knowledge of the CeCILL-B license and that you accept its terms.
29 * ------------------------------------------------------------------------ */                                                                         
30    
31
32 /**
33  * \brief Short description in one line
34  * 
35  * Long description which 
36  * can span multiple lines
37  */
38 /**
39  * \file 
40  * \brief 
41  */
42 /**
43  * \class bbtk::
44  * \brief 
45  */
46
47
48 #ifdef _USE_WXWIDGETS_
49
50 #include <iostream>     
51 #include "bbtkWxGUIScriptingInterface.h"
52 #include "bbtkWxBlackBox.h"
53 #include "bbtkConfigurationFile.h"
54 #include "bbtkWxStreamRedirector.h"
55 #include "bbtkUtilities.h"
56
57 #include <wx/tipwin.h>
58
59 //#include "icons/cc_run.xpm"
60
61 namespace bbtk
62 {
63
64     enum
65     {
66       ID_Menu_Quit = 1,
67       ID_Menu_About,
68       ID_Menu_EditConfig,
69       ID_Menu_CreatePackage,
70       ID_Menu_CreateBlackBox,
71       ID_Menu_ShowImageGraph,
72       ID_Menu_RegeneratePackageDoc,
73       ID_Menu_RegenerateBoxesLists,
74       ID_Menu_RegenerateAll,
75       ID_Menu_PlugPackage,
76       ID_Menu_Windows_Files,
77       ID_Menu_Windows_Help,
78       ID_Menu_Windows_Messages,
79       ID_Menu_Windows_Command,
80       ID_Menu_Windows_Save,
81       ID_Menu_Windows_PackageBrowser
82       //      ID_Button_Run
83     };
84     
85   
86   //================================================================
87   WxGUIScriptingInterface::WxGUIScriptingInterface( wxWindow *parent )
88     : wxFrame((wxFrame *)parent, -1, _T("bbStudio"), 
89               wxDefaultPosition, wxSize(1200,800) )
90   {     
91     //    m_mgr = new wxAuiManager(this);
92     m_mgr.SetManagedWindow(this);
93     
94     mInterpreter = bbtk::Interpreter::New();
95     mInterpreter->SetUser(this);
96     mInterpreter->SetCommandLine(true);
97     mInterpreter->SetThrow(true);
98     //    mInterpreter->AddBreakObserver
99     //boost::bind( &WxGUIScriptingInterface::InterpreterUserOnBreak, this ));
100     //==============
101     // Menu
102     wxInitAllImageHandlers();
103     
104     wxMenu *menuFile = new wxMenu;
105     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
106     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
107     
108     wxMenu *menuAbout = new wxMenu;
109     menuAbout->Append( ID_Menu_About, _T("&About...") );
110
111     wxMenu *menuTools = new wxMenu;
112     menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
113     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
114     menuTools->Append( ID_Menu_PlugPackage, _T("&Plug package") );
115     menuTools->AppendSeparator();
116     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
117     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
118     menuTools->Append( ID_Menu_RegenerateAll,_T("Regenerate &all") );
119     menuTools->AppendSeparator();
120     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
121
122     wxMenu *menuWindows = new wxMenu;
123     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
124                                  _T("Show 'files' panel") )->Check();
125     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
126                                  _T("Show 'help' panel") )->Check();
127     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
128                                  _T("Show 'messages' panel") )->Check();
129     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
130                                  _T("Show 'command' panel") )->Check();
131     menuWindows->AppendSeparator();
132     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
133     
134     //    menuWindows->AppendSeparator();
135     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
136
137     wxMenu *menuOptions = new wxMenu;
138     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
139                                                     _T("Reset before running") );
140     mwxMenuItemReset->Check();
141
142     wxMenuBar *menuBar = new wxMenuBar;
143     menuBar->Append( menuFile, _T("&File") );
144     menuBar->Append( menuTools, _T("&Tools") );
145     menuBar->Append( menuOptions, _T("&Options") );
146     menuBar->Append( menuWindows, _T("&Windows") );
147     menuBar->Append( menuAbout, _T("About") );
148     
149     SetMenuBar( menuBar );
150     
151     //=== 
152     // Status bar
153     CreateStatusBar();
154     SetStatusText( _T("Welcome to bbStudio !") );
155     
156     //===
157     // Panes (Files, Messages, Help, Command)
158     mWxGUITextEditor = new WxGUITextEditor(this,this);
159     mWxGUITextEditor->SetFileNameFilter("*.bbs");
160         
161     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
162
163     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
164
165     mWxGUICommand = new WxGUICommand(this,this);
166    
167     mWxGUICommand->SetFocus();
168
169  
170 #if NOTEBOOK
171
172     mwxNotebook = new wxAuiNotebook(this,  
173                                     -1,
174                                     wxPoint(0, 0),
175                                     wxSize(500,500),
176                                     wxAUI_NB_TAB_SPLIT 
177                                     | wxAUI_NB_TAB_MOVE
178                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
179                                     //| wxAUI_NB_WINDOWLIST_BUTTON
180                                     //|wxAUI_NB_SCROLL_BUTTONS
181                                     // | wxAUI_NB_CLOSE_BUTTON 
182                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
183                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
184                                     | wxNO_BORDER);
185   
186
187     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
188     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
189
190     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
191
192     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
193
194
195     m_mgr.AddPane(mwxNotebook,
196                   wxAuiPaneInfo().Name(wxT("nb"))
197                   .CaptionVisible(false)
198                   .MinimizeButton(false)
199                   .MaximizeButton(false)
200                   .Center()
201                   //              .MinSize(wxSize(100,100))
202                   );   
203 #else 
204
205     //
206     m_mgr.AddPane(mWxGUITextEditor,
207                   wxAuiPaneInfo().Name(wxT("editor_content"))
208                   .Caption(wxT("Files"))
209                   .MinimizeButton(true)
210                   .MaximizeButton(true)
211                   .Center()
212                   .MinSize(wxSize(100,100))
213                   );   
214   
215     m_mgr.AddPane(mWxGUIHtmlBrowser,
216                   wxAuiPaneInfo().Name(wxT("browser_content"))
217                   .Caption(wxT("Help"))
218                   .MinimizeButton(true)
219                   .MaximizeButton(true)
220                   .Right()
221                   .Layer(2)
222                   .MinSize(wxSize(400,100))
223                   );
224
225     m_mgr.AddPane(mWxGUIOutputMessages,
226                   wxAuiPaneInfo().Name(wxT("messages_content"))
227                   .Caption(wxT("Messages"))
228                   .MinimizeButton(true)
229                   .MaximizeButton(true)
230                   .Bottom()
231                   .MinSize(wxSize(100,100))
232                   );
233     m_mgr.AddPane(mWxGUICommand,
234                   wxAuiPaneInfo().Name(wxT("command_content"))
235                   .Caption(wxT("Command"))
236                   .MinimizeButton(true)
237                   .MaximizeButton(true)
238                   .Bottom()
239                   .Layer(1)
240                   .MinSize(wxSize(100,100))
241                   );     
242 #endif
243
244     // parent window of all bbtk windows will be a child of this
245     Wx::SetTopWindowParent(this);
246     // Add the method OnWxSignal as a Wx::Signal observer 
247     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
248
249     //.PaneBorder(false)); 
250     // Load the interface appearance saved on last closing
251     LoadPerspective();
252
253     // Done in LoadPerspective
254     //    m_mgr.Update();
255         
256     SetAutoLayout(true);
257     Layout();
258     //    mwxNotebook->SetSelection(1);
259     mWxGUIHtmlBrowser->GoHome();
260 //    Refresh();
261     m_mgr.Update();
262     //   LoadPerspective();
263
264     mBreaked = false;   
265     
266     wxTipWindow* tip = new wxTipWindow(this,
267                                        _T("\n                  Welcome to bbStudio !\n\n   To run a demo or example:\n     1. click on the 'Demos' or 'Examples' link\n     2. select a demo or example\n     3. click on the '[source]' link : the source file is loaded in bbStudio\n     4. click on the 'Run' button (the arrow at the bottom right of the source file)   \n"),1000);
268     tip->CenterOnParent();
269     tip->Show();
270   }
271   //================================================================
272
273  //================================================================
274   WxGUIScriptingInterface::~WxGUIScriptingInterface()
275   {
276     SavePerspective();
277     m_mgr.UnInit();
278   }
279   //================================================================
280
281   //================================================================
282   void WxGUIScriptingInterface::Open(const std::string& filename)
283   {
284     mWxGUITextEditor->Open(filename);
285   }
286   //================================================================
287   /*
288   catch (BreakException e)                                              \
289     {                                                                   \
290       std::cout << "* BREAK"<<std::endl;                                \
291       if (e.IsInScriptFile())                                           \
292         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
293       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
294     }                                                                   \
295   catch (QuitException e)                                               \
296     {                                                                   \
297       std::cout << "* QUIT"<<std::endl;                                 \
298       if (e.IsInScriptFile())                                           \
299         std::cout << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
300       std::cout << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
301     }                                                                   \
302 */
303   
304 #define CATCH_MACRO                                                     \
305   catch (InterpreterException e)                                        \
306     {                                                                   \
307       if (e.GetErrorMessage()=="quit")                                  \
308         {                                                               \
309           std::cerr << "* QUIT ENCOUNTERED"<<std::endl;                 \
310           if (e.IsInScriptFile())                                       \
311             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
312           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
313         }                                                               \
314       else if (e.GetErrorMessage()=="break")                            \
315         {                                                               \
316           mBreaked = true;                                              \
317           std::cerr << "* BREAK"<<std::endl;                            \
318           if (e.IsInScriptFile())                                       \
319             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
320           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
321         }                                                               \
322       else                                                              \
323         {                                                               \
324           std::cerr << "* ERROR : "<<e.GetErrorMessage()<<std::endl;    \
325           if (e.IsInScriptFile())                                       \
326             std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
327           std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;     \
328           int lev = bbtk::MessageManager::GetMessageLevel("Error");     \
329           if (lev > 0) {                                                \
330             std::cerr << "* Exception thrown : "<<std::endl;            \
331             std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;     \
332             std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl; \
333           }                                                             \
334         }                                                               \
335     }
336   
337   //================================================================
338   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
339   {
340     std::string s("> ");
341     s += command + "\n";
342     mWxGUIOutputMessages->Print(s,wxRED);
343     
344     try
345       {
346         mInterpreter->InterpretLine( command );
347       }
348     CATCH_MACRO;
349   }
350   //================================================================
351   
352   //================================================================
353   /// Runs the interpretation of a file
354   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
355   { 
356     try
357       {
358         mInterpreter->InterpretFile(filename);
359       }
360     CATCH_MACRO;
361     return true;
362   }
363   //================================================================
364  
365   //================================================================
366   void WxGUIScriptingInterface::WxGUITextEditorRun()
367   {
368     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
369     std::stringstream* buf = new std::stringstream;
370     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
371     try 
372       {
373         if (!mBreaked)
374           {
375             if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
376             mInterpreter->InterpretBuffer(buf);
377           }
378         else 
379           {
380             mBreaked = false;
381             mInterpreter->InterpretCurrentStreams();
382           }
383         //      std::cout << "EO RUN"<<std::endl;
384       }
385     CATCH_MACRO;
386     //    std::cout << "EO RUN 3"<<std::endl;
387   }
388   //================================================================  
389
390   //================================================================
391   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
392   {
393     if (!mWxGUITextEditor->CloseAllPages()) return;
394     Close(true);
395   }
396   //================================================================
397
398
399   //================================================================
400   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
401   {
402     m_mgr.Update();
403         Refresh();
404     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
405                  _T("About ..."), wxOK | wxICON_INFORMATION,
406                  this);
407   }
408   //================================================================
409
410
411   //================================================================
412   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
413   {
414     std::string configFile = 
415       ConfigurationFile::GetInstance().Get_config_xml_full_path();
416     Open(configFile);
417   }
418   //================================================================
419
420   //================================================================
421   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
422   {
423     wxBusyCursor wait;
424     WxGUIPackageBrowser2Window *helpbrowser = new
425       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
426     helpbrowser->Show();
427     
428     /*
429     wxBusyCursor wait;
430     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
431     browser->IncludeAll();
432     */
433 #if NOTEBOOK
434     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
435 #else
436      /*
437      m_mgr.AddPane(browser,
438                    wxAuiPaneInfo().Name(wxT("package_brower"))
439                    .Caption(wxT("Package browser"))
440                    .MinimizeButton(true)
441                    .MaximizeButton(true)
442                    .Bottom()
443                    .Position(1)
444                    .MinSize(wxSize(100,100))
445                    );     
446      */
447 #endif
448   }
449   //================================================================
450
451
452
453   //================================================================
454   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
455   {
456 /*
457     std::string command("toolsbbtk/appli/GUICreatePackage");
458     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
459   
460         Interpreter::Pointer I = Interpreter::New();    
461     I->InterpretFile(command);
462 */
463     std::string command("reset");
464         mWxGUICommand->SendCommand(command);
465     command = "include toolsbbtk/appli/GUICreatePackage";
466     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
467         mWxGUICommand->SendCommand(command);
468
469   }
470   //================================================================
471
472
473   //================================================================
474   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
475   {
476           /*
477     std::string command("toolsbbtk/appli/GUICreateBlackBox");
478     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
479     
480     Interpreter::Pointer I = Interpreter::New();    
481     I->InterpretFile(command);
482 */
483     std::string command("reset");
484         mWxGUICommand->SendCommand(command);
485     command = "include toolsbbtk/appli/GUICreateBlackBox";
486     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
487         mWxGUICommand->SendCommand(command);
488   }
489   //================================================================
490   
491   //================================================================
492   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
493   {
494     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
495
496 #if defined(WIN32)
497     std::string strappli="start ";
498 #else
499     std::string strappli="gnome-open ";
500 #endif
501     std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
502     //  std::cout << "system: " << strcommand << std::endl;
503     system ( strcommand.c_str() );
504
505   }
506   //================================================================
507
508   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
509   {
510             std::string command;
511 #if defined(WIN32)
512         command = "\"";
513 #endif
514         command += ConfigurationFile::GetInstance().Get_bin_path();
515     command += ConfigurationFile::GetInstance().Get_file_separator();
516     command += "bbRegeneratePackageDoc";
517 #if defined(WIN32)
518         command += "\"";
519 #endif
520         command += " " + pack + " -q";
521     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
522     
523
524     if ( ! system ( command.c_str() ) )
525       {
526         wxMessageBox(_T("Done !"),_T("Regenerate package '")+std2wx(pack)+_T("' doc"),
527                      wxOK | wxICON_INFORMATION);
528       }
529     else 
530       {
531         wxString err(_T("An error occured while running '"));
532         err +=  bbtk::std2wx(command) + _T("'");
533         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
534       }
535   }
536
537
538   //================================================================
539   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
540   {
541     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
542                                       _T("Regenerate package doc"),
543                                       _T(""));
544     if (name.IsEmpty()) return;
545     std::string pack = bbtk::wx2std(name);
546     
547         DoRegeneratePackageDoc(pack);
548   }
549   //================================================================
550
551
552   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
553   {
554     std::string command;
555 #if defined(WIN32)
556         command = "\"";
557 #endif
558     command += ConfigurationFile::GetInstance().Get_bin_path();
559     command += ConfigurationFile::GetInstance().Get_file_separator();
560     command += "bbRegenerateBoxesLists";
561 #if defined(WIN32)
562         command += "\"";
563 #endif
564         command += " -q";
565         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
566
567         if ( ! system ( command.c_str() ) )
568     {
569        wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
570                     wxOK | wxICON_INFORMATION);
571      }
572    else 
573      {
574        wxString err(_T("An error occured while running '"));
575        err +=  bbtk::std2wx(command) + _T("'");
576        wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
577      }
578   }
579
580   //================================================================
581   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
582   {
583         DoRegenerateBoxesLists();
584   }
585   //================================================================
586
587   //================================================================
588   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
589   {
590         
591     DoRegeneratePackageDoc("-a");       
592         DoRegenerateBoxesLists();
593   }
594   //================================================================
595
596  
597   //================================================================
598   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
599   {
600     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
601     wxDirDialog* FD = 
602       new wxDirDialog( 0, 
603                        _T("Select package directory"),
604                        _T(""),
605                        style);
606     
607     if (FD->ShowModal()==wxID_OK)
608       {
609         std::string path = wx2std (FD->GetPath()) ;
610         std::string fname = path + "/bbtkPackage"; 
611         if ( ! Utilities::FileExists( fname ) )
612           {
613             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
614             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
615             return;
616           }
617         
618         std::ifstream f;
619         f.open(fname.c_str());
620         std::string pname;
621         f >> pname;
622         f.close();
623         
624         
625         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
626         
627         DoRegeneratePackageDoc(pname);
628         DoRegenerateBoxesLists();
629
630           }     
631   }
632   //================================================================
633
634   //================================================================
635   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
636   {
637     std::string s(page);
638     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
639     if (mWxGUIHtmlBrowser->GoTo(s)) 
640       {
641 //EED   mwxNotebook->ChangeSelection(1);
642 //      mwxNotebook->SetSelection(1);
643       }
644     else 
645       {
646          // std::cout << "ERROR html"<<std::endl;
647       }
648   } 
649   //================================================================  
650   
651   /*
652   //================================================================
653   void WxGUIScriptingInterface::InterpreterUserOnBreak()
654   {
655     //    std::cout << "Break" << std::endl;
656     
657   }
658   //================================================================
659   */
660
661   //================================================================  
662   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
663   {
664     size_t s = target.length();
665     if ((s>3) && (target[s-1]=='s')
666         && (target[s-2]=='b')
667         && (target[s-3]=='b')
668         && (target[s-4]=='.'))
669       {
670         mWxGUITextEditor->Open(target);
671 #if NOTEBOOK
672         mwxNotebook->SetSelection(0);
673 #endif
674         mWxGUITextEditor->SetFocus();
675         return false;
676       }
677     return true;
678   }
679   //================================================================  
680
681   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
682                                                     wxWindow* w)
683   {
684     bool checked = event.IsChecked();
685     bool shown = m_mgr.GetPane(w).IsShown();
686     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
687     if (checked ^ shown) 
688       {
689         m_mgr.GetPane(w).Show(checked);
690         m_mgr.Update();
691       }
692   }
693
694
695   //================================================================  
696   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
697   {
698     OnMenuWindowsCheck(event,mWxGUITextEditor);
699   }
700   //================================================================  
701
702   //================================================================  
703   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
704   {
705     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
706   }
707   //================================================================  
708
709   //================================================================  
710   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
711   {
712     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
713   }
714   //================================================================  
715
716   //================================================================  
717   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
718   {
719     OnMenuWindowsCheck(event,mWxGUICommand);
720   }
721   //================================================================  
722
723   //================================================================  
724   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
725   {
726     SavePerspective();
727   }
728   //================================================================  
729
730   //================================================================  
731   void WxGUIScriptingInterface::SavePerspective()
732   {
733     //    std::cout  << "Saving configuration..."<<std::endl;
734     std::string conf = wx2std(m_mgr.SavePerspective());
735     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
736     std::ofstream f;
737     f.open(fname.c_str(), std::ios::out );
738     f << conf << std::endl;
739
740     //    int x,y;
741     //    GetPosition(&x,&y);
742     //    f << x << "  " << y << std::endl;
743
744
745     int w,h;
746     GetSize(&w,&h);
747
748     f << w << " " << h << std::endl;
749
750     f.close();
751   }
752   //================================================================  
753
754   //================================================================  
755   void WxGUIScriptingInterface::LoadPerspective()
756   {
757     std::string fname = 
758       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
759     if ( Utilities::FileExists( fname ))
760       {
761         //      std::cout  << "Loading configuration..."<<std::endl;
762
763         std::ifstream f;
764         f.open(fname.c_str());
765         std::string conf;
766         f >> conf;
767
768         //      int x,y;
769         //      f >> x >> y ;
770
771         int w,h;
772         f >> w >> h ;
773
774         f.close();
775         
776         //      std::cout << conf << std::endl;
777
778         //      Move(x,y);
779         SetSize(w,h);
780         m_mgr.LoadPerspective(std2wx(conf));
781       }
782     else 
783       {
784         m_mgr.Update();
785       }
786   }
787   //================================================================  
788
789   //================================================================  
790   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
791   {
792     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
793     // TO DO : Uncheck 
794     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
795   }
796   //================================================================  
797
798   
799   //================================================================  
800   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
801     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
802     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
803     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
804     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
805     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
806     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
807     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
808     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
809     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
810     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
811     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
812     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
813     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
814     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
815     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
816     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
817     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
818   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
819     END_EVENT_TABLE()
820   //================================================================
821
822 } // namespace bbtk
823
824
825 #endif //_USE_WXWIDGETS_