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