Changeset 52b8b74 in sasview for guiframe/gui_manager.py


Ignore:
Timestamp:
Jan 25, 2011 9:45:50 PM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
0912feab
Parents:
5385a9e
Message:

working on guiframe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/gui_manager.py

    r749eb8a r52b8b74  
    4141from sans.guiframe.events import StatusEvent 
    4242from sans.guiframe.events import NewPlotEvent 
    43  
    44  
     43from sans.guiframe.gui_style import * 
     44from sans.guiframe.events import NewLoadedDataEvent 
    4545STATE_FILE_EXT = ['.inv', '.fitv', '.prv'] 
    4646 
     
    5555     
    5656    def __init__(self, parent, id, title,  
    57                  window_height=300, window_width=300): 
     57                 window_height=300, window_width=300, 
     58                 gui_style=GUIFRAME.SINGLE_APPLICATION): 
    5859        """ 
    5960        Initialize the Frame object 
     
    6566        self._window_height = window_height 
    6667        self._window_width  = window_width 
     68        self.__gui_style = gui_style 
    6769         
    6870        # Logging info 
     
    8789        #data manager 
    8890        from data_manager import DataManager 
    89         self.data_manager = DataManager() 
     91        self._data_manager = DataManager() 
     92        self._data_panel = None 
    9093        #add current perpsective 
    9194        self._current_perspective = None 
    92         #file menu 
    93         self.file_menu = None 
     95        self._plotting_plugin = None 
     96        self._data_plugin = None 
     97        #Menu bar and item 
     98        self._menubar = None 
     99        self._file_menu = None 
     100        self._data_menu = None 
     101        self._window_menu = None 
     102        self._window_menu = None 
     103        self._help = None 
    94104         
    95105        ## Find plug-ins 
     
    97107        self.plugins = [] 
    98108        #add local plugin 
    99        
    100         from sans.guiframe.local_perspectives.plotting import plotting 
    101         from sans.guiframe.local_perspectives.data_loader import data_loader 
    102         self.plugins.append(plotting.Plugin()) 
    103         self.plugins.append(data_loader.Plugin()) 
    104          
     109        self.plugins += self._get_local_plugins() 
    105110        self.plugins += self._find_plugins() 
    106111       
     
    154159        self.SetStatusBar(self.sb) 
    155160        # Add panel 
    156         self._mgr = wx.aui.AuiManager(self) 
    157         self._mgr.SetDockSizeConstraint(0.5, 0.5)  
     161        default_flag = wx.aui.AUI_MGR_DEFAULT| wx.aui.AUI_MGR_ALLOW_ACTIVE_PANE 
     162        self._mgr = wx.aui.AuiManager(self, flags=default_flag) 
     163        """ 
     164        if self.__gui_style in [GUIFRAME.MULTIPLE_APPLICATIONS]: 
     165            from data_panel import DataPanel 
     166            self._data_panel = DataPanel(self) 
     167            """ 
    158168        # Load panels 
    159169        self._load_panels() 
    160170        self._mgr.Update() 
    161171         
     172    def _layout(self, style): 
     173        """ 
     174        Layout the frame according to a style 
     175        """ 
     176        if self.__gui_style == GUIFRAME.SINGLE_APPLICATION: 
     177            #Divide the frame into  
     178            print "GUIFRAME.SINGLE_APPLICATION" 
     179        elif self.__gui_style == GUIFRAME.MULTIPLE_APPLICATIONS: 
     180            print 'GUIFRAME.MULTIPLE_APPLICATION' 
     181        elif self.__gui_style == GUIFRAME.FLOATING_PANEL: 
     182            print "GUIFRAME.FLOATING_PANEL" 
     183             
    162184    def SetStatusText(self, *args, **kwds): 
    163185        """ 
     
    192214            self.plugins.append(plugin) 
    193215       
     216    def _get_local_plugins(self): 
     217        """ 
     218        get plugins local to guiframe and others  
     219        """ 
     220        plugins = [] 
     221        #import guiframe local plugins 
     222        if self.__gui_style == GUIFRAME.DATALOADER_ON: 
     223            try: 
     224                from sans.guiframe.local_perspectives.data_loader import data_loader 
     225                self._data_plugin =data_loader.Plugin() 
     226                plugins.append(self._data_plugin) 
     227            except: 
     228                msg = "ViewerFrame._find_plugins:" 
     229                msg += "cannot import dataloader plugin.\n %s" % sys.exc_value 
     230                logging.error(msg) 
     231        elif self.__gui_style == GUIFRAME.PLOTTIN_ON: 
     232            try: 
     233                from sans.guiframe.local_perspectives.plotting import plotting 
     234                self._plotting_plugin = plotting.Plugin() 
     235                plugins.append(self._plotting_plugin) 
     236            except: 
     237                msg = "ViewerFrame._find_plugins:" 
     238                msg += "cannot import plotting plugin.\n %s" % sys.exc_value 
     239        elif self.__gui_style in [6, 7, 8]: 
     240            try: 
     241                from sans.guiframe.local_perspectives.data_loader import data_loader 
     242                self._data_plugin =data_loader.Plugin() 
     243                plugins.append(self._data_plugin) 
     244                from sans.guiframe.local_perspectives.plotting import plotting 
     245                self._plotting_plugin = plotting.Plugin() 
     246                plugins.append(self._plotting_plugin) 
     247            except: 
     248                msg = "ViewerFrame._get_local_plugins: %s" % sys.exc_value 
     249                logging.error(msg) 
     250        return plugins 
     251     
    194252    def _find_plugins(self, dir="perspectives"): 
    195253        """ 
     
    392450                    id = wx.NewId() 
    393451                    m_name, m_hint, m_handler = item 
    394                     self.filemenu.Append(id, m_name, m_hint) 
     452                    self._filemenu.Append(id, m_name, m_hint) 
    395453                    wx.EVT_MENU(self, id, m_handler) 
    396                 self.filemenu.AppendSeparator() 
     454                self._filemenu.AppendSeparator() 
    397455                 
    398456    def _setup_menus(self): 
     
    402460        # Menu 
    403461        self._menubar = wx.MenuBar() 
    404         # File menu 
    405         self.filemenu = wx.Menu() 
    406          
    407         # some menu of plugin to be seen under file menu 
    408         self._populate_file_menu() 
    409         id = wx.NewId() 
    410         self.filemenu.Append(id, '&Save state into File', 
    411                              'Save project as a SansView (svs) file') 
    412         wx.EVT_MENU(self, id, self._on_save) 
    413         #self.filemenu.AppendSeparator() 
    414          
    415         id = wx.NewId() 
    416         self.filemenu.Append(id, '&Quit', 'Exit')  
    417         wx.EVT_MENU(self, id, self.Close) 
    418          
    419         # Add sub menus 
    420         self._menubar.Append(self.filemenu, '&File') 
    421          
    422         # Window menu 
    423         # Attach a menu item for each panel in our 
    424         # panel list that also appears in a plug-in. 
    425          
    426         # Only add the panel menu if there is only one perspective and 
    427         # it has more than two panels. 
    428         # Note: the first plug-in is always the plotting plug-in.  
    429         #The first application 
    430         # plug-in is always the second one in the list. 
    431         if len(self.plugins) == 2: 
    432             plug = self.plugins[1] 
    433             pers = plug.get_perspective() 
     462        self._add_menu_file() 
     463        self._add_menu_data() 
     464        self._add_menu_application() 
     465        self._add_menu_window() 
    434466        
    435             if len(pers) > 1: 
    436                 viewmenu = wx.Menu() 
    437                 for item in self.panels: 
    438                     if item == 'default': 
    439                         continue 
    440                     panel = self.panels[item] 
    441                     if panel.window_name in pers: 
    442                         viewmenu.Append(int(item), panel.window_caption, 
    443                                         "Show %s window" % panel.window_caption) 
    444                         wx.EVT_MENU(self, int(item), self._on_view) 
    445                 self._menubar.Append(viewmenu, '&Window') 
    446  
    447         # Perspective 
    448         # Attach a menu item for each defined perspective. 
    449         # Only add the perspective menu if there are more than one perspectives 
    450         n_perspectives = 0 
    451         for plug in self.plugins: 
    452             if len(plug.get_perspective()) > 0: 
    453                 n_perspectives += 1 
    454          
    455         if n_perspectives > 1: 
    456             p_menu = wx.Menu() 
    457             for plug in self.plugins: 
    458                 if len(plug.get_perspective()) > 0: 
    459                     id = wx.NewId() 
    460                     p_menu.Append(id, plug.sub_menu, 
    461                                   "Switch to %s perspective" % plug.sub_menu) 
    462                     wx.EVT_MENU(self, id, plug.on_perspective) 
    463             self._menubar.Append(p_menu, '&Perspective') 
     467 
     468         
    464469  
    465470        # Tools menu 
     
    509514        # Add available plug-in sub-menus.  
    510515        for item in self.plugins: 
    511             if hasattr(item, "populate_menu"): 
     516            if item != self._plotting_plugin: 
    512517                for (self.next_id, menu, name) in \ 
    513518                    item.populate_menu(self.next_id, self): 
     
    517522        self.SetMenuBar(self._menubar) 
    518523     
     524    def _add_menu_window(self): 
     525        """ 
     526        add a menu window to the menu bar 
     527        Window menu 
     528        Attach a menu item for each panel in our 
     529        panel list that also appears in a plug-in. 
     530         
     531        Only add the panel menu if there is only one perspective and 
     532        it has more than two panels. 
     533        Note: the first plug-in is always the plotting plug-in.  
     534        The first application 
     535        #plug-in is always the second one in the list. 
     536        """ 
     537        self._window_menu = wx.Menu() 
     538        if self._plotting_plugin is not None: 
     539            for (self.next_id, menu, name) in \ 
     540                self._plotting_plugin.populate_menu(self.next_id, self): 
     541                self._window_menu.AppendSubMenu(menu, name) 
     542        self._window_menu.AppendSeparator() 
     543        self._menubar.Append(self._window_menu, '&Window') 
     544        if self.defaultPanel is not None : 
     545            id = wx.NewId() 
     546            self._window_menu.Append(id,'&Welcome', '') 
     547             
     548            wx.EVT_MENU(self, id, self.show_welcome_panel) 
     549        if self.__gui_style in [GUIFRAME.MANAGER_ON, 
     550                                 GUIFRAME.MULTIPLE_APPLICATIONS]: 
     551            id = wx.NewId() 
     552            self._window_menu.Append(id,'&Data Manager', '') 
     553             
     554            wx.EVT_MENU(self, id, self.show_data_panel) 
     555             
     556        """ 
     557        if len(self.plugins) == 2: 
     558            plug = self.plugins[1] 
     559            pers = plug.get_perspective() 
     560        
     561            if len(pers) > 1: 
     562                self._window_menu = wx.Menu() 
     563                for item in self.panels: 
     564                    if item == 'default': 
     565                        continue 
     566                    panel = self.panels[item] 
     567                    if panel.window_name in pers: 
     568                        self._window_menu.Append(int(item), 
     569                                                  panel.window_caption, 
     570                                        "Show %s window" % panel.window_caption) 
     571                        wx.EVT_MENU(self, int(item), self._on_view) 
     572                self._menubar.Append(self._window_menu, '&Window') 
     573                """ 
     574                 
     575    def _add_menu_application(self): 
     576        """ 
     577         
     578        # Attach a menu item for each defined perspective or application. 
     579        # Only add the perspective menu if there are more than one perspectives 
     580        add menu application 
     581        """ 
     582        if self.__gui_style in [GUIFRAME.MULTIPLE_APPLICATIONS]: 
     583            p_menu = wx.Menu() 
     584            for plug in self.plugins: 
     585                if len(plug.get_perspective()) > 0: 
     586                    id = wx.NewId() 
     587                    p_menu.Append(id, plug.sub_menu, 
     588                                  "Switch to application: %s" % plug.sub_menu) 
     589                    wx.EVT_MENU(self, id, plug.on_perspective) 
     590            self._menubar.Append(p_menu, '&Applications') 
     591             
     592    def _add_menu_file(self): 
     593        """ 
     594        add menu file 
     595        """ 
     596         # File menu 
     597        self._filemenu = wx.Menu() 
     598         
     599        # some menu of plugin to be seen under file menu 
     600        self._populate_file_menu() 
     601         
     602        id = wx.NewId() 
     603        self._filemenu.Append(id, '&Save state into File', 
     604                             'Save project as a SansView (svs) file') 
     605        wx.EVT_MENU(self, id, self._on_save) 
     606        #self.__filemenu.AppendSeparator() 
     607         
     608        id = wx.NewId() 
     609        self._filemenu.Append(id, '&Quit', 'Exit')  
     610        wx.EVT_MENU(self, id, self.Close) 
     611         
     612        # Add sub menus 
     613        self._menubar.Append(self._filemenu, '&File') 
     614         
     615    def _add_menu_data(self): 
     616        """ 
     617        Add menu item item data to menu bar 
     618        """ 
     619        # Add menu data  
     620        self._data_menu = wx.Menu() 
     621        #menu for data files 
     622        data_file_id = wx.NewId() 
     623        data_file_hint = "load one or more data in the application" 
     624        self._data_menu.Append(data_file_id,  
     625                         '&Load Data File(s)', data_file_hint) 
     626        wx.EVT_MENU(self, data_file_id, self._load_data) 
     627        if self.__gui_style == GUIFRAME.SINGLE_APPLICATION: 
     628            self._menubar.Append(self._data_menu, '&Data') 
     629            return  
     630        else: 
     631            #menu for data from folder 
     632            data_folder_id = wx.NewId() 
     633            data_folder_hint = "load multiple data in the application" 
     634            self._data_menu.Append(data_folder_id,  
     635                             '&Load Data Folder', data_folder_hint) 
     636            wx.EVT_MENU(self, data_folder_id, self._load_folder) 
     637            self._menubar.Append(self._data_menu, '&Data') 
     638         
     639    def _load_data(self, event): 
     640        """ 
     641        connect menu item load data with the first plugin that can load data 
     642        """ 
     643        for plug in self.plugins: 
     644            if plug.can_load_data(): 
     645                plug.load_data(event) 
     646                 
     647    def _load_folder(self, event): 
     648        """ 
     649        connect menu item load data with the first plugin that can load data and 
     650        folder 
     651        """ 
     652        for plug in self.plugins: 
     653            if plug.can_load_data(): 
     654                plug.load_folder(event) 
     655                 
    519656    def _on_status_event(self, evt): 
    520657        """ 
     
    832969        return path 
    833970     
     971    def show_data_panel(self, event): 
     972        """ 
     973        """ 
     974    def show_welcome_panel(self, event): 
     975        """ 
     976        show welcome panel 
     977        """ 
     978         
    834979    def add_data(self, data_list): 
    835980        """ 
     
    837982        determine if data was be plot of send to data perspectives 
    838983        """ 
    839         self.data_manager.add_data(data_list) 
     984        #send a list of available data to plotting plugin 
     985        avalaible_data = [] 
     986        if self._data_manager is not None: 
     987            self._data_manager.add_data(data_list) 
     988            avalaible_data = self._data_manager.get_all_data() 
     989        wx.PostEvent(self, NewLoadedDataEvent(data_to_add=avalaible_data, 
     990                                              data_to_remove = []))  
     991             
    840992        if AUTO_SET_DATA: 
    841993            if self._current_perspective is not None: 
     
    8531005        if AUTO_PLOT: 
    8541006            self.plot_data(data_list) 
    855              
     1007        
     1008         
     1009         
    8561010    def plot_data(self, data_list): 
    8571011        """ 
Note: See TracChangeset for help on using the changeset viewer.