Changeset fc2b91a in sasview for guiframe/local_perspectives


Ignore:
Timestamp:
Jun 18, 2008 4:07:18 PM (16 years ago)
Author:
Mathieu Doucet <doucetm@…>
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:
4972de2
Parents:
ad8bcd6
Message:

Updated for interactive graphs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • guiframe/local_perspectives/plotting/plotting.py

    r96f13a9 rfc2b91a  
    1818class PanelMenu(wx.Menu): 
    1919    plots = None 
     20    graph = None 
    2021     
    2122    def set_plots(self, plots): 
    2223        self.plots = plots 
    2324     
     25    def set_graph(self, graph): 
     26        self.graph = graph 
    2427 
    2528class View1DPanel(PlotPanel): 
     
    7174        is_new = True 
    7275        if event.plot.name in self.plots.keys(): 
    73             is_new = False 
     76            # Check whether the class of plottable changed 
     77            if not event.plot.__class__==self.plots[event.plot.name].__class__: 
     78                self.graph.delete(self.plots[event.plot.name]) 
     79            else: 
     80                is_new = False 
    7481         
    7582        if is_new: 
     
    103110        slicerpop = PanelMenu() 
    104111        slicerpop.set_plots(self.plots) 
     112        slicerpop.set_graph(self.graph) 
    105113                 
    106114        # Option to save the data displayed 
    107         for plot in self.graph.plottables: 
     115         
     116        #for plot in self.graph.plottables: 
     117        if self.graph.selected_plottable in self.plots: 
     118            plot = self.plots[self.graph.selected_plottable] 
    108119            id = wx.NewId() 
    109120            name = plot.name 
     
    117128        wx.EVT_MENU(self, id, self.onSaveImage) 
    118129         
    119         slicerpop.AppendSeparator() 
     130         
    120131        item_list = self.parent.get_context_menu(self.graph) 
    121         if not item_list==None: 
    122             for item in item_list: 
    123                 try: 
    124                     id = wx.NewId() 
    125                     slicerpop.Append(id, item[0], item[1]) 
    126                     wx.EVT_MENU(self, id, item[2]) 
    127                 except: 
    128                     print sys.exc_value 
    129                     print RuntimeError, "View1DPanel.onContextMenu: bad menu item" 
     132        if (not item_list==None) and (not len(item_list)==0): 
     133                slicerpop.AppendSeparator() 
     134                for item in item_list: 
     135                    try: 
     136                        id = wx.NewId() 
     137                        slicerpop.Append(id, item[0], item[1]) 
     138                        wx.EVT_MENU(self, id, item[2]) 
     139                    except: 
     140                        print sys.exc_value 
     141                        print RuntimeError, "View1DPanel.onContextMenu: bad menu item" 
    130142         
    131143        slicerpop.AppendSeparator() 
     
    135147        #wx.EVT_MENU(self, id, self._onToggleScale) 
    136148 
     149        if self.graph.selected_plottable in self.plots: 
     150            if self.plots[self.graph.selected_plottable].__class__.__name__=="Theory1D": 
     151                id = wx.NewId() 
     152                slicerpop.Append(id, '&Add errors to data') 
     153                wx.EVT_MENU(self, id, self._on_add_errors) 
     154 
    137155        id = wx.NewId() 
    138156        slicerpop.Append(id, '&Change scale') 
     
    140158         
    141159        id = wx.NewId() 
    142         slicerpop.AppendSeparator() 
     160        #slicerpop.AppendSeparator() 
    143161        slicerpop.Append(id, '&Reset Graph') 
    144162        wx.EVT_MENU(self, id, self.onResetGraph)         
     
    147165        pos = self.ScreenToClient(pos) 
    148166        self.PopupMenu(slicerpop, pos) 
     167     
     168    def _on_add_errors(self, evt): 
     169        """ 
     170            Compute reasonable errors for a data set without  
     171            errors and transorm the plottable to a Data1D 
     172        """ 
     173        import math 
     174        import numpy 
     175        from sans.guitools.plottables import Data1D 
     176         
     177        if not self.graph.selected_plottable == None: 
     178            length = len(self.plots[self.graph.selected_plottable].x) 
     179            dy = numpy.zeros(length) 
     180            for i in range(length): 
     181                dy[i] = math.sqrt(self.plots[self.graph.selected_plottable].y[i]) 
     182                 
     183            new_plot = Data1D(self.plots[self.graph.selected_plottable].x, 
     184                              self.plots[self.graph.selected_plottable].y, 
     185                              dy=dy) 
     186            new_plot.interactive = True 
     187            new_plot.name = self.plots[self.graph.selected_plottable].name 
     188            label, unit = self.plots[self.graph.selected_plottable].get_xaxis() 
     189            new_plot.xaxis(label, unit) 
     190            label, unit = self.plots[self.graph.selected_plottable].get_yaxis() 
     191            new_plot.yaxis(label, unit) 
     192             
     193            self.graph.delete(self.plots[self.graph.selected_plottable]) 
     194             
     195            self.graph.add(new_plot) 
     196            self.plots[self.graph.selected_plottable]=new_plot 
     197             
     198            self.graph.render(self) 
     199            self.subplot.figure.canvas.draw_idle()     
    149200     
    150201    def _onSave(self, evt): 
Note: See TracChangeset for help on using the changeset viewer.