Changeset 278cc25 in sasview for guiframe/local_perspectives


Ignore:
Timestamp:
May 27, 2008 2:32:45 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:
4a5de6f
Parents:
14b8154
Message:

Allow adding base perspectives to an app (as opposed of only dynamically finding them out).
Modified plot label update

File:
1 edited

Legend:

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

    r383189f9 r278cc25  
    5252        ## Unique ID (from gui_manager) 
    5353        self.uid = None 
     54         
     55        ## Action IDs for internal call-backs 
     56        self.action_ids = {} 
    5457         
    5558        ## Graph         
     
    8386        # Check axis labels 
    8487        #TODO: Should re-factor this 
    85         if event.plot._xunit != self.graph.prop["xunit"]: 
    86             self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 
    87              
    88         if event.plot._yunit != self.graph.prop["yunit"]: 
    89             self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 
     88        #if event.plot._xunit != self.graph.prop["xunit"]: 
     89        self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 
     90             
     91        #if event.plot._yunit != self.graph.prop["yunit"]: 
     92        self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 
    9093       
    9194        self.graph.render(self) 
     
    100103        slicerpop = PanelMenu() 
    101104        slicerpop.set_plots(self.plots) 
     105                 
     106        # Option to save the data displayed 
     107        id = wx.NewId() 
     108        for plot in self.graph.plottables: 
     109            name = plot.name 
     110            slicerpop.Append(id, "&Save %s points" % name) 
     111            self.action_ids[str(id)] = plot 
     112            wx.EVT_MENU(self, id, self._onSave) 
    102113                 
    103114        # Various plot options 
     
    127138        pos = self.ScreenToClient(pos) 
    128139        self.PopupMenu(slicerpop, pos) 
     140     
     141    def _onSave(self, evt): 
     142        """ 
     143            Save a data set to a text file 
     144            @param evt: Menu event 
     145        """ 
     146        import os 
     147        id = str(evt.GetId()) 
     148        if id in self.action_ids:          
     149             
     150            path = None 
     151            dlg = wx.FileDialog(self, "Choose a file", os.getcwd(), "", "*.txt", wx.SAVE) 
     152            if dlg.ShowModal() == wx.ID_OK: 
     153                path = dlg.GetPath() 
     154                mypath = os.path.basename(path) 
     155                print path 
     156            dlg.Destroy() 
     157             
     158            if not path == None: 
     159                out = open(path, 'w') 
     160                has_errors = True 
     161                if self.action_ids[id].dy==None or self.action_ids[id].dy==[]: 
     162                    has_errors = False 
     163                     
     164                # Sanity check 
     165                if has_errors: 
     166                    try: 
     167                        if len(self.action_ids[id].y) != len(self.action_ids[id].dy): 
     168                            print "Y and dY have different lengths" 
     169                            has_errors = False 
     170                    except: 
     171                        has_errors = False 
     172                 
     173                if has_errors: 
     174                    out.write("<X>   <Y>   <dY>\n") 
     175                else: 
     176                    out.write("<X>   <Y>\n") 
     177                     
     178                for i in range(len(self.action_ids[id].x)): 
     179                    if has_errors: 
     180                        out.write("%g  %g  %g\n" % (self.action_ids[id].x[i],  
     181                                                    self.action_ids[id].y[i], 
     182                                                    self.action_ids[id].dy[i])) 
     183                    else: 
     184                        out.write("%g  %g\n" % (self.action_ids[id].x[i],  
     185                                                self.action_ids[id].y[i])) 
     186                         
     187                out.close() 
     188     
    129189     
    130190    def _onToggleScale(self, event): 
Note: See TracChangeset for help on using the changeset viewer.