]> Creatis software - bbtk.git/blob - kernel/src/bbtkWxGUIScriptingInterface.cxx
245e1f2a927ebfcb3258f1c350b2090e3b66b68f
[bbtk.git] / kernel / src / bbtkWxGUIScriptingInterface.cxx
1 /*=========================================================================                                                                               
2   Program:   bbtk
3   Module:    $RCSfile: bbtkWxGUIScriptingInterface.cxx,v $
4   Language:  C++
5   Date:      $Date: 2008/10/21 14:38:31 $
6   Version:   $Revision: 1.31 $
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     
99     //==============
100     // Menu
101     wxInitAllImageHandlers();
102     
103     wxMenu *menuFile = new wxMenu;
104     menuFile->Append( ID_Menu_EditConfig, _T("Open bbtk &Config file") );
105     menuFile->Append( ID_Menu_Quit, _T("&Quit") );
106     
107     wxMenu *menuAbout = new wxMenu;
108     menuAbout->Append( ID_Menu_About, _T("&About...") );
109
110     wxMenu *menuTools = new wxMenu;
111     menuTools->Append( ID_Menu_CreatePackage, _T("Create &package") );
112     menuTools->Append( ID_Menu_CreateBlackBox, _T("Create &black box") );
113     menuTools->Append( ID_Menu_PlugPackage, _T("&Plug package") );
114     menuTools->AppendSeparator();
115     menuTools->Append( ID_Menu_RegeneratePackageDoc,_T("Regenerate package &doc") );
116     menuTools->Append( ID_Menu_RegenerateBoxesLists,_T("Regenerate boxes &lists") );
117     menuTools->Append( ID_Menu_RegenerateAll,_T("Regenerate &all") );
118     menuTools->AppendSeparator();
119     menuTools->Append( ID_Menu_ShowImageGraph, _T("&Show last graph") );
120
121     wxMenu *menuWindows = new wxMenu;
122     menuWindows->AppendCheckItem(ID_Menu_Windows_Files,
123                                  _T("Show 'files' panel") )->Check();
124     menuWindows->AppendCheckItem(ID_Menu_Windows_Help,
125                                  _T("Show 'help' panel") )->Check();
126     menuWindows->AppendCheckItem(ID_Menu_Windows_Messages,
127                                  _T("Show 'messages' panel") )->Check();
128     menuWindows->AppendCheckItem(ID_Menu_Windows_Command,
129                                  _T("Show 'command' panel") )->Check();
130     menuWindows->AppendSeparator();
131     menuWindows->Append( ID_Menu_Windows_PackageBrowser, _T("Start Package &Browser") );
132     
133     //    menuWindows->AppendSeparator();
134     //    menuWindows->Append ( ID_Menu_Windows_Save, _T("Save interface configuration"));
135
136     wxMenu *menuOptions = new wxMenu;
137     mwxMenuItemReset = menuOptions->AppendCheckItem(-1,
138                                                     _T("Reset before running") );
139     mwxMenuItemReset->Check();
140
141     wxMenuBar *menuBar = new wxMenuBar;
142     menuBar->Append( menuFile, _T("&File") );
143     menuBar->Append( menuTools, _T("&Tools") );
144     menuBar->Append( menuOptions, _T("&Options") );
145     menuBar->Append( menuWindows, _T("&Windows") );
146     menuBar->Append( menuAbout, _T("About") );
147     
148     SetMenuBar( menuBar );
149     
150     //=== 
151     // Status bar
152     CreateStatusBar();
153     SetStatusText( _T("Welcome to bbStudio !") );
154     
155     //===
156     // Panes (Files, Messages, Help, Command)
157     mWxGUITextEditor = new WxGUITextEditor(this,this);
158     mWxGUITextEditor->SetFileNameFilter("*.bbs");
159         
160     mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0),this);
161
162     mWxGUIOutputMessages = new WxGUIOutputMessages(this);
163
164     mWxGUICommand = new WxGUICommand(this,this);
165    
166     mWxGUICommand->SetFocus();
167
168  
169 #if NOTEBOOK
170
171     mwxNotebook = new wxAuiNotebook(this,  
172                                     -1,
173                                     wxPoint(0, 0),
174                                     wxSize(500,500),
175                                     wxAUI_NB_TAB_SPLIT 
176                                     | wxAUI_NB_TAB_MOVE
177                                     | wxAUI_NB_TAB_EXTERNAL_MOVE
178                                     //| wxAUI_NB_WINDOWLIST_BUTTON
179                                     //|wxAUI_NB_SCROLL_BUTTONS
180                                     // | wxAUI_NB_CLOSE_BUTTON 
181                                     //| wxAUI_NB_CLOSE_ON_ACTIVE_TAB
182                                     //| wxAUI_NB_CLOSE_ON_ALL_TABS
183                                     | wxNO_BORDER);
184   
185
186     mwxNotebook->AddPage(mWxGUITextEditor,_T("Files"),true);
187     mwxNotebook->AddPage(mWxGUIHtmlBrowser,_T("Help"),true);
188
189     mwxNotebook->AddPage(mWxGUIOutputMessages,_T("Messages"),true);
190
191     mwxNotebook->AddPage(mWxGUICommand,_T("Command"),true);
192
193
194     m_mgr.AddPane(mwxNotebook,
195                   wxAuiPaneInfo().Name(wxT("nb"))
196                   .CaptionVisible(false)
197                   .MinimizeButton(false)
198                   .MaximizeButton(false)
199                   .Center()
200                   //              .MinSize(wxSize(100,100))
201                   );   
202 #else 
203
204     //
205     m_mgr.AddPane(mWxGUITextEditor,
206                   wxAuiPaneInfo().Name(wxT("editor_content"))
207                   .Caption(wxT("Files"))
208                   .MinimizeButton(true)
209                   .MaximizeButton(true)
210                   .Center()
211                   .MinSize(wxSize(100,100))
212                   );   
213   
214     m_mgr.AddPane(mWxGUIHtmlBrowser,
215                   wxAuiPaneInfo().Name(wxT("browser_content"))
216                   .Caption(wxT("Help"))
217                   .MinimizeButton(true)
218                   .MaximizeButton(true)
219                   .Right()
220                   .Layer(2)
221                   .MinSize(wxSize(400,100))
222                   );
223
224     m_mgr.AddPane(mWxGUIOutputMessages,
225                   wxAuiPaneInfo().Name(wxT("messages_content"))
226                   .Caption(wxT("Messages"))
227                   .MinimizeButton(true)
228                   .MaximizeButton(true)
229                   .Bottom()
230                   .MinSize(wxSize(100,100))
231                   );
232     m_mgr.AddPane(mWxGUICommand,
233                   wxAuiPaneInfo().Name(wxT("command_content"))
234                   .Caption(wxT("Command"))
235                   .MinimizeButton(true)
236                   .MaximizeButton(true)
237                   .Bottom()
238                   .Layer(1)
239                   .MinSize(wxSize(100,100))
240                   );     
241 #endif
242
243     // parent window of all bbtk windows will be a child of this
244     Wx::SetTopWindowParent(this);
245     // Add the method OnWxSignal as a Wx::Signal observer 
246     //bbtkAddWxSignalObserver(WxGUIPackageBrowser2Window::OnWxSignal);
247
248     //.PaneBorder(false)); 
249     // Load the interface appearance saved on last closing
250     LoadPerspective();
251
252     // Done in LoadPerspective
253     //    m_mgr.Update();
254         
255     SetAutoLayout(true);
256     Layout();
257     //    mwxNotebook->SetSelection(1);
258     mWxGUIHtmlBrowser->GoHome();
259 //    Refresh();
260     m_mgr.Update();
261     //   LoadPerspective();
262
263
264     wxTipWindow* tip = new wxTipWindow(this,
265                                        _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);
266     tip->CenterOnParent();
267     tip->Show();
268   }
269   //================================================================
270
271  //================================================================
272   WxGUIScriptingInterface::~WxGUIScriptingInterface()
273   {
274     SavePerspective();
275     m_mgr.UnInit();
276   }
277   //================================================================
278
279   //================================================================
280   void WxGUIScriptingInterface::Open(const std::string& filename)
281   {
282     mWxGUITextEditor->Open(filename);
283   }
284   //================================================================
285   
286 #define CATCH_MACRO                                                     \
287   catch (QuitException e)                                               \
288     {                                                                   \
289       std::cout << "* quit exception caught"<<std::endl;                \
290     }                                                                   \
291   catch (InterpreterError e)                                            \
292     {                                                                   \
293       std::cerr << "* IERROR : "<<e.GetErrorMessage()<<std::endl;               \
294       if (e.IsInScriptFile())                                           \
295         std::cerr << "* FILE   : '"<<e.GetScriptFile()<<"'"<<std::endl; \
296       std::cerr << "* LINE   : "<<e.GetScriptLine()<<std::endl;         \
297       int lev = bbtk::MessageManager::GetMessageLevel("Error");         \
298       if (lev > 0) {                                                    \
299         std::cerr << "* Exception thrown : "<<std::endl;                \
300         std::cerr << "*  OBJECT : " <<e.GetObject()<<std::endl;         \
301         std::cerr << "*  FILE   : " <<e.GetSourceFile()<<std::endl;     \
302       }                                                                 \
303     }
304   
305   //================================================================
306   void WxGUIScriptingInterface::WxGUICommandEnter(const std::string& command)
307   {
308     std::string s("> ");
309     s += command + "\n";
310     mWxGUIOutputMessages->Print(s,wxRED);
311     
312     try
313       {
314         mInterpreter->InterpretLine( command );
315       }
316     CATCH_MACRO;
317   }
318   //================================================================
319   
320   //================================================================
321   /// Runs the interpretation of a file
322   bool WxGUIScriptingInterface::InterpretFile( const std::string& filename) 
323   { 
324     try
325       {
326         mInterpreter->InterpretFile(filename);
327       }
328     CATCH_MACRO;
329     return true;
330   }
331   //================================================================
332  
333   //================================================================
334   void WxGUIScriptingInterface::WxGUITextEditorRun()
335   {
336     //    wxString temp = mWxGUIHtmlBrowser->GetCurrentPage();
337     std::stringstream* buf = new std::stringstream;
338     (*buf) << mWxGUITextEditor->GetCurrentPage()->GetText();
339     try 
340       {
341         //      std::cout << "RUN"<<std::endl;
342         if (mwxMenuItemReset->IsChecked()) WxGUICommandEnter("reset");
343         mInterpreter->InterpretBuffer(buf);
344         //      std::cout << "EO RUN"<<std::endl;
345       }
346     CATCH_MACRO;
347     //    std::cout << "EO RUN 3"<<std::endl;
348   }
349   //================================================================  
350
351   //================================================================
352   void WxGUIScriptingInterface::OnMenuQuit(wxCommandEvent& WXUNUSED(event))
353   {
354     if (!mWxGUITextEditor->CloseAllPages()) return;
355     Close(true);
356   }
357   //================================================================
358
359
360   //================================================================
361   void WxGUIScriptingInterface::OnMenuAbout(wxCommandEvent& WXUNUSED(event))
362   {
363     m_mgr.Update();
364         Refresh();
365     wxMessageBox(_T("  bbStudio\nThe Black Box Toolkit Development Studio\n(c) CREATIS-LRMN 2008"),
366                  _T("About ..."), wxOK | wxICON_INFORMATION,
367                  this);
368   }
369   //================================================================
370
371
372   //================================================================
373   void WxGUIScriptingInterface::OnMenuEditConfig(wxCommandEvent& WXUNUSED(event))
374   {
375     std::string configFile = 
376       ConfigurationFile::GetInstance().Get_config_xml_full_path();
377     Open(configFile);
378   }
379   //================================================================
380
381   //================================================================
382   void WxGUIScriptingInterface::OnMenuWindowsPackageBrowser(wxCommandEvent& WXUNUSED(event))
383   {
384     wxBusyCursor wait;
385     WxGUIPackageBrowser2Window *helpbrowser = new
386       WxGUIPackageBrowser2Window(this,_T("Package Browser"), wxSize(600,600) );
387     helpbrowser->Show();
388     
389     /*
390     wxBusyCursor wait;
391     WxGUIPackageBrowser2 *browser = new WxGUIPackageBrowser2(this);
392     browser->IncludeAll();
393     */
394 #if NOTEBOOK
395     //     mwxNotebook->AddPage(browser,_T("Package Browser"),true);
396 #else
397      /*
398      m_mgr.AddPane(browser,
399                    wxAuiPaneInfo().Name(wxT("package_brower"))
400                    .Caption(wxT("Package browser"))
401                    .MinimizeButton(true)
402                    .MaximizeButton(true)
403                    .Bottom()
404                    .Position(1)
405                    .MinSize(wxSize(100,100))
406                    );     
407      */
408 #endif
409   }
410   //================================================================
411
412
413
414   //================================================================
415   void WxGUIScriptingInterface::OnMenuCreatePackage(wxCommandEvent& WXUNUSED(event))
416   {
417 /*
418     std::string command("toolsbbtk/appli/GUICreatePackage");
419     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
420   
421         Interpreter::Pointer I = Interpreter::New();    
422     I->InterpretFile(command);
423 */
424     std::string command("reset");
425         mWxGUICommand->SendCommand(command);
426     command = "include toolsbbtk/appli/GUICreatePackage";
427     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
428         mWxGUICommand->SendCommand(command);
429
430   }
431   //================================================================
432
433
434   //================================================================
435   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
436   {
437           /*
438     std::string command("toolsbbtk/appli/GUICreateBlackBox");
439     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
440     
441     Interpreter::Pointer I = Interpreter::New();    
442     I->InterpretFile(command);
443 */
444     std::string command("reset");
445         mWxGUICommand->SendCommand(command);
446     command = "include toolsbbtk/appli/GUICreateBlackBox";
447     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
448         mWxGUICommand->SendCommand(command);
449   }
450   //================================================================
451   
452   //================================================================
453   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
454   {
455     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
456
457 #if defined(WIN32)
458     std::string strappli="start ";
459 #else
460     std::string strappli="gnome-open ";
461 #endif
462     std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
463     //  std::cout << "system: " << strcommand << std::endl;
464     system ( strcommand.c_str() );
465
466   }
467   //================================================================
468
469   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
470   {
471             std::string command;
472 #if defined(WIN32)
473         command = "\"";
474 #endif
475         command += ConfigurationFile::GetInstance().Get_bin_path();
476     command += ConfigurationFile::GetInstance().Get_file_separator();
477     command += "bbRegeneratePackageDoc";
478 #if defined(WIN32)
479         command += "\"";
480 #endif
481         command += " " + pack + " -q";
482     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
483     
484
485     if ( ! system ( command.c_str() ) )
486       {
487         wxMessageBox(_T("Done !"),_T("Regenerate package '")+std2wx(pack)+_T("' doc"),
488                      wxOK | wxICON_INFORMATION);
489       }
490     else 
491       {
492         wxString err(_T("An error occured while running '"));
493         err +=  bbtk::std2wx(command) + _T("'");
494         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
495       }
496   }
497
498
499   //================================================================
500   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
501   {
502     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
503                                       _T("Regenerate package doc"),
504                                       _T(""));
505     if (name.IsEmpty()) return;
506     std::string pack = bbtk::wx2std(name);
507     
508         DoRegeneratePackageDoc(pack);
509   }
510   //================================================================
511
512
513   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
514   {
515     std::string command;
516 #if defined(WIN32)
517         command = "\"";
518 #endif
519     command += ConfigurationFile::GetInstance().Get_bin_path();
520     command += ConfigurationFile::GetInstance().Get_file_separator();
521     command += "bbRegenerateBoxesLists";
522 #if defined(WIN32)
523         command += "\"";
524 #endif
525         command += " -q";
526         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
527
528         if ( ! system ( command.c_str() ) )
529     {
530        wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
531                     wxOK | wxICON_INFORMATION);
532      }
533    else 
534      {
535        wxString err(_T("An error occured while running '"));
536        err +=  bbtk::std2wx(command) + _T("'");
537        wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
538      }
539   }
540
541   //================================================================
542   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
543   {
544         DoRegenerateBoxesLists();
545   }
546   //================================================================
547
548   //================================================================
549   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
550   {
551         
552     DoRegeneratePackageDoc("-a");       
553         DoRegenerateBoxesLists();
554   }
555   //================================================================
556
557  
558   //================================================================
559   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
560   {
561     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
562     wxDirDialog* FD = 
563       new wxDirDialog( 0, 
564                        _T("Select package directory"),
565                        _T(""),
566                        style);
567     
568     if (FD->ShowModal()==wxID_OK)
569       {
570         std::string path = wx2std (FD->GetPath()) ;
571         std::string fname = path + "/bbtkPackage"; 
572         if ( ! Utilities::FileExists( fname ) )
573           {
574             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
575             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
576             return;
577           }
578         
579         std::ifstream f;
580         f.open(fname.c_str());
581         std::string pname;
582         f >> pname;
583         f.close();
584         
585         
586         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
587         
588         DoRegeneratePackageDoc(pname);
589         DoRegenerateBoxesLists();
590
591           }     
592   }
593   //================================================================
594
595   //================================================================
596   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
597   {
598     std::string s(page);
599     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
600     if (mWxGUIHtmlBrowser->GoTo(s)) 
601       {
602 //EED   mwxNotebook->ChangeSelection(1);
603 //      mwxNotebook->SetSelection(1);
604       }
605     else 
606       {
607          // std::cout << "ERROR html"<<std::endl;
608       }
609   } 
610   //================================================================  
611   
612   //================================================================  
613   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
614   {
615     size_t s = target.length();
616     if ((s>3) && (target[s-1]=='s')
617         && (target[s-2]=='b')
618         && (target[s-3]=='b')
619         && (target[s-4]=='.'))
620       {
621         mWxGUITextEditor->Open(target);
622 #if NOTEBOOK
623         mwxNotebook->SetSelection(0);
624 #endif
625         mWxGUITextEditor->SetFocus();
626         return false;
627       }
628     return true;
629   }
630   //================================================================  
631
632   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
633                                                     wxWindow* w)
634   {
635     bool checked = event.IsChecked();
636     bool shown = m_mgr.GetPane(w).IsShown();
637     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
638     if (checked ^ shown) 
639       {
640         m_mgr.GetPane(w).Show(checked);
641         m_mgr.Update();
642       }
643   }
644
645
646   //================================================================  
647   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
648   {
649     OnMenuWindowsCheck(event,mWxGUITextEditor);
650   }
651   //================================================================  
652
653   //================================================================  
654   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
655   {
656     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
657   }
658   //================================================================  
659
660   //================================================================  
661   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
662   {
663     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
664   }
665   //================================================================  
666
667   //================================================================  
668   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
669   {
670     OnMenuWindowsCheck(event,mWxGUICommand);
671   }
672   //================================================================  
673
674   //================================================================  
675   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
676   {
677     SavePerspective();
678   }
679   //================================================================  
680
681   //================================================================  
682   void WxGUIScriptingInterface::SavePerspective()
683   {
684     //    std::cout  << "Saving configuration..."<<std::endl;
685     std::string conf = wx2std(m_mgr.SavePerspective());
686     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
687     std::ofstream f;
688     f.open(fname.c_str(), std::ios::out );
689     f << conf << std::endl;
690
691     //    int x,y;
692     //    GetPosition(&x,&y);
693     //    f << x << "  " << y << std::endl;
694
695
696     int w,h;
697     GetSize(&w,&h);
698
699     f << w << " " << h << std::endl;
700
701     f.close();
702   }
703   //================================================================  
704
705   //================================================================  
706   void WxGUIScriptingInterface::LoadPerspective()
707   {
708     std::string fname = 
709       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
710     if ( Utilities::FileExists( fname ))
711       {
712         //      std::cout  << "Loading configuration..."<<std::endl;
713
714         std::ifstream f;
715         f.open(fname.c_str());
716         std::string conf;
717         f >> conf;
718
719         //      int x,y;
720         //      f >> x >> y ;
721
722         int w,h;
723         f >> w >> h ;
724
725         f.close();
726         
727         //      std::cout << conf << std::endl;
728
729         //      Move(x,y);
730         SetSize(w,h);
731         m_mgr.LoadPerspective(std2wx(conf));
732       }
733     else 
734       {
735         m_mgr.Update();
736       }
737   }
738   //================================================================  
739
740   //================================================================  
741   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
742   {
743     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
744     // TO DO : Uncheck 
745     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
746   }
747   //================================================================  
748
749   
750   //================================================================  
751   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
752     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
753     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
754     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
755     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
756     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
757     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
758     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
759     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
760     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
761     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
762     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
763     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
764     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
765     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
766     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
767     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
768     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
769   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
770     END_EVENT_TABLE()
771   //================================================================
772
773 } // namespace bbtk
774
775
776 #endif //_USE_WXWIDGETS_