Changeset a07e72f in sasview


Ignore:
Timestamp:
Feb 28, 2011 2:07:14 PM (13 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:
243a8d4
Parents:
6bbeacd4
Message:

remove other type of data into sansview

Files:
4 added
14 edited

Legend:

Unmodified
Added
Removed
  • guiframe/data_manager.py

    r0348245 ra07e72f  
    2323from sans.guiframe.dataFitting import Data2D 
    2424   
     25import wx 
     26 
    2527class DataManager(object): 
    2628    """ 
     
    7779        new_plot.interactive = True 
    7880        ## when 2 data have the same id override the 1 st plotted 
    79         new_plot.id = name 
     81        new_plot.id = wx.NewId() 
    8082        ##group_id specify on which panel to plot this data 
    81         new_plot.group_id = name 
     83        new_plot.group_id = [wx.NewId()] 
    8284        new_plot.is_data = True 
    8385        new_plot.path = path 
     
    151153        """ 
    152154        """ 
    153         print "append theory", self.stored_data, data_id 
    154155        if data_id in self.stored_data: 
    155156            data_state = self.stored_data[data_id] 
  • guiframe/events.py

    r4e4d3bb ra07e72f  
    1616#slicer event 
    1717(SlicerEvent, EVT_SLICER)   = wx.lib.newevent.NewEvent() 
    18 # event containinG A DICTIONARY OF NAME and errors of selected data 
    19 (ErrorDataEvent, ERR_DATA) = wx.lib.newevent.NewEvent() 
    2018## event that that destroy a page associate with Data1D removed from the graph 
    2119(RemoveDataEvent, EVT_REMOVE_DATA)   = wx.lib.newevent.NewEvent() 
  • guiframe/gui_manager.py

    r4c0572f ra07e72f  
    431431                                  Hide())         
    432432       
    433     def get_context_menu(self, graph=None): 
     433    def get_context_menu(self, plotpanel=None): 
    434434        """ 
    435435        Get the context menu items made available  
     
    437437        This function is used by the plotting module 
    438438        """ 
     439        if plotpanel is None: 
     440            return 
    439441        menu_list = [] 
    440442        for item in self.plugins: 
    441             if hasattr(item, "get_context_menu"): 
    442                 menu_list.extend(item.get_context_menu(graph)) 
     443            menu_list.extend(item.get_context_menu(plotpanel=plotpanel)) 
    443444        return menu_list 
    444445         
  • guiframe/gui_style.py

    r59a4a750 ra07e72f  
    3333    PRINT_ID = wx.NewId() 
    3434    CURRENT_APPLICATION = wx.NewId() 
     35    CURVE_SYMBOL_NUM = 13 
    3536     
    3637class GUIFRAME_ICON: 
  • guiframe/local_perspectives/plotting/Plotter1D.py

    ra45037aa ra07e72f  
    1818import numpy 
    1919import time 
    20 import danse.common.plottools 
     20 
    2121from danse.common.plottools.PlotPanel import PlotPanel 
    2222from danse.common.plottools.plottables import Graph 
     
    2626from sans.guiframe.events import NewPlotEvent 
    2727from sans.guiframe.events import SlicerEvent 
    28 from sans.guiframe.events import ErrorDataEvent 
    2928from sans.guiframe.events import RemoveDataEvent 
    3029from sans.guiframe.events import PanelOnFocusEvent 
     
    3231from sans.guiframe.utils import PanelMenu 
    3332from sans.guiframe.dataFitting import Data1D 
    34 from sans.guiframe.dataFitting import Theory1D 
    3533from sans.guiframe.panel_base import PanelBase 
    3634from binder import BindArtist 
     
    6765        #context menu 
    6866        self._slicerpop = None 
    69         self._menu_add_plot = None 
     67         
    7068        self._available_data = [] 
    7169        self._menu_add_ids = [] 
    72         ## save errors dy  for each data plotted 
    73         self.err_dy = {} 
    74         ## flag to determine if the hide or show context menu item should 
    75         ## be displayed 
    76         self.errors_hide = False 
     70        self._symbol_labels = self.get_symbol_label() 
     71       
     72        self.hide_menu = None 
    7773        ## Unique ID (from gui_manager) 
    7874        self.uid = None 
    79         ## Action IDs for internal call-backs 
    80         self.action_ids = {} 
     75        
    8176        ## Default locations 
    8277        self._default_save_location = os.getcwd()         
     
    8681        self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    8782        self.graph.render(self) 
    88         #bind with event to contrst context menu 
    89         #self.parent.Bind(EVT_NEW_LOADED_DATA, self._add_new_plot) 
    90          
    91     def on_add_new_plot(self, event): 
    92         """ 
    93         """ 
    94     def _add_new_plot(self, event): 
    95         """ 
    96         Construct the context menu given available data 
    97         """ 
    98         self._available_data = event.data_to_add 
     83        
     84    def get_symbol_label(self): 
     85        """ 
     86        Associates label to symbol 
     87        """ 
     88        _labels = {} 
     89        i = 0 
     90        _labels['Points'] = i 
     91        i += 1 
     92        _labels['X '] = i 
     93        i += 1 
     94        _labels['Triangle Down'] = i 
     95        i += 1 
     96        _labels['Triangle Up'] = i 
     97        i += 1 
     98        _labels['Triangle Left'] = i 
     99        i += 1 
     100        _labels['Triangle Right'] = i 
     101        i += 1 
     102        _labels['Plus'] = i 
     103        i += 1 
     104        _labels['Square'] = i 
     105        i += 1 
     106        _labels['Thin Diamond'] = i 
     107        i += 1 
     108        _labels['Diamond'] = i 
     109        i += 1 
     110        _labels['Hexagon1'] = i 
     111        i += 1 
     112        _labels['Hexagon2'] = i 
     113        i += 1 
     114        _labels['Pentagon'] = i 
     115        i += 1 
     116        _labels['Curve'] = i 
     117        return _labels 
     118 
    99119     
    100     def _fill_menu_add_plot(self): 
    101         """ 
    102         """ 
    103         if self._menu_add_plot is not None: 
    104             if self._available_data: 
    105                 for id in self._menu_add_ids: 
    106                     item = self._menu_add_plot.FindItemById(id) 
    107                     if item is None: 
    108                         for data in self._available_data: 
    109                             new_id = wx.NewId() 
    110                             hint = 'Add %s to this panel' % str(data.name) 
    111                             self._menu_add_plot.Append(new_id, str(data.name), hint) 
    112                             wx.EVT_MENU(self, id, self.on_add_new_plot) 
    113                             self._menu_add_ids.append(new_id) 
    114                     else: 
    115                         if item.GetLabel() == 'No Loaded Data': 
    116                             self._menu_add_plot.RemoveItem(item) 
    117                          
    118120    def set_data(self, list=None): 
    119121        """ 
     
    127129        self.graph.reset() 
    128130        self.plots      = {} 
    129         self.action_ids = {} 
    130131     
    131     def _onEVT_1DREPLOT(self, event): 
     132    def remove_data_by_id(self, id): 
     133        """' 
     134        remove data from plot 
     135        """ 
     136        if id in self.plots.keys(): 
     137            data =  self.plots[id] 
     138            self.graph.delete(data) 
     139            data_manager = self._manager.parent.get_data_manager() 
     140            data_list = data_manager.get_by_id(id_list=[id]) 
     141            data = data_list.values()[0].data 
     142            data.group_id.remove(self.group_id) 
     143            del self.plots[id] 
     144                  
     145            self.graph.render(self) 
     146            self.subplot.figure.canvas.draw_idle()     
     147            if len(self.graph.plottables) == 0: 
     148                print "_onRemove: graph is empty must be destroyed" 
     149            
     150        else: 
     151            msg = "Attempt to remove an unexisting plot with ID %s " % str(id) 
     152            raise ValueError, msg 
     153         
     154    def plot_data(self, data): 
    132155        """ 
    133156        Data is ready to be displayed 
     
    135158        :param event: data event 
    136159        """ 
    137         #TODO: Check for existence of plot attribute 
    138         # Check whether this is a replot. If we ask for a replot 
    139         # and the plottable no longer exists, ignore the event. 
    140         if hasattr(event, "update") and event.update == True \ 
    141             and event.plot.name not in self.plots.keys(): 
    142             return 
    143         if hasattr(event, "reset"): 
    144             self._reset() 
    145         # Check whether the plottable is empty 
    146         is_empty = len(event.plot.x) == 0 
    147                  
    148         is_new = True 
    149         if event.plot.name in self.plots.keys(): 
    150             # If the plottable is empty, just remove the plottable from the graph 
    151             if is_empty: 
    152                 self.graph.delete(self.plots[event.plot.name]) 
    153                 del self.plots[event.plot.name] 
    154             else:   
    155                 # Check whether the class of plottable changed 
    156                 if not event.plot.__class__ == self.plots[event.plot.name].__class__: 
    157                     #overwrite a plottable using the same name 
    158                     self.graph.delete(self.plots[event.plot.name])               
    159                 else: 
    160                     # plottable is already draw on the panel 
    161                     is_new = False 
    162          
    163         if not is_empty: 
    164             if is_new: 
    165                 # a new plottable overwrites a plotted one  using the same id 
    166                 for plottable in self.plots.itervalues(): 
    167                     if hasattr(event.plot, "id") and hasattr(plottable, "id"): 
    168                         #remove the existing plot and same id and same name 
    169                         if event.plot.id == plottable.id and \ 
    170                             event.plot.name == plottable.name: 
    171                             self.graph.delete(plottable) 
    172                  
    173                 self.plots[event.plot.name] = event.plot 
    174                 self.graph.add(self.plots[event.plot.name]) 
    175             else: 
    176                 #replot the graph 
    177                 self.plots[event.plot.name].x = event.plot.x     
    178                 self.plots[event.plot.name].y = event.plot.y     
    179                 self.plots[event.plot.name].dy = event.plot.dy   
    180                 if hasattr(event.plot, 'dx') and \ 
    181                     hasattr(self.plots[event.plot.name], 'dx'): 
    182                     self.plots[event.plot.name].dx = event.plot.dx     
    183            
    184         #TODO: Should re-factor this 
    185         ## for all added plot the option to hide error show be displayed first 
    186         #self.errors_hide = 0 
    187         ## Set axis labels 
    188         self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 
    189         self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 
     160        if data.id in self.plots.keys(): 
     161            #replace 
     162            self.graph.replace(data) 
     163            self.plots[data.id] = data 
     164        else: 
     165            self.plots[data.id] = data 
     166            self.graph.add(self.plots[data.id])  
     167         
     168        x_label, x_unit = data.get_xaxis() 
     169        y_label, y_unit = data.get_yaxis() 
     170        self.graph.xaxis(x_unit, x_label) 
     171        self.graph.yaxis(y_unit, y_label) 
    190172        ## Set the view scale for all plots 
    191173        self._onEVT_FUNC_PROPERTY() 
     
    193175        self.graph.render(self) 
    194176        self.subplot.figure.canvas.draw_idle() 
    195         #if self.errors_hide: 
    196         #    self._on_remove_errors(evt=None) 
    197         #else: 
    198         #    self._on_add_errors( evt=None) 
    199      
     177 
     178        
    200179    def onLeftDown(self,event):  
    201180        """  
     
    211190        #post nd event to notify guiframe that this panel is on focus 
    212191        wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 
    213          
     192        self._manager.set_panel_on_focus(self) 
     193         
     194    def _ontoggle_hide_error(self, event): 
     195        """ 
     196        Toggle error display to hide or show 
     197        """ 
     198         
     199        selected_plot = self.plots[self.graph.selected_plottable] 
     200        if self.hide_menu.GetText() == "Hide Error": 
     201            selected_plot.hide_error = True 
     202        else: 
     203            selected_plot.hide_error = False 
     204        ## increment graph color 
     205        self.graph.render(self) 
     206        self.subplot.figure.canvas.draw_idle()   
     207           
    214208    def _onRemove(self, event): 
    215209        """ 
     
    219213         
    220214        """ 
    221         selected_plot = self.plots[self.graph.selected_plottable] 
    222215        ## Check if there is a selected graph to remove 
    223         if not self.graph.selected_plottable == None and\ 
    224             self.graph.selected_plottable in self.plots.keys(): 
    225             color = self.graph.plottables[selected_plot] 
     216        if self.graph.selected_plottable in self.plots.keys(): 
     217            selected_plot = self.plots[self.graph.selected_plottable] 
     218            id = self.graph.selected_plottable 
     219            self.remove_data_by_id( id) 
    226220            event = RemoveDataEvent(data=selected_plot) 
    227221            wx.PostEvent(self.parent, event) 
    228222            self.graph.delete(selected_plot) 
    229223            del selected_plot 
    230             ## increment graph color 
    231             self.graph.color += color 
    232             self.graph.render(self) 
    233             self.subplot.figure.canvas.draw_idle()     
    234             
     224        
    235225    def onContextMenu(self, event): 
    236226        """ 
     
    253243        self._slicerpop.Append(id, '&Print Preview', 'image preview for print') 
    254244        wx.EVT_MENU(self, id, self.onPrinterPreview) 
    255         """ 
    256         #add plot 
    257         self._menu_add_plot = wx.Menu() 
    258         id = wx.NewId() 
    259         self._menu_add_plot.Append(id, '&No Loaded Data', 'Add new plot') 
    260         self._menu_add_plot.FindItemByPosition(0).Enable(False) 
    261         self._menu_add_ids.append(id) 
    262          
    263         self._slicerpop.AppendSubMenu(self._menu_add_plot, '&Add New Plot') 
    264         self._fill_menu_add_plot() 
    265         """ 
     245         
     246        symbol_menu = wx.Menu() 
     247        for label in self._symbol_labels: 
     248            id = wx.NewId() 
     249            symbol_menu.Append(id, str(label), str(label)) 
     250            wx.EVT_MENU(self, id, self.onChangeSymbol) 
     251        id = wx.NewId() 
     252        self._slicerpop.AppendMenu(id,'&Modify Symbol',  symbol_menu) 
    266253        self._slicerpop.AppendSeparator() 
     254         
    267255        #add menu of other plugins 
    268         item_list = self.parent.get_context_menu(self.graph) 
     256        item_list = self.parent.get_context_menu(self) 
    269257        if (not item_list == None) and (not len(item_list) == 0): 
    270258            for item in item_list: 
     
    275263                except: 
    276264                    msg = "ModelPanel1D.onContextMenu: " 
    277                     msg += "bad menu item  %s"%sys.exc_value 
     265                    msg += "bad menu item  %s" % sys.exc_value 
    278266                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    279267                    pass 
    280268            self._slicerpop.AppendSeparator() 
    281269        id = wx.NewId() 
    282         self._menu_add_plot = wx.Menu() 
     270         
    283271        self._slicerpop.Append(id, '&Print image', 'Print image') 
    284272        if self.graph.selected_plottable in self.plots: 
     
    287275            name = plot.name 
    288276            self._slicerpop.Append(id, "&Save points") 
    289             self.action_ids[str(id)] = plot 
    290277            wx.EVT_MENU(self, id, self._onSave) 
    291278            id = wx.NewId() 
    292279            self._slicerpop.Append(id, "Remove %s curve" % name) 
    293             self.action_ids[str(id)] = plot 
    294280            wx.EVT_MENU(self, id, self._onRemove) 
     281            id = wx.NewId() 
     282            self.hide_menu = self._slicerpop.Append(id, "Hide Error") 
     283            if plot.dy is not None or plot.dy != []: 
     284                if plot.hide_error : 
     285                    self.hide_menu.SetText('Show Error') 
     286                else: 
     287                    self.hide_menu.SetText('Hide Error') 
     288            else: 
     289                self.hide_menu.Disable() 
     290            wx.EVT_MENU(self, id, self._ontoggle_hide_error) 
     291             
    295292            self._slicerpop.AppendSeparator() 
    296293            # Option to hide 
    297294            #TODO: implement functionality to hide a plottable (legend click) 
    298         if self.graph.selected_plottable in self.plots: 
    299             selected_plot = self.plots[self.graph.selected_plottable] 
    300             id = wx.NewId() 
    301             self._slicerpop.Append(id, '&Linear fit') 
    302             wx.EVT_MENU(self, id, self.onFitting) 
    303             self._slicerpop.AppendSeparator() 
     295        id = wx.NewId() 
     296        self._slicerpop.Append(id, '&Linear Fit') 
     297        wx.EVT_MENU(self, id, self.onFitting) 
     298         
    304299        id = wx.NewId() 
    305300        self._slicerpop.Append(id, '&Change scale') 
     
    311306        pos = self.ScreenToClient(pos) 
    312307        self.PopupMenu(self._slicerpop, pos) 
    313          
    314     def _on_remove_errors(self, evt): 
    315         """ 
    316         Save name and dy of data in dictionary self.err_dy 
    317         Create a new data1D with the same x, y 
    318         vector and dy with zeros. 
    319         post self.err_dy as event (ErrorDataEvent) for any object 
    320         which wants to reconstruct the initial data. 
    321          
    322         :param evt: Menu event 
    323          
    324         """ 
    325         if not self.graph.selected_plottable == None: 
    326             ## store existing dy 
    327             name =self.plots[self.graph.selected_plottable].name 
    328             dy = self.plots[self.graph.selected_plottable].dy 
    329             self.err_dy[name] = dy 
    330             ## Create a new dy for a new plottable 
    331             #import numpy 
    332             dy = numpy.zeros(len(self.plots[self.graph.selected_plottable].y)) 
    333             selected_plot = self.plots[self.graph.selected_plottable] 
    334              
    335             if selected_plot.__class__.__name__ == "Data1D": 
    336                 # Make sure that we can pass a basic Data1D 
    337                 dxl = None 
    338                 dxw = None 
    339                 if hasattr(selected_plot, "dxl"): 
    340                     dxl = selected_plot.dxl 
    341                 if hasattr(selected_plot, "dxw"): 
    342                     dxw = selected_plot.dxw 
    343                 new_plot = Data1D(x=selected_plot.x, y=selected_plot.y, 
    344                                dx=selected_plot.dx, dy=dy) 
    345                 new_plot.dxl = dxl 
    346                 new_plot.dxw = dxw             
    347             else: 
    348                  new_plot = Theory1D(x=selected_plot.x,  
    349                                      y=selected_plot.y, dy=dy) 
    350             new_plot.interactive = True 
    351             self.errors_hide = True 
    352             new_plot.name = self.plots[self.graph.selected_plottable].name  
    353             if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 
    354                 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 
    355                 if hasattr(self.plots[self.graph.selected_plottable], "id"): 
    356                     new_plot.id = self.plots[self.graph.selected_plottable].id 
    357                 else: 
    358                     new_plot.id = str(time.time()) 
    359             else: 
    360                 new_plot.group_id = str(time.time()) 
    361                 new_plot.id = str(time.time()) 
    362             label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 
    363             new_plot.xaxis(label, unit) 
    364             label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 
    365             new_plot.yaxis(label, unit) 
    366             ## save the color of the selected plottable before it is deleted 
    367             color = self.graph.plottables[self.plots[self.graph.selected_plottable]] 
    368             self.graph.delete(self.plots[self.graph.selected_plottable]) 
    369             ## add newly created plottable to the graph with the save color 
    370             self.graph.color += color 
    371             self.graph.add(new_plot, color) 
    372             ## transforming the view of the new data into the same of  
    373             #the previous data 
    374             self._onEVT_FUNC_PROPERTY() 
    375             ## save the plot  
    376             self.plots[self.graph.selected_plottable] = new_plot 
    377             ## Render the graph 
    378             self.graph.render(self) 
    379             self.subplot.figure.canvas.draw_idle()  
    380             event = ErrorDataEvent(err_dy=self.err_dy) 
    381             wx.PostEvent(self.parent, event) 
    382  
    383     def _on_add_errors(self, evt): 
    384         """ 
    385         create a new data1D witht the errors saved in self.err_dy 
    386         to show errors of the plot. 
    387         Compute reasonable errors for a data set without  
    388         errors and transorm the plottable to a Data1D 
    389          
    390         :param evt: Menu event 
    391          
    392         """ 
    393         if not self.graph.selected_plottable == None \ 
    394             and self.graph.selected_plottable in self.plots.keys(): 
    395             ##Reset the flag to display the hide option on the context menu 
    396             self.errors_hide = False 
    397             ## restore dy  
    398             length = len(self.plots[self.graph.selected_plottable].x) 
    399             dy = numpy.zeros(length) 
    400             selected_plot = self.plots[self.graph.selected_plottable] 
    401             try: 
    402                 dy = self.err_dy[selected_plot.name] 
    403             except: 
    404                 if hasattr(selected_plot, "dy"): 
    405                     dy = selected_plot.dy 
    406                 else: 
    407                     dy = numpy.zeros(selected_plot.dy) 
    408             ## Create a new plottable data1D 
    409             if selected_plot.__class__.__name__ == "Data1D": 
    410                 # Make sure that we can pass a basic Data1D 
    411                 dxl = None 
    412                 dxw = None 
    413                 if hasattr(selected_plot, "dxl"): 
    414                     dxl = selected_plot.dxl 
    415                 if hasattr(selected_plot, "dxw"): 
    416                     dxw = selected_plot.dxw 
    417                 new_plot = Data1D(x=selected_plot.x, 
    418                                                y=selected_plot.y, 
    419                                                dx=selected_plot.dx, 
    420                                                dy=dy) 
    421                 new_plot.dxl = dxl 
    422                 new_plot.dxw = dxw                        
    423             else: 
    424                 ## Create a new plottable Theory1D 
    425                 new_plot = Theory1D(x=selected_plot.x, y=selected_plot.y, dy=dy) 
    426             new_plot.interactive = True 
    427             new_plot.name = self.plots[self.graph.selected_plottable].name  
    428             if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 
    429                 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 
    430                 if hasattr(self.plots[self.graph.selected_plottable],"id"): 
    431                     new_plot.id = self.plots[self.graph.selected_plottable].id 
    432                 else: 
    433                     new_plot.id = str(time.time()) 
    434             else: 
    435                 new_plot.group_id = str(time.time()) 
    436                 new_plot.id = str(time.time()) 
    437              
    438             label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 
    439             new_plot.xaxis(label, unit) 
    440             label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 
    441             new_plot.yaxis(label, unit) 
    442             ## save the color of the selected plottable before it is deleted 
    443             color=self.graph.plottables[self.plots[self.graph.selected_plottable]] 
    444             self.graph.delete(self.plots[self.graph.selected_plottable]) 
    445             self.graph.color += color 
    446             ## add newly created plottable to the graph with the save color 
    447             self.graph.add(new_plot, color) 
    448             ## transforming the view of the new data into the same of 
    449             # the previous data 
    450             self._onEVT_FUNC_PROPERTY() 
    451             ## save the plot  
    452             self.plots[self.graph.selected_plottable]=new_plot 
    453             ## render the graph with its new content 
    454             self.graph.render(self) 
    455             self.subplot.figure.canvas.draw_idle()  
    456                 
    457                 
     308      
     309    def onChangeSymbol(self, event): 
     310        """ 
     311        """ 
     312        menu = event.GetEventObject() 
     313        id = event.GetId() 
     314        label =  menu.GetLabel(id) 
     315        selected_plot = self.plots[self.graph.selected_plottable] 
     316        selected_plot.symbol = self._symbol_labels[label] 
     317        ## Set the view scale for all plots 
     318        self._onEVT_FUNC_PROPERTY() 
     319        ## render the graph 
     320        self.graph.render(self) 
     321        self.subplot.figure.canvas.draw_idle() 
     322         
    458323    def _onsaveTXT(self, path): 
    459324        """ 
     
    503368         
    504369        """ 
    505         id = str(evt.GetId()) 
    506         if id in self.action_ids:          
     370        
     371        path = None 
     372        wildcard = "Text files (*.txt)|*.txt|"\ 
     373        "CanSAS 1D files(*.xml)|*.xml"  
     374        dlg = wx.FileDialog(self, "Choose a file", 
     375                            self._default_save_location, 
     376                             "", wildcard , wx.SAVE) 
     377        
     378        if dlg.ShowModal() == wx.ID_OK: 
     379            path = dlg.GetPath() 
     380            mypath = os.path.basename(path) 
    507381             
    508             path = None 
    509             wildcard = "Text files (*.txt)|*.txt|"\ 
    510             "CanSAS 1D files(*.xml)|*.xml"  
    511             dlg = wx.FileDialog(self, "Choose a file", 
    512                                 self._default_save_location, 
    513                                  "", wildcard , wx.SAVE) 
    514             
    515             if dlg.ShowModal() == wx.ID_OK: 
    516                 path = dlg.GetPath() 
    517                 mypath = os.path.basename(path) 
    518                  
    519                 #TODO: This is bad design. The DataLoader is designed  
    520                 #to recognize extensions. 
    521                 # It should be a simple matter of calling the . 
    522                 #save(file, data, '.xml') method 
    523                 # of the DataLoader.loader.Loader class. 
    524                 from DataLoader.loader import  Loader 
    525                 #Instantiate a loader  
    526                 loader = Loader()  
    527                 data = self.plots[self.graph.selected_plottable] 
    528                 format = ".txt" 
    529                 if os.path.splitext(mypath)[1].lower() == format: 
    530                      self._onsaveTXT( path) 
    531                 format = ".xml" 
    532                 if os.path.splitext(mypath)[1].lower() == format: 
    533                     loader.save(path, data, format) 
    534                 try: 
    535                     self._default_save_location = os.path.dirname(path) 
    536                 except: 
    537                     pass     
    538             dlg.Destroy() 
     382            #TODO: This is bad design. The DataLoader is designed  
     383            #to recognize extensions. 
     384            # It should be a simple matter of calling the . 
     385            #save(file, data, '.xml') method 
     386            # of the DataLoader.loader.Loader class. 
     387            from DataLoader.loader import  Loader 
     388            #Instantiate a loader  
     389            loader = Loader()  
     390            data = self.plots[self.graph.selected_plottable] 
     391            format = ".txt" 
     392            if os.path.splitext(mypath)[1].lower() == format: 
     393                 self._onsaveTXT( path) 
     394            format = ".xml" 
     395            if os.path.splitext(mypath)[1].lower() == format: 
     396                loader.save(path, data, format) 
     397            try: 
     398                self._default_save_location = os.path.dirname(path) 
     399            except: 
     400                pass     
     401        dlg.Destroy() 
  • guiframe/local_perspectives/plotting/Plotter2D.py

    red8ad21 ra07e72f  
    2323from sans.guiframe.events import StatusEvent  
    2424from sans.guiframe.events import NewPlotEvent 
     25from sans.guiframe.events import PanelOnFocusEvent 
    2526from sans.guiframe.events import SlicerEvent 
    2627from sans.guiframe.utils import PanelMenu 
     
    122123        self.default_zmax_ctl = self.zmax_2D 
    123124        
     125    def onLeftDown(self, event):  
     126        """ 
     127        left button down and ready to drag 
     128         
     129        """ 
     130        # Check that the LEFT button was pressed 
     131        if event.button == 1: 
     132            self.leftdown = True 
     133            ax = event.inaxes 
     134            if ax != None: 
     135                self.xInit, self.yInit = event.xdata, event.ydata 
     136        self.plottable_selected(self.data2D.id) 
     137        
     138        self._manager.set_panel_on_focus(self) 
     139        wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 
     140         
    124141    def add_toolbar(self): 
    125142        """ 
     
    138155        self.toolbar.update() 
    139156          
    140     def _onEVT_1DREPLOT(self, event): 
     157    def plot_data(self, data): 
    141158        """ 
    142159        Data is ready to be displayed 
     
    149166        """ 
    150167        ## Update self.data2d with the current plot 
    151         self.data2D = event.plot 
    152          
    153         #TODO: Check for existence of plot attribute 
    154          
    155         # Check whether this is a replot. If we ask for a replot 
    156         # and the plottable no longer exists, ignore the event. 
    157         if hasattr(event, "update") and event.update == True \ 
    158             and event.plot.name not in self.plots.keys(): 
    159             return 
    160         if hasattr(event, "reset"): 
    161             self._reset() 
    162         is_new = True 
    163         if event.plot.name in self.plots.keys(): 
    164             # Check whether the class of plottable changed 
    165             if not event.plot.__class__ == self.plots[event.plot.name].__class__: 
    166                 #overwrite a plottable using the same name 
    167                 self.graph.delete(self.plots[event.plot.name]) 
    168             else: 
    169                 # plottable is already draw on the panel 
    170                 is_new = False 
    171             
    172         if is_new: 
    173             # a new plottable overwrites a plotted one  using the same id 
    174             for plottable in self.plots.itervalues(): 
    175                 if hasattr(event.plot,"id"): 
    176                     if event.plot.id == plottable.id: 
    177                         self.graph.delete(plottable) 
    178              
    179             self.plots[event.plot.name] = event.plot 
    180             self.graph.add(self.plots[event.plot.name]) 
     168        self.data2D = data 
     169        if data.id in self.plots.keys(): 
     170            #replace 
     171            self.graph.replace(data) 
     172            self.plots[data.id] = data 
    181173        else: 
    182             # Update the plottable with the new data 
    183              
    184             #TODO: we should have a method to do this,  
    185             #      something along the lines of: 
    186             #      plottable1.update_data_from_plottable(plottable2) 
    187              
    188             self.plots[event.plot.name].xmin = event.plot.xmin 
    189             self.plots[event.plot.name].xmax = event.plot.xmax 
    190             self.plots[event.plot.name].ymin = event.plot.ymin 
    191             self.plots[event.plot.name].ymax = event.plot.ymax 
    192             self.plots[event.plot.name].data = event.plot.data 
    193             self.plots[event.plot.name].qx_data = event.plot.qx_data 
    194             self.plots[event.plot.name].qy_data = event.plot.qy_data 
    195             self.plots[event.plot.name].err_data = event.plot.err_data 
     174            self.plots[data.id] = data 
     175            self.graph.add(self.plots[data.id])  
    196176            # update qmax with the new xmax of data plotted 
    197             self.qmax = event.plot.xmax 
     177            self.qmax = data.xmax 
    198178             
    199179        self.slicer = None 
     
    204184        #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 
    205185        if len(self.data2D.detector) < 1:  
    206             if len(event.plot._xunit) < 1 and len(event.plot._yunit) < 1: 
    207                 event.plot._xaxis = '\\rm{x}' 
    208                 event.plot._yaxis = '\\rm{y}' 
    209                 event.plot._xunit = 'pixel' 
    210                 event.plot._yunit = 'pixel' 
    211         self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 
    212         self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 
     186            if len(data._xunit) < 1 and len(data._yunit) < 1: 
     187                data._xaxis = '\\rm{x}' 
     188                data._yaxis = '\\rm{y}' 
     189                data._xunit = 'pixel' 
     190                data._yunit = 'pixel' 
     191        self.graph.xaxis(data._xaxis, data._xunit) 
     192        self.graph.yaxis(data._yaxis, data._yunit) 
    213193        self.graph.title(self.data2D.name) 
    214194        self.graph.render(self) 
     
    252232        if len(self.data2D.detector) == 1:         
    253233             
    254             item_list = self.parent.get_context_menu(self.graph) 
     234            item_list = self.parent.get_context_menu(self) 
    255235            if (not item_list == None) and (not len(item_list) == 0): 
    256236                for item in item_list: 
  • guiframe/local_perspectives/plotting/plotting.py

    rbf4402c3 ra07e72f  
    1717from sans.guiframe.events import StatusEvent  
    1818from sans.guiframe.plugin_base import PluginBase 
     19from sans.guiframe.dataFitting import Data1D 
     20from sans.guiframe.dataFitting import Data2D 
    1921 
    2022class Plugin(PluginBase): 
     
    2830        ## Plot panels 
    2931        self.plot_panels = [] 
    30         
     32        self.new_plot_panels = {} 
     33        self._panel_on_focus = None 
     34      
     35    def set_panel_on_focus(self, panel): 
     36        """ 
     37        """ 
     38        self._panel_on_focus = panel 
     39         
    3140    def is_always_active(self): 
    3241        """ 
     
    7685         
    7786        """ 
     87        if hasattr(event, 'remove'): 
     88            group_id = event.group_id 
     89            id = event.id 
     90            if group_id in self.new_plot_panels.keys(): 
     91                panel = self.new_plot_panels[group_id] 
     92                panel.remove_data_by_id(id=id) 
     93            else: 
     94                msg = "Panel with GROUP_ID: %s canot be located" % str(group_id) 
     95                raise ValueError, msg 
     96            return 
    7897        # Check whether we already have a graph with the same units 
    7998        # as the plottable we just received.  
    80         is_available = False 
    81         for panel in self.plot_panels: 
    82             if event.plot._xunit == panel.graph.prop["xunit_base"] \ 
    83             and event.plot._yunit == panel.graph.prop["yunit_base"]: 
    84                 if hasattr(event.plot, "group_id"): 
    85                     ## if same group_id used the same panel to plot 
    86                     if not event.plot.group_id == None \ 
    87                         and event.plot.group_id == panel.group_id: 
    88                         is_available = True 
    89                         panel._onEVT_1DREPLOT(event) 
    90                         self.parent.show_panel(panel.uid)    
    91                 else: 
    92                     # Check that the plot panel has no group ID 
    93                     ## Use a panel with group_id ==None to plot 
    94                     if panel.group_id == None: 
    95                         is_available = True 
    96                         panel._onEVT_1DREPLOT(event) 
    97                         self.parent.show_panel(panel.uid) 
    98         # Create a new plot panel if none was available         
    99         if not is_available: 
    100             #print"event.plot",hasattr(event.plot,'data') 
    101             if not hasattr(event.plot, 'data'): 
     99        data = event.plot 
     100         
     101        group_id_list = data.group_id 
     102        group_id = None 
     103        if group_id_list: 
     104            group_id = group_id_list[len(group_id_list)-1] 
     105        if group_id in self.new_plot_panels.keys(): 
     106            panel = self.new_plot_panels[group_id] 
     107            _, x_unit =  data.get_xaxis() 
     108            _, y_unit =  data.get_yaxis() 
     109            
     110            if x_unit != panel.graph.prop["xunit"] \ 
     111                or  y_unit != panel.graph.prop["yunit"]: 
     112                msg = "Cannot add %s" % str(data.name) 
     113                msg += " to panel %s\n" % str(panel.window_caption) 
     114                msg += "Please edit %s's units, labels" % str(data.name) 
     115                raise ValueError, msg 
     116            else: 
     117                panel.plot_data( data) 
     118                self.parent.show_panel(panel.uid)    
     119        else: 
     120            # Create a new plot panel if none was available         
     121            if issubclass(data.__class__, Data1D): 
    102122                from Plotter1D import ModelPanel1D 
    103123                ## get the data representation label of the data to plot 
    104124                ## when even the user select "change scale" 
    105                 if hasattr(event.plot, "xtransform"): 
    106                     xtransform = event.plot.xtransform 
    107                 else: 
    108                     xtransform = None 
    109                      
    110                 if hasattr(event.plot, "ytransform"): 
    111                     ytransform = event.plot.ytransform 
    112                 else: 
    113                     ytransform = None 
     125                xtransform = data.xtransform 
     126                ytransform = data.ytransform 
    114127                ## create a plotpanel for 1D Data 
    115128                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform, 
    116129                         ytransform=ytransform, style=wx.RAISED_BORDER) 
    117             else: 
     130                new_panel.set_manager(self) 
     131                new_panel.group_id = group_id 
     132            elif issubclass(data.__class__, Data2D): 
    118133                ##Create a new plotpanel for 2D data 
    119134                from Plotter2D import ModelPanel2D 
    120                 if hasattr(event.plot, "scale"): 
    121                     scale = event.plot.scale 
    122                 else: 
    123                     scale = 'log' 
     135                scale = data.scale 
    124136                new_panel = ModelPanel2D(self.parent, id = -1, 
    125137                                    data2d=event.plot, scale = scale,  
    126138                                    style=wx.RAISED_BORDER) 
     139                new_panel.set_manager(self) 
     140                new_panel.group_id = group_id 
     141            else: 
     142                msg = "Plotting received unexpected" 
     143                msg += " data type : %s" % str(data.__class__) 
     144                raise ValueError, msg 
    127145            ## Set group ID if available 
    128146            ## Assign data properties to the new create panel 
    129             group_id_str = '' 
    130             if hasattr(event.plot, "group_id"): 
    131                 if not event.plot.group_id == None: 
    132                     new_panel.group_id = event.plot.group_id 
    133                     group_id_str = ' [%s]' % event.plot.group_id 
    134             if hasattr(event, "title"): 
    135                 new_panel.window_caption = event.title 
    136                 new_panel.window_name = event.title 
     147            title = data.title 
     148            new_panel.window_caption = title 
     149            new_panel.window_name = title 
    137150            event_id = self.parent.popup_panel(new_panel) 
    138151            #remove the default item in the menu 
    139             if len(self.plot_panels) == 0: 
     152            if len(self.new_plot_panels) == 0: 
    140153                self.menu.RemoveItem(self.menu.FindItemByPosition(0)) 
    141154            self.menu.Append(event_id, new_panel.window_caption,  
     
    144157            new_panel.uid = event_id 
    145158            # Ship the plottable to its panel 
    146             new_panel._onEVT_1DREPLOT(event) 
    147             self.plot_panels.append(new_panel)         
     159            new_panel.plot_data(data) 
     160            self.plot_panels.append(new_panel)        
     161            self.new_plot_panels[new_panel.group_id] = new_panel 
    148162             
    149163        return 
    150          
     164    
  • guiframe/plugin_base.py

    r03314e7 ra07e72f  
    143143         
    144144     
    145     def get_context_menu(self, graph=None): 
     145    def get_context_menu(self, plotpanel=None): 
    146146        """ 
    147147        This method is optional. 
     
    151151        chance to add a menu item to the context menu. 
    152152         
    153         A ref to a Graph object is passed so that you can 
     153        A ref to a plotpanel object is passed so that you can 
    154154        investigate the plot content and decide whether you 
    155155        need to add items to the context menu.   
  • invariantview/perspectives/invariant/invariant.py

    rcb69775 ra07e72f  
    1818import logging 
    1919 
    20 from DataLoader.data_info import Data1D as LoaderData1D 
    21 from sans.guiframe.dataFitting import Theory1D 
     20 
    2221from sans.guiframe.dataFitting import Data1D 
    23  
    2422from sans.guiframe.events import NewPlotEvent 
    25 from sans.guiframe.events import ERR_DATA 
     23from sans.guiframe.gui_style import GUIFRAME_ID 
    2624from .invariant_state import Reader as reader 
    2725from DataLoader.loader import Loader 
    2826from .invariant_panel import InvariantPanel 
    29 #from sans.guiframe.events import EVT_INVSTATE_UPDATE 
    30  
    3127from sans.guiframe.plugin_base import PluginBase 
    3228 
     
    8076        ## Save a reference to the parent 
    8177        self.parent = parent 
    82         #add error back to the data 
    83         self.parent.Bind(ERR_DATA, self._on_data_error) 
    84         #self.parent.Bind(EVT_INVSTATE_UPDATE, self.on_set_state_helper) 
    85          
    8678        self.invariant_panel = InvariantPanel(parent=self.parent) 
    8779        self.invariant_panel.set_manager(manager=self) 
     
    9688        return [self.invariant_panel] 
    9789   
    98     def get_context_menu(self, graph=None): 
     90    def get_context_menu(self, plotpanel=None): 
    9991        """ 
    10092        This method is optional. 
     
    117109        :return: a list of menu items with call-back function 
    118110        """ 
    119         self.graph = graph 
     111        graph = plotpanel.graph 
    120112        invariant_option = "Compute invariant" 
    121113        invariant_hint = "Will displays the invariant panel for" 
    122114        invariant_hint += " futher computation" 
    123         
    124         for item in self.graph.plottables: 
    125             if item.name == graph.selected_plottable : 
    126                 if issubclass(item.__class__, LoaderData1D): 
    127             
    128                     if item.name != "$I_{obs}(q)$" and \ 
    129                         item.name != " $P_{fit}(r)$": 
    130                         if hasattr(item, "group_id"): 
    131                             return [[invariant_option,  
    132                                         invariant_hint,  
     115         
     116        if graph.selected_plottable not in plotpanel.plots: 
     117            return [] 
     118        data = plotpanel.plots[graph.selected_plottable] 
     119         
     120        if not issubclass(data.__class__, Data1D): 
     121            name = data.__class__.__name__ 
     122            msg = "Invariant use only Data1D got: [%s] " % str(name) 
     123            raise ValueError, msg  
     124         
     125        if data.name != "$I_{obs}(q)$" and  data.name != " $P_{fit}(r)$": 
     126           return [[invariant_option, invariant_hint,  
    133127                                        self._compute_invariant]] 
    134         return []    
    135  
    136     def copy_data(self, item, dy=None): 
    137         """ 
    138         receive a data 1D and the list of errors on dy 
    139         and create a new data1D data 
    140         """ 
    141         id = None 
    142         if hasattr(item,"id"): 
    143             id = item.id 
    144  
    145         data = Data1D(x=item.x, y=item.y, dx=None, dy=None) 
    146         data.copy_from_datainfo(item) 
    147         item.clone_without_data(clone=data)     
    148         data.dy = dy 
    149         data.name = item.name 
    150         data.title = item.title 
    151          
    152         ## allow to highlight data when plotted 
    153         data.interactive = item.interactive 
    154         ## when 2 data have the same id override the 1 st plotted 
    155         data.id = id 
    156         data.group_id = item.group_id 
    157         return data 
    158      
    159     def _on_data_error(self, event): 
    160         """ 
    161         receives and event from plotting plu-gins to store the data name and  
    162         their errors of y coordinates for 1Data hide and show error 
    163         """ 
    164         self.err_dy = event.err_dy 
    165          
     128        return [] 
     129 
    166130    def _compute_invariant(self, event):     
    167131        """ 
     
    170134        self.panel = event.GetEventObject() 
    171135        Plugin.on_perspective(self, event=event) 
    172         for plottable in self.panel.graph.plottables: 
    173             if plottable.name == self.panel.graph.selected_plottable: 
    174                 ## put the errors values back to the model if the errors  
    175                 ## were hiden before sending them to the fit engine 
    176                 if len(self.err_dy) > 0: 
    177                     dy = plottable.dy 
    178                     if plottable.name in  self.err_dy.iterkeys(): 
    179                         dy = self.err_dy[plottable.name] 
    180                     data = self.copy_data(plottable, dy) 
    181                 else: 
    182                     data = plottable 
    183                 self.compute_helper(data=data) 
     136        id = self.panel.graph.selected_plottable 
     137        data = self.panel.plots[self.panel.graph.selected_plottable] 
     138        if data is None: 
     139            return 
     140        if not issubclass(data.__class__, Data1D): 
     141            name = data.__class__.__name__ 
     142            msg = "Invariant use only Data1D got: [%s] " % str(name) 
     143            raise ValueError, msg  
     144        self.compute_helper(data=data) 
    184145                 
    185146    def set_data(self, data_list): 
     
    187148        receive a list of data and compute invariant 
    188149        """ 
     150        data = None 
    189151        if len(data_list) > 1: 
    190152            msg = "invariant panel does not allow multiple data!\n" 
     
    194156            if dlg.ShowModal() == wx.ID_OK: 
    195157                data = dlg.get_data() 
    196                 if issubclass(data.__class__, LoaderData1D): 
    197                     wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 
    198                                                title=data_list[0].title)) 
    199                     self.compute_helper(data_list[0]) 
    200                 else:     
    201                     msg = "invariant cannot be computed for data of " 
    202                     msg += "type %s" % (data_list[0].__class__.__name__) 
    203                     wx.PostEvent(self.parent,  
    204                              StatusEvent(status=msg, info='error')) 
    205158        elif len(data_list) == 1: 
    206             if issubclass(data_list[0].__class__, LoaderData1D): 
    207                 wx.PostEvent(self.parent, NewPlotEvent(plot=data_list[0], 
    208                                                title=data_list[0].title)) 
    209                 self.compute_helper(data_list[0]) 
    210             else: 
    211                 msg = "invariant cannot be computed for" 
    212                 msg += " data of type %s" % (data_list[0].__class__.__name__) 
    213                 wx.PostEvent(self.parent,  
    214                              StatusEvent(status=msg, info='error')) 
    215              
    216              
     159            data = data_list[0] 
     160        if data is None: 
     161            return 
     162        if issubclass(data.__class__, Data1D): 
     163            wx.PostEvent(self.parent, NewPlotEvent(plot=data, 
     164                                       title=data.title)) 
     165            self.compute_helper(data) 
     166        else:     
     167            msg = "invariant cannot be computed for data of " 
     168            msg += "type %s" % (data.__class__.__name__) 
     169            wx.PostEvent(self.parent,  
     170                     StatusEvent(status=msg, info='error')) 
     171     
    217172    def clear_panel(self): 
     173        """ 
     174        """ 
    218175        self.invariant_panel.clear_panel() 
    219176         
     
    311268        #import copy 
    312269        if data is None: 
    313             new_plot = Theory1D(x=[], y=[], dy=None) 
     270            id = str(self.__data.id) + name 
     271            self.__data.group_id 
     272            wx.PostEvent(self.parent, NewPlotEvent(id=id, 
     273                                               group_id=group_id, 
     274                                               remove=true)) 
     275            return 
     276     
     277        new_plot = Data1D(x=[], y=[], dy=None) 
     278        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
     279        scale = self.invariant_panel.get_scale() 
     280        background = self.invariant_panel.get_background() 
     281         
     282        if scale != 0: 
     283            # Put back the sacle and bkg for plotting 
     284            data.y = (data.y + background)/scale 
     285            new_plot = Data1D(x=data.x, y=data.y, dy=None) 
     286            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    314287        else: 
    315             scale = self.invariant_panel.get_scale() 
    316             background = self.invariant_panel.get_background() 
    317              
    318             if scale != 0: 
    319                 # Put back the sacle and bkg for plotting 
    320                 data.y = (data.y + background)/scale 
    321                 new_plot = Theory1D(x=data.x, y=data.y, dy=None) 
    322             else: 
    323                 msg = "Scale can not be zero." 
    324                 raise ValueError, msg 
    325  
     288            msg = "Scale can not be zero." 
     289            raise ValueError, msg 
     290        if len(new_plot.x)== 0 : 
     291            return 
     292         
    326293        new_plot.name = name 
    327294        new_plot.xaxis(self.__data._xaxis, self.__data._xunit) 
    328295        new_plot.yaxis(self.__data._yaxis, self.__data._yunit) 
    329296        new_plot.group_id = self.__data.group_id 
    330         new_plot.id = self.__data.id + name 
     297        new_plot.id = str(self.__data.id) + name 
    331298        new_plot.title = self.__data.title 
    332299        # Save theory_data in a state 
  • invariantview/perspectives/invariant/invariant_panel.py

    r97ec26b ra07e72f  
    364364                                           name="Low-Q extrapolation") 
    365365            except: 
     366                raise 
    366367                self.inv_container.qstar_low = "ERROR" 
    367368                self.inv_container.qstar_low_err = "ERROR" 
     
    393394                                           name="High-Q extrapolation") 
    394395            except: 
     396                raisee 
    395397                self.inv_container.qstar_high = "ERROR" 
    396398                self.inv_container.qstar_high_err = "ERROR" 
  • prview/perspectives/pr/inversion_state.py

    r229da98 ra07e72f  
    1717from xml.dom.minidom import parse 
    1818from lxml import etree 
    19 import DataLoader 
     19from sans.guiframe.dataFitting import Data1D 
    2020from DataLoader.readers.cansas_reader import Reader as CansasReader 
    2121from DataLoader.readers.cansas_reader import get_content 
     
    519519        """ 
    520520        if datainfo is None: 
    521             datainfo = DataLoader.data_info.Data1D(x=[], y=[])     
    522         elif not issubclass(datainfo.__class__, DataLoader.data_info.Data1D): 
     521            datainfo = Data1D(x=[], y=[])     
     522        elif not issubclass(datainfo.__class__, Data1D): 
    523523            msg = "The cansas writer expects a Data1D " 
    524524            msg += "instance: %s" % str(datainfo.__class__.__name__) 
  • prview/perspectives/pr/pr.py

    r229da98 ra07e72f  
    2424import pylab 
    2525from sans.guiframe.dataFitting import Data1D 
    26 from sans.guiframe.dataFitting import Theory1D 
    2726from sans.guiframe.events import NewPlotEvent 
    28 from sans.guiframe.events import StatusEvent     
    29  
     27from sans.guiframe.events import StatusEvent  
     28from sans.guiframe.gui_style import GUIFRAME_ID    
    3029from sans.pr.invertor import Invertor 
    3130from DataLoader.loader import Loader 
    32 from DataLoader.data_info import Data1D as LoaderData1D 
    33 import DataLoader 
     31 
    3432from pr_widgets import load_error  
    3533from sans.guiframe.plugin_base import PluginBase 
     
    4139IQ_FIT_LABEL       = r"$I_{fit}(q)$" 
    4240IQ_SMEARED_LABEL   = r"$I_{smeared}(q)$" 
    43  
    44 #import wx.lib 
    45 #(NewPrFileEvent, EVT_PR_FILE) = wx.lib.newevent.NewEvent() 
    46  
    4741 
    4842 
     
    10397         
    10498        # Associate the inversion state reader with .prv files 
    105         from DataLoader.loader import Loader 
    10699        from inversion_state import Reader 
    107100          
     
    166159            self.control_panel.set_state(state) 
    167160        except: 
    168             raise 
    169             #logging.error("prview.set_state: %s" % sys.exc_value) 
     161            logging.error("prview.set_state: %s" % sys.exc_value) 
    170162 
    171163   
     
    188180        """ 
    189181        from sans.pr.invertor import Invertor 
    190              
    191         from danse.common.plottools import Data1D as PlotData1D 
    192         from danse.common.plottools import Theory1D as Theory1D 
    193          
    194182        # Generate P(r) for sphere 
    195183        radius = 60.0 
     
    220208        for i in range(len(out)): 
    221209            print "%g +- %g" % (out[i], math.sqrt(cov[i][i])) 
    222  
     210         
    223211        # Show input P(r) 
    224         new_plot = PlotData1D(pr.x, pr.y, dy=pr.err) 
     212        title = "Pr" 
     213        new_plot = Data1D(pr.x, pr.y, dy=pr.err) 
    225214        new_plot.name = "P_{obs}(r)" 
    226215        new_plot.xaxis("\\rm{r}", 'A') 
    227216        new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    228         print "_fit_pr" 
    229         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Pr")) 
     217        group_id = "P_{obs}(r)" 
     218        if group_id not in new_plot.group_id: 
     219            new_plot.group_id.append(group_id) 
     220        new_plot.id = "P_{obs}(r)" 
     221        new_plot.title = title 
     222        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 
    230223 
    231224        # Show P(r) fit 
     
    239232        """ 
    240233        """ 
    241         from danse.common.plottools import Theory1D as PlotTheory1D 
    242234        # Show P(r) 
    243235        y_true = numpy.zeros(len(x)) 
     
    251243         
    252244        # Show the theory P(r) 
    253         new_plot = PlotTheory1D(x, y_true) 
     245        new_plot = Data1D(x, y_true) 
     246        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    254247        new_plot.name = "P_{true}(r)" 
    255248        new_plot.xaxis("\\rm{r}", 'A') 
     
    272265        """ 
    273266        """   
    274         from danse.common.plottools import Theory1D as PlotTheory1D 
    275  
    276267        qtemp = pr.x 
    277268        if not q==None: 
     
    304295                print "Error getting error", value, x[i] 
    305296                 
    306         new_plot = PlotTheory1D(x, y) 
     297        new_plot = Data1D(x, y) 
     298        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    307299        new_plot.name = IQ_FIT_LABEL 
    308300        new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    309301        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    310          
    311302        title = "I(q)" 
     303        new_plot.title = title 
     304         
    312305        # If we have a group ID, use it 
    313306        if pr.info.has_key("plot_group_id"): 
    314             new_plot.group_id = pr.info["plot_group_id"] 
    315             title = pr.info["plot_group_id"] 
    316              
     307            if len( pr.info["plot_group_id"]) > 0: 
     308                index =  len( pr.info["plot_group_id"]) - 1 
     309                new_plot.group_id.append( pr.info["plot_group_id"][index]) 
     310        new_plot.id = IQ_FIT_LABEL 
     311        #new_plot.group_id.append(2) 
    317312        wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 
    318313         
     
    331326                    print "Error getting error", value, x[i] 
    332327                     
    333             new_plot = Theory1D(x, y) 
     328            new_plot = Data1D(x, y) 
     329            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    334330            new_plot.name = IQ_SMEARED_LABEL 
    335331            new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
     
    337333            # If we have a group ID, use it 
    338334            if pr.info.has_key("plot_group_id"): 
    339                 new_plot.group_id = pr.info["plot_group_id"] 
     335                if len( pr.info["plot_group_id"]) > 0: 
     336                    index =  len( pr.info["plot_group_id"]) - 1 
     337                    new_plot.group_id.append( pr.info["plot_group_id"][index]) 
     338            
     339            new_plot.id = IQ_SMEARED_LABEL 
     340            new_plot.title = title 
     341            #new_plot.group_id.append(2) 
    340342            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=title)) 
    341343         
     
    359361        """ 
    360362        """      
    361         from danse.common.plottools import Data1D as PlotData1D  
    362         from danse.common.plottools import Theory1D as PlotTheory1D 
    363          
    364363        # Show P(r) 
    365364        x = pylab.arange(0.0, pr.d_max, pr.d_max/self._pr_npts) 
     
    394393         
    395394        if cov2==None: 
    396             new_plot = PlotTheory1D(x, y) 
     395            new_plot = Data1D(x, y) 
     396            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    397397        else: 
    398             new_plot = PlotData1D(x, y, dy=dy) 
     398            new_plot = Data1D(x, y, dy=dy) 
    399399        new_plot.name = PR_FIT_LABEL 
    400400        new_plot.xaxis("\\rm{r}", 'A') 
    401401        new_plot.yaxis("\\rm{P(r)} ","cm^{-3}") 
    402402        new_plot.title = "P(r) fit" 
     403        new_plot.id = PR_FIT_LABEL 
    403404        # Make sure that the plot is linear 
    404405        new_plot.xtransform = "x" 
     
    563564            return 0.0 
    564565 
    565     def get_context_menu(self, graph=None): 
     566    def get_context_menu(self, plotpanel=None): 
    566567        """ 
    567568        Get the context menu items available for P(r) 
     
    572573         
    573574        """ 
     575        graph = plotpanel.graph 
    574576        # Look whether this Graph contains P(r) data 
    575         #if graph.selected_plottable==IQ_DATA_LABEL: 
    576         for item in graph.plottables: 
    577             if item.name == PR_FIT_LABEL: 
    578                 #add_data_hint = "Load a data file and display it on this plot" 
    579                 #["Add P(r) data",add_data_hint , self._on_add_data], 
    580                 change_n_hint = "Change the number of" 
    581                 change_n_hint += " points on the P(r) output" 
    582                 change_n_label = "Change number of P(r) points" 
    583                 m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 
    584  
    585                 if self._scale_output_unity or self._normalize_output: 
    586                     hint = "Let the output P(r) keep the scale of the data" 
    587                     m_list.append(["Disable P(r) scaling", hint,  
    588                                    self._on_disable_scaling]) 
    589                 if not self._scale_output_unity: 
    590                     m_list.append(["Scale P_max(r) to unity",  
    591                                    "Scale P(r) so that its maximum is 1",  
    592                                    self._on_scale_unity]) 
    593                 if not self._normalize_output: 
    594                     m_list.append(["Normalize P(r) to unity",  
    595                                    "Normalize the integral of P(r) to 1",  
    596                                    self._on_normalize]) 
    597                      
    598                 return m_list 
    599                 #return [["Add P(r) data",  
    600                 #"Load a data file and display it on this plot", 
    601                 # self._on_add_data], 
    602                 #       ["Change number of P(r) points", 
    603                 # "Change the number of points on the P(r) output", 
    604                 # self._on_pr_npts]] 
    605  
    606             elif item.name == graph.selected_plottable: 
    607                     #TODO: we might want to check that the units are  
    608                     #     consistent with I(q) before allowing this menu item 
    609                 if not self.standalone and \ 
    610                 issubclass(item.__class__, DataLoader.data_info.Data1D): 
    611                     return [["Compute P(r)",  
     577        if graph.selected_plottable not in plotpanel.plots: 
     578            return [] 
     579        item = plotpanel.plots[graph.selected_plottable] 
     580        if item.id == PR_FIT_LABEL: 
     581            #add_data_hint = "Load a data file and display it on this plot" 
     582            #["Add P(r) data",add_data_hint , self._on_add_data], 
     583            change_n_hint = "Change the number of" 
     584            change_n_hint += " points on the P(r) output" 
     585            change_n_label = "Change number of P(r) points" 
     586            m_list = [[change_n_label, change_n_hint , self._on_pr_npts]] 
     587 
     588            if self._scale_output_unity or self._normalize_output: 
     589                hint = "Let the output P(r) keep the scale of the data" 
     590                m_list.append(["Disable P(r) scaling", hint,  
     591                               self._on_disable_scaling]) 
     592            if not self._scale_output_unity: 
     593                m_list.append(["Scale P_max(r) to unity",  
     594                               "Scale P(r) so that its maximum is 1",  
     595                               self._on_scale_unity]) 
     596            if not self._normalize_output: 
     597                m_list.append(["Normalize P(r) to unity",  
     598                               "Normalize the integral of P(r) to 1",  
     599                               self._on_normalize]) 
     600                 
     601            return m_list 
     602              
     603        elif item.id in [PR_LOADED_LABEL, IQ_DATA_LABEL, IQ_FIT_LABEL, 
     604                          IQ_SMEARED_LABEL]: 
     605            return [] 
     606        elif item.id == graph.selected_plottable: 
     607               if not self.standalone and issubclass(item.__class__, Data1D): 
     608                return [["Compute P(r)",  
    612609                             "Compute P(r) from distribution",  
    613610                             self._on_context_inversion]]       
     
    657654            y = self._added_plots[plot].y/sum 
    658655             
    659             new_plot = Theory1D(self._added_plots[plot].x, y) 
     656            new_plot = Data1D(self._added_plots[plot].x, y) 
     657            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
     658            index  = len(self._added_plots[plot].group_id) - 1 
     659            if group_id not in new_plot.group_id: 
     660                new_plot.group_id.append(group_id) 
     661            new_plot.id = self._added_plots[plot].id 
     662            new_plot.title = self._added_plots[plot].title 
    660663            new_plot.name = self._added_plots[plot].name 
    661664            new_plot.xaxis("\\rm{r}", 'A') 
     
    686689            y = self._added_plots[plot].y/_max 
    687690             
    688             new_plot = Theory1D(self._added_plots[plot].x, y) 
     691            new_plot = Data1D(self._added_plots[plot].x, y) 
     692            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    689693            new_plot.name = self._added_plots[plot].name 
    690694            new_plot.xaxis("\\rm{r}", 'A') 
     
    736740         
    737741        filename = os.path.basename(path) 
    738          
    739         #new_plot = Data1D(x, y, dy=err) 
    740         new_plot = Theory1D(x, y) 
     742 
     743        new_plot = Data1D(x, y) 
     744        new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    741745        new_plot.name = filename 
    742746        new_plot.xaxis("\\rm{r}", 'A') 
     
    863867            new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    864868            new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    865             #new_plot.group_id = "test group" 
     869            if pr.info.has_key("plot_group_id"): 
     870                new_plot.group_id.append(pr.info["plot_group_id"]) 
     871            new_plot.id = IQ_DATA_LABEL 
    866872            wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title="Iq")) 
    867873                 
     
    884890         
    885891        """ 
    886         print "show_data", data.name 
    887892        #if path is not None: 
    888893        if data is not None: 
    889894            try: 
    890                 #pr = self._create_file_pr(path) 
    891895                pr = self._create_file_pr(data) 
    892896            except: 
     
    902906        
    903907        # Make a plot of I(q) data 
    904         if self.pr.err==None: 
    905             new_plot = Theory1D(self.pr.x, self.pr.y) 
     908        if self.pr.err == None: 
     909            new_plot = Data1D(self.pr.x, self.pr.y) 
     910            new_plot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
    906911        else: 
    907912            new_plot = Data1D(self.pr.x, self.pr.y, dy=self.pr.err) 
     
    910915        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    911916        new_plot.interactive = True 
    912         #new_plot.group_id = "test group" 
     917        new_plot.group_id.append(IQ_DATA_LABEL) 
     918        new_plot.id = IQ_DATA_LABEL 
     919        new_plot.title = "I(q)" 
    913920        wx.PostEvent(self.parent,  
    914921                     NewPlotEvent(plot=new_plot, title="I(q)", reset=reset)) 
    915922         
    916923        self.current_plottable = new_plot 
    917         self.current_plottable.group_id = IQ_DATA_LABEL 
    918          
    919          
    920924        # Get Q range 
    921925        self.control_panel.q_min = self.pr.x.min() 
     
    10211025        # Keep track of the plot window title to ensure that 
    10221026        # we can overlay the plots 
    1023         if hasattr(self.current_plottable, "group_id"): 
     1027        if self.current_plottable.group_id: 
     1028            index = len(self.current_plottable.group_id) - 1 
     1029            group_id = self.current_plottable.group_id[index] 
    10241030            pr.info["plot_group_id"] = self.current_plottable.group_id 
    10251031         
     
    13291335            if dlg.ShowModal() == wx.ID_OK: 
    13301336                data = dlg.get_data() 
    1331                 if issubclass(data.__class__, LoaderData1D): 
     1337                if issubclass(data.__class__, Data1D): 
    13321338                    self.control_panel._change_file(evt=None, data=data) 
    13331339                else:     
     
    13371343                             StatusEvent(status=msg, info='error')) 
    13381344        elif len(data_list) == 1: 
    1339             if issubclass(data_list[0].__class__, LoaderData1D): 
     1345            if issubclass(data_list[0].__class__, Data1D): 
    13401346                self.control_panel._change_file(evt=None, data=data_list[0]) 
    13411347            else: 
  • prview/perspectives/pr/pr_widgets.py

    raf91b68 ra07e72f  
    2727         
    2828        ## Set to True when the mouse is clicked while the whole string is selected 
    29         full_selection = False 
     29        self.full_selection = False 
    3030        ## Call back for EVT_SET_FOCUS events 
    3131        _on_set_focus_callback = None 
  • sansview/sansview.py

    r75fbd17 ra07e72f  
    7474            self.gui.add_perspective(invariant_plug) 
    7575        except: 
    76             logging.error("SansView: could not find Invariant plug-in module")  
    77             logging.error(sys.exc_value)   
     76            raise 
     77            #logging.error("SansView: could not find Invariant plug-in module")  
     78            #logging.error(sys.exc_value)   
    7879         
    7980        #Calculator perspective    
     
    8586            logging.error("SansView: could not find Calculator plug-in module") 
    8687            logging.error(sys.exc_value)   
    87              
     88        """     
    8889        # theory perspective 
    8990        try: 
     
    9394        except: 
    9495            logging.error("SansView: could not find theory plug-in module") 
    95             logging.error(sys.exc_value)   
     96            logging.error(sys.exc_value)  
     97        """  
    9698             
    9799        # Fitting perspective 
Note: See TracChangeset for help on using the changeset viewer.