Changeset c039589 in sasview


Ignore:
Timestamp:
Mar 5, 2015 2:37:00 PM (9 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:
b40ad40
Parents:
090e07e
Message:

pylint fixes

Location:
src/sas/guiframe/local_perspectives/plotting
Files:
4 edited
1 moved

Legend:

Unmodified
Added
Removed
  • src/sas/guiframe/local_perspectives/plotting/Plotter2D.py

    r79492222 rc039589  
    33#This software was developed by the University of Tennessee as part of the 
    44#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    5 #project funded by the US National Science Foundation.  
     5#project funded by the US National Science Foundation. 
    66# 
    77#See the license text in license.txt 
     
    1515import math 
    1616import numpy 
     17import logging 
    1718from sas.plottools.PlotPanel import PlotPanel 
    1819from sas.plottools.plottables import Graph 
    1920from sas.plottools.TextDialog import TextDialog 
    20 from sas.guiframe.events import StatusEvent  
     21from sas.guiframe.events import StatusEvent 
    2122from sas.guiframe.events import NewPlotEvent 
    2223from sas.guiframe.events import PanelOnFocusEvent 
     
    2526from  sas.guiframe.local_perspectives.plotting.binder import BindArtist 
    2627from Plotter1D import ModelPanel1D 
    27 from sas.plottools.toolbar import NavigationToolBar  
     28from sas.plottools.toolbar import NavigationToolBar 
    2829from matplotlib.font_manager import FontProperties 
    2930from graphAppearance import graphAppearance 
     
    4647    def __init__(self, canvas, parent=None): 
    4748        NavigationToolBar.__init__(self, canvas=canvas, parent=parent) 
    48          
     49 
    4950    def delete_option(self): 
    5051        """ 
     
    5253        """ 
    5354        #delete reset button 
    54         self.DeleteToolByPos(0)  
     55        self.DeleteToolByPos(0) 
    5556        #delete dragging 
    56         self.DeleteToolByPos(2)  
     57        self.DeleteToolByPos(2) 
    5758        #delete unwanted button that configures subplot parameters 
    5859        self.DeleteToolByPos(4) 
    59          
     60 
    6061    def add_option(self): 
    6162        """ 
     
    6566        id_context = wx.NewId() 
    6667        context_tip = 'Graph Menu' 
    67         context =  wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 
    68         self.InsertSimpleTool(0, id_context, context,  
    69                                    context_tip, context_tip) 
    70         wx.EVT_TOOL(self, id_context,  self.parent.onToolContextMenu) 
     68        context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 
     69        self.InsertSimpleTool(0, id_context, context, context_tip, context_tip) 
     70        wx.EVT_TOOL(self, id_context, self.parent.onToolContextMenu) 
    7171        self.InsertSeparator(1) 
    7272        #add print button 
    7373        id_print = wx.NewId() 
    74         print_bmp =  wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 
    75         self.AddSimpleTool(id_print, print_bmp, 
    76                            'Print', 'Activate printing') 
     74        print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 
     75        self.AddSimpleTool(id_print, print_bmp, 'Print', 'Activate printing') 
    7776        wx.EVT_TOOL(self, id_print, self.on_print) 
    78          
    79          
     77 
     78 
    8079class ModelPanel2D(ModelPanel1D): 
    8180    """ 
    8281    Plot panel for use with the GUI manager 
    8382    """ 
    84      
     83 
    8584    ## Internal name for the AUI manager 
    8685    window_name = "plotpanel" 
     
    9291    ## Group ID 
    9392    group_id = None 
    94      
    95      
    96     def __init__(self, parent, id=-1, data2d=None, color = None, 
     93 
     94 
     95    def __init__(self, parent, id=-1, data2d=None, color=None, 
    9796                 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
    9897        """ 
     
    106105        ## Dictionary containing Plottables 
    107106        self.plots = {} 
    108         ## Save reference of the current plotted  
     107        ## Save reference of the current plotted 
    109108        self.data2D = data2d 
    110109        ## Unique ID (from gui_manager) 
     
    120119        ## Reference to the current slicer 
    121120        self.slicer = None 
    122         ## event to send slicer info  
     121        ## event to send slicer info 
    123122        self.Bind(EVT_INTERNAL, self._onEVT_INTERNAL) 
    124          
     123 
    125124        self.axes_frozen = False 
    126125        ## panel that contains result from slicer motion (ex: Boxsum info) 
     
    129128        self.title_font = None 
    130129        self.title_color = 'black' 
    131         ## Graph         
     130        ## Graph 
    132131        self.graph = Graph() 
    133132        self.graph.xaxis("\\rm{Q}", 'A^{-1}') 
    134133        self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    135134        self.graph.render(self) 
    136         ## store default value of zmin and zmax  
     135        ## store default value of zmin and zmax 
    137136        self.default_zmin_ctl = self.zmin_2D 
    138137        self.default_zmax_ctl = self.zmax_2D 
     
    145144        if event == None: 
    146145            return 
    147         event.Skip()  
    148                         
    149     def onLeftDown(self, event):  
     146        event.Skip() 
     147 
     148    def onLeftDown(self, event): 
    150149        """ 
    151150        left button down and ready to drag 
    152          
     151 
    153152        """ 
    154153        # Check that the LEFT button was pressed 
    155         PlotPanel.onLeftDown(self, event)     
     154        PlotPanel.onLeftDown(self, event) 
    156155        ax = event.inaxes 
    157156        if ax != None: 
    158157            # data coordinate position 
    159             pos_x = "%8.3g"% event.xdata 
    160             pos_y = "%8.3g"% event.ydata 
     158            pos_x = "%8.3g" % event.xdata 
     159            pos_y = "%8.3g" % event.ydata 
    161160            position = "x: %s    y: %s" % (pos_x, pos_y) 
    162161            wx.PostEvent(self.parent, StatusEvent(status=position)) 
     
    164163        self._manager.set_panel_on_focus(self) 
    165164        wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 
    166          
     165 
    167166    def add_toolbar(self): 
    168167        """ 
     
    174173        # On Windows platform, default window size is incorrect, so set 
    175174        # toolbar width to figure width. 
    176         tw, th = self.toolbar.GetSizeTuple() 
    177         fw, fh = self.canvas.GetSizeTuple() 
     175        _, th = self.toolbar.GetSizeTuple() 
     176        fw, _ = self.canvas.GetSizeTuple() 
    178177        self.toolbar.SetSize(wx.Size(fw, th)) 
    179         self.sizer.Add(self.toolbar, 0, wx.LEFT|wx.EXPAND) 
     178        self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 
    180179        # update the axes menu on the toolbar 
    181180        self.toolbar.update() 
    182           
     181 
    183182    def plot_data(self, data): 
    184183        """ 
    185184        Data is ready to be displayed 
    186          
     185 
    187186        :TODO: this name should be changed to something more appropriate 
    188187             Don't forget that changing this name will mean changing code 
    189188             in plotting.py 
    190           
     189 
    191190        :param event: data event 
    192191        """ 
    193192        xlo = None 
    194193        xhi = None 
    195         ylo = None  
     194        ylo = None 
    196195        yhi = None 
    197196        if data.__class__.__name__ == 'Data1D': 
     
    207206        else: 
    208207            self.plots[data.id] = data 
    209             self.graph.add(self.plots[data.id])  
     208            self.graph.add(self.plots[data.id]) 
    210209            # update qmax with the new xmax of data plotted 
    211             self.qmax = data.xmax   
     210            self.qmax = data.xmax 
    212211        self.slicer = None 
    213212        # Check axis labels 
    214213        #TODO: Should re-factor this 
    215         ## render the graph with its new content    
     214        ## render the graph with its new content 
    216215        #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 
    217         if len(data.detector) < 1:  
     216        if len(data.detector) < 1: 
    218217            if len(data._xunit) < 1 and len(data._yunit) < 1: 
    219218                data._xaxis = '\\rm{x}' 
     
    224223        self.graph.xaxis(data._xaxis, data._xunit) 
    225224        self.graph.yaxis(data._yaxis, data._yunit) 
    226         if self._is_changed_legend_label:    
    227                 data.label = self.title_label 
     225        if self._is_changed_legend_label: 
     226            data.label = self.title_label 
    228227        if data.label == None: 
    229             data.label = data.name    
     228            data.label = data.name 
    230229        if not self.title_font: 
    231230            self.graph.title(data.label) 
     
    240239                                   fontproperties=self.title_font, 
    241240                                   color=self.title_color) 
    242             self.subplot.figure.canvas.draw_idle()     
    243         ## store default value of zmin and zmax  
     241            self.subplot.figure.canvas.draw_idle() 
     242        ## store default value of zmin and zmax 
    244243        self.default_zmin_ctl = self.zmin_2D 
    245244        self.default_zmax_ctl = self.zmax_2D 
     
    247246            return 
    248247        # Recover the x,y limits 
    249         if (xlo and xhi and ylo and yhi) != None: 
    250             if (xlo > data.xmin and xhi < data.xmax and\ 
    251                         ylo > data.ymin and yhi < data.ymax): 
    252                 self.subplot.set_xlim((xlo, xhi))      
    253                 self.subplot.set_ylim((ylo, yhi))  
    254             else:  
     248        if xlo and xhi and ylo and yhi: 
     249            if xlo > data.xmin and xhi < data.xmax and \ 
     250                        ylo > data.ymin and yhi < data.ymax: 
     251                self.subplot.set_xlim((xlo, xhi)) 
     252                self.subplot.set_ylim((ylo, yhi)) 
     253            else: 
    255254                self.toolbar.update() 
    256255                self.is_zoomed = False 
     
    276275            self.xaxis_label = xname 
    277276            self.xaxis_unit = xunits 
    278         self.xaxis(xname, xunits, self.xaxis_font,  
     277        self.xaxis(xname, xunits, self.xaxis_font, 
    279278                   self.xaxis_color, self.xaxis_tick) 
    280         self.yaxis(yname, yunits, self.yaxis_font,  
     279        self.yaxis(yname, yunits, self.yaxis_font, 
    281280                   self.yaxis_color, self.yaxis_tick) 
    282          
     281 
    283282    def onContextMenu(self, event): 
    284283        """ 
    285284        2D plot context menu 
    286          
     285 
    287286        :param event: wx context event 
    288          
     287 
    289288        """ 
    290289        slicerpop = PanelMenu() 
    291290        slicerpop.set_plots(self.plots) 
    292291        slicerpop.set_graph(self.graph) 
    293               
    294         id = wx.NewId() 
    295         slicerpop.Append(id, '&Save Image') 
    296         wx.EVT_MENU(self, id, self.onSaveImage) 
    297          
    298         id = wx.NewId() 
    299         slicerpop.Append(id,'&Print Image', 'Print image') 
    300         wx.EVT_MENU(self, id, self.onPrint) 
    301          
    302         id = wx.NewId() 
    303         slicerpop.Append(id,'&Print Preview', 'Print preview') 
    304         wx.EVT_MENU(self, id, self.onPrinterPreview) 
    305  
    306         id = wx.NewId() 
    307         slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') 
    308         wx.EVT_MENU(self, id, self.OnCopyFigureMenu) 
     292 
     293        wx_id = wx.NewId() 
     294        slicerpop.Append(wx_id, '&Save Image') 
     295        wx.EVT_MENU(self, wx_id, self.onSaveImage) 
     296 
     297        wx_id = wx.NewId() 
     298        slicerpop.Append(wx_id, '&Print Image', 'Print image') 
     299        wx.EVT_MENU(self, wx_id, self.onPrint) 
     300 
     301        wx_id = wx.NewId() 
     302        slicerpop.Append(wx_id, '&Print Preview', 'Print preview') 
     303        wx.EVT_MENU(self, wx_id, self.onPrinterPreview) 
     304 
     305        wx_id = wx.NewId() 
     306        slicerpop.Append(wx_id, '&Copy to Clipboard', 'Copy to the clipboard') 
     307        wx.EVT_MENU(self, wx_id, self.OnCopyFigureMenu) 
    309308        slicerpop.AppendSeparator() 
    310309        # saving data 
    311310        plot = self.data2D 
    312         id = wx.NewId() 
    313         name = plot.name 
    314         slicerpop.Append(id, "&Data Info" ) 
    315         wx.EVT_MENU(self, id, self._onDataShow) 
    316  
    317         id = wx.NewId() 
    318         name = plot.name 
    319         slicerpop.Append(id, "&Save as a File (DAT)" ) 
    320         self.action_ids[str(id)] = plot 
    321         wx.EVT_MENU(self, id, self._onSave) 
     311        wx_id = wx.NewId() 
     312        slicerpop.Append(wx_id, "&Data Info") 
     313        wx.EVT_MENU(self, wx_id, self._onDataShow) 
     314 
     315        wx_id = wx.NewId() 
     316        slicerpop.Append(wx_id, "&Save as a File (DAT)") 
     317        self.action_ids[str(wx_id)] = plot 
     318        wx.EVT_MENU(self, wx_id, self._onSave) 
    322319 
    323320        slicerpop.AppendSeparator() 
    324         if len(self.data2D.detector) == 1:         
    325              
     321        if len(self.data2D.detector) == 1: 
    326322            item_list = self.parent.get_current_context_menu(self) 
    327323            if (not item_list == None) and (not len(item_list) == 0) and\ 
    328                 self.data2D.name.split(" ")[0] != 'Residuals':   
     324                self.data2D.name.split(" ")[0] != 'Residuals': 
    329325                # The line above; Not for trunk 
    330326                for item in item_list: 
    331327                    try: 
    332                         id = wx.NewId() 
    333                         slicerpop.Append(id, item[0], item[1]) 
    334                         wx.EVT_MENU(self, id, item[2]) 
     328                        wx_id = wx.NewId() 
     329                        slicerpop.Append(wx_id, item[0], item[1]) 
     330                        wx.EVT_MENU(self, wx_id, item[2]) 
    335331                    except: 
    336332                        msg = "ModelPanel1D.onContextMenu: " 
    337                         msg += "bad menu item  %s"%sys.exc_value 
     333                        msg += "bad menu item  %s" % sys.exc_value 
    338334                        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    339                         pass 
    340335                slicerpop.AppendSeparator() 
    341              
    342             id = wx.NewId() 
    343             slicerpop.Append(id, '&Perform Circular Average') 
    344             wx.EVT_MENU(self, id, self.onCircular) \ 
     336 
     337            wx_id = wx.NewId() 
     338            slicerpop.Append(wx_id, '&Perform Circular Average') 
     339            wx.EVT_MENU(self, wx_id, self.onCircular) \ 
    345340            # For Masked Data 
    346341            if not plot.mask.all(): 
    347                 id = wx.NewId() 
    348                 slicerpop.Append(id, '&Masked Circular Average') 
    349                 wx.EVT_MENU(self, id, self.onMaskedCircular)  
    350             id = wx.NewId() 
    351             slicerpop.Append(id, '&Sector [Q View]') 
    352             wx.EVT_MENU(self, id, self.onSectorQ)  
    353             id = wx.NewId() 
    354             slicerpop.Append(id, '&Annulus [Phi View ]') 
    355             wx.EVT_MENU(self, id, self.onSectorPhi)  
    356             id = wx.NewId() 
    357             slicerpop.Append(id, '&Box Sum') 
    358             wx.EVT_MENU(self, id, self.onBoxSum)  
    359             id = wx.NewId() 
    360             slicerpop.Append(id, '&Box Averaging in Qx') 
    361             wx.EVT_MENU(self, id, self.onBoxavgX)  
    362             id = wx.NewId() 
    363             slicerpop.Append(id, '&Box Averaging in Qy') 
    364             wx.EVT_MENU(self, id, self.onBoxavgY)  
     342                wx_id = wx.NewId() 
     343                slicerpop.Append(wx_id, '&Masked Circular Average') 
     344                wx.EVT_MENU(self, wx_id, self.onMaskedCircular) 
     345            wx_id = wx.NewId() 
     346            slicerpop.Append(wx_id, '&Sector [Q View]') 
     347            wx.EVT_MENU(self, wx_id, self.onSectorQ) 
     348            wx_id = wx.NewId() 
     349            slicerpop.Append(wx_id, '&Annulus [Phi View ]') 
     350            wx.EVT_MENU(self, wx_id, self.onSectorPhi) 
     351            wx_id = wx.NewId() 
     352            slicerpop.Append(wx_id, '&Box Sum') 
     353            wx.EVT_MENU(self, wx_id, self.onBoxSum) 
     354            wx_id = wx.NewId() 
     355            slicerpop.Append(wx_id, '&Box Averaging in Qx') 
     356            wx.EVT_MENU(self, wx_id, self.onBoxavgX) 
     357            wx_id = wx.NewId() 
     358            slicerpop.Append(wx_id, '&Box Averaging in Qy') 
     359            wx.EVT_MENU(self, wx_id, self.onBoxavgY) 
    365360            if self.slicer != None: 
    366                 id = wx.NewId() 
    367                 slicerpop.Append(id, '&Clear Slicer') 
    368                 wx.EVT_MENU(self, id,  self.onClearSlicer)  
    369                 if self.slicer.__class__.__name__  != "BoxSum": 
    370                     id = wx.NewId() 
    371                     slicerpop.Append(id, '&Edit Slicer Parameters') 
    372                     wx.EVT_MENU(self, id, self._onEditSlicer)  
    373             slicerpop.AppendSeparator()  
    374              
    375         id = wx.NewId() 
    376         slicerpop.Append(id, '&Edit Graph Label', 'Edit Graph Label') 
    377         wx.EVT_MENU(self, id, self.onEditLabels) 
     361                wx_id = wx.NewId() 
     362                slicerpop.Append(wx_id, '&Clear Slicer') 
     363                wx.EVT_MENU(self, wx_id, self.onClearSlicer) 
     364                if self.slicer.__class__.__name__ != "BoxSum": 
     365                    wx_id = wx.NewId() 
     366                    slicerpop.Append(wx_id, '&Edit Slicer Parameters') 
     367                    wx.EVT_MENU(self, wx_id, self._onEditSlicer) 
     368            slicerpop.AppendSeparator() 
     369 
     370        wx_id = wx.NewId() 
     371        slicerpop.Append(wx_id, '&Edit Graph Label', 'Edit Graph Label') 
     372        wx.EVT_MENU(self, wx_id, self.onEditLabels) 
    378373        slicerpop.AppendSeparator() 
    379          
     374 
    380375        # ILL mod here 
    381376 
    382         id = wx.NewId() 
    383         slicerpop.Append(id, '&Modify graph appearance','Modify graph appearance') 
    384         wx.EVT_MENU(self, id, self.modifyGraphAppearance) 
     377        wx_id = wx.NewId() 
     378        slicerpop.Append(wx_id, '&Modify graph appearance', 'Modify graph appearance') 
     379        wx.EVT_MENU(self, wx_id, self.modifyGraphAppearance) 
    385380        slicerpop.AppendSeparator() 
    386381 
    387  
    388          
    389         id = wx.NewId() 
    390         slicerpop.Append(id, '&2D Color Map') 
    391         wx.EVT_MENU(self, id, self._onEditDetector) 
     382        wx_id = wx.NewId() 
     383        slicerpop.Append(wx_id, '&2D Color Map') 
     384        wx.EVT_MENU(self, wx_id, self._onEditDetector) 
    392385        slicerpop.AppendSeparator() 
    393          
    394         id = wx.NewId() 
    395         slicerpop.Append(id, '&Toggle Linear/Log Scale') 
    396         wx.EVT_MENU(self, id, self._onToggleScale)  
    397          
    398          
     386 
     387        wx_id = wx.NewId() 
     388        slicerpop.Append(wx_id, '&Toggle Linear/Log Scale') 
     389        wx.EVT_MENU(self, wx_id, self._onToggleScale) 
     390 
    399391        slicerpop.AppendSeparator() 
    400         id = wx.NewId() 
    401         slicerpop.Append(id, '&Window Title') 
    402         wx.EVT_MENU(self, id, self.onChangeCaption) 
    403          
     392        wx_id = wx.NewId() 
     393        slicerpop.Append(wx_id, '&Window Title') 
     394        wx.EVT_MENU(self, wx_id, self.onChangeCaption) 
     395 
    404396        try: 
    405397            pos_evt = event.GetPosition() 
     
    409401            pos = (pos_x, pos_y + 5) 
    410402        self.PopupMenu(slicerpop, pos) 
    411          
    412              
     403 
    413404    def onEditLabels(self, event): 
    414405        """ 
     
    443434                                           color=self.title_color) 
    444435                    self._is_changed_legend_label = True 
    445                     self.subplot.figure.canvas.draw_idle()   
     436                    self.subplot.figure.canvas.draw_idle() 
    446437            except: 
     438                msg = "Add Text: Error. Check your property values..." 
     439                logging.error(msg) 
    447440                if self.parent != None: 
    448                     from sas.guiframe.events import StatusEvent  
    449                     msg= "Add Text: Error. Check your property values..." 
    450                     wx.PostEvent(self.parent, StatusEvent(status = msg )) 
    451                 else: 
    452                     raise 
     441                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    453442        dial.Destroy() 
    454          
     443 
    455444    def _onEditDetector(self, event): 
    456445        """ 
    457446        Allow to view and edits  detector parameters 
    458          
     447 
    459448        :param event: wx.menu event 
    460          
     449 
    461450        """ 
    462451        import detector_dialog 
    463         dialog = detector_dialog.DetectorDialog(self, -1,base=self.parent, 
    464                        reset_zmin_ctl =self.default_zmin_ctl, 
    465                        reset_zmax_ctl = self.default_zmax_ctl,cmap=self.cmap) 
     452        dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent, 
     453                                                reset_zmin_ctl=self.default_zmin_ctl, 
     454                                                reset_zmax_ctl=self.default_zmax_ctl, cmap=self.cmap) 
    466455        ## info of current detector and data2D 
    467456        xnpts = len(self.data2D.x_bins) 
     
    470459        ymax = max(self.data2D.ymin, self.data2D.ymax) 
    471460        qmax = math.sqrt(math.pow(xmax, 2) + math.pow(ymax, 2)) 
    472         beam = self.data2D.xmin 
    473461        ## set dialog window content 
    474         dialog.setContent(xnpts=xnpts,ynpts=ynpts,qmax=qmax, 
    475                            beam=self.data2D.xmin, 
    476                            zmin = self.zmin_2D, 
    477                           zmax = self.zmax_2D) 
     462        dialog.setContent(xnpts=xnpts, ynpts=ynpts, qmax=qmax, 
     463                          beam=self.data2D.xmin, 
     464                          zmin=self.zmin_2D, 
     465                          zmax=self.zmax_2D) 
    478466        if dialog.ShowModal() == wx.ID_OK: 
    479467            evt = dialog.getContent() 
     
    486474                   qx_data=self.data2D.qx_data, 
    487475                   qy_data=self.data2D.qy_data, 
    488                    xmin= self.data2D.xmin, 
    489                    xmax= self.data2D.xmax, 
    490                    ymin= self.data2D.ymin, 
    491                    ymax= self.data2D.ymax, 
    492                    zmin= self.zmin_2D, 
    493                    zmax= self.zmax_2D, 
    494                    cmap= self.cmap, 
     476                   xmin=self.data2D.xmin, 
     477                   xmax=self.data2D.xmax, 
     478                   ymin=self.data2D.ymin, 
     479                   ymax=self.data2D.ymax, 
     480                   zmin=self.zmin_2D, 
     481                   zmax=self.zmax_2D, 
     482                   cmap=self.cmap, 
    495483                   color=0, symbol=0, label=self.data2D.name) 
    496484        self.subplot.figure.canvas.draw_idle() 
    497          
     485 
    498486    def freeze_axes(self): 
    499487        """ 
    500488        """ 
    501489        self.axes_frozen = True 
    502          
     490 
    503491    def thaw_axes(self): 
    504492        """ 
    505493        """ 
    506494        self.axes_frozen = False 
    507          
    508     def onMouseMotion(self,event): 
     495 
     496    def onMouseMotion(self, event): 
    509497        """ 
    510498        """ 
    511499        pass 
    512      
     500 
    513501    def onWheel(self, event): 
    514502        """ 
    515503        """ 
    516         pass   
    517        
     504        pass 
     505 
    518506    def update(self, draw=True): 
    519507        """ 
    520         Respond to changes in the model by recalculating the  
     508        Respond to changes in the model by recalculating the 
    521509        profiles and resetting the widgets. 
    522510        """ 
    523511        self.draw_plot() 
    524          
     512 
    525513    def _getEmptySlicerEvent(self): 
    526514        """ 
    527         create an empty slicervent  
     515        create an empty slicervent 
    528516        """ 
    529517        return SlicerEvent(type=None, params=None, obj_class=None) 
    530          
     518 
    531519    def _onEVT_INTERNAL(self, event): 
    532520        """ 
    533521        Draw the slicer 
    534          
     522 
    535523        :param event: wx.lib.newevent (SlicerEvent) containing slicer 
    536524            parameter 
    537              
     525 
    538526        """ 
    539527        self._setSlicer(event.slicer) 
    540              
     528 
    541529    def _setSlicer(self, slicer): 
    542530        """ 
    543531        Clear the previous slicer and create a new one.Post an internal 
    544532        event. 
    545          
     533 
    546534        :param slicer: slicer class to create 
    547          
     535 
    548536        """ 
    549537        ## Clear current slicer 
    550         if not self.slicer == None:   
    551             self.slicer.clear()             
    552         ## Create a new slicer     
     538        if not self.slicer == None: 
     539            self.slicer.clear() 
     540        ## Create a new slicer 
    553541        self.slicer_z += 1 
    554542        self.slicer = slicer(self, self.subplot, zorder=self.slicer_z) 
     
    558546        self.update() 
    559547        self.slicer.update() 
    560         msg = "Plotter2D._setSlicer  %s"%self.slicer.__class__.__name__ 
     548        msg = "Plotter2D._setSlicer  %s" % self.slicer.__class__.__name__ 
    561549        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    562550        # Post slicer event 
     
    566554        event.params = self.slicer.get_params() 
    567555        wx.PostEvent(self, event) 
    568          
     556 
    569557    def onMaskedCircular(self, event): 
    570558        """ 
    571559        perform circular averaging on Data2D with mask if it exists 
    572          
     560 
    573561        :param event: wx.menu event 
    574          
     562 
    575563        """ 
    576564        self.onCircular(event, True) 
    577          
     565 
    578566    def onCircular(self, event, ismask=False): 
    579567        """ 
    580568        perform circular averaging on Data2D 
    581          
     569 
    582570        :param event: wx.menu event 
    583          
     571 
    584572        """ 
    585573        # Find the best number of bins 
     
    588576        from sas.dataloader.manipulations import CircularAverage 
    589577        ## compute the maximum radius of data2D 
    590         self.qmax = max(math.fabs(self.data2D.xmax),  
     578        self.qmax = max(math.fabs(self.data2D.xmax), 
    591579                        math.fabs(self.data2D.xmin)) 
    592580        self.ymax = max(math.fabs(self.data2D.ymax), 
    593581                        math.fabs(self.data2D.ymin)) 
    594         self.radius = math.sqrt(math.pow(self.qmax, 2)+ math.pow(self.ymax, 2))  
     582        self.radius = math.sqrt(math.pow(self.qmax, 2) + math.pow(self.ymax, 2)) 
    595583        ##Compute beam width 
    596         bin_width = (self.qmax + self.qmax)/npt 
     584        bin_width = (self.qmax + self.qmax) / npt 
    597585        ## Create data1D circular average of data2D 
    598         Circle = CircularAverage(r_min=0, r_max=self.radius,  
     586        Circle = CircularAverage(r_min=0, r_max=self.radius, 
    599587                                 bin_width=bin_width) 
    600588        circ = Circle(self.data2D, ismask=ismask) 
     
    617605        new_plot.interactive = True 
    618606        new_plot.detector = self.data2D.detector 
    619          
     607 
    620608        ## If the data file does not tell us what the axes are, just assume... 
    621609        new_plot.xaxis("\\rm{Q}", "A^{-1}") 
     
    627615            new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    628616 
    629         new_plot.group_id = "2daverage"  + self.data2D.name 
     617        new_plot.group_id = "2daverage" + self.data2D.name 
    630618        new_plot.id = "Circ avg " + self.data2D.name 
    631619        new_plot.is_data = True 
    632620        self.parent.update_theory(data_id=self.data2D.id, \ 
    633621                                       theory=new_plot) 
    634         wx.PostEvent(self.parent,  
     622        wx.PostEvent(self.parent, 
    635623                     NewPlotEvent(plot=new_plot, title=new_plot.name)) 
    636         
     624 
    637625    def _onEditSlicer(self, event): 
    638626        """ 
    639         Is available only when a slicer is drawn.Create a dialog  
     627        Is available only when a slicer is drawn.Create a dialog 
    640628        window where the user can enter value to reset slicer 
    641629        parameters. 
    642          
     630 
    643631        :param event: wx.menu event 
    644          
     632 
    645633        """ 
    646634        if self.slicer != None: 
     
    648636            dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 
    649637            dialog.set_slicer(self.slicer.__class__.__name__, 
    650                             self.slicer.get_params()) 
     638                              self.slicer.get_params()) 
    651639            if dialog.ShowModal() == wx.ID_OK: 
    652                 dialog.Destroy()  
    653          
     640                dialog.Destroy() 
     641 
    654642    def onSectorQ(self, event): 
    655643        """ 
     
    659647        self.onClearSlicer(event) 
    660648        wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 
    661          
     649 
    662650    def onSectorPhi(self, event): 
    663651        """ 
     
    667655        self.onClearSlicer(event) 
    668656        wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 
    669          
     657 
    670658    def onBoxSum(self, event): 
    671659        """ 
     
    675663        self.onClearSlicer(event) 
    676664        self.slicer_z += 1 
    677         self.slicer =  BoxSum(self, self.subplot, zorder=self.slicer_z) 
     665        self.slicer = BoxSum(self, self.subplot, zorder=self.slicer_z) 
    678666        self.subplot.set_ylim(self.data2D.ymin, self.data2D.ymax) 
    679667        self.subplot.set_xlim(self.data2D.xmin, self.data2D.xmax) 
     
    681669        self.slicer.update() 
    682670        ## Value used to initially set the slicer panel 
    683         type = self.slicer.__class__.__name__ 
    684671        params = self.slicer.get_params() 
    685672        ## Create a new panel to display results of summation of Data2D 
     
    687674        win = MDIFrame(self.parent, None, 'None', (100, 200)) 
    688675        new_panel = SlicerPanel(parent=win, id=-1, 
    689                                     base=self, type=type, 
    690                                     params=params, style=wx.RAISED_BORDER) 
    691          
     676                                base=self, type=self.slicer.__class__.__name__, 
     677                                params=params, style=wx.RAISED_BORDER) 
     678 
    692679        new_panel.window_caption = self.slicer.__class__.__name__ + " " + \ 
    693680                                    str(self.data2D.name) 
    694         new_panel.window_name = self.slicer.__class__.__name__+ " " + \ 
     681        new_panel.window_name = self.slicer.__class__.__name__ + " " + \ 
    695682                                    str(self.data2D.name) 
    696683        ## Store a reference of the new created panel 
    697          
     684 
    698685        ## save the window_caption of the new panel in the current slicer 
    699686        self.slicer.set_panel_name(name=new_panel.window_caption) 
    700         ## post slicer panel to guiframe to display it  
     687        ## post slicer panel to guiframe to display it 
    701688        from sas.guiframe.events import SlicerPanelEvent 
    702          
     689 
    703690        win.set_panel(new_panel) 
    704691        new_panel.frame = win 
    705692        wx.PostEvent(self.parent, SlicerPanelEvent(panel=new_panel, 
    706                                                     main_panel=self)) 
     693                                                   main_panel=self)) 
    707694        wx.CallAfter(new_panel.frame.Show) 
    708695        self.panel_slicer = new_panel 
    709          
    710     def onBoxavgX(self,event): 
     696 
     697    def onBoxavgX(self, event): 
    711698        """ 
    712699        Perform 2D data averaging on Qx 
    713700        Create a new slicer . 
    714          
     701 
    715702        :param event: wx.menu event 
    716703        """ 
     
    718705        self.onClearSlicer(event) 
    719706        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 
    720         
    721     def onBoxavgY(self,event): 
     707 
     708    def onBoxavgY(self, event): 
    722709        """ 
    723710        Perform 2D data averaging on Qy 
    724711        Create a new slicer . 
    725          
     712 
    726713        :param event: wx.menu event 
    727          
     714 
    728715        """ 
    729716        from boxSlicer import BoxInteractorY 
    730717        self.onClearSlicer(event) 
    731718        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 
    732          
     719 
    733720    def onClearSlicer(self, event): 
    734721        """ 
     
    742729            event = self._getEmptySlicerEvent() 
    743730            wx.PostEvent(self, event) 
    744              
     731 
    745732    def _onSave(self, evt): 
    746733        """ 
    747734        Save a data set to a dat(text) file 
    748          
     735 
    749736        :param evt: Menu event 
    750          
    751         """ 
    752         id = str(evt.GetId()) 
     737 
     738        """ 
     739        event_id = str(evt.GetId()) 
    753740        if self.parent != None: 
    754741            self._default_save_location = self.parent._default_save_location 
     
    757744            default_name = default_name.split('.')[0] 
    758745        default_name += "_out" 
    759         if id in self.action_ids:          
    760             path = None 
     746        if event_id in self.action_ids: 
    761747            self.parent.save_data2d(self.data2D, default_name) 
    762              
     748 
    763749    def _onDataShow(self, evt): 
    764750        """ 
    765751        Show the data set in text 
    766          
     752 
    767753        :param evt: Menu event 
    768          
     754 
    769755        """ 
    770756        menu = evt.GetEventObject() 
    771         id = evt.GetId() 
    772         self.set_selected_from_menu(menu, id) 
     757        event_id = evt.GetId() 
     758        self.set_selected_from_menu(menu, event_id) 
    773759        data = self.plots[self.graph.selected_plottable] 
    774760        default_name = data.label 
     
    778764        if self.parent != None: 
    779765            self.parent.show_data2d(data, default_name) 
    780          
    781  
    782     def modifyGraphAppearance(self,e): 
    783         self.graphApp = graphAppearance(self,'Modify graph appearance', 
    784                                         legend=False) 
    785  
    786          
    787  
    788         self.graphApp.setDefaults(self.grid_on,self.legend_on, 
    789                                   self.xaxis_label,self.yaxis_label, 
    790                                   self.xaxis_unit,self.yaxis_unit, 
    791                                   self.xaxis_font,self.yaxis_font, 
    792                                   find_key(self.get_loc_label(),self.legendLoc), 
    793                                   self.xcolor,self.ycolor, 
    794                                    self.is_xtick, self.is_ytick) 
     766 
     767    def modifyGraphAppearance(self, e): 
     768        self.graphApp = graphAppearance(self, 'Modify graph appearance', legend=False) 
     769        self.graphApp.setDefaults(self.grid_on, self.legend_on, 
     770                                  self.xaxis_label, self.yaxis_label, 
     771                                  self.xaxis_unit, self.yaxis_unit, 
     772                                  self.xaxis_font, self.yaxis_font, 
     773                                  find_key(self.get_loc_label(), self.legendLoc), 
     774                                  self.xcolor, self.ycolor, 
     775                                  self.is_xtick, self.is_ytick) 
    795776        self.graphApp.Bind(wx.EVT_CLOSE, self.on_graphApp_close) 
    796      
    797  
    798     def on_graphApp_close(self,e): 
    799         # gets values from graph appearance dialog and sends them off 
    800         # to modify the plot 
    801  
     777 
     778    def on_graphApp_close(self, e): 
     779        """ 
     780            Gets values from graph appearance dialog and sends them off 
     781            to modify the plot 
     782        """ 
    802783        self.onGridOnOff(self.graphApp.get_togglegrid()) 
    803  
    804          
    805784        self.xaxis_label = self.graphApp.get_xlab() 
    806785        self.yaxis_label = self.graphApp.get_ylab() 
     
    809788        self.xaxis_font = self.graphApp.get_xfont() 
    810789        self.yaxis_font = self.graphApp.get_yfont() 
    811         self.is_xtick =  self.graphApp.get_xtick_check() 
    812         self.is_ytick =  self.graphApp.get_ytick_check() 
     790        self.is_xtick = self.graphApp.get_xtick_check() 
     791        self.is_ytick = self.graphApp.get_ytick_check() 
    813792        if self.is_xtick: 
    814793            self.xaxis_tick = self.xaxis_font 
     
    816795            self.yaxis_tick = self.yaxis_font 
    817796 
    818         self.xaxis(self.xaxis_label, self.xaxis_unit,  
    819                    self.graphApp.get_xfont(), self.graphApp.get_xcolor(),  
     797        self.xaxis(self.xaxis_label, self.xaxis_unit, 
     798                   self.graphApp.get_xfont(), self.graphApp.get_xcolor(), 
    820799                   self.xaxis_tick) 
    821         self.yaxis(self.yaxis_label, self.yaxis_unit,  
     800        self.yaxis(self.yaxis_label, self.yaxis_unit, 
    822801                   self.graphApp.get_yfont(), self.graphApp.get_ycolor(), 
    823802                   self.yaxis_tick) 
  • src/sas/guiframe/local_perspectives/plotting/masking.py

    r7d56795 rc039589  
    3030from sas.guiframe.dataFitting import Data1D, Data2D 
    3131from boxMask import BoxMask 
    32 from sectorMask import SectorMask 
     32from sector_mask import SectorMask 
    3333from AnnulusSlicer import CircularMask 
    3434 
  • src/sas/guiframe/local_perspectives/plotting/plotting.py

    rb9dbd6b rc039589  
    55#This software was developed by the University of Tennessee as part of the 
    66#Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation.  
     7#project funded by the US National Science Foundation. 
    88# 
    99#See the license text in license.txt 
     
    1616from sas.guiframe.events import EVT_NEW_PLOT 
    1717from sas.guiframe.events import EVT_PLOT_QRANGE 
    18 from sas.guiframe.events import StatusEvent  
    1918from sas.guiframe.events import DeletePlotPanelEvent 
    2019from sas.guiframe.plugin_base import PluginBase 
     
    2524DEFAULT_MENU_ITEM_ID = wx.NewId() 
    2625 
    27 IS_WIN = True     
    28 if sys.platform.count("win32")==0: 
     26IS_WIN = True 
     27if sys.platform.count("win32") == 0: 
    2928    if int(str(wx.__version__).split('.')[0]) == 2: 
    3029        if int(str(wx.__version__).split('.')[1]) < 9: 
     
    3635    Plug-in class to be instantiated by the GUI manager 
    3736    """ 
    38      
     37 
    3938    def __init__(self, standalone=False): 
    4039        PluginBase.__init__(self, name="Plotting", standalone=standalone) 
    41        
     40 
    4241        ## Plot panels 
    4342        self.plot_panels = {} 
     
    4746        self.menu = None 
    4847 
    49       
     48 
    5049    def set_panel_on_focus(self, panel): 
    5150        """ 
    5251        """ 
    5352        self._panel_on_focus = panel 
    54          
     53 
    5554    def is_always_active(self): 
    5655        """ 
    57         return True is this plugin is always active even if the user is  
     56        return True is this plugin is always active even if the user is 
    5857        switching between perspectives 
    5958        """ 
    6059        return True 
    61      
     60 
    6261    def populate_menu(self, parent): 
    6362        """ 
    6463        Create a 'Plot' menu to list the panels 
    6564        available for displaying 
    66          
     65 
    6766        :param id: next available unique ID for wx events 
    6867        :param parent: parent window 
    69          
     68 
    7069        """ 
    7170        return [] 
    72         """ 
    73         self.menu = wx.Menu() 
    74         self.menu.Append(DEFAULT_MENU_ITEM_ID, DEFAULT_MENU_ITEM_LABEL,  
    75                              "No graph available") 
    76         self.menu.FindItemByPosition(0).Enable(False) 
    77         return [(self.menu, "Show")] 
    78         """ 
    79      
     71 
    8072    def get_panels(self, parent): 
    8173        """ 
     
    8981        # We have no initial panels for this plug-in 
    9082        return [] 
    91      
    92     def _on_plot_qrange(self, event= None): 
     83 
     84    def _on_plot_qrange(self, event=None): 
    9385        """ 
    9486        On Qmin Qmax vertical line event 
     
    10395            return 
    10496        panel.on_plot_qrange(event) 
    105              
     97 
    10698    def _on_show_panel(self, event): 
    10799        """show plug-in panel""" 
    108100        pass 
    109      
     101 
    110102    def remove_plot(self, group_id, id): 
    111103        """ 
    112104        remove plot of ID = id from a panel of group ID =group_id 
    113105        """ 
    114          
     106 
    115107        if group_id in self.plot_panels.keys(): 
    116108            panel = self.plot_panels[group_id] 
    117109            panel.remove_data_by_id(id=id) 
    118              
     110 
    119111            return True 
    120112        return False 
    121          
     113 
    122114    def clear_panel(self): 
    123115        """ 
     
    129121            self.hide_panel(group_id) 
    130122        self.plot_panels = {} 
    131      
     123 
    132124    def clear_panel_by_id(self, group_id): 
    133125        """ 
     
    141133            return True 
    142134        return False 
    143              
     135 
    144136    def hide_panel(self, group_id): 
    145137        """ 
     
    148140        # Not implemeted 
    149141        return False 
    150      
     142 
    151143    def create_panel_helper(self, new_panel, data, group_id, title=None): 
    152144        """ 
     
    167159        new_panel.uid = event_id 
    168160        # Ship the plottable to its panel 
    169         wx.CallAfter(new_panel.plot_data, data)  
     161        wx.CallAfter(new_panel.plot_data, data) 
    170162        #new_panel.canvas.set_resizing(new_panel.resizing) 
    171163        self.plot_panels[new_panel.group_id] = new_panel 
    172          
    173         # Set Graph menu and help string         
    174         self.help_string = ' Graph: ' 
    175         for plot in  new_panel.plots.itervalues(): 
    176             help_string += (' ' + plot.label + ';') 
    177         #self.menu.AppendCheckItem(event_id, new_panel.window_caption,  
    178         #                          helpString) 
    179         #self.menu.Check(event_id, IS_WIN) 
    180         #wx.EVT_MENU(self.parent, event_id, self._on_check_menu) 
    181  
    182          
     164 
    183165    def create_1d_panel(self, data, group_id): 
    184166        """ 
    185167        """ 
    186         # Create a new plot panel if none was available         
     168        # Create a new plot panel if none was available 
    187169        if issubclass(data.__class__, Data1D): 
    188170            from Plotter1D import ModelPanel1D 
     
    194176            win = MDIFrame(self.parent, None, 'None', (100, 200)) 
    195177            new_panel = ModelPanel1D(win, -1, xtransform=xtransform, 
    196                      ytransform=ytransform, style=wx.RAISED_BORDER) 
     178                                     ytransform=ytransform, style=wx.RAISED_BORDER) 
    197179            win.set_panel(new_panel) 
    198180            win.Show(False) 
     
    200182            #win.Show(True) 
    201183            return  new_panel 
    202          
     184 
    203185        msg = "1D Panel of group ID %s could not be created" % str(group_id) 
    204186        raise ValueError, msg 
    205      
     187 
    206188    def create_2d_panel(self, data, group_id): 
    207189        """ 
     
    213195            win = MDIFrame(self.parent, None, 'None', (200, 150)) 
    214196            win.Show(False) 
    215             new_panel = ModelPanel2D(win, id = -1, 
    216                                 data2d=data, scale = scale,  
    217                                 style=wx.RAISED_BORDER) 
     197            new_panel = ModelPanel2D(win, id=-1, 
     198                                     data2d=data, scale=scale, 
     199                                     style=wx.RAISED_BORDER) 
    218200            win.set_panel(new_panel) 
    219201            new_panel.frame = win 
    220             #win.Show(True) 
    221202            return new_panel 
    222203        msg = "2D Panel of group ID %s could not be created" % str(group_id) 
    223204        raise ValueError, msg 
    224      
     205 
    225206    def update_panel(self, data, panel): 
    226207        """ 
     
    228209        """ 
    229210        # Check whether we already have a graph with the same units 
    230         # as the plottable we just received.  
    231         _, x_unit =  data.get_xaxis() 
    232         _, y_unit =  data.get_yaxis() 
     211        # as the plottable we just received. 
     212        _, x_unit = data.get_xaxis() 
     213        _, y_unit = data.get_yaxis() 
    233214        flag_x = (panel.graph.prop["xunit"] is not None) and \ 
    234215                    (panel.graph.prop["xunit"].strip() != "") and\ 
     
    237218                    (panel.graph.prop["yunit"].strip() != "") and\ 
    238219                    (y_unit != panel.graph.prop["yunit"]) and False 
    239         if (flag_x and flag_y): 
     220        if flag_x and flag_y: 
    240221            msg = "Cannot add %s" % str(data.name) 
    241222            msg += " to panel %s\n" % str(panel.window_caption) 
     
    253234            panel = self.plot_panels[group_id] 
    254235            uid = panel.uid 
    255             wx.PostEvent(self.parent,  
     236            wx.PostEvent(self.parent, 
    256237                         DeletePlotPanelEvent(name=panel.window_caption, 
    257                                     caption=panel.window_caption)) 
    258             #remove menu item 
    259             #self.delete_menu_item(panel.window_caption, panel.uid) 
     238                                              caption=panel.window_caption)) 
    260239            del self.plot_panels[group_id] 
    261240            if uid in self.parent.plot_panels.keys(): 
     
    265244 
    266245        return False 
    267      
     246 
    268247    def _on_plot_event(self, event): 
    269248        """ 
     
    271250        Check whether we have a panel to put in on, or create 
    272251        a new one 
    273          
     252 
    274253        :param event: EVT_NEW_PLOT event 
    275          
     254 
    276255        """ 
    277256        action_check = False 
     
    285264                    #remove data from panel 
    286265                    if action_string == 'remove': 
    287                         id = event.id 
    288                         return self.remove_plot(group_id, id) 
     266                        return self.remove_plot(group_id, event.id) 
    289267                    if action_string == 'hide': 
    290268                        return self.hide_panel(group_id) 
     
    295273                    if action_string == "clear": 
    296274                        return self.clear_panel_by_id(group_id) 
    297                      
    298         if not hasattr(event, 'plot'):     
     275 
     276        if not hasattr(event, 'plot'): 
    299277            return 
    300278        title = None 
    301279        if hasattr(event, 'title'): 
    302             title = 'Graph'#event.title       
     280            title = 'Graph'  #event.title 
    303281        data = event.plot 
    304         group_id = data.group_id     
     282        group_id = data.group_id 
    305283        if group_id in self.plot_panels.keys(): 
    306284            if action_check: 
    307285                # Check if the plot already exist. if it does, do nothing. 
    308286                if data.id in self.plot_panels[group_id].plots.keys(): 
    309                     return  
    310             #update a panel graph  
     287                    return 
     288            #update a panel graph 
    311289            panel = self.plot_panels[group_id] 
    312290            self.update_panel(data, panel) 
     
    331309                            p_plot.group_id = group_id 
    332310                            return 
    333                  
     311 
    334312                new_panel = self.create_2d_panel(data, group_id) 
    335             self.create_panel_helper(new_panel, data, group_id, title)  
     313            self.create_panel_helper(new_panel, data, group_id, title) 
    336314        return 
    337         frame.Show(True) 
  • src/sas/guiframe/local_perspectives/plotting/profile_dialog.py

    r090e07e rc039589  
    33""" 
    44import wx 
    5 import os 
    65import sys 
    76from copy import deepcopy 
     
    109from sas.guiframe.dataFitting import Data1D 
    1110from sas.guiframe.gui_style import GUIFRAME_ID 
    12 import pylab 
    13  
    14 DEFAULT_CMAP = None#pylab.cm.jet 
     11 
     12DEFAULT_CMAP = None  #pylab.cm.jet 
    1513_BOX_WIDTH = 76 
    1614_STATICBOX_WIDTH = 400 
     
    1917_Y_OFF = 0.5 
    2018 
    21 #SLD panel size  
     19#SLD panel size 
    2220if sys.platform.count("win32") > 0: 
    2321    _STATICBOX_WIDTH = 563 
     
    2826    PANEL_SIZE = 500 
    2927    FONT_VARIANT = 1 
    30      
    31       
     28 
     29 
    3230class SLDPanel(wx.Dialog): 
    3331    """ 
     
    4038    ## Flag to tell the AUI manager to put this panel in the center pane 
    4139    CENTER_PANE = True 
    42     def __init__(self, parent=None, base=None, data=None, axes =['Radius'],  
     40    def __init__(self, parent=None, base=None, data=None, axes=['Radius'], 
    4341                 id=-1, *args, **kwds): 
    4442        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    45         kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE)  
     43        kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE) 
    4644        wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 
    4745 
    4846        if data != None: 
    49             #Font size  
     47            #Font size 
    5048            kwds = [] 
    5149            self.SetWindowVariant(variant=FONT_VARIANT) 
     
    5957            self.name = self.data.name 
    6058            # Panel for plot 
    61             self.plotpanel = SLDplotpanel(self, axes, -1,  
    62                                              style=wx.TRANSPARENT_WINDOW) 
     59            self.plotpanel = SLDplotpanel(self, axes, -1, 
     60                                          style=wx.TRANSPARENT_WINDOW) 
    6361            self.cmap = DEFAULT_CMAP 
    6462            ## Create Artist and bind it 
     
    6664            # layout 
    6765            self._setup_layout() 
    68              
     66 
    6967            # plot 
    7068            data_plot = deepcopy(self.data) 
     
    7270            # unit increase to M times for users 
    7371            data_plot.y = self._set_y_data() 
    74              
     72 
    7573            self.newplot = Data1D(data_plot.x, data_plot.y, data_plot.dy) 
    7674            self.newplot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM 
     
    7876            self.newplot.name = 'SLD' 
    7977            self.newplot.is_data = False 
    80              
     78 
    8179            self.newplot.id = self.newplot.name 
    82             self.plotpanel.add_image(self.newplot)  
    83              
     80            self.plotpanel.add_image(self.newplot) 
     81 
    8482            self.plotpanel.resizing = False 
    8583            self.plotpanel.canvas.set_resizing(self.plotpanel.resizing) 
    86              
    87             self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF ,  
    88                                                 max(data_plot.y) + _Y_OFF) 
    89             self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF,  
    90                                                 max(data_plot.x) + _X_OFF) 
     84 
     85            self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF, 
     86                                            max(data_plot.y) + _Y_OFF) 
     87            self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF, 
     88                                            max(data_plot.x) + _X_OFF) 
    9189            self.plotpanel.graph.render(self.plotpanel) 
    9290            self.plotpanel.canvas.draw() 
    9391 
    94     def _set_dy_data(self):  
     92    def _set_dy_data(self): 
    9593        """ 
    9694        make fake dy data 
    97          
    98         :return dy:  
     95 
     96        :return dy: 
    9997        """ 
    10098        # set dy as zero 
    10199        dy = [0 for y in self.data.y] 
    102         return dy       
    103  
    104     def _set_y_data(self):  
     100        return dy 
     101 
     102    def _set_y_data(self): 
    105103        """ 
    106104        make y data unit Mega times 
    107          
    108         :return y_value:  
     105 
     106        :return y_value: 
    109107        """ 
    110108        # changes the unit 
    111109        y_value = [yvalue * 1e+006 for yvalue in self.data.y] 
    112          
    113         return y_value      
    114      
     110 
     111        return y_value 
     112 
    115113    def _setup_layout(self): 
    116114        """ 
     
    119117        # panel sizer 
    120118        sizer = wx.BoxSizer(wx.VERTICAL) 
    121         sizer.Add(self.plotpanel, 0, wx.LEFT|wx.RIGHT, 5) 
    122         sizer.Add(wx.StaticLine(self), 0, wx.ALL|wx.EXPAND, 5) 
     119        sizer.Add(self.plotpanel, 0, wx.LEFT | wx.RIGHT, 5) 
     120        sizer.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5) 
    123121        sizer.Add((0, 5)) 
    124122        #-----Button------------1 
    125         id = wx.NewId() 
    126         button_reset = wx.Button(self, id, "Close") 
     123        button_reset = wx.Button(self, wx.NewId(), "Close") 
    127124        button_reset.SetToolTipString("Close...") 
    128         button_reset.Bind(wx.EVT_BUTTON, self._close,  
    129                           id=button_reset.GetId())  
    130         sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80)  
     125        button_reset.Bind(wx.EVT_BUTTON, self._close, 
     126                          id=button_reset.GetId()) 
     127        sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 
    131128        sizer.Add((0, 10)) 
    132129        self.SetSizerAndFit(sizer) 
     
    134131        self.Show(True) 
    135132        button_reset.SetFocus() 
    136          
     133 
    137134    def _close(self, event): 
    138135        """ 
     
    149146    def get_current_context_menu(self, graph=None): 
    150147        """ 
    151         When the context menu of a plot is rendered, the  
    152         get_context_menu method will be called to give you a  
     148        When the context menu of a plot is rendered, the 
     149        get_context_menu method will be called to give you a 
    153150        chance to add a menu item to the context menu. 
    154151        :param graph: the Graph object to which we attach the context menu 
    155          
     152 
    156153        :return: a list of menu items with call-back function 
    157154        """ 
    158155        return [] 
    159      
     156 
    160157    def set_schedule_full_draw(self, panel=None, func=None): 
    161158        """ 
     
    164161        # Not implemented 
    165162        pass 
    166      
     163 
    167164    def set_schedule(self, schedule=False): 
    168165        """ 
     
    171168        # Not implemented 
    172169        pass 
    173          
     170 
    174171    def set_plot_unfocus(self): 
    175172        """ 
     
    178175        # NOt implemented 
    179176        pass 
    180      
     177 
    181178    def on_change_caption(self, name, old_caption, new_caption): 
    182179        """ 
    183180        """ 
    184181        self.parent.parent.parent.on_change_caption(name, old_caption, new_caption) 
    185      
     182 
    186183    def disable_app_menu(self, panel): 
    187184        """ 
     
    190187        # Not implemented! 
    191188        return 
    192      
     189 
    193190    def show_data1d(self, data, name): 
    194191        """ 
    195192        Show data dialog 
    196         """    
     193        """ 
    197194        self.parent._manager.parent.show_data1d(data, name) 
    198          
     195 
    199196class SLDplotpanel(PlotPanel): 
    200197    """ 
    201198    Panel 
    202199    """ 
    203     def __init__(self, parent, axes=[], id=-1, color=None, dpi=None, 
    204                   **kwargs): 
    205         """ 
    206         """ 
    207         PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y',  
    208                            color=color, dpi=dpi,  
    209                            size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs) 
     200    def __init__(self, parent, axes=[], id=-1, color=None, dpi=None, **kwargs): 
     201        """ 
     202        """ 
     203        PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 
     204                           color=color, dpi=dpi, 
     205                           size=(_STATICBOX_WIDTH, PANEL_SIZE - 100), **kwargs) 
    210206 
    211207        # Keep track of the parent Frame 
     
    216212        self.prevYtrans = "y" 
    217213        self.viewModel = "--" 
    218         # Internal list of plottable names (because graph  
     214        # Internal list of plottable names (because graph 
    219215        # doesn't have a dictionary of handles for the plottables) 
    220216        self.plots = {} 
     
    230226        self.xcolor = 'black' 
    231227        self.ycolor = 'black' 
    232          
     228 
    233229    def add_image(self, plot): 
    234230        """ 
     
    241237        #add axes 
    242238        x1_label = self.axes_label[0] 
    243         self.xaxis_label = '\\rm{%s} '% x1_label 
     239        self.xaxis_label = '\\rm{%s} ' % x1_label 
    244240        self.xaxis_unit = 'A' 
    245241        self.graph.xaxis(self.xaxis_label, self.xaxis_unit) 
     
    247243        self.yaxis_unit = '10^{-6}A^{-2}' 
    248244        self.graph.yaxis(self.yaxis_label, self.yaxis_unit) 
    249         #self.subplot.figure.canvas.draw_idle() 
    250         # For latter scale changes  
    251         self.plots[plot.id].xaxis('\\rm{%s} '% x1_label, 'A') 
     245        # For latter scale changes 
     246        self.plots[plot.id].xaxis('\\rm{%s} ' % x1_label, 'A') 
    252247        self.plots[plot.id].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}') 
    253         #draw 
    254         #self.graph.render(self) 
    255          
     248 
    256249    def on_set_focus(self, event): 
    257250        """ 
    258251        send to the parenet the current panel on focus 
    259          
     252 
    260253        """ 
    261254        #Not implemented 
     
    265258        """ 
    266259        reset the panel color 
    267          
     260 
    268261        """ 
    269262        #Not implemented 
    270263        pass 
    271      
     264 
    272265    def onChangeCaption(self, event): 
    273266        """ 
     
    275268        """ 
    276269        pass 
    277                             
     270 
    278271    def _onSave(self, evt): 
    279272        """ 
    280273        Save a data set to a text file 
    281          
     274 
    282275        :param evt: Menu event 
    283          
     276 
    284277        """ 
    285278        menu = evt.GetEventObject() 
    286         id = evt.GetId() 
    287         self.set_selected_from_menu(menu, id) 
     279        event_id = evt.GetId() 
     280        self.set_selected_from_menu(menu, event_id) 
    288281        data = self.plots[self.graph.selected_plottable] 
    289282        default_name = data.label 
     
    295288            fit_panel = self.parent.parent.parent 
    296289            fit_panel._manager.parent.save_data1d(data, default_name) 
    297               
     290 
    298291class ViewerFrame(wx.Frame): 
    299292    """ 
     
    306299        """ 
    307300        # Initialize the Frame object 
    308         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition,  
     301        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 
    309302                          wx.Size(_STATICBOX_WIDTH, PANEL_SIZE)) 
    310303        # Panel for 1D plot 
    311         self.plotpanel    = SLDplotpanel(self, -1, style=wx.RAISED_BORDER) 
     304        self.plotpanel = SLDplotpanel(self, -1, style=wx.RAISED_BORDER) 
    312305 
    313306class ViewApp(wx.App): 
    314307    def OnInit(self): 
    315         frame = ViewerFrame(None, -1, 'testView')     
     308        frame = ViewerFrame(None, -1, 'testView') 
    316309        frame.Show(True) 
    317310        self.SetTopWindow(frame) 
    318          
     311 
    319312        return True 
    320                 
    321 if __name__ == "__main__":  
     313 
     314if __name__ == "__main__": 
    322315    app = ViewApp(0) 
    323     app.MainLoop()      
     316    app.MainLoop() 
  • src/sas/guiframe/local_perspectives/plotting/sector_mask.py

    r79492222 rc039589  
    1  
     1""" 
     2    Sector mask interactor 
     3""" 
    24import math 
    35import wx 
     
    1820        ## Class initialization 
    1921        self.markers = [] 
    20         self.axes = axes    
     22        self.axes = axes 
    2123        self.is_inside = side 
    22         ## connect the plot to event  
     24        ## connect the plot to event 
    2325        self.connect = self.base.connect 
    24          
    25         ## compute qmax limit to reset the graph      
    26         x = math.pow(max(self.base.data.xmax,  
     26 
     27        ## compute qmax limit to reset the graph 
     28        x = math.pow(max(self.base.data.xmax, 
    2729                         math.fabs(self.base.data.xmin)), 2) 
    28         y = math.pow(max(self.base.data.ymax,  
     30        y = math.pow(max(self.base.data.ymax, 
    2931                         math.fabs(self.base.data.ymin)), 2) 
    3032        self.qmax = math.sqrt(x + y) 
     
    3234        self.nbins = 20 
    3335        ## Angle of the middle line 
    34         self.theta2 = math.pi/3 
     36        self.theta2 = math.pi / 3 
    3537        ## Absolute value of the Angle between the middle line and any side line 
    36         self.phi = math.pi/12 
    37          
     38        self.phi = math.pi / 12 
     39 
    3840        ## Middle line 
    3941        self.main_line = LineInteractor(self, self.base.subplot, color='blue', 
    40                                 zorder=zorder, r=self.qmax, theta=self.theta2) 
     42                                        zorder=zorder, r=self.qmax, theta=self.theta2) 
    4143        self.main_line.qmax = self.qmax 
    4244        ## Right Side line 
    4345        self.right_line = SideInteractor(self, self.base.subplot, color='gray', 
    44                             zorder=zorder, r=self.qmax, phi= -1*self.phi, 
    45                                                             theta2=self.theta2) 
     46                                         zorder=zorder, r=self.qmax, phi=-1 * self.phi, 
     47                                         theta2=self.theta2) 
    4648        self.right_line.qmax = self.qmax 
    47         ## Left Side line  
    48         self.left_line = SideInteractor(self, self.base.subplot, color='gray',  
    49                                     zorder=zorder, r=self.qmax, phi= self.phi, 
    50                                                         theta2=self.theta2) 
     49        ## Left Side line 
     50        self.left_line = SideInteractor(self, self.base.subplot, color='gray', 
     51                                        zorder=zorder, r=self.qmax, phi=self.phi, 
     52                                        theta2=self.theta2) 
    5153        self.left_line.qmax = self.qmax 
    52         ## draw the sector                
     54        ## draw the sector 
    5355        self.update() 
    5456        self._post_data() 
    55          
     57 
    5658    def clear(self): 
    5759        """ 
     
    6365        self.right_line.clear() 
    6466        self.base.connect.clearall() 
    65         #self.base.Unbind(EVT_SLICER_PARS) 
    66          
     67 
    6768    def update(self): 
    6869        """ 
     
    7071        resetting the widgets. 
    7172        """ 
    72         # Update locations   
    73         ## Check if the middle line was dragged and  
    74         #update the picture accordingly      
     73        # Update locations 
     74        ## Check if the middle line was dragged and 
     75        #update the picture accordingly 
    7576        if self.main_line.has_move: 
    7677            self.main_line.update() 
    77             self.right_line.update(delta=-self.left_line.phi/2, 
    78                                     mline=self.main_line.theta) 
    79             self.left_line.update(delta=self.left_line.phi/2, 
     78            self.right_line.update(delta=-self.left_line.phi / 2, 
    8079                                   mline=self.main_line.theta) 
    81         ## Check if the left side has moved and update the slicer accordingly   
     80            self.left_line.update(delta=self.left_line.phi / 2, 
     81                                  mline=self.main_line.theta) 
     82        ## Check if the left side has moved and update the slicer accordingly 
    8283        if self.left_line.has_move: 
    8384            self.main_line.update() 
    84             self.left_line.update(phi=None, delta=None, mline=self.main_line , 
    85                                   side=True, left=True ) 
     85            self.left_line.update(phi=None, delta=None, mline=self.main_line, 
     86                                  side=True, left=True) 
    8687            self.right_line.update(phi=self.left_line.phi, delta=None, 
    87                                      mline=self.main_line, side=True, 
    88                                      left=False, right=True) 
    89         ## Check if the right side line has moved and  
     88                                   mline=self.main_line, side=True, 
     89                                   left=False, right=True) 
     90        ## Check if the right side line has moved and 
    9091        #update the slicer accordingly 
    9192        if self.right_line.has_move: 
     
    9495                                   side=True, left=False, right=True) 
    9596            self.left_line.update(phi=self.right_line.phi, delta=None, 
    96                                     mline=self.main_line, side=True, left=False) 
     97                                  mline=self.main_line, side=True, left=False) 
    9798        #if self.is_inside != None: 
    9899        out = self._post_data() 
     
    118119        if data == None: 
    119120            return 
    120  
    121         mask = data.mask 
    122121        ## Averaging 
    123122        from sas.dataloader.manipulations import Sectorcut 
    124         radius = self.qmax  
    125         phimin =  -self.left_line.phi + self.main_line.theta 
     123        phimin = -self.left_line.phi + self.main_line.theta 
    126124        phimax = self.left_line.phi + self.main_line.theta 
    127           
     125 
    128126        mask = Sectorcut(phi_min=phimin, phi_max=phimax) 
    129127        if self.is_inside: 
     
    131129        else: 
    132130            out = (mask(data)) 
    133         #self.base.data.mask=out 
    134         return out        
     131        return out 
    135132 
    136133    def moveend(self, ev): 
    137134        """ 
    138         Called a dragging motion ends.Get slicer event  
     135        Called a dragging motion ends.Get slicer event 
    139136        """ 
    140137        self.base.thaw_axes() 
     
    146143        wx.PostEvent(self.base, event) 
    147144        self._post_data() 
    148              
     145 
    149146    def restore(self): 
    150147        """ 
     
    160157        """ 
    161158        pass 
    162          
     159 
    163160    def set_cursor(self, x, y): 
    164161        pass 
    165          
     162 
    166163    def get_params(self): 
    167164        """ 
    168165        Store a copy of values of parameters of the slicer into a dictionary. 
    169          
     166 
    170167        :return params: the dictionary created 
    171          
     168 
    172169        """ 
    173170        params = {} 
    174         ## Always make sure that the left and the right line are at phi  
     171        ## Always make sure that the left and the right line are at phi 
    175172        ## angle of the middle line 
    176173        if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 
    177174            msg = "Phi left and phi right are " 
    178             msg += "different %f, %f" % (self.left_line.phi,  
     175            msg += "different %f, %f" % (self.left_line.phi, 
    179176                                         self.right_line.phi) 
    180177            raise ValueError, msg 
     
    182179        params["Delta_Phi"] = math.fabs(self.left_line.phi) 
    183180        return params 
    184      
     181 
    185182    def set_params(self, params): 
    186183        """ 
    187         Receive a dictionary and reset the slicer with values contained  
     184        Receive a dictionary and reset the slicer with values contained 
    188185        in the values of the dictionary. 
    189          
    190         :param params: a dictionary containing name of slicer parameters and  
     186 
     187        :param params: a dictionary containing name of slicer parameters and 
    191188            values the user assigned to the slicer. 
    192189        """ 
    193         main = params["Phi"]  
     190        main = params["Phi"] 
    194191        phi = math.fabs(params["Delta_Phi"]) 
    195          
     192 
    196193        self.main_line.theta = main 
    197194        ## Reset the slicer parameters 
     
    203200        ## post the new corresponding data 
    204201        self._post_data() 
    205          
     202 
    206203    def freeze_axes(self): 
    207204        """ 
    208205        """ 
    209206        self.base.freeze_axes() 
    210          
     207 
    211208    def thaw_axes(self): 
    212209        """ 
     
    218215        """ 
    219216        self.base.update() 
    220          
Note: See TracChangeset for help on using the changeset viewer.