]> 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/10/21 08:37:04 $
6   Version:   $Revision: 1.30 $
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   }
425   //================================================================
426
427
428   //================================================================
429   void WxGUIScriptingInterface::OnMenuCreateBlackBox(wxCommandEvent& WXUNUSED(event))
430   {
431     std::string command("toolsbbtk/appli/GUICreateBlackBox");
432     bbtkMessage("Debug",1,"Executing : '"<<command<<"'"<<std::endl);
433     
434     Interpreter::Pointer I = Interpreter::New();    
435     I->InterpretFile(command);
436   }
437   //================================================================
438   
439   //================================================================
440   void WxGUIScriptingInterface::OnMenuShowImageGraph(wxCommandEvent& WXUNUSED(event))
441   {
442     std::string default_temp_dir = ConfigurationFile::GetInstance().Get_default_temp_dir();
443
444 #if defined(WIN32)
445     std::string strappli="start ";
446 #else
447     std::string strappli="gnome-open ";
448 #endif
449     std::string strcommand = strappli +default_temp_dir+"/temp_dir/workspace_workspacePrototype.png";
450     //  std::cout << "system: " << strcommand << std::endl;
451     system ( strcommand.c_str() );
452
453   }
454   //================================================================
455
456   void WxGUIScriptingInterface::DoRegeneratePackageDoc( const std::string& pack )
457   {
458             std::string command;
459 #if defined(WIN32)
460         command = "\"";
461 #endif
462         command += ConfigurationFile::GetInstance().Get_bin_path();
463     command += ConfigurationFile::GetInstance().Get_file_separator();
464     command += "bbRegeneratePackageDoc";
465 #if defined(WIN32)
466         command += "\"";
467 #endif
468         command += " " + pack + " -q";
469     bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
470     
471
472     if ( ! system ( command.c_str() ) )
473       {
474         wxMessageBox(_T("Done !"),_T("Regenerate package '")+std2wx(pack)+_T("' doc"),
475                      wxOK | wxICON_INFORMATION);
476       }
477     else 
478       {
479         wxString err(_T("An error occured while running '"));
480         err +=  bbtk::std2wx(command) + _T("'");
481         wxMessageBox(err,_T("Regenerate package doc"),wxOK | wxICON_ERROR);      
482       }
483   }
484
485
486   //================================================================
487   void WxGUIScriptingInterface::OnMenuRegeneratePackageDoc(wxCommandEvent& WXUNUSED(event))
488   {
489     wxString name = wxGetTextFromUser(_T("Enter package name (-a for all)"),
490                                       _T("Regenerate package doc"),
491                                       _T(""));
492     if (name.IsEmpty()) return;
493     std::string pack = bbtk::wx2std(name);
494     
495         DoRegeneratePackageDoc(pack);
496   }
497   //================================================================
498
499
500   void WxGUIScriptingInterface::DoRegenerateBoxesLists()
501   {
502     std::string command;
503 #if defined(WIN32)
504         command = "\"";
505 #endif
506     command += ConfigurationFile::GetInstance().Get_bin_path();
507     command += ConfigurationFile::GetInstance().Get_file_separator();
508     command += "bbRegenerateBoxesLists";
509 #if defined(WIN32)
510         command += "\"";
511 #endif
512         command += " -q";
513         bbtkMessage("debug",1,"Executing system command '"<<command<<"'"<<std::endl);
514
515         if ( ! system ( command.c_str() ) )
516     {
517        wxMessageBox(_T("Done !"),_T("Regenerate boxes lists"),
518                     wxOK | wxICON_INFORMATION);
519      }
520    else 
521      {
522        wxString err(_T("An error occured while running '"));
523        err +=  bbtk::std2wx(command) + _T("'");
524        wxMessageBox(err,_T("Regenerate boxes lists"),wxOK | wxICON_ERROR);      
525      }
526   }
527
528   //================================================================
529   void WxGUIScriptingInterface::OnMenuRegenerateBoxesLists(wxCommandEvent& WXUNUSED(event))
530   {
531         DoRegenerateBoxesLists();
532   }
533   //================================================================
534
535   //================================================================
536   void WxGUIScriptingInterface::OnMenuRegenerateAll(wxCommandEvent& WXUNUSED(event))
537   {
538         
539     DoRegeneratePackageDoc("-a");       
540         DoRegenerateBoxesLists();
541   }
542   //================================================================
543
544  
545   //================================================================
546   void WxGUIScriptingInterface::OnMenuPlugPackage(wxCommandEvent& WXUNUSED(event))
547   {
548     long style = wxDD_DEFAULT_STYLE | wxDD_DIR_MUST_EXIST;
549     wxDirDialog* FD = 
550       new wxDirDialog( 0, 
551                        _T("Select package directory"),
552                        _T(""),
553                        style);
554     
555     if (FD->ShowModal()==wxID_OK)
556       {
557         std::string path = wx2std (FD->GetPath()) ;
558         std::string fname = path + "/bbtkPackage"; 
559         if ( ! Utilities::FileExists( fname ) )
560           {
561             wxString err(_T("The directory does not contain a 'bbtkPackage' file"));
562             wxMessageBox(err,_T("Plug package"),wxOK | wxICON_ERROR);      
563             return;
564           }
565         
566         std::ifstream f;
567         f.open(fname.c_str());
568         std::string pname;
569         f >> pname;
570         f.close();
571         
572         
573         bbtk::ConfigurationFile::GetInstance().AddPackagePathsAndWrite( path );
574         
575         DoRegeneratePackageDoc(pname);
576         DoRegenerateBoxesLists();
577
578           }     
579   }
580   //================================================================
581
582   //================================================================
583   void WxGUIScriptingInterface::InterpreterUserViewHtmlPage(const std::string& page)
584   {
585     std::string s(page);
586     //  std::cout << "WxGUIScriptingInterface::ShowHtmlPage('"<<page<<"')"<<std::endl;
587     if (mWxGUIHtmlBrowser->GoTo(s)) 
588       {
589 //EED   mwxNotebook->ChangeSelection(1);
590 //      mwxNotebook->SetSelection(1);
591       }
592     else 
593       {
594          // std::cout << "ERROR html"<<std::endl;
595       }
596   } 
597   //================================================================  
598   
599   //================================================================  
600   bool WxGUIScriptingInterface::WxGUIHtmlBrowserUserOnLinkClicked(const std::string& target)
601   {
602     size_t s = target.length();
603     if ((s>3) && (target[s-1]=='s')
604         && (target[s-2]=='b')
605         && (target[s-3]=='b')
606         && (target[s-4]=='.'))
607       {
608         mWxGUITextEditor->Open(target);
609 #if NOTEBOOK
610         mwxNotebook->SetSelection(0);
611 #endif
612         mWxGUITextEditor->SetFocus();
613         return false;
614       }
615     return true;
616   }
617   //================================================================  
618
619   void WxGUIScriptingInterface::OnMenuWindowsCheck( wxCommandEvent& event, 
620                                                     wxWindow* w)
621   {
622     bool checked = event.IsChecked();
623     bool shown = m_mgr.GetPane(w).IsShown();
624     //    std::cout << "checked = "<<checked<<" - shown = "<<shown<<std::endl;
625     if (checked ^ shown) 
626       {
627         m_mgr.GetPane(w).Show(checked);
628         m_mgr.Update();
629       }
630   }
631
632
633   //================================================================  
634   void WxGUIScriptingInterface::OnMenuWindowsFiles(wxCommandEvent& event)
635   {
636     OnMenuWindowsCheck(event,mWxGUITextEditor);
637   }
638   //================================================================  
639
640   //================================================================  
641   void  WxGUIScriptingInterface::OnMenuWindowsHelp(wxCommandEvent& event)
642   {
643     OnMenuWindowsCheck(event,mWxGUIHtmlBrowser);
644   }
645   //================================================================  
646
647   //================================================================  
648   void  WxGUIScriptingInterface::OnMenuWindowsMessages(wxCommandEvent& event)
649   {
650     OnMenuWindowsCheck(event,mWxGUIOutputMessages);
651   }
652   //================================================================  
653
654   //================================================================  
655   void  WxGUIScriptingInterface::OnMenuWindowsCommand(wxCommandEvent& event)
656   {
657     OnMenuWindowsCheck(event,mWxGUICommand);
658   }
659   //================================================================  
660
661   //================================================================  
662   void WxGUIScriptingInterface::OnMenuWindowsSave( wxCommandEvent& WXUNUSED(event))
663   {
664     SavePerspective();
665   }
666   //================================================================  
667
668   //================================================================  
669   void WxGUIScriptingInterface::SavePerspective()
670   {
671     //    std::cout  << "Saving configuration..."<<std::endl;
672     std::string conf = wx2std(m_mgr.SavePerspective());
673     std::string fname = Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
674     std::ofstream f;
675     f.open(fname.c_str(), std::ios::out );
676     f << conf << std::endl;
677
678     //    int x,y;
679     //    GetPosition(&x,&y);
680     //    f << x << "  " << y << std::endl;
681
682
683     int w,h;
684     GetSize(&w,&h);
685
686     f << w << " " << h << std::endl;
687
688     f.close();
689   }
690   //================================================================  
691
692   //================================================================  
693   void WxGUIScriptingInterface::LoadPerspective()
694   {
695     std::string fname = 
696       Utilities::MakeUserSettingsFullFileName("bbStudio.aui");
697     if ( Utilities::FileExists( fname ))
698       {
699         //      std::cout  << "Loading configuration..."<<std::endl;
700
701         std::ifstream f;
702         f.open(fname.c_str());
703         std::string conf;
704         f >> conf;
705
706         //      int x,y;
707         //      f >> x >> y ;
708
709         int w,h;
710         f >> w >> h ;
711
712         f.close();
713         
714         //      std::cout << conf << std::endl;
715
716         //      Move(x,y);
717         SetSize(w,h);
718         m_mgr.LoadPerspective(std2wx(conf));
719       }
720     else 
721       {
722         m_mgr.Update();
723       }
724   }
725   //================================================================  
726
727   //================================================================  
728   void WxGUIScriptingInterface::OnPaneClose(wxAuiManagerEvent& evt)
729   {
730     std::cout  << "Closing panel '"<<evt.pane->name<<"'"<<std::endl;
731     // TO DO : Uncheck 
732     //    OnMenuWindowsCheck( wxCommandEvent& event, wxWindow* w);
733   }
734   //================================================================  
735
736   
737   //================================================================  
738   BEGIN_EVENT_TABLE(WxGUIScriptingInterface, wxFrame)
739     EVT_MENU(ID_Menu_Quit, WxGUIScriptingInterface::OnMenuQuit)
740     EVT_MENU(ID_Menu_About, WxGUIScriptingInterface::OnMenuAbout)
741     EVT_MENU(ID_Menu_EditConfig, WxGUIScriptingInterface::OnMenuEditConfig)
742     EVT_MENU(ID_Menu_CreatePackage, WxGUIScriptingInterface::OnMenuCreatePackage)
743     EVT_MENU(ID_Menu_CreateBlackBox, WxGUIScriptingInterface::OnMenuCreateBlackBox)
744     EVT_MENU(ID_Menu_ShowImageGraph, WxGUIScriptingInterface::OnMenuShowImageGraph)
745     EVT_MENU(ID_Menu_RegeneratePackageDoc, WxGUIScriptingInterface::OnMenuRegeneratePackageDoc)
746     EVT_MENU(ID_Menu_RegenerateBoxesLists, WxGUIScriptingInterface::OnMenuRegenerateBoxesLists)
747     EVT_MENU(ID_Menu_RegenerateAll, WxGUIScriptingInterface::OnMenuRegenerateAll)
748     EVT_MENU(ID_Menu_PlugPackage, WxGUIScriptingInterface::OnMenuPlugPackage)
749     EVT_MENU(ID_Menu_Windows_Files, WxGUIScriptingInterface::OnMenuWindowsFiles)
750     EVT_MENU(ID_Menu_Windows_Help, WxGUIScriptingInterface::OnMenuWindowsHelp)
751     EVT_MENU(ID_Menu_Windows_Messages, WxGUIScriptingInterface::OnMenuWindowsMessages)
752     EVT_MENU(ID_Menu_Windows_Command, WxGUIScriptingInterface::OnMenuWindowsCommand)
753     EVT_MENU(ID_Menu_Windows_Save, WxGUIScriptingInterface::OnMenuWindowsSave)
754     EVT_MENU(ID_Menu_Windows_PackageBrowser, WxGUIScriptingInterface::OnMenuWindowsPackageBrowser)
755     EVT_AUI_PANE_CLOSE(WxGUIScriptingInterface::OnPaneClose)
756   //    EVT_BUTTON(ID_Button_Run, WxGUIScriptingInterface::OnButtonRun )
757     END_EVENT_TABLE()
758   //================================================================
759
760 } // namespace bbtk
761
762
763 #endif //_USE_WXWIDGETS_