Ignore:
Timestamp:
Nov 23, 2010 11:21:20 AM (14 years ago)
Author:
Gervaise Alina <gervyh@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
a54e4be
Parents:
4a2b054
Message:

working on pylint

Location:
guiframe/local_perspectives/plotting
Files:
18 edited

Legend:

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

    r83f4445 r32c0841  
    88import math 
    99import wx 
    10 from copy import deepcopy  
     10#from copy import deepcopy  
    1111# Debug printout 
    12 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
     12from sans.guicomm.events import NewPlotEvent 
     13from sans.guicomm.events import StatusEvent 
     14from sans.guicomm.events import SlicerParameterEvent 
     15from sans.guicomm.events import EVT_SLICER_PARS 
    1316from BaseInteractor import _BaseInteractor 
    1417from sans.guiframe.dataFitting import Data1D 
     
    2124    this class is defined by 2 Ringinterators. 
    2225    """ 
    23     def __init__(self,base,axes,color='black', zorder=3): 
     26    def __init__(self, base, axes, color='black', zorder=3): 
    2427         
    2528        _BaseInteractor.__init__(self, base, axes, color=color) 
    2629        self.markers = [] 
    2730        self.axes = axes 
    28         self.base= base 
    29         self.qmax = min(math.fabs(self.base.data2D.xmax),math.fabs(self.base.data2D.xmin))  #must be positive 
     31        self.base = base 
     32        self.qmax = min(math.fabs(self.base.data2D.xmax), 
     33                        math.fabs(self.base.data2D.xmin))  #must be positive 
    3034        self.connect = self.base.connect 
    3135     
    3236        ## Number of points on the plot 
    3337        self.nbins = 20 
    34          
    3538        #Cursor position of Rings (Left(-1) or Right(1)) 
    36         self.xmaxd=self.base.data2D.xmax 
    37         self.xmind=self.base.data2D.xmin 
    38  
    39         if (self.xmaxd+self.xmind)>0: 
    40             self.sign=1 
     39        self.xmaxd = self.base.data2D.xmax 
     40        self.xmind = self.base.data2D.xmin 
     41 
     42        if (self.xmaxd + self.xmind) > 0: 
     43            self.sign = 1 
    4144        else: 
    42             self.sign=-1 
    43                   
     45            self.sign = -1 
    4446        # Inner circle 
    45         self.inner_circle = RingInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0,sign=self.sign) 
     47        self.inner_circle = RingInteractor(self, self.base.subplot, 
     48                                            zorder=zorder, 
     49                                            r=self.qmax/2.0, sign=self.sign) 
    4650        self.inner_circle.qmax = self.qmax 
    47         self.outer_circle = RingInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8,sign=self.sign) 
    48         self.outer_circle.qmax = self.qmax*1.2 
    49         
     51        self.outer_circle = RingInteractor(self, self.base.subplot, 
     52                                           zorder=zorder+1, r=self.qmax/1.8, 
     53                                           sign=self.sign) 
     54        self.outer_circle.qmax = self.qmax * 1.2 
    5055        self.update() 
    5156        self._post_data() 
     
    6267             
    6368        """ 
    64         wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 
     69        wx.PostEvent(self.base, 
     70                     StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 
    6571        event.Skip() 
    6672        if event.type == self.__class__.__name__: 
     
    106112        self.outer_circle.save(ev) 
    107113 
    108     def _post_data(self,nbins=None): 
     114    def _post_data(self, nbins=None): 
    109115        """ 
    110116        Uses annulus parameters to plot averaged data into 1D data. 
     
    120126         
    121127        from DataLoader.manipulations import Ring 
    122      
    123         rmin= min(math.fabs(self.inner_circle.get_radius()), 
     128        rmin = min(math.fabs(self.inner_circle.get_radius()), 
    124129                  math.fabs(self.outer_circle.get_radius())) 
    125130        rmax = max(math.fabs(self.inner_circle.get_radius()), 
     
    127132        #if the user does not specify the numbers of points to plot  
    128133        # the default number will be nbins= 20 
    129         if nbins==None: 
    130             self.nbins= 20 
     134        if nbins == None: 
     135            self.nbins = 20 
    131136        else: 
    132137            self.nbins = nbins 
    133138        ## create the data1D Q average of data2D     
    134         sect = Ring(r_min=rmin , r_max= rmax, nbins=self.nbins) 
     139        sect = Ring(r_min=rmin, r_max=rmax, nbins=self.nbins) 
    135140        sector = sect(self.base.data2D) 
    136          
    137          
    138         if hasattr(sector,"dxl"): 
    139             dxl= sector.dxl 
     141     
     142        if hasattr(sector, "dxl"): 
     143            dxl = sector.dxl 
    140144        else: 
    141             dxl= None 
    142         if hasattr(sector,"dxw"): 
    143             dxw= sector.dxw 
     145            dxl = None 
     146        if hasattr(sector, "dxw"): 
     147            dxw = sector.dxw 
    144148        else: 
    145             dxw= None 
    146         
    147         new_plot = Data1D(x=(sector.x-math.pi)*180/math.pi,y=sector.y,dy=sector.dy) 
     149            dxw = None 
     150        new_plot = Data1D(x=(sector.x - math.pi) * 180/math.pi, 
     151                          y=sector.y, dy=sector.dy) 
    148152        new_plot.dxl = dxl 
    149153        new_plot.dxw = dxw 
    150154        new_plot.name = "AnnulusPhi" +"("+ self.base.data2D.name+")" 
    151155         
    152         new_plot.source=self.base.data2D.source 
     156        new_plot.source = self.base.data2D.source 
    153157        #new_plot.info=self.base.data2D.info 
    154          
    155158        new_plot.interactive = True 
    156         new_plot.detector =self.base.data2D.detector 
     159        new_plot.detector = self.base.data2D.detector 
    157160        # If the data file does not tell us what the axes are, just assume... 
    158161        new_plot.xaxis("\\rm{\phi}", 'degrees') 
    159         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    160         new_plot.group_id = "AnnulusPhi"+self.base.data2D.name 
    161         new_plot.id= "AnnulusPhi"+self.base.data2D.name 
     162        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     163        new_plot.group_id = "AnnulusPhi" + self.base.data2D.name 
     164        new_plot.id = "AnnulusPhi" + self.base.data2D.name 
    162165        #new_plot.is_data= True 
    163          
    164         new_plot.xtransform="x" 
    165         new_plot.ytransform="y" 
     166        new_plot.xtransform = "x" 
     167        new_plot.ytransform = "y" 
    166168        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    167                                                  title="AnnulusPhi" )) 
     169                                                 title="AnnulusPhi")) 
    168170         
    169171    def moveend(self, ev): 
     
    221223             
    222224        """ 
    223         inner = math.fabs(params["inner_radius"] ) 
    224         outer = math.fabs(params["outer_radius"] ) 
     225        inner = math.fabs(params["inner_radius"]) 
     226        outer = math.fabs(params["outer_radius"]) 
    225227        self.nbins = int(params["nbins"]) 
    226228        ## Update the picture 
     
    250252     Draw a ring Given a radius  
    251253    """ 
    252     def __init__(self,base,axes,color='black', zorder=5, r=1.0,sign=1): 
     254    def __init__(self, base, axes, color='black', zorder=5, r=1.0, sign=1): 
    253255        """ 
    254256        :param: the color of the line that defined the ring 
     
    269271        self._inner_save_y  = 0 
    270272        #Class instantiating RingIterator class 
    271         self.base= base 
     273        self.base = base 
    272274        #the direction of the motion of the marker 
    273         self.sign=sign 
     275        self.sign = sign 
    274276        ## Create a marker  
    275277        try: 
    276278            # Inner circle marker 
    277             self.inner_marker = self.axes.plot([self.sign*math.fabs(self._inner_mouse_x)],[0], linestyle='', 
     279            x_value = [self.sign * math.fabs(self._inner_mouse_x)] 
     280            self.inner_marker = self.axes.plot(x_value, 
     281                                               [0], 
     282                                                linestyle='', 
    278283                                          marker='s', markersize=10, 
    279284                                          color=self.color, alpha=0.6, 
    280285                                          pickradius=5, label="pick",  
    281                                           zorder=zorder, # Prefer this to other lines 
     286                                          zorder=zorder, 
    282287                                          visible=True)[0] 
    283288        except: 
    284             self.inner_marker = self.axes.plot([self.sign*math.fabs(self._inner_mouse_x)],[0], linestyle='', 
     289            x_value = [self.sign * math.fabs(self._inner_mouse_x)] 
     290            self.inner_marker = self.axes.plot(x_value, 
     291                                               [0],  
     292                                               linestyle='', 
    285293                                          marker='s', markersize=10, 
    286294                                          color=self.color, alpha=0.6, 
    287295                                          label="pick",  
    288296                                          visible=True)[0] 
    289             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    290             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    291              
    292             owner=self.base.base.parent 
    293             wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     297            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST" 
     298            message += " VERSION OF MATPLOTLIB\n" 
     299            message += "Get the SVN version that is at " 
     300            message += " least as recent as June 1, 2007" 
     301             
     302            owner = self.base.base.parent 
     303            wx.PostEvent(owner,  
     304                         StatusEvent(status="AnnulusSlicer: %s" % message)) 
    294305             
    295306        # Draw a circle  
    296         [self.inner_circle] = self.axes.plot([],[], 
     307        [self.inner_circle] = self.axes.plot([], [], 
    297308                                      linestyle='-', marker='', 
    298309                                      color=self.color) 
     
    340351        y = [] 
    341352        for i in range(self.npts): 
    342             phi = 2.0*math.pi/(self.npts-1)*i 
    343              
    344             xval = 1.0*self._inner_mouse_x*math.cos(phi)  
    345             yval = 1.0*self._inner_mouse_x*math.sin(phi)  
     353            phi = 2.0 * math.pi / (self.npts - 1) * i 
     354             
     355            xval = 1.0 * self._inner_mouse_x * math.cos(phi)  
     356            yval = 1.0 * self._inner_mouse_x * math.sin(phi)  
    346357             
    347358            x.append(xval) 
    348359            y.append(yval) 
    349360             
    350         self.inner_marker.set(xdata=[self.sign*math.fabs(self._inner_mouse_x)],ydata=[0]) 
     361        self.inner_marker.set(xdata=[self.sign*math.fabs(self._inner_mouse_x)], 
     362                              ydata=[0]) 
    351363        self.inner_circle.set_data(x, y)         
    352364 
     
    416428     Draw a ring Given a radius  
    417429    """ 
    418     def __init__(self,base,axes,color='grey', zorder=3, side=None): 
     430    def __init__(self, base, axes, color='grey', zorder=3, side=None): 
    419431        """ 
    420432         
     
    427439        self.markers = [] 
    428440        self.axes = axes 
    429         self.base= base 
     441        self.base = base 
    430442        self.is_inside = side 
    431         self.qmax = min(math.fabs(self.base.data.xmax),math.fabs(self.base.data.xmin))  #must be positive 
     443        self.qmax = min(math.fabs(self.base.data.xmax), 
     444                        math.fabs(self.base.data.xmin))  #must be positive 
    432445        self.connect = self.base.connect 
    433446         
    434447        #Cursor position of Rings (Left(-1) or Right(1)) 
    435         self.xmaxd=self.base.data.xmax 
    436         self.xmind=self.base.data.xmin 
    437  
    438         if (self.xmaxd+self.xmind)>0: 
    439             self.sign=1 
     448        self.xmaxd = self.base.data.xmax 
     449        self.xmind = self.base.data.xmin 
     450 
     451        if (self.xmaxd + self.xmind) > 0: 
     452            self.sign = 1 
    440453        else: 
    441             self.sign=-1 
    442                   
     454            self.sign = -1 
    443455        # Inner circle 
    444         self.outer_circle = RingInteractor(self, self.base.subplot, 'blue', zorder=zorder+1, r=self.qmax/1.8,sign=self.sign) 
    445         self.outer_circle.qmax = self.qmax*1.2 
    446         
     456        self.outer_circle = RingInteractor(self, self.base.subplot, 'blue', 
     457                                            zorder=zorder+1, r=self.qmax/1.8, 
     458                                            sign=self.sign) 
     459        self.outer_circle.qmax = self.qmax * 1.2 
    447460        self.update() 
    448461        self._post_data() 
     
    458471            attribute 
    459472        """ 
    460         wx.PostEvent(self.base, StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 
     473        wx.PostEvent(self.base, 
     474                     StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 
    461475        event.Skip() 
    462476        if event.type == self.__class__.__name__: 
     
    518532        from DataLoader.manipulations import Ringcut 
    519533     
    520         rmin= 0 
     534        rmin = 0 
    521535        rmax = math.fabs(self.outer_circle.get_radius()) 
    522536 
    523537        ## create the data1D Q average of data2D     
    524         mask = Ringcut(r_min=rmin , r_max= rmax) 
     538        mask = Ringcut(r_min=rmin, r_max= rmax) 
    525539 
    526540        if self.is_inside: 
    527             out = (mask(data)==False) 
     541            out = (mask(data) == False) 
    528542        else: 
    529543            out = (mask(data)) 
  • guiframe/local_perspectives/plotting/Arc.py

    r83f4445 r32c0841  
    55 
    66from BaseInteractor import _BaseInteractor 
    7 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
     7from sans.guicomm.events import NewPlotEvent 
     8from sans.guicomm.events import StatusEvent 
     9from sans.guicomm.events import SlicerParameterEvent 
     10from sans.guicomm.events import EVT_SLICER_PARS 
    811   
    912  
     
    1215    Select an annulus through a 2D plot 
    1316    """ 
    14     def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta1=math.pi/8, 
    15                  theta2=math.pi/4): 
     17    def __init__(self, base, axes, color='black', zorder=5, r=1.0,  
     18                 theta1=math.pi/8, theta2=math.pi/4): 
    1619         
    1720        _BaseInteractor.__init__(self, base, axes, color=color) 
     
    2629        self.scale = 10.0 
    2730         
    28         self.theta1=theta1 
    29         self.theta2=theta2 
    30         self.radius= r 
    31         [self.arc] = self.axes.plot([],[], 
     31        self.theta1 = theta1 
     32        self.theta2 = theta2 
     33        self.radius = r 
     34        [self.arc] = self.axes.plot([], [], 
    3235                                      linestyle='-', marker='', 
    3336                                      color=self.color) 
    3437        self.npts = 20 
    35         self.has_move= False     
     38        self.has_move = False     
    3639        self.connect_markers([self.arc]) 
    3740        self.update() 
     
    5861        """ 
    5962        """ 
    60         radius =math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2)) 
     63        radius = math.sqrt(math.pow(self._mouse_x, 2) + \ 
     64                           math.pow(self._mouse_y, 2)) 
    6165        return radius 
    6266         
    63     def update(self,theta1=None,theta2=None, nbins=None, r=None): 
     67    def update(self, theta1=None, theta2=None, nbins=None, r=None): 
    6468        """ 
    6569        """ 
     
    6771        x = [] 
    6872        y = [] 
    69         if theta1 !=None: 
    70             self.theta1= theta1 
    71         if theta2 !=None: 
    72             self.theta2= theta2 
    73          
    74         print "ring update theta1 theta2", math.degrees(self.theta1), math.degrees(self.theta2) 
    75         while self.theta2 < self.theta1: self.theta2 += 2*math.pi 
    76         while self.theta2 >= self.theta1+2*math.pi: self.theta2 -= 2*math.pi 
    77  
     73        if theta1 != None: 
     74            self.theta1 = theta1 
     75        if theta2 != None: 
     76            self.theta2 = theta2 
     77        #print "ring update theta1 theta2", math.degrees(self.theta1),  
     78        #math.degrees(self.theta2) 
     79        while self.theta2 < self.theta1: 
     80            self.theta2 += (2 * math.pi) 
     81        while self.theta2 >= (self.theta1 + 2 * math.pi): 
     82            self.theta2 -= (2 * math.pi) 
    7883        npts = int((self.theta2 - self.theta1)/(math.pi/120))   
    7984              
    80         if r ==None: 
    81             self.radius=  math.sqrt(math.pow(self._mouse_x, 2)+math.pow(self._mouse_y, 2)) 
     85        if r == None: 
     86            self.radius =  math.sqrt(math.pow(self._mouse_x, 2) + \ 
     87                                     math.pow(self._mouse_y, 2)) 
    8288        else: 
    83             self.radius= r 
    84              
     89            self.radius = r 
    8590        for i in range(self.npts): 
    86              
    87             phi =(self.theta2-self.theta1)/(self.npts-1)*i +self.theta1 
    88              
    89             xval = 1.0*self.radius*math.cos(phi)  
    90             yval = 1.0*self.radius*math.sin(phi)  
     91            phi = (self.theta2 - self.theta1)/(self.npts - 1) * i + self.theta1 
     92            xval = 1.0 * self.radius * math.cos(phi)  
     93            yval = 1.0 * self.radius * math.sin(phi)  
    9194             
    9295            x.append(xval) 
    9396            y.append(yval) 
    94          
    9597        #self.marker.set(xdata=[self._mouse_x],ydata=[0]) 
    9698        self.arc.set_data(x, y)  
    9799         
    98        
    99100    def save(self, ev): 
    100101        """ 
     
    106107        #self._save_x = ev.xdata 
    107108        #self._save_y = ev.ydata 
    108          
    109109        self.base.freeze_axes() 
    110110 
     
    112112        """ 
    113113        """ 
    114         self.has_move= False 
     114        self.has_move = False 
    115115         
    116116        event = SlicerParameterEvent() 
    117117        event.type = self.__class__.__name__ 
    118118        event.params = self.get_params() 
    119         print "in arc moveend params",self.get_params() 
     119        #print "in arc moveend params",self.get_params() 
    120120        #wx.PostEvent(self.base.base.parent, event) 
    121          
    122121        self.base.moveend(ev) 
    123122             
     
    136135        self._mouse_x = x 
    137136        self._mouse_y = y 
    138         self.has_move= True 
     137        self.has_move = True 
    139138        self.base.base.update() 
    140139         
    141     def set_cursor(self,radius, phi_min, phi_max,nbins): 
     140    def set_cursor(self, radius, phi_min, phi_max, nbins): 
    142141        """ 
    143142        """ 
    144         self.theta1= phi_min 
    145         self.theta2= phi_max 
     143        self.theta1 = phi_min 
     144        self.theta2 = phi_max 
    146145        self.update(nbins=nbins, r=radius) 
    147          
    148          
     146 
    149147    def get_params(self): 
    150148        """ 
  • guiframe/local_perspectives/plotting/AzimutSlicer.py

    r83f4445 r32c0841  
    1111import wx 
    1212from copy import deepcopy 
    13  
    1413from BaseInteractor import _BaseInteractor 
    15 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
    16  
     14from sans.guicomm.events import NewPlotEvent 
     15from sans.guicomm.events import StatusEvent 
     16from sans.guicomm.events import SlicerParameterEvent 
     17from sans.guicomm.events import EVT_SLICER_PARS 
    1718 
    1819 
     
    2122    Select an annulus through a 2D plot 
    2223    """ 
    23     def __init__(self,base,axes,color='black', zorder=3): 
     24    def __init__(self, base, axes, color='black', zorder=3): 
    2425        """ 
    2526        """ 
     
    3233        ## Number of points on the plot 
    3334        self.nbins = 20 
    34         theta1=math.pi/8 
    35         theta2=math.pi/2 
    36         theta1=2*math.pi/3 
    37         theta2=-2*math.pi/3 
    38         r1=self.qmax/2.0 
    39         r2=self.qmax/1.8 
     35        theta1 = math.pi/8 
     36        theta2 = math.pi/2 
     37        theta1 = 2 * math.pi/3 
     38        theta2 = -2 * math.pi/3 
     39        r1 = self.qmax/2.0 
     40        r2 = self.qmax/1.8 
    4041        
    4142        # Inner circle 
    4243        from Arc import ArcInteractor 
    43         self.inner_circle = ArcInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0,theta1= theta1, 
     44        self.inner_circle = ArcInteractor(self, self.base.subplot, 
     45                                           zorder=zorder, 
     46                                           r=self.qmax/2.0, 
     47                                           theta1=theta1, 
    4448                                           theta2=theta2) 
    4549        self.inner_circle.qmax = self.qmax 
    46         self.outer_circle = ArcInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8,theta1= theta1, 
     50        self.outer_circle = ArcInteractor(self, self.base.subplot, 
     51                                          zorder=zorder+1, 
     52                                          r=self.qmax/1.8, 
     53                                          theta1=theta1, 
    4754                                           theta2=theta2) 
    48         self.outer_circle.qmax = self.qmax*1.2 
     55        self.outer_circle.qmax = self.qmax * 1.2 
    4956        #self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 
    5057        from Edge import RadiusInteractor 
    51         self.right_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 
     58        self.right_edge= RadiusInteractor(self, self.base.subplot, 
     59                                          zorder=zorder+1, 
    5260                                             arc1=self.inner_circle, 
    5361                                             arc2=self.outer_circle, 
    5462                                            theta=theta1) 
    55         self.left_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 
     63        self.left_edge= RadiusInteractor(self, self.base.subplot, 
     64                                         zorder=zorder+1, 
    5665                                             arc1=self.inner_circle, 
    5766                                             arc2=self.outer_circle, 
     
    7584        """ 
    7685        output = open(path, 'w') 
    77          
    7886        data_x, data_y = self.get_data(image, x, y) 
    7987         
     
    109117            #print "inner circle has moved"  
    110118            self.inner_circle.update() 
    111             r1=self.inner_circle.get_radius() 
    112             r2=self.outer_circle.get_radius() 
    113             self.right_edge.update(r1,r2) 
    114             self.left_edge.update(r1,r2) 
     119            r1 = self.inner_circle.get_radius() 
     120            r2 = self.outer_circle.get_radius() 
     121            self.right_edge.update(r1, r2) 
     122            self.left_edge.update(r1, r2) 
    115123        if self.outer_circle.has_move:     
    116124            #print "outer circle has moved"  
    117125            self.outer_circle.update() 
    118             r1=self.inner_circle.get_radius() 
    119             r2=self.outer_circle.get_radius() 
    120             self.left_edge.update(r1,r2) 
    121             self.right_edge.update(r1,r2) 
     126            r1 = self.inner_circle.get_radius() 
     127            r2 = self.outer_circle.get_radius() 
     128            self.left_edge.update(r1, r2) 
     129            self.right_edge.update(r1, r2) 
    122130        if self.right_edge.has_move: 
    123131            #print "right edge has moved" 
    124132            self.right_edge.update() 
    125             self.inner_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 
    126             self.outer_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 
     133            self.inner_circle.update(theta1=self.right_edge.get_angle(), 
     134                                     theta2=None) 
     135            self.outer_circle.update(theta1=self.right_edge.get_angle(), 
     136                                     theta2=None) 
    127137        if  self.left_edge.has_move: 
    128138            #print "left Edge has moved" 
    129139            self.left_edge.update() 
    130             self.inner_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 
    131             self.outer_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 
     140            self.inner_circle.update(theta1=None, 
     141                                     theta2=self.left_edge.get_angle()) 
     142            self.outer_circle.update(theta1=None, 
     143                                     theta2=self.left_edge.get_angle()) 
    132144              
    133          
    134145    def save(self, ev): 
    135146        """ 
     
    149160        """ post data averaging in Q""" 
    150161        if self.inner_circle.get_radius() < self.outer_circle.get_radius(): 
    151             rmin=self.inner_circle.get_radius() 
    152             rmax=self.outer_circle.get_radius() 
     162            rmin = self.inner_circle.get_radius() 
     163            rmax = self.outer_circle.get_radius() 
    153164        else: 
    154             rmin=self.outer_circle.get_radius() 
    155             rmax=self.inner_circle.get_radius() 
     165            rmin = self.outer_circle.get_radius() 
     166            rmax = self.inner_circle.get_radius() 
    156167        if self.right_edge.get_angle() < self.left_edge.get_angle(): 
    157             phimin=self.right_edge.get_angle() 
    158             phimax=self.left_edge.get_angle() 
     168            phimin = self.right_edge.get_angle() 
     169            phimax = self.left_edge.get_angle() 
    159170        else: 
    160             phimin=self.left_edge.get_angle() 
    161             phimax=self.right_edge.get_angle() 
    162              
    163         #print "phimin, phimax, rmin ,rmax",math.degrees(phimin), math.degrees(phimax), rmin ,rmax 
     171            phimin = self.left_edge.get_angle() 
     172            phimax = self.right_edge.get_angle()    
     173        #print "phimin, phimax, rmin ,rmax",math.degrees(phimin), 
     174        # math.degrees(phimax), rmin ,rmax 
    164175        #from DataLoader.manipulations import SectorQ 
    165176         
    166         sect = new_sector(r_min=rmin, r_max=rmax, phi_min=phimin, phi_max=phimax) 
     177        sect = new_sector(r_min=rmin, r_max=rmax, 
     178                          phi_min=phimin, phi_max=phimax) 
    167179        sector = sect(self.base.data2D) 
    168180         
    169181        from sans.guiframe.dataFitting import Data1D 
    170         if hasattr(sector,"dxl"): 
    171             dxl= sector.dxl 
     182        if hasattr(sector, "dxl"): 
     183            dxl = sector.dxl 
    172184        else: 
    173             dxl= None 
    174         if hasattr(sector,"dxw"): 
    175             dxw= sector.dxw 
     185            dxl = None 
     186        if hasattr(sector, "dxw"): 
     187            dxw = sector.dxw 
    176188        else: 
    177             dxw= None 
    178         
    179         new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy,dxl=dxl,dxw=dxw) 
    180         new_plot.name = str(new_sector.__name__) +"("+ self.base.data2D.name+")" 
    181          
    182         
    183  
    184         new_plot.source=self.base.data2D.source 
     189            dxw = None 
     190        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy, 
     191                          dxl=dxl, dxw=dxw) 
     192        new_plot.name = str(new_sector.__name__) + \ 
     193                        "("+ self.base.data2D.name+")" 
     194        new_plot.source = self.base.data2D.source 
    185195        new_plot.interactive = True 
    186196        #print "loader output.detector",output.source 
    187         new_plot.detector =self.base.data2D.detector 
     197        new_plot.detector = self.base.data2D.detector 
    188198        # If the data file does not tell us what the axes are, just assume... 
    189199        new_plot.xaxis("\\rm{Q}", 'rad') 
    190         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    191         new_plot.group_id = str(new_sector.__name__)+self.base.data2D.name 
    192         wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    193                                                  title=str(new_sector.__name__) )) 
    194          
     200        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     201        new_plot.group_id = str(new_sector.__name__) + self.base.data2D.name 
     202        wx.PostEvent(self.base.parent, 
     203                    NewPlotEvent(plot=new_plot, title=str(new_sector.__name__))) 
    195204         
    196205    def moveend(self, ev): 
    197206        #self.base.thaw_axes() 
    198207         
    199          # Post paramters 
     208        # Post paramters 
    200209        #event = SlicerParameterEvent() 
    201210        #event.type = self.__class__.__name__ 
     
    271280    """ 
    272281    """ 
    273     def __init__(self,base,axes,color='black', zorder=3): 
     282    def __init__(self, base, axes, color='black', zorder=3): 
    274283        """ 
    275284        """ 
     
    282291        """ 
    283292        from DataLoader.manipulations import SectorQ 
    284         self.post_data(SectorQ )    
     293        self.post_data(SectorQ)    
    285294         
    286295 
     
    288297    """ 
    289298    """ 
    290     def __init__(self,base,axes,color='black', zorder=3): 
     299    def __init__(self, base, axes, color='black', zorder=3): 
    291300        """ 
    292301        """ 
  • guiframe/local_perspectives/plotting/BaseInteractor.py

    r83f4445 r32c0841  
    4040         
    4141    """ 
    42     def __init__(self,base,axes,color='black'): 
     42    def __init__(self, base, axes, color='black'): 
    4343        """ 
    4444        """ 
     
    4646        self.axes = axes 
    4747        self.color = color 
     48        self.clickx = None 
     49        self.clicky = None 
     50        self.markers = [] 
    4851         
    4952    def clear_markers(self): 
     
    5255        """ 
    5356        for h in self.markers: h.remove() 
    54         if self.markers: self.base.connect.clear(*self.markers) 
     57        if self.markers: 
     58            self.base.connect.clear(*self.markers) 
    5559        self.markers = [] 
    5660 
     
    7579        pass 
    7680 
    77     def connect_markers(self,markers): 
     81    def connect_markers(self, markers): 
    7882        """ 
    7983        Connect markers to callbacks 
     
    111115        later restore(). 
    112116        """ 
    113         self.clickx,self.clicky = ev.xdata,ev.ydata 
     117        self.clickx, self.clicky = ev.xdata, ev.ydata 
    114118        self.save(ev) 
    115119        return True 
     
    126130        the mouse leaves the window. 
    127131        """ 
    128         inside,prop = self.axes.contains(ev) 
     132        inside, _ = self.axes.contains(ev) 
    129133        if inside: 
    130             self.clickx,self.clicky = ev.xdata,ev.ydata 
    131             self.move(ev.xdata,ev.ydata,ev) 
     134            self.clickx, self.clicky = ev.xdata, ev.ydata 
     135            self.move(ev.xdata, ev.ydata, ev) 
    132136        else: 
    133137            self.restore() 
     
    145149            self.restore() 
    146150        elif ev.key in ['up', 'down', 'right', 'left']: 
    147             dx,dy = self.dpixel(self.clickx,self.clicky,nudge=ev.control) 
    148             if ev.key == 'up': self.clicky += dy 
    149             elif ev.key == 'down': self.clicky -= dy 
    150             elif ev.key == 'right': self.clickx += dx 
     151            dx, dy = self.dpixel(self.clickx, self.clicky, nudge=ev.control) 
     152            if ev.key == 'up': 
     153                self.clicky += dy 
     154            elif ev.key == 'down': 
     155                self.clicky -= dy 
     156            elif ev.key == 'right': 
     157                self.clickx += dx 
    151158            else: self.clickx -= dx 
    152             self.move(self.clickx,self.clicky,ev) 
     159            self.move(self.clickx, self.clicky, ev) 
    153160        else: 
    154161            return False 
     
    156163        return True 
    157164 
    158     def dpixel(self,x,y,nudge=False): 
     165    def dpixel(self, x, y, nudge=False): 
    159166        """ 
    160167        Return the step size in data coordinates for a small 
     
    164171        """ 
    165172        ax = self.axes 
    166         px,py = ax.transData.inverse_xy_tup((x,y)) 
     173        px, py = ax.transData.inverse_xy_tup((x, y)) 
    167174        if nudge: 
    168             nx,ny = ax.transData.xy_tup((px+0.2,py+0.2)) 
     175            nx, ny = ax.transData.xy_tup((px+0.2, py+0.2)) 
    169176        else: 
    170             nx,ny = ax.transData.xy_tup((px+1.,py+1.)) 
    171         dx,dy = nx-x,ny-y 
    172         return dx,dy 
     177            nx, ny = ax.transData.xy_tup((px+1.0, py+1.0)) 
     178        dx, dy = nx-x, ny-y 
     179        return dx, dy 
    173180 
  • guiframe/local_perspectives/plotting/Edge.py

    rd955bf19 r32c0841  
    11 
    22import math 
    3 import wx   
    4 from copy import deepcopy 
    5  
     3#import wx   
     4#from copy import deepcopy 
    65from BaseInteractor import _BaseInteractor 
    7 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
     6#from sans.guicomm.events import NewPlotEvent 
     7#from sans.guicomm.events import StatusEvent 
     8#from sans.guicomm.events import SlicerParameterEvent 
     9#from sans.guicomm.events import EVT_SLICER_PARS 
    810    
    911 
    10  
    11         
    1212class RadiusInteractor(_BaseInteractor): 
    1313    """ 
    1414    Select an annulus through a 2D plot 
    1515    """ 
    16     def __init__(self,base,axes,color='black', zorder=5, arc1=None,arc2=None, 
    17                  theta=math.pi/8): 
    18          
     16    def __init__(self, base, axes, color='black', zorder=5, arc1=None, 
     17                 arc2=None, theta=math.pi/8): 
     18        """ 
     19        """ 
    1920        _BaseInteractor.__init__(self, base, axes, color=color) 
    2021        self.markers = [] 
    2122        self.axes = axes 
    22          
    2323        self.r1 = arc1.get_radius() 
    2424        self.r2 = arc2.get_radius() 
    2525        #print "radius init", self.r1, self.r2 
    26         self.theta=theta 
    27         self.save_theta= theta 
     26        self.theta = theta 
     27        self.save_theta = theta 
    2828        #self.scale = 10.0 
    29         self.move_stop=False 
    30         self.theta_left=None 
    31         self.theta_right=None 
    32         self.arc1= arc1 
    33         self.arc2=arc2 
     29        self.move_stop = False 
     30        self.theta_left = None 
     31        self.theta_right = None 
     32        self.arc1 = arc1 
     33        self.arc2 = arc2 
    3434        #raise "Version error", message 
    35         x1= self.r1*math.cos(self.theta) 
    36         y1= self.r1*math.sin(self.theta) 
    37         x2= self.r2*math.cos(self.theta) 
    38         y2= self.r2*math.sin(self.theta) 
    39         self.line = self.axes.plot([x1,x2],[y1,y2], 
     35        x1 = self.r1 * math.cos(self.theta) 
     36        y1 = self.r1 * math.sin(self.theta) 
     37        x2 = self.r2 * math.cos(self.theta) 
     38        y2 = self.r2 * math.sin(self.theta) 
     39        self.line = self.axes.plot([x1, x2], [y1, y2], 
    4040                                      linestyle='-', marker='', 
    4141                                      color=self.color, 
    4242                                      visible=True)[0] 
    43         self.phi= theta 
     43        self.phi = theta 
    4444        self.npts = 20 
    45         self.has_move= False 
     45        self.has_move = False 
    4646        self.connect_markers([self.line]) 
    4747        self.update() 
    48          
    4948         
    5049    def set_layer(self, n): 
     
    6059        try: 
    6160            self.line.remove() 
    62            
    6361        except: 
    6462            # Old version of matplotlib 
     
    7169        return self.theta 
    7270         
    73     def update(self,r1=None, r2=None, theta=None): 
     71    def update(self, r1=None, r2=None, theta=None): 
    7472        """ 
    7573        Draw the new roughness on the graph. 
     
    7977        if r2 != None: 
    8078            self.r2 = r2 
    81         if theta !=None: 
    82             self.theta= theta 
    83         
     79        if theta != None: 
     80            self.theta = theta 
    8481        #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) 
    85         x1= self.r1*math.cos(self.theta) 
    86         y1= self.r1*math.sin(self.theta) 
    87         x2= self.r2*math.cos(self.theta) 
    88         y2= self.r2*math.sin(self.theta)   
    89               
    90         self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 
     82        x1 = self.r1 * math.cos(self.theta) 
     83        y1 = self.r1 * math.sin(self.theta) 
     84        x2 = self.r2 * math.cos(self.theta) 
     85        y2 = self.r2 * math.sin(self.theta)   
     86        self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 
    9187         
    92   
    9388    def save(self, ev): 
    9489        """ 
     
    9691        can restore on Esc. 
    9792        """ 
    98         self.save_theta= math.atan2(ev.y,ev.x) 
     93        self.save_theta = math.atan2(ev.y,ev.x) 
    9994        #self.save_theta= self.theta 
    10095        self.base.freeze_axes() 
     
    10398        """ 
    10499        """ 
    105         self.has_move= False 
     100        self.has_move = False 
    106101        self.base.moveend(ev) 
    107102             
    108     def restore(self): 
     103    def restore(self, ev): 
    109104        """ 
    110105        Restore the roughness for this layer. 
     
    116111        Process move to a new position, making sure that the move is allowed. 
    117112        """ 
    118         self.theta= math.atan2(y,x) 
    119         self.has_move= True 
     113        self.theta = math.atan2(y, x) 
     114        self.has_move = True 
    120115        self.base.base.update() 
    121116         
    122     def set_cursor(self,r_min, r_max, theta): 
     117    def set_cursor(self, r_min, r_max, theta): 
    123118        """ 
    124119        """ 
    125         self.theta= theta 
    126         self.r1= r_min 
    127         self.r2=r_max 
     120        self.theta = theta 
     121        self.r1 = r_min 
     122        self.r2 = r_max 
    128123        self.update() 
    129124         
  • guiframe/local_perspectives/plotting/Plotter1D.py

    r3c44c66 r32c0841  
    1818import numpy 
    1919import time 
    20  
    2120import danse.common.plottools 
    2221from danse.common.plottools.PlotPanel import PlotPanel 
     
    2423from sans.guiframe import dataFitting  
    2524from sans.guicomm.events import EVT_NEW_PLOT 
    26 from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent,ErrorDataEvent 
    27 from sans.guicomm.events import RemoveDataEvent, AddManyDataEvent 
     25from sans.guicomm.events import StatusEvent  
     26from sans.guicomm.events import NewPlotEvent 
     27from sans.guicomm.events import SlicerEvent 
     28from sans.guicomm.events import ErrorDataEvent 
     29from sans.guicomm.events import RemoveDataEvent 
     30from sans.guicomm.events import AddManyDataEvent 
    2831from sans.guiframe.utils import PanelMenu 
    2932from sans.guiframe.dataFitting import Data1D 
     
    3134from binder import BindArtist 
    3235 
    33  
    3436DEFAULT_QMAX = 0.05 
    3537DEFAULT_QSTEP = 0.001 
    3638DEFAULT_BEAM = 0.005 
    37 BIN_WIDTH =1 
     39BIN_WIDTH = 1 
    3840 
    3941 
     
    5355    group_id = None 
    5456     
    55     def __init__(self, parent, id = -1, color = None,\ 
    56         dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
     57    def __init__(self, parent, id=-1, color = None, 
     58                 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
    5759        """ 
    5860        Initialize the panel 
    5961        """ 
    60         PlotPanel.__init__(self, parent, id = id, style = style, **kwargs) 
    61          
     62        PlotPanel.__init__(self, parent, id=id, style=style, **kwargs) 
    6263        ## Reference to the parent window 
    6364        self.parent = parent 
     
    6566        self.plots = {} 
    6667        ## save errors dy  for each data plotted 
    67         self.err_dy={} 
     68        self.err_dy = {} 
    6869        ## flag to determine if the hide or show context menu item should 
    6970        ## be displayed 
    70         self.errors_hide=False 
     71        self.errors_hide = False 
    7172        ## Unique ID (from gui_manager) 
    7273        self.uid = None 
     
    7879        self.graph = Graph() 
    7980        self.graph.xaxis("\\rm{Q}", 'A^{-1}') 
    80         self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 
     81        self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    8182        self.graph.render(self) 
    8283    
    83     def set_data(self, list=[]): 
     84    def set_data(self, list=None): 
    8485        """ 
    8586        """ 
    8687        pass 
    87      
    8888     
    8989    def _reset(self): 
     
    100100         
    101101        :param event: data event 
    102          
    103102        """ 
    104103        #TODO: Check for existence of plot attribute 
    105104        # Check whether this is a replot. If we ask for a replot 
    106105        # and the plottable no longer exists, ignore the event. 
    107         if hasattr(event, "update") and event.update==True \ 
     106        if hasattr(event, "update") and event.update == True \ 
    108107            and event.plot.name not in self.plots.keys(): 
    109108            return 
    110          
    111109        if hasattr(event, "reset"): 
    112110            self._reset() 
    113          
    114111        # Check whether the plottable is empty 
    115         is_empty = len(event.plot.x)==0 
     112        is_empty = len(event.plot.x) == 0 
    116113                 
    117114        is_new = True 
     
    123120            else:   
    124121                # Check whether the class of plottable changed 
    125                 if not event.plot.__class__==self.plots[event.plot.name].__class__: 
     122                if not event.plot.__class__ == self.plots[event.plot.name].__class__: 
    126123                    #overwrite a plottable using the same name 
    127124                    self.graph.delete(self.plots[event.plot.name])               
     
    134131                # a new plottable overwrites a plotted one  using the same id 
    135132                for plottable in self.plots.itervalues(): 
    136                     if hasattr(event.plot,"id") and hasattr(plottable, "id"): 
     133                    if hasattr(event.plot, "id") and hasattr(plottable, "id"): 
    137134                        #remove the existing plot and same id and same name 
    138                         if event.plot.id==plottable.id and event.plot.name== plottable.name: 
     135                        if event.plot.id == plottable.id and \ 
     136                            event.plot.name == plottable.name: 
    139137                            self.graph.delete(plottable) 
    140138                 
     
    146144                self.plots[event.plot.name].y = event.plot.y     
    147145                self.plots[event.plot.name].dy = event.plot.dy   
    148                 if hasattr(event.plot, 'dx') and hasattr(self.plots[event.plot.name], 'dx'): 
     146                if hasattr(event.plot, 'dx') and \ 
     147                    hasattr(self.plots[event.plot.name], 'dx'): 
    149148                    self.plots[event.plot.name].dx = event.plot.dx     
    150149           
     
    186185         
    187186        """ 
     187        selected_plot = self.plots[self.graph.selected_plottable] 
    188188        ## Check if there is a selected graph to remove 
    189189        if not self.graph.selected_plottable == None and\ 
    190190            self.graph.selected_plottable in self.plots.keys(): 
    191             color=self.graph.plottables[self.plots[self.graph.selected_plottable]] 
    192             
    193             event = RemoveDataEvent(data =self.plots[self.graph.selected_plottable]) 
     191            color = self.graph.plottables[selected_plot] 
     192            event = RemoveDataEvent(data=selected_plot) 
    194193            wx.PostEvent(self.parent, event) 
    195             self.graph.delete(self.plots[self.graph.selected_plottable]) 
    196             del self.plots[self.graph.selected_plottable] 
     194            self.graph.delete(selected_plot) 
     195            del selected_plot 
    197196            ## increment graph color 
    198197            self.graph.color += color 
     
    209208        slicerpop = PanelMenu() 
    210209        slicerpop.set_plots(self.plots) 
    211         slicerpop.set_graph(self.graph) 
    212                  
     210        slicerpop.set_graph(self.graph)      
    213211        # Various plot options 
    214212        id = wx.NewId() 
    215         slicerpop.Append(id,'&Save image', 'Save image as PNG') 
     213        slicerpop.Append(id, '&Save image', 'Save image as PNG') 
    216214        wx.EVT_MENU(self, id, self.onSaveImage) 
    217          
    218215        id = wx.NewId() 
    219         slicerpop.Append(id,'&Print image', 'Print image ') 
     216        slicerpop.Append(id, '&Print image', 'Print image ') 
    220217        wx.EVT_MENU(self, id, self.onPrint) 
    221            
    222218        id = wx.NewId() 
    223         slicerpop.Append(id,'&Print Preview', 'image preview for print') 
     219        slicerpop.Append(id, '&Print Preview', 'image preview for print') 
    224220        wx.EVT_MENU(self, id, self.onPrinterPreview) 
    225             
    226221        slicerpop.AppendSeparator() 
    227222        item_list = self.parent.get_context_menu(self.graph) 
    228         
    229         if (not item_list==None) and (not len(item_list)==0): 
     223        if (not item_list == None) and (not len(item_list) == 0): 
    230224            for item in item_list: 
    231225                try: 
     
    234228                    wx.EVT_MENU(self, id, item[2]) 
    235229                except: 
    236                     wx.PostEvent(self.parent, StatusEvent(status=\ 
    237                         "ModelPanel1D.onContextMenu: bad menu item  %s"%sys.exc_value)) 
     230                    msg = "ModelPanel1D.onContextMenu: " 
     231                    msg += "bad menu item  %s"%sys.exc_value 
     232                    wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    238233                    pass 
    239234            slicerpop.AppendSeparator() 
     
    243238            id = wx.NewId() 
    244239            name = plot.name 
    245             
    246240            slicerpop.Append(id, "&Save points" ) 
    247241            self.action_ids[str(id)] = plot 
    248242            wx.EVT_MENU(self, id, self._onSave) 
    249            
    250243            id = wx.NewId() 
    251244            slicerpop.Append(id, "Remove %s curve" % name) 
     
    255248            # Option to hide 
    256249            #TODO: implement functionality to hide a plottable (legend click) 
    257         
    258250        if self.graph.selected_plottable in self.plots: 
    259             selected_plot= self.plots[self.graph.selected_plottable] 
    260             
     251            selected_plot = self.plots[self.graph.selected_plottable] 
    261252            id = wx.NewId() 
    262253            slicerpop.Append(id, '&Linear fit') 
    263254            wx.EVT_MENU(self, id, self.onFitting) 
    264                  
    265255            slicerpop.AppendSeparator() 
    266          
    267256        id = wx.NewId() 
    268257        slicerpop.Append(id, '&Change scale') 
    269258        wx.EVT_MENU(self, id, self._onProperties) 
    270         
    271259        id = wx.NewId() 
    272260        slicerpop.Append(id, '&Reset Graph') 
    273261        wx.EVT_MENU(self, id, self.onResetGraph)   
    274         
    275262        pos = event.GetPosition() 
    276263        pos = self.ScreenToClient(pos) 
    277264        self.PopupMenu(slicerpop, pos) 
    278          
    279265         
    280266    def _on_remove_errors(self, evt): 
     
    293279            name =self.plots[self.graph.selected_plottable].name 
    294280            dy = self.plots[self.graph.selected_plottable].dy 
    295             self.err_dy[name]= dy 
     281            self.err_dy[name] = dy 
    296282            ## Create a new dy for a new plottable 
    297             import numpy 
     283            #import numpy 
    298284            dy = numpy.zeros(len(self.plots[self.graph.selected_plottable].y)) 
    299285            selected_plot = self.plots[self.graph.selected_plottable] 
    300286             
    301             if selected_plot.__class__.__name__=="Data1D": 
     287            if selected_plot.__class__.__name__ == "Data1D": 
    302288                # Make sure that we can pass a basic Data1D 
    303289                dxl = None 
     
    307293                if hasattr(selected_plot, "dxw"): 
    308294                    dxw = selected_plot.dxw 
    309                 new_plot = Data1D( x=selected_plot.x, 
    310                               y= selected_plot.y, 
    311                                dx=selected_plot.dx, 
    312                               dy=dy) 
    313                 new_plot.dxl  = dxl 
    314                 new_plot.dxw = dxw 
    315                               
    316             else: 
    317                  new_plot = Theory1D(x=selected_plot.x,y=selected_plot.y,dy=dy) 
     295                new_plot = Data1D(x=selected_plot.x, y=selected_plot.y, 
     296                               dx=selected_plot.dx, dy=dy) 
     297                new_plot.dxl = dxl 
     298                new_plot.dxw = dxw             
     299            else: 
     300                 new_plot = Theory1D(x=selected_plot.x,  
     301                                     y=selected_plot.y, dy=dy) 
    318302            new_plot.interactive = True 
    319303            self.errors_hide = True 
     
    321305            if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 
    322306                new_plot.group_id = self.plots[self.graph.selected_plottable].group_id 
    323                 if hasattr(self.plots[self.graph.selected_plottable],"id"): 
     307                if hasattr(self.plots[self.graph.selected_plottable], "id"): 
    324308                    new_plot.id = self.plots[self.graph.selected_plottable].id 
    325309                else: 
     
    333317            new_plot.yaxis(label, unit) 
    334318            ## save the color of the selected plottable before it is deleted 
    335             color=self.graph.plottables[self.plots[self.graph.selected_plottable]] 
     319            color = self.graph.plottables[self.plots[self.graph.selected_plottable]] 
    336320            self.graph.delete(self.plots[self.graph.selected_plottable]) 
    337321            ## add newly created plottable to the graph with the save color 
    338322            self.graph.color += color 
    339             self.graph.add(new_plot,color) 
    340             ## transforming the view of the new data into the same of the previous data 
     323            self.graph.add(new_plot, color) 
     324            ## transforming the view of the new data into the same of  
     325            #the previous data 
    341326            self._onEVT_FUNC_PROPERTY() 
    342327            ## save the plot  
    343             self.plots[self.graph.selected_plottable]=new_plot 
     328            self.plots[self.graph.selected_plottable] = new_plot 
    344329            ## Render the graph 
    345330            self.graph.render(self) 
    346331            self.subplot.figure.canvas.draw_idle()  
    347              
    348332            event = ErrorDataEvent(err_dy=self.err_dy) 
    349333            wx.PostEvent(self.parent, event) 
     
    366350            length = len(self.plots[self.graph.selected_plottable].x) 
    367351            dy = numpy.zeros(length) 
    368              
    369             selected_plot= self.plots[self.graph.selected_plottable] 
    370              
     352            selected_plot = self.plots[self.graph.selected_plottable] 
    371353            try: 
    372354                dy = self.err_dy[selected_plot.name] 
    373                 
    374355            except: 
    375                 #for i in range(length): 
    376                 #dy[i] = math.sqrt(self.plots[self.graph.selected_plottable].y[i])       
    377                 if hasattr(selected_plot,"dy"): 
    378                     dy= selected_plot.dy 
     356                if hasattr(selected_plot, "dy"): 
     357                    dy = selected_plot.dy 
    379358                else: 
    380359                    dy = numpy.zeros(selected_plot.dy) 
    381                      
    382360            ## Create a new plottable data1D 
    383             if selected_plot.__class__.__name__=="Data1D": 
     361            if selected_plot.__class__.__name__ == "Data1D": 
    384362                # Make sure that we can pass a basic Data1D 
    385363                dxl = None 
     
    389367                if hasattr(selected_plot, "dxw"): 
    390368                    dxw = selected_plot.dxw 
    391                 new_plot = Data1D( x=selected_plot.x, 
    392                                                y= selected_plot.y, 
     369                new_plot = Data1D(x=selected_plot.x, 
     370                                               y=selected_plot.y, 
    393371                                               dx=selected_plot.dx, 
    394372                                               dy=dy) 
    395373                new_plot.dxl = dxl 
    396                 new_plot.dxw = dxw 
    397                                        
     374                new_plot.dxw = dxw                        
    398375            else: 
    399376                ## Create a new plottable Theory1D 
    400                 new_plot = Theory1D(x=selected_plot.x,y=selected_plot.y,dy=dy) 
    401              
     377                new_plot = Theory1D(x=selected_plot.x, y=selected_plot.y, dy=dy) 
    402378            new_plot.interactive = True 
    403379            new_plot.name = self.plots[self.graph.selected_plottable].name  
     
    422398            ## add newly created plottable to the graph with the save color 
    423399            self.graph.add(new_plot, color) 
    424             ## transforming the view of the new data into the same of the previous data 
     400            ## transforming the view of the new data into the same of 
     401            # the previous data 
    425402            self._onEVT_FUNC_PROPERTY() 
    426403            ## save the plot  
     
    443420            out = open(path, 'w') 
    444421            has_errors = True 
    445             if data.dy==None or data.dy==[]: 
     422            if data.dy == None or data.dy == []: 
    446423                has_errors = False 
    447                  
    448424            # Sanity check 
    449425            if has_errors: 
    450426                try: 
    451427                    if len(data.y) != len(data.dy): 
    452  
    453428                        has_errors = False 
    454429                except: 
    455430                    has_errors = False 
    456              
    457431            if has_errors: 
    458432                out.write("<X>   <Y>   <dY>\n") 
     
    468442                    out.write("%g  %g\n" % (data.x[i],  
    469443                                            data.y[i])) 
    470                      
    471444            out.close()                  
    472445            try: 
     
    489462            "CanSAS 1D files(*.xml)|*.xml"  
    490463            dlg = wx.FileDialog(self, "Choose a file", 
    491                                 self._default_save_location, "",wildcard , wx.SAVE) 
     464                                self._default_save_location, 
     465                                 "", wildcard , wx.SAVE) 
    492466            
    493467            if dlg.ShowModal() == wx.ID_OK: 
     
    495469                mypath = os.path.basename(path) 
    496470                 
    497                 #TODO: This is bad design. The DataLoader is designed to recognize extensions. 
    498                 # It should be a simple matter of calling the .save(file, data, '.xml') method 
     471                #TODO: This is bad design. The DataLoader is designed  
     472                #to recognize extensions. 
     473                # It should be a simple matter of calling the . 
     474                #save(file, data, '.xml') method 
    499475                # of the DataLoader.loader.Loader class. 
    500476                from DataLoader.loader import  Loader 
     
    502478                loader = Loader()  
    503479                data = self.plots[self.graph.selected_plottable] 
    504                 format=".txt" 
     480                format = ".txt" 
    505481                if os.path.splitext(mypath)[1].lower() == format: 
    506482                     self._onsaveTXT( path) 
    507  
    508                 format= ".xml" 
    509                 if os.path.splitext(mypath)[1].lower() ==format: 
    510                     loader.save( path, data, format) 
     483                format = ".xml" 
     484                if os.path.splitext(mypath)[1].lower() == format: 
     485                    loader.save(path, data, format) 
    511486                try: 
    512487                    self._default_save_location = os.path.dirname(path) 
  • guiframe/local_perspectives/plotting/Plotter2D.py

    rd955bf19 r32c0841  
    1212 
    1313import wx 
    14 import sys, math 
     14import sys 
     15import math 
    1516import pylab 
    16  
    1717import danse.common.plottools 
    1818from danse.common.plottools.PlotPanel import PlotPanel 
     
    2020from sans.guicomm.events import EVT_NEW_PLOT 
    2121from sans.guicomm.events import EVT_SLICER_PARS 
    22 from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent 
     22from sans.guicomm.events import StatusEvent  
     23from sans.guicomm.events import NewPlotEvent 
     24from sans.guicomm.events import SlicerEvent 
    2325from sans.guiframe.utils import PanelMenu 
    2426from binder import BindArtist 
    2527from Plotter1D import ModelPanel1D 
    26   
     28from danse.common.plottools.toolbar import NavigationToolBar  
    2729from sans.guiframe.dataFitting import Data1D 
    28 (InternalEvent, EVT_INTERNAL)   = wx.lib.newevent.NewEvent() 
    29  
    30  
     30(InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 
    3131 
    3232DEFAULT_QMAX = 0.05 
     
    3434DEFAULT_BEAM = 0.005 
    3535BIN_WIDTH = 1.0 
    36 from danse.common.plottools.toolbar import NavigationToolBar 
     36 
    3737 
    3838class NavigationToolBar2D(NavigationToolBar): 
     
    8181     
    8282     
    83     def __init__(self, parent, id = -1,data2d=None, color = None,\ 
    84         dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
     83    def __init__(self, parent, id=-1, data2d=None, color = None, 
     84                 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 
    8585        """ 
    8686        Initialize the panel 
    8787        """ 
    88         ModelPanel1D.__init__(self, parent, id = id, style = style, **kwargs) 
     88        ModelPanel1D.__init__(self, parent, id=id, style=style, **kwargs) 
    8989         
    9090        ## Reference to the parent window 
     
    111111        self.axes_frozen = False 
    112112        ## panel that contains result from slicer motion (ex: Boxsum info) 
    113         self.panel_slicer=None 
    114          
     113        self.panel_slicer = None 
    115114        ## Graph         
    116115        self.graph = Graph() 
    117116        self.graph.xaxis("\\rm{Q}", 'A^{-1}') 
    118         self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 
     117        self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 
    119118        self.graph.render(self) 
    120119        ## store default value of zmin and zmax  
     
    127126        """ 
    128127        self.enable_toolbar = True 
    129          
    130         self.toolbar = NavigationToolBar2D(parent=self,canvas=self.canvas) 
     128        self.toolbar = NavigationToolBar2D(parent=self, canvas=self.canvas) 
    131129        self.toolbar.Realize() 
    132        
    133130        # On Windows platform, default window size is incorrect, so set 
    134131        # toolbar width to figure width. 
    135132        tw, th = self.toolbar.GetSizeTuple() 
    136133        fw, fh = self.canvas.GetSizeTuple() 
    137        
    138134        self.toolbar.SetSize(wx.Size(fw, th)) 
    139         self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 
    140          
     135        self.sizer.Add(self.toolbar, 0, wx.LEFT|wx.EXPAND) 
    141136        # update the axes menu on the toolbar 
    142137        self.toolbar.update() 
     
    159154        # Check whether this is a replot. If we ask for a replot 
    160155        # and the plottable no longer exists, ignore the event. 
    161         if hasattr(event, "update") and event.update==True \ 
     156        if hasattr(event, "update") and event.update == True \ 
    162157            and event.plot.name not in self.plots.keys(): 
    163158            return 
    164          
    165159        if hasattr(event, "reset"): 
    166160            self._reset() 
     
    168162        if event.plot.name in self.plots.keys(): 
    169163            # Check whether the class of plottable changed 
    170             if not event.plot.__class__==self.plots[event.plot.name].__class__: 
     164            if not event.plot.__class__ == self.plots[event.plot.name].__class__: 
    171165                #overwrite a plottable using the same name 
    172166                self.graph.delete(self.plots[event.plot.name]) 
     
    179173            for plottable in self.plots.itervalues(): 
    180174                if hasattr(event.plot,"id"): 
    181                     if event.plot.id==plottable.id : 
     175                    if event.plot.id == plottable.id: 
    182176                        self.graph.delete(plottable) 
    183177             
     
    200194            self.plots[event.plot.name].err_data = event.plot.err_data 
    201195            # update qmax with the new xmax of data plotted 
    202             self.qmax= event.plot.xmax 
    203              
    204         self.slicer= None 
     196            self.qmax = event.plot.xmax 
     197             
     198        self.slicer = None 
    205199        # Check axis labels 
    206200        #TODO: Should re-factor this 
     
    209203        #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 
    210204        if len(self.data2D.detector) < 1:  
    211             if len(event.plot._xunit)< 1 and len(event.plot._yunit) < 1: 
     205            if len(event.plot._xunit) < 1 and len(event.plot._yunit) < 1: 
    212206                event.plot._xaxis = '\\rm{x}' 
    213207                event.plot._yaxis = '\\rm{y}' 
    214208                event.plot._xunit = 'pixel' 
    215209                event.plot._yunit = 'pixel' 
    216  
    217210        self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 
    218211        self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 
     
    224217        self.default_zmax_ctl = self.zmax_2D 
    225218 
    226  
    227219    def onContextMenu(self, event): 
    228220        """ 
     
    241233         
    242234        id = wx.NewId() 
    243         slicerpop.Append(id,'&Print image', 'Print image ') 
     235        slicerpop.Append(id,'&Print image', 'Print image') 
    244236        wx.EVT_MENU(self, id, self.onPrint) 
    245237         
     
    252244             
    253245            item_list = self.parent.get_context_menu(self.graph) 
    254             if (not item_list==None) and (not len(item_list)==0): 
    255                      
    256                     for item in item_list: 
    257                         try: 
    258                             id = wx.NewId() 
    259                             slicerpop.Append(id, item[0], item[1]) 
    260                             wx.EVT_MENU(self, id, item[2]) 
    261                         except: 
    262                             wx.PostEvent(self.parent, StatusEvent(status=\ 
    263                             "ModelPanel1D.onContextMenu: bad menu item  %s"%sys.exc_value)) 
    264                             pass 
    265                     slicerpop.AppendSeparator() 
     246            if (not item_list == None) and (not len(item_list) == 0): 
     247                for item in item_list: 
     248                    try: 
     249                        id = wx.NewId() 
     250                        slicerpop.Append(id, item[0], item[1]) 
     251                        wx.EVT_MENU(self, id, item[2]) 
     252                    except: 
     253                        msg = "ModelPanel1D.onContextMenu: " 
     254                        msg += "bad menu item  %s"%sys.exc_value 
     255                        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
     256                        pass 
     257                slicerpop.AppendSeparator() 
    266258             
    267259            id = wx.NewId() 
    268260            slicerpop.Append(id, '&Perform circular average') 
    269261            wx.EVT_MENU(self, id, self.onCircular)  
    270              
    271262            id = wx.NewId() 
    272263            slicerpop.Append(id, '&Sector [Q view]') 
    273264            wx.EVT_MENU(self, id, self.onSectorQ)  
    274              
    275265            id = wx.NewId() 
    276266            slicerpop.Append(id, '&Annulus [Phi view ]') 
    277267            wx.EVT_MENU(self, id, self.onSectorPhi)  
    278             
    279268            id = wx.NewId() 
    280269            slicerpop.Append(id, '&Box Sum') 
    281270            wx.EVT_MENU(self, id, self.onBoxSum)  
    282              
    283271            id = wx.NewId() 
    284272            slicerpop.Append(id, '&Box averaging in Qx') 
    285273            wx.EVT_MENU(self, id, self.onBoxavgX)  
    286              
    287274            id = wx.NewId() 
    288275            slicerpop.Append(id, '&Box averaging in Qy') 
    289276            wx.EVT_MENU(self, id, self.onBoxavgY)  
    290              
    291             if self.slicer !=None : 
     277            if self.slicer != None: 
    292278                id = wx.NewId() 
    293279                slicerpop.Append(id, '&Clear slicer') 
    294280                wx.EVT_MENU(self, id,  self.onClearSlicer)  
    295                  
    296                 if self.slicer.__class__.__name__ !="BoxSum": 
     281                if self.slicer.__class__.__name__  != "BoxSum": 
    297282                    id = wx.NewId() 
    298283                    slicerpop.Append(id, '&Edit Slicer Parameters') 
    299284                    wx.EVT_MENU(self, id, self._onEditSlicer)  
    300                      
    301285            slicerpop.AppendSeparator()  
    302              
    303286        id = wx.NewId() 
    304287        slicerpop.Append(id, '&Detector Parameters') 
    305         wx.EVT_MENU(self, id, self._onEditDetector)  
    306          
    307         
     288        wx.EVT_MENU(self, id, self._onEditDetector) 
    308289        id = wx.NewId() 
    309290        slicerpop.Append(id, '&Toggle Linear/Log scale') 
    310291        wx.EVT_MENU(self, id, self._onToggleScale)  
    311                   
    312292        pos = event.GetPosition() 
    313293        pos = self.ScreenToClient(pos) 
    314294        self.PopupMenu(slicerpop, pos) 
    315295    
    316     
    317296    def _onEditDetector(self, event): 
    318297        """ 
     
    322301         
    323302        """ 
    324          
    325303        import detector_dialog 
    326         
    327304        dialog = detector_dialog.DetectorDialog(self, -1,base=self.parent, 
    328305                       reset_zmin_ctl =self.default_zmin_ctl, 
     
    333310        xmax = max(self.data2D.xmin, self.data2D.xmax) 
    334311        ymax = max(self.data2D.ymin, self.data2D.ymax) 
    335         qmax = math.sqrt(math.pow(xmax,2)+math.pow(ymax,2)) 
     312        qmax = math.sqrt(math.pow(xmax, 2) + math.pow(ymax, 2)) 
    336313        beam = self.data2D.xmin 
    337       
    338314        ## set dialog window content 
    339315        dialog.setContent(xnpts=xnpts,ynpts=ynpts,qmax=qmax, 
     
    345321            self.zmin_2D = evt.zmin 
    346322            self.zmax_2D = evt.zmax 
    347             self.cmap= evt.cmap 
    348         
     323            self.cmap = evt.cmap 
    349324        dialog.Destroy() 
    350325        ## Redraw the current image 
    351         self.image(data= self.data2D.data, 
     326        self.image(data=self.data2D.data, 
    352327                   qx_data=self.data2D.qx_data, 
    353328                   qy_data=self.data2D.qy_data, 
     
    359334                   zmax= self.zmax_2D, 
    360335                   cmap= self.cmap, 
    361                    color=0,symbol=0,label=self.data2D.name)#'data2D') 
     336                   color=0, symbol=0, label=self.data2D.name) 
    362337        self.subplot.figure.canvas.draw_idle() 
    363338         
    364          
    365    
    366339    def freeze_axes(self): 
    367340        """ 
     
    395368        create an empty slicervent  
    396369        """ 
    397         return SlicerEvent(type=None, 
    398                            params=None, 
    399                            obj_class=None) 
     370        return SlicerEvent(type=None, params=None, obj_class=None) 
    400371         
    401372    def _onEVT_INTERNAL(self, event): 
     
    417388         
    418389        """ 
    419          
    420390        ## Clear current slicer 
    421391        if not self.slicer == None:   
     
    429399        self.update() 
    430400        self.slicer.update() 
    431         wx.PostEvent(self.parent, StatusEvent(status=\ 
    432                         "Plotter2D._setSlicer  %s"%self.slicer.__class__.__name__)) 
     401        msg = "Plotter2D._setSlicer  %s"%self.slicer.__class__.__name__ 
     402        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    433403        # Post slicer event 
    434404        event = self._getEmptySlicerEvent() 
    435405        event.type = self.slicer.__class__.__name__ 
    436          
    437406        event.obj_class = self.slicer.__class__ 
    438407        event.params = self.slicer.get_params() 
    439408        wx.PostEvent(self, event) 
    440409 
    441  
    442410    def onCircular(self, event): 
    443411        """ 
     
    447415         
    448416        """ 
    449          
    450417        from DataLoader.manipulations import CircularAverage 
    451418        ## compute the maximum radius of data2D 
    452         self.qmax= max(math.fabs(self.data2D.xmax),math.fabs(self.data2D.xmin)) 
    453         self.ymax=max(math.fabs(self.data2D.ymax),math.fabs(self.data2D.ymin)) 
    454         self.radius= math.sqrt( math.pow(self.qmax,2)+math.pow(self.ymax,2))  
     419        self.qmax = max(math.fabs(self.data2D.xmax),  
     420                        math.fabs(self.data2D.xmin)) 
     421        self.ymax = max(math.fabs(self.data2D.ymax), 
     422                        math.fabs(self.data2D.ymin)) 
     423        self.radius = math.sqrt(math.pow(self.qmax, 2)+ math.pow(self.ymax, 2))  
    455424        ##Compute beam width 
    456         bin_width = (self.qmax +self.qmax)/100 
     425        bin_width = (self.qmax + self.qmax)/100 
    457426        ## Create data1D circular average of data2D 
    458         Circle = CircularAverage( r_min=0, r_max=self.radius, bin_width=bin_width) 
     427        Circle = CircularAverage(r_min=0, r_max=self.radius,  
     428                                 bin_width=bin_width) 
    459429        circ = Circle(self.data2D) 
    460          
    461430        from sans.guiframe.dataFitting import Data1D 
    462         if hasattr(circ,"dxl"): 
    463             dxl= circ.dxl 
     431        if hasattr(circ, "dxl"): 
     432            dxl = circ.dxl 
    464433        else: 
    465             dxl= None 
    466         if hasattr(circ,"dxw"): 
    467             dxw= circ.dxw 
     434            dxl = None 
     435        if hasattr(circ, "dxw"): 
     436            dxw = circ.dxw 
    468437        else: 
    469             dxw= None 
    470          
    471         new_plot = Data1D(x=circ.x,y=circ.y,dy=circ.dy) 
    472         new_plot.dxl=dxl 
    473         new_plot.dxw=dxw 
    474         new_plot.name = "Circ avg "+ self.data2D.name 
    475         new_plot.source=self.data2D.source 
    476         #new_plot.info=self.data2D.info 
     438            dxw = None 
     439        new_plot = Data1D(x=circ.x, y=circ.y, dy=circ.dy) 
     440        new_plot.dxl = dxl 
     441        new_plot.dxw = dxw 
     442        new_plot.name = "Circ avg " + self.data2D.name 
     443        new_plot.source = self.data2D.source 
     444        #new_plot.info = self.data2D.info 
    477445        new_plot.interactive = True 
    478         new_plot.detector =self.data2D.detector 
     446        new_plot.detector = self.data2D.detector 
    479447        ## If the data file does not tell us what the axes are, just assume... 
    480         new_plot.xaxis("\\rm{Q}","A^{-1}") 
    481         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    482         new_plot.group_id = "Circ avg "+ self.data2D.name 
    483         new_plot.id = "Circ avg "+ self.data2D.name 
    484         new_plot.is_data= True 
    485         wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 
     448        new_plot.xaxis("\\rm{Q}", "A^{-1}") 
     449        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     450        new_plot.group_id = "Circ avg " + self.data2D.name 
     451        new_plot.id = "Circ avg " + self.data2D.name 
     452        new_plot.is_data = True 
     453        wx.PostEvent(self.parent,  
     454                     NewPlotEvent(plot=new_plot, title=new_plot.name)) 
    486455        
    487456    def _onEditSlicer(self, event): 
     
    494463         
    495464        """ 
    496         if self.slicer !=None: 
     465        if self.slicer != None: 
    497466            from SlicerParameters import SlicerParameterPanel 
    498467            dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 
     
    508477        from SectorSlicer import SectorInteractor 
    509478        self.onClearSlicer(event) 
    510         wx.PostEvent(self, InternalEvent(slicer= SectorInteractor)) 
     479        wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 
    511480         
    512481    def onSectorPhi(self, event): 
     
    516485        from AnnulusSlicer import AnnulusInteractor 
    517486        self.onClearSlicer(event) 
    518         wx.PostEvent(self, InternalEvent(slicer= AnnulusInteractor)) 
     487        wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 
    519488         
    520489    def onBoxSum(self, event): 
     
    523492        from boxSum import BoxSum 
    524493        self.onClearSlicer(event) 
    525                      
    526494        self.slicer_z += 1 
    527495        self.slicer =  BoxSum(self, self.subplot, zorder=self.slicer_z) 
    528         
    529496        self.subplot.set_ylim(self.data2D.ymin, self.data2D.ymax) 
    530497        self.subplot.set_xlim(self.data2D.xmin, self.data2D.xmax) 
    531         
    532498        self.update() 
    533499        self.slicer.update() 
     
    537503        ## Create a new panel to display results of summation of Data2D 
    538504        from slicerpanel import SlicerPanel 
    539         new_panel = SlicerPanel(parent= self.parent, id= -1, 
    540                                     base= self, type= type, 
    541                                     params= params, style= wx.RAISED_BORDER) 
    542          
    543         new_panel.window_caption=self.slicer.__class__.__name__+" "+ str(self.data2D.name) 
    544         new_panel.window_name = self.slicer.__class__.__name__+" "+ str(self.data2D.name) 
     505        new_panel = SlicerPanel(parent=self.parent, id=-1, 
     506                                    base=self, type=type, 
     507                                    params=params, style=wx.RAISED_BORDER) 
     508         
     509        new_panel.window_caption = self.slicer.__class__.__name__ + " " + \ 
     510                                    str(self.data2D.name) 
     511        new_panel.window_name = self.slicer.__class__.__name__+ " " + \ 
     512                                    str(self.data2D.name) 
    545513        ## Store a reference of the new created panel 
    546         self.panel_slicer= new_panel 
     514        self.panel_slicer = new_panel 
    547515        ## save the window_caption of the new panel in the current slicer 
    548         self.slicer.set_panel_name( name= new_panel.window_caption) 
     516        self.slicer.set_panel_name(name=new_panel.window_caption) 
    549517        ## post slicer panel to guiframe to display it  
    550518        from sans.guicomm.events import SlicerPanelEvent 
    551         wx.PostEvent(self.parent, SlicerPanelEvent (panel= self.panel_slicer, 
    552                                                     main_panel =self)) 
     519        wx.PostEvent(self.parent, SlicerPanelEvent(panel=self.panel_slicer, 
     520                                                    main_panel=self)) 
    553521 
    554522    def onBoxavgX(self,event): 
     
    561529        from boxSlicer import BoxInteractorX 
    562530        self.onClearSlicer(event) 
    563         wx.PostEvent(self, InternalEvent(slicer= BoxInteractorX)) 
     531        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 
    564532        
    565533    def onBoxavgY(self,event): 
     
    573541        from boxSlicer import BoxInteractorY 
    574542        self.onClearSlicer(event) 
    575         wx.PostEvent(self, InternalEvent(slicer= BoxInteractorY)) 
     543        wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 
    576544         
    577545    def onClearSlicer(self, event): 
     
    579547        Clear the slicer on the plot 
    580548        """ 
    581         if not self.slicer==None: 
     549        if not self.slicer == None: 
    582550            self.slicer.clear() 
    583551            self.subplot.figure.canvas.draw() 
    584552            self.slicer = None 
    585          
    586553            # Post slicer None event 
    587554            event = self._getEmptySlicerEvent() 
  • guiframe/local_perspectives/plotting/SectorSlicer.py

    rd955bf19 r32c0841  
    22import math 
    33import wx 
    4 from copy import deepcopy 
    5  
     4#from copy import deepcopy 
    65from BaseInteractor import _BaseInteractor 
    7 from sans.guicomm.events import NewPlotEvent, StatusEvent 
    8 from sans.guicomm.events import SlicerParameterEvent,EVT_SLICER_PARS 
    9  
     6from sans.guicomm.events import NewPlotEvent 
     7from sans.guicomm.events import StatusEvent 
     8from sans.guicomm.events import SlicerParameterEvent 
     9from sans.guicomm.events import EVT_SLICER_PARS 
    1010from sans.guiframe.dataFitting import Data1D 
     11 
    1112 
    1213class SectorInteractor(_BaseInteractor): 
     
    1415    Draw a sector slicer.Allow to performQ averaging on data 2D 
    1516    """ 
    16     def __init__(self,base,axes,color='black', zorder=3): 
     17    def __init__(self, base, axes, color='black', zorder=3): 
    1718         
    1819        _BaseInteractor.__init__(self, base, axes, color=color) 
     
    2425         
    2526        ## compute qmax limit to reset the graph      
    26         x = math.pow(max(self.base.data2D.xmax,math.fabs(self.base.data2D.xmin)),2) 
    27         y = math.pow(max(self.base.data2D.ymax,math.fabs(self.base.data2D.ymin)),2) 
    28         self.qmax= math.sqrt(x + y) 
     27        x = math.pow(max(self.base.data2D.xmax,  
     28                         math.fabs(self.base.data2D.xmin)), 2) 
     29        y = math.pow(max(self.base.data2D.ymax,  
     30                         math.fabs(self.base.data2D.ymin)), 2) 
     31        self.qmax = math.sqrt(x + y) 
    2932        ## Number of points on the plot 
    3033        self.nbins = 20 
    3134        ## Angle of the middle line 
    32         self.theta2= math.pi/3 
     35        self.theta2 = math.pi/3 
    3336        ## Absolute value of the Angle between the middle line and any side line 
    34         self.phi=math.pi/12 
    35          
     37        self.phi = math.pi/12 
    3638        ## Middle line 
    37         self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax, 
     39        self.main_line = LineInteractor(self, self.base.subplot, color='blue',  
     40                                        zorder=zorder, r=self.qmax, 
    3841                                           theta= self.theta2) 
    3942        self.main_line.qmax = self.qmax 
    4043        ## Right Side line 
    41         self.right_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 
    42                                      r=self.qmax, 
    43                                            phi= -1*self.phi, 
    44                                            theta2=self.theta2) 
     44        self.right_line = SideInteractor(self, self.base.subplot, color='black', 
     45                                          zorder=zorder, r=self.qmax, 
     46                                          phi=-1*self.phi, theta2=self.theta2) 
    4547        self.right_line.qmax = self.qmax 
    4648        ## Left Side line  
    47         self.left_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 
    48                                      r=self.qmax, 
    49                                            phi= self.phi, 
    50                                            theta2=self.theta2) 
     49        self.left_line = SideInteractor(self, self.base.subplot, color='black', 
     50                                        zorder=zorder, r=self.qmax, 
     51                                           phi=self.phi, theta2=self.theta2) 
    5152        self.left_line.qmax = self.qmax 
    5253        ## draw the sector                
    5354        self.update() 
    5455        self._post_data() 
    55  
    5656        ## Bind to slice parameter events 
    5757        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    5858 
    59  
    6059    def _onEVT_SLICER_PARS(self, event): 
    6160        """ 
     
    6665         
    6766        """ 
    68         wx.PostEvent(self.base.parent, StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 
     67        wx.PostEvent(self.base.parent, 
     68                     StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 
    6969        event.Skip() 
    7070        if event.type == self.__class__.__name__: 
     
    9999        """ 
    100100        # Update locations   
    101         ## Check if the middle line was dragged and update the picture accordingly      
     101        ## Check if the middle line was dragged and  
     102        #update the picture accordingly      
    102103        if self.main_line.has_move: 
    103104            self.main_line.update() 
    104             self.right_line.update( delta= -self.left_line.phi/2, 
    105                                     mline= self.main_line.theta ) 
    106             self.left_line.update( delta = self.left_line.phi/2, 
    107                                    mline= self.main_line.theta ) 
     105            self.right_line.update(delta=-self.left_line.phi/2, 
     106                                    mline=self.main_line.theta) 
     107            self.left_line.update(delta=self.left_line.phi/2, 
     108                                   mline=self.main_line.theta) 
    108109        ## Check if the left side has moved and update the slicer accordingly   
    109110        if self.left_line.has_move: 
    110111            self.main_line.update() 
    111             self.left_line.update( phi=None, delta=None, mline=self.main_line , 
    112                                   side=True, left=True ) 
    113             self.right_line.update( phi= self.left_line.phi, delta= None, 
    114                                      mline= self.main_line, side= True, 
    115                                      left=False, right= True ) 
    116         ## Check if the right side line has moved and update the slicer accordingly 
     112            self.left_line.update(phi=None, delta=None, mline=self.main_line, 
     113                                  side=True, left=True) 
     114            self.right_line.update(phi=self.left_line.phi, delta=None, 
     115                                     mline=self.main_line, side=True, 
     116                                     left=False, right=True) 
     117        ## Check if the right side line has moved and  
     118        #update the slicer accordingly 
    117119        if self.right_line.has_move: 
    118120            self.main_line.update() 
    119             self.right_line.update( phi=None, delta=None, mline=self.main_line, 
    120                                    side=True, left=False, right=True ) 
    121             self.left_line.update( phi=self.right_line.phi, delta=None, 
    122                                     mline=self.main_line, side=True, left=False ) 
     121            self.right_line.update(phi=None, delta=None, mline=self.main_line, 
     122                                   side=True, left=False, right=True) 
     123            self.left_line.update(phi=self.right_line.phi, delta=None, 
     124                                    mline=self.main_line, side=True, left=False) 
    123125             
    124126    def save(self, ev): 
     
    148150        phimin =  -self.left_line.phi + self.main_line.theta 
    149151        phimax = self.left_line.phi + self.main_line.theta 
    150         
    151         if nbins==None: 
     152        if nbins == None: 
    152153            nbins = 20 
    153         sect = SectorQ(r_min= 0.0, r_max= radius , 
    154                         phi_min= phimin + math.pi, 
    155                         phi_max= phimax + math.pi, nbins=nbins) 
     154        sect = SectorQ(r_min=0.0, r_max=radius, 
     155                        phi_min=phimin + math.pi, 
     156                        phi_max=phimax + math.pi, nbins=nbins) 
    156157      
    157158        sector = sect(self.base.data2D) 
    158159        ##Create 1D data resulting from average 
    159160        
    160         if hasattr(sector,"dxl"): 
    161             dxl= sector.dxl 
     161        if hasattr(sector, "dxl"): 
     162            dxl = sector.dxl 
    162163        else: 
    163             dxl= None 
    164         if hasattr(sector,"dxw"): 
    165             dxw= sector.dxw 
     164            dxl = None 
     165        if hasattr(sector, "dxw"): 
     166            dxw = sector.dxw 
    166167        else: 
    167             dxw= None 
    168         
    169         new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy) 
     168            dxw = None 
     169        new_plot = Data1D(x=sector.x, y=sector.y, dy=sector.dy) 
    170170        new_plot.dxl = dxl 
    171171        new_plot.dxw = dxw 
    172         new_plot.name = "SectorQ" +"("+ self.base.data2D.name+")" 
    173          
    174         new_plot.source=self.base.data2D.source 
     172        new_plot.name = "SectorQ" + "(" + self.base.data2D.name + ")" 
     173        new_plot.source = self.base.data2D.source 
    175174        #new_plot.info=self.base.data2D.info 
    176175        new_plot.interactive = True 
    177         new_plot.detector =self.base.data2D.detector 
     176        new_plot.detector = self.base.data2D.detector 
    178177        # If the data file does not tell us what the axes are, just assume... 
    179178        new_plot.xaxis("\\rm{Q}", 'A^{-1}') 
    180         new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    181         new_plot.group_id = "SectorQ"+self.base.data2D.name 
    182         new_plot.id = "SectorQ"+self.base.data2D.name 
    183         new_plot.is_data= True 
     179        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     180        new_plot.group_id = "SectorQ" + self.base.data2D.name 
     181        new_plot.id = "SectorQ" + self.base.data2D.name 
     182        new_plot.is_data = True 
    184183        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    185                                     title="SectorQ"+self.base.data2D.name )) 
     184                                    title="SectorQ" + self.base.data2D.name)) 
    186185         
    187186    def moveend(self, ev): 
     
    227226        ## angle of the middle line 
    228227        if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 
    229             raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 
    230          
     228            msg = "Phi left and phi right are different" 
     229            msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 
     230            raise ValueError, msg 
    231231        params["Phi"] = self.main_line.theta 
    232232        params["Delta_Phi"] = math.fabs(self.left_line.phi) 
     
    243243        """ 
    244244        main = params["Phi"]  
    245         phi = math.fabs(params["Delta_Phi"] ) 
     245        phi = math.fabs(params["Delta_Phi"]) 
    246246        self.nbins = int(params["nbins"]) 
    247         self.main_line.theta= main 
     247        self.main_line.theta = main 
    248248        ## Reset the slicer parameters 
    249249        self.main_line.update() 
    250         self.right_line.update( phi=phi,delta=None, mline=self.main_line, 
    251                                side=True, right=True ) 
    252         self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True ) 
     250        self.right_line.update(phi=phi, delta=None, mline=self.main_line, 
     251                               side=True, right=True) 
     252        self.left_line.update(phi=phi, delta=None,  
     253                              mline=self.main_line, side=True) 
    253254        ## post the new corresponding data 
    254255        self._post_data(nbins=self.nbins) 
     
    278279     
    279280    """ 
    280     def __init__(self,base,axes,color='black', zorder=5, r=1.0,phi=math.pi/4, theta2= math.pi/3): 
    281          
     281    def __init__(self, base, axes, color='black', zorder=5, r=1.0, 
     282                 phi=math.pi/4, theta2= math.pi/3): 
     283        """ 
     284        """ 
    282285        _BaseInteractor.__init__(self, base, axes, color=color) 
    283286        ## Initialize the class 
     
    287290        ## the x-axis   
    288291        self.save_theta = theta2 + phi 
    289         self.theta= theta2 + phi 
     292        self.theta = theta2 + phi 
    290293        ## the value of the middle line angle with respect to the x-axis 
    291294        self.theta2 = theta2 
     
    294297        ## phi is the phase between the current line and the middle line 
    295298        self.phi = phi 
    296          
    297299        ## End points polar coordinates 
    298         x1= self.radius*math.cos(self.theta) 
    299         y1= self.radius*math.sin(self.theta) 
    300         x2= -1*self.radius*math.cos(self.theta) 
    301         y2= -1*self.radius*math.sin(self.theta) 
     300        x1 = self.radius * math.cos(self.theta) 
     301        y1 = self.radius * math.sin(self.theta) 
     302        x2 = -1 * self.radius * math.cos(self.theta) 
     303        y2 = -1 * self.radius * math.sin(self.theta) 
    302304        ## defining a new marker  
    303305        try: 
    304             self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 
     306            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 
    305307                                          marker='s', markersize=10, 
    306308                                          color=self.color, alpha=0.6, 
    307309                                          pickradius=5, label="pick",  
    308                                           zorder=zorder, # Prefer this to other lines 
    309                                           visible=True)[0] 
     310                                          # Prefer this to other lines 
     311                                          zorder=zorder, visible=True)[0] 
    310312        except: 
    311313            self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 
    312314                                          marker='s', markersize=10, 
    313315                                          color=self.color, alpha=0.6, 
    314                                           label="pick",  
    315                                           visible=True)[0] 
    316             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    317             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    318             owner=self.base.base.parent 
    319             wx.PostEvent(owner, StatusEvent(status="sectorSlicer: %s"%message)) 
     316                                          label="pick", visible=True)[0] 
     317            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST" 
     318            message += " VERSION OF MATPLOTLIB\n Get the SVN version that" 
     319            message += " is at least as recent as June 1, 2007" 
     320            owner = self.base.base.parent 
     321            wx.PostEvent(owner,  
     322                         StatusEvent(status="sectorSlicer: %s" % message)) 
    320323         
    321324        ## Defining the current line 
    322         self.line = self.axes.plot([x1,x2],[y1,y2], 
     325        self.line = self.axes.plot([x1, x2], [y1, y2], 
    323326                                      linestyle='-', marker='', 
    324                                       color=self.color, 
    325                                       visible=True)[0] 
     327                                      color=self.color, visible=True)[0] 
    326328        ## Flag to differentiate the left line from the right line motion 
    327         self.left_moving=False 
     329        self.left_moving = False 
    328330        ## Flag to define a motion 
    329         self.has_move=False 
     331        self.has_move = False 
    330332        ## connecting markers and draw the picture 
    331333        self.connect_markers([self.inner_marker, self.line]) 
     
    364366        """ 
    365367        #print "update left or right ", self.has_move 
    366         self.left_moving=left 
    367         theta3=0 
    368         if phi !=None: 
    369             self.phi= phi 
    370         if delta==None: 
     368        self.left_moving = left 
     369        theta3 = 0 
     370        if phi != None: 
     371            self.phi = phi 
     372        if delta == None: 
    371373            delta = 0 
    372374        if  right: 
    373             self.phi = -1*math.fabs(self.phi) 
     375            self.phi = -1 * math.fabs(self.phi) 
    374376            #delta=-delta 
    375377        else: 
    376             self.phi =math.fabs(self.phi) 
     378            self.phi = math.fabs(self.phi) 
    377379        if side: 
    378             self.theta= mline.theta + self.phi 
     380            self.theta = mline.theta + self.phi 
    379381                     
    380         if mline!=None : 
    381             if delta!=0: 
    382                 self.theta2 = mline+delta 
     382        if mline != None : 
     383            if delta != 0: 
     384                self.theta2 = mline + delta 
    383385            else: 
    384386                self.theta2 = mline.theta 
    385         if delta==0: 
    386             theta3=self.theta+delta 
     387        if delta == 0: 
     388            theta3 = self.theta + delta 
    387389        else: 
    388             theta3=self.theta2+delta 
    389          
    390         x1= self.radius*math.cos(theta3) 
    391         y1= self.radius*math.sin(theta3) 
    392         x2= -1*self.radius*math.cos(theta3) 
    393         y2= -1*self.radius*math.sin(theta3) 
    394         
    395         self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5]) 
    396         self.line.set(xdata=[x1,x2], ydata=[y1,y2])   
     390            theta3 = self.theta2 + delta 
     391        x1 = self.radius * math.cos(theta3) 
     392        y1 = self.radius * math.sin(theta3) 
     393        x2 = -1 * self.radius * math.cos(theta3) 
     394        y2 = -1 * self.radius * math.sin(theta3) 
     395        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 
     396        self.line.set(xdata=[x1, x2], ydata=[y1, y2])   
    397397         
    398398    def save(self, ev): 
     
    401401        can restore on Esc. 
    402402        """ 
    403         self.save_theta= self.theta 
     403        self.save_theta = self.theta 
    404404        self.base.freeze_axes() 
    405405 
     
    407407        """ 
    408408        """ 
    409         self.has_move=False 
     409        self.has_move = False 
    410410        self.base.moveend(ev) 
    411411             
     
    420420        Process move to a new position, making sure that the move is allowed. 
    421421        """ 
    422         self.theta= math.atan2(y,x) 
    423         self.has_move=True 
     422        self.theta = math.atan2(y, x) 
     423        self.has_move = True 
    424424        #ToDo: Simplify below 
    425425        if not self.left_moving: 
    426             if  self.theta2-self.theta <= 0 and self.theta2>0:#>= self.theta2: 
     426            if  self.theta2 - self.theta <= 0 and self.theta2 > 0: 
     427                self.restore() 
     428                return  
     429            elif self.theta2 < 0 and self.theta < 0 and \ 
     430                self.theta-self.theta2 >= 0: 
     431                self.restore() 
     432                return                              
     433            elif  self.theta2 < 0 and self.theta > 0 and \ 
     434                (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2: 
    427435                #print "my theta", self.theta 
    428436                self.restore() 
    429437                return  
    430             elif self.theta2 < 0 and self.theta < 0 and self.theta-self.theta2 >= 0: 
    431                 self.restore() 
    432                 return                              
    433             elif  self.theta2 < 0 and self.theta > 0 and self.theta2+2*math.pi-self.theta >=math.pi/2: 
     438            elif  self.theta2 < 0 and self.theta < 0 and \ 
     439                (self.theta2 - self.theta) >= math.pi/2: 
    434440                #print "my theta", self.theta 
    435441                self.restore() 
    436442                return  
    437             elif  self.theta2 < 0 and self.theta < 0 and self.theta2-self.theta >=math.pi/2: 
    438                 #print "my theta", self.theta 
    439                 self.restore() 
    440                 return  
    441             elif self.theta2>0 and (self.theta2-self.theta >= math.pi/2 or (self.theta2-self.theta >= math.pi/2)):#<= self.theta2 -math.pi/2: 
     443            elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \ 
     444                (self.theta2-self.theta >= math.pi/2)): 
    442445                #print "self theta encore" 
    443446                self.restore() 
     
    445448        else: 
    446449            #print "left move" 
    447             if  self.theta < 0 and self.theta+math.pi*2-self.theta2 <= 0: 
     450            if  self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0: 
    448451                self.restore() 
    449452                return  
    450             elif self.theta2 < 0 and self.theta-self.theta2 <= 0: 
     453            elif self.theta2 < 0 and (self.theta-self.theta2) <= 0: 
    451454                self.restore() 
    452455                return                              
    453             elif  self.theta > 0 and self.theta-self.theta2 <=0: 
     456            elif  self.theta > 0 and self.theta-self.theta2 <= 0: 
    454457                #print "my theta", self.theta 
    455458                self.restore() 
    456459                return  
    457             elif self.theta-self.theta2 >= math.pi/2 or  (self.theta+math.pi*2-self.theta2 >= math.pi/2 and self.theta<0 and self.theta2>0): 
     460            elif self.theta-self.theta2 >= math.pi/2 or  \ 
     461                ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \ 
     462                 self.theta < 0 and self.theta2 > 0): 
    458463                #print "self theta encore" 
    459464                self.restore() 
    460465                return  
    461466             
    462         self.phi= math.fabs(self.theta2 - self.theta) 
    463         if self.phi>math.pi: 
    464             self.phi= 2*math.pi-math.fabs(self.theta2 - self.theta) 
    465  
     467        self.phi = math.fabs(self.theta2 - self.theta) 
     468        if self.phi > math.pi: 
     469            self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta) 
    466470        self.base.base.update() 
    467471         
     
    491495    Select an annulus through a 2D plot 
    492496    """ 
    493     def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4): 
     497    def __init__(self, base, axes, color='black', 
     498                 zorder=5, r=1.0, theta=math.pi/4): 
    494499        """ 
    495500        """ 
     
    503508        self.scale = 10.0 
    504509        # Inner circle 
    505         x1= self.radius*math.cos(self.theta) 
    506         y1= self.radius*math.sin(self.theta) 
    507         x2= -1*self.radius*math.cos(self.theta) 
    508         y2= -1*self.radius*math.sin(self.theta) 
     510        x1 = self.radius * math.cos(self.theta) 
     511        y1 = self.radius * math.sin(self.theta) 
     512        x2 = -1*self.radius * math.cos(self.theta) 
     513        y2 = -1*self.radius * math.sin(self.theta) 
    509514        try: 
    510515            # Inner circle marker 
    511             self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 
     516            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 
    512517                                          marker='s', markersize=10, 
    513518                                          color=self.color, alpha=0.6, 
    514519                                          pickradius=5, label="pick",  
    515                                           zorder=zorder, # Prefer this to other lines 
     520                                          # Prefer this to other lines 
     521                                          zorder=zorder,  
    516522                                          visible=True)[0] 
    517523        except: 
    518             self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 
     524            self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 
    519525                                          marker='s', markersize=10, 
    520526                                          color=self.color, alpha=0.6, 
    521527                                          label="pick",  
    522528                                          visible=True)[0] 
    523             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    524             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    525              
    526         self.line = self.axes.plot([x1,x2],[y1,y2], 
     529            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
     530            message += " OF MATPLOTLIB\n Get the SVN version that is at" 
     531            message += " least as recent as June 1, 2007" 
     532        self.line = self.axes.plot([x1, x2], [y1, y2], 
    527533                                      linestyle='-', marker='', 
    528                                       color=self.color, 
    529                                       visible=True)[0] 
     534                                      color=self.color, visible=True)[0] 
    530535        self.npts = 20 
    531         self.has_move=False 
     536        self.has_move = False 
    532537        self.connect_markers([self.inner_marker, self.line]) 
    533538        self.update() 
     
    556561        """ 
    557562        
    558         if theta !=None: 
    559             self.theta= theta 
    560         x1= self.radius*math.cos(self.theta) 
    561         y1= self.radius*math.sin(self.theta) 
    562         x2= -1*self.radius*math.cos(self.theta) 
    563         y2= -1*self.radius*math.sin(self.theta) 
    564          
    565         self.inner_marker.set(xdata=[x1/2.5],ydata=[y1/2.5]) 
    566         self.line.set(xdata=[x1,x2], ydata=[y1,y2])   
     563        if theta != None: 
     564            self.theta = theta 
     565        x1 = self.radius * math.cos(self.theta) 
     566        y1 = self.radius * math.sin(self.theta) 
     567        x2 = -1 * self.radius * math.cos(self.theta) 
     568        y2 = -1 * self.radius * math.sin(self.theta) 
     569         
     570        self.inner_marker.set(xdata=[x1/2.5], ydata=[y1/2.5]) 
     571        self.line.set(xdata=[x1, x2], ydata=[y1, y2])   
    567572     
    568573    def save(self, ev): 
     
    577582        """ 
    578583        """ 
    579         self.has_move=False 
     584        self.has_move = False 
    580585        self.base.moveend(ev) 
    581586             
     
    590595        Process move to a new position, making sure that the move is allowed. 
    591596        """ 
    592         self.theta= math.atan2(y,x) 
    593         self.has_move=True 
     597        self.theta = math.atan2(y, x) 
     598        self.has_move = True 
    594599        self.base.base.update() 
    595600         
  • guiframe/local_perspectives/plotting/SlicerParameters.py

    rd955bf19 r32c0841  
    33import wx 
    44import wx.lib.newevent 
    5 from copy import deepcopy 
     5#from copy import deepcopy 
     6from sans.guicomm.events import EVT_SLICER_PARS 
     7from sans.guiframe.utils import format_number 
     8from sans.guicomm.events import EVT_SLICER 
     9from sans.guicomm.events import SlicerParameterEvent 
    610 
    7 from sans.guiframe.utils import format_number 
    8 from sans.guicomm.events import EVT_SLICER,EVT_SLICER_PARS,SlicerParameterEvent 
    911 
    1012class SlicerParameterPanel(wx.Dialog): 
     
    2628        self.listeners = [] 
    2729        self.parameters = [] 
    28         self.bck = wx.GridBagSizer(5,5) 
     30        self.bck = wx.GridBagSizer(5, 5) 
    2931        self.SetSizer(self.bck) 
    30                 
    31         title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 
    32         self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    33          
     32        label = "Right-click on 2D plot for slicer options" 
     33        title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 
     34        self.bck.Add(title, (0, 0), (1, 2), 
     35                     flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    3436        # Bindings 
    3537        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) 
     
    4446        """ 
    4547        event.Skip() 
    46         if event.obj_class==None: 
     48        if event.obj_class == None: 
    4749            self.set_slicer(None, None) 
    4850        else: 
     
    5557        self.bck.Clear(True)   
    5658        self.type = type   
    57          
    58         if type==None: 
    59             title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 
    60             self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    61  
     59        if type == None: 
     60            label = "Right-click on 2D plot for slicer options" 
     61            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 
     62            self.bck.Add(title, (0, 0), (1, 2),  
     63                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    6264        else: 
    63             title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT) 
    64             self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
     65            title = wx.StaticText(self, -1,  
     66                                  "Slicer Parameters", style=wx.ALIGN_LEFT) 
     67            self.bck.Add(title, (0, 0), (1, 2), 
     68                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    6569            ix = 0 
    6670            iy = 0 
     
    6872            keys = params.keys() 
    6973            keys.sort() 
    70              
    7174            for item in keys: 
    7275                iy += 1 
    7376                ix = 0 
    74                 if not item in ["count","errors"]: 
    75                      
     77                if not item in ["count", "errors"]: 
    7678                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 
    77                     self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    78                     ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 
    79                      
    80                     ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 
    81                      
     79                    self.bck.Add(text, (iy, ix), (1, 1),  
     80                                 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     81                    ctl = wx.TextCtrl(self, -1, size=(80, 20), 
     82                                      style=wx.TE_PROCESS_ENTER) 
     83                    hint_msg = "Modify the value of %s to change" 
     84                    hint_msg += " the 2D slicer" % item 
     85                    ctl.SetToolTipString(hint_msg) 
    8286                    ix = 1 
    8387                    ctl.SetValue(format_number(str(params[item]))) 
     
    8589                    ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 
    8690                    self.parameters.append([item, ctl]) 
    87                     self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    88                      
    89                     ix =3 
    90                     self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     91                    self.bck.Add(ctl, (iy, ix), (1, 1),  
     92                                 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     93                    ix = 3 
     94                    self.bck.Add((20, 20), (iy, ix), (1, 1),  
     95                                 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    9196                else: 
    92                     text = wx.StaticText(self, -1, item+ " : ", style=wx.ALIGN_LEFT) 
    93                     self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    94                     ctl =wx.StaticText(self, -1, format_number(str(params[item])), style=wx.ALIGN_LEFT) 
    95                     ix =1 
    96                     self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    97             iy +=1 
     97                    text = wx.StaticText(self, -1, item + " : ",  
     98                                         style=wx.ALIGN_LEFT) 
     99                    self.bck.Add(text, (iy, ix), (1, 1),  
     100                                 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     101                    ctl = wx.StaticText(self, -1,  
     102                                    format_number(str(params[item])),  
     103                                    style=wx.ALIGN_LEFT) 
     104                    ix = 1 
     105                    self.bck.Add(ctl, (iy, ix), (1, 1),  
     106                                 wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     107            iy += 1 
    98108            ix = 1 
    99             self.bck.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     109            self.bck.Add((20, 20), (iy, ix), (1, 1),  
     110                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    100111        self.bck.Layout() 
    101112        self.bck.Fit(self) 
     
    111122            for item in self.parameters:               
    112123                if item[0] in evt.params: 
    113                     item[1].SetValue("%-5.3g" %evt.params[item[0]]) 
     124                    item[1].SetValue("%-5.3g" % evt.params[item[0]]) 
    114125                    item[1].Refresh() 
    115126         
     
    131142                item[1].Refresh() 
    132143 
    133         if has_error==False: 
     144        if has_error == False: 
    134145            # Post parameter event 
    135146            ##parent hier is plotter2D 
  • guiframe/local_perspectives/plotting/binder.py

    r83f4445 r32c0841  
    1010    # TODO: without imposing structure on prop. 
    1111         
    12     artist=None 
    13     prop={} 
    14     def __init__(self,artist=None,prop={}): 
    15         self.artist,self.prop = artist,self.prop 
    16     def __eq__(self,other): 
     12    artist = None 
     13    prop = {} 
     14    def __init__(self, artist=None, prop={}): 
     15        self.artist, self.prop = artist, self.prop 
     16         
     17    def __eq__(self, other): 
    1718        return self.artist is other.artist 
    18     def __ne__(self,other): 
     19     
     20    def __ne__(self, other): 
    1921        return self.artist is not other.artist 
     22     
    2023    def __nonzero__(self): 
    2124        return self.artist is not None 
     
    2831    # TODO: is no way to recognized whether shift is held down when the mouse 
    2932    # TODO: first clicks on the the application window. 
    30     control,shift,alt,meta=False,False,False,False 
     33    control, shift, alt, meta = False, False, False, False 
    3134 
    3235    # Track doubleclick 
     
    3538     
    3639    # Mouse/keyboard events we can bind to 
    37     events= ['enter','leave','motion','click','dclick','drag','release', 
    38              'scroll','key','keyup'] 
     40    events = ['enter', 'leave', 'motion', 'click', 'dclick', 'drag', 'release', 
     41             'scroll', 'key', 'keyup'] 
    3942    # TODO: Need our own event structure 
    40      
    41     def __init__(self,figure): 
     43    def __init__(self, figure): 
    4244        canvas = figure.canvas 
    43  
    4445        # Link to keyboard/mouse 
    4546        try: 
    4647            self._connections = [ 
    47                 canvas.mpl_connect('motion_notify_event',self._onMotion), 
    48                 canvas.mpl_connect('button_press_event',self._onClick), 
    49                 canvas.mpl_connect('button_release_event',self._onRelease), 
    50                 canvas.mpl_connect('key_press_event',self._onKey), 
    51                 canvas.mpl_connect('key_release_event',self._onKeyRelease), 
    52                 canvas.mpl_connect('scroll_event',self._onScroll) 
     48                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     49                canvas.mpl_connect('button_press_event', self._onClick), 
     50                canvas.mpl_connect('button_release_event', self._onRelease), 
     51                canvas.mpl_connect('key_press_event', self._onKey), 
     52                canvas.mpl_connect('key_release_event', self._onKeyRelease), 
     53                canvas.mpl_connect('scroll_event', self._onScroll) 
    5354            ] 
    5455        except: 
    55             print "bypassing scroll_event: wrong matplotlib version" 
     56            #print "bypassing scroll_event: wrong matplotlib version" 
    5657            self._connections = [ 
    57                 canvas.mpl_connect('motion_notify_event',self._onMotion), 
    58                 canvas.mpl_connect('button_press_event',self._onClick), 
    59                 canvas.mpl_connect('button_release_event',self._onRelease), 
    60                 canvas.mpl_connect('key_press_event',self._onKey), 
    61                 canvas.mpl_connect('key_release_event',self._onKeyRelease), 
     58                canvas.mpl_connect('motion_notify_event', self._onMotion), 
     59                canvas.mpl_connect('button_press_event', self._onClick), 
     60                canvas.mpl_connect('button_release_event', self._onRelease), 
     61                canvas.mpl_connect('key_press_event', self._onKey), 
     62                canvas.mpl_connect('key_release_event', self._onKeyRelease), 
    6263            ] 
    63              
    64  
    6564        # Turn off picker if it hasn't already been done 
    6665        try: 
     
    6968        except:  
    7069            pass 
    71          
    7270        self.canvas = canvas 
    7371        self.figure = figure 
     
    8280         
    8381        """ 
    84  
    8582        for h in artists: 
    8683            for a in self.events: 
    87                 if h in self._actions[a]: del self._actions[a][h] 
    88             if h in self._artists: self._artists.remove(h) 
    89         if self._current.artist in artists: self._current = Selection() 
    90         if self._hasclick.artist in artists: self._hasclick = Selection() 
    91         if self._haskey.artist in artists: self._haskey = Selection() 
     84                if h in self._actions[a]: 
     85                    del self._actions[a][h] 
     86            if h in self._artists: 
     87                self._artists.remove(h) 
     88        if self._current.artist in artists: 
     89            self._current = Selection() 
     90        if self._hasclick.artist in artists: 
     91            self._hasclick = Selection() 
     92        if self._haskey.artist in artists: 
     93            self._haskey = Selection() 
    9294         
    9395    def clearall(self): 
     
    101103        for action in self.events: 
    102104            self._actions[action] = {} 
    103  
    104105        # Need activity state 
    105106        self._artists = [] 
     
    113114        """ 
    114115        try:  
    115             for cid in self._connections: self.canvas.mpl_disconnect(cid) 
     116            for cid in self._connections: 
     117                self.canvas.mpl_disconnect(cid) 
    116118        except:  
    117119            pass 
     
    121123        self.disconnect() 
    122124 
    123     def __call__(self,trigger,artist,action): 
     125    def __call__(self, trigger, artist, action): 
    124126        """Register a callback for an artist to a particular trigger event. 
    125127         
     
    173175        :TODO: Attach multiple callbacks to the same event? 
    174176        :TODO: Clean up interaction with toolbar modes 
    175         :TODO: push/pushclear/pop context so that binding changes for the duration 
     177        :TODO: push/pushclear/pop context so that binding changes  
     178            for the duration 
    176179        :TODO:   e.g., to support ? context sensitive help 
    177180         
     
    179182        # Check that the trigger is valid 
    180183        if trigger not in self._actions: 
    181             raise ValueError,"%s invalid --- valid triggers are %s"\ 
    182                 %(trigger,", ".join(self.events)) 
    183  
     184            raise ValueError, "%s invalid --- valid triggers are %s" \ 
     185                % (trigger, ", ".join(self.events)) 
    184186        # Register the trigger callback 
    185         self._actions[trigger][artist]=action 
    186         #print "==> added",artist,[artist],"to",trigger,":",self._actions[trigger].keys() 
    187  
     187        self._actions[trigger][artist] = action 
     188        #print "==> added",artist,[artist],"to",trigger,":", 
     189        #self._actions[trigger].keys() 
    188190        # Maintain a list of all artists 
    189191        if artist not in self._artists:  
    190192            self._artists.append(artist) 
    191193 
    192     def trigger(self,actor,action,ev): 
     194    def trigger(self, actor, action, ev): 
    193195        """ 
    194196        Trigger a particular event for the artist.  Fallback to axes, 
     
    196198        """ 
    197199        if action not in self.events: 
    198             raise ValueError, "Trigger expects "+", ".join(self.events) 
    199          
     200            raise ValueError, "Trigger expects " + ", ".join(self.events) 
    200201        # Tag the event with modifiers 
    201         for mod in ('alt','control','shift','meta'): 
    202             setattr(ev,mod,getattr(self,mod)) 
    203         setattr(ev,'artist',None) 
    204         setattr(ev,'action',action) 
    205         setattr(ev,'prop',{}) 
    206          
    207         # Fallback scheme.  If the event does not return false, pass to parent. 
     202        for mod in ('alt', 'control', 'shift', 'meta'): 
     203            setattr(ev, mod, getattr(self, mod)) 
     204        setattr(ev, 'artist', None) 
     205        setattr(ev, 'action', action) 
     206        setattr(ev, 'prop', {}) 
     207        # Fallback scheme. If the event does not return false, pass to parent. 
    208208        processed = False 
    209         artist,prop = actor.artist,actor.prop 
     209        artist, prop = actor.artist, actor.prop 
    210210        if artist in self._actions[action]: 
    211             ev.artist,ev.prop = artist,prop 
     211            ev.artist, ev.prop = artist, prop 
    212212            processed = self._actions[action][artist](ev) 
    213213        if not processed and ev.inaxes in self._actions[action]: 
    214             ev.artist,ev.prop = ev.inaxes,{} 
     214            ev.artist, ev.prop = ev.inaxes, {} 
    215215            processed = self._actions[action][ev.inaxes](ev) 
    216216        if not processed and self.figure in self._actions[action]: 
    217             ev.artist,ev.prop = self.figure,{} 
     217            ev.artist, ev.prop = self.figure, {} 
    218218            processed = self._actions[action][self.figure](ev) 
    219219        if not processed and 'all' in self._actions[action]: 
    220             ev.artist,ev.prop = None,{} 
     220            ev.artist, ev.prop = None, {} 
    221221            processed = self._actions[action]['all'](ev) 
    222222        return processed 
     
    228228        """ 
    229229        # TODO: sort by zorder of axes then by zorder within axes 
    230         self._artists.sort(cmp=lambda x,y: cmp(y.zorder,x.zorder)) 
     230        self._artists.sort(cmp=lambda x, y: cmp(y.zorder, x.zorder)) 
    231231        # print "search"," ".join([str(h) for h in self._artists]) 
    232232        found = Selection() 
     
    243243                inside = False 
    244244            if inside: 
    245                 found.artist,found.prop = artist,prop 
     245                found.artist, found.prop = artist, prop 
    246246                break 
    247247        #print "found",found.artist 
     
    249249        # TODO: how to check if prop is equal? 
    250250        if found != self._current: 
    251             self.trigger(self._current,'leave',event) 
    252             self.trigger(found,'enter',event) 
     251            self.trigger(self._current, 'leave', event) 
     252            self.trigger(found, 'enter', event) 
    253253        self._current = found 
    254  
    255254        return found 
    256255         
    257     def _onMotion(self,event): 
     256    def _onMotion(self, event): 
    258257        """ 
    259258        Track enter/leave/motion through registered artists; all 
     
    271270            transform = self._hasclick.artist.get_transform() 
    272271            #x,y = event.xdata,event.ydata 
    273             x,y = event.x,event.y 
     272            x, y = event.x, event.y 
    274273            try: 
    275                 x,y = transform.inverted().transform_point((x, y)) 
     274                x, y = transform.inverted().transform_point((x, y)) 
    276275 
    277276            except: 
    278                 x,y = transform.inverse_xy_tup((x,y)) 
    279             event.xdata,event.ydata = x,y 
    280             self.trigger(self._hasclick,'drag',event) 
     277                x, y = transform.inverse_xy_tup((x, y)) 
     278            event.xdata, event.ydata = x, y 
     279            self.trigger(self._hasclick, 'drag', event) 
    281280        else: 
    282281            found = self._find_current(event) 
    283282            #print "found",found.artist 
    284             self.trigger(found,'motion',event) 
    285  
    286     def _onClick(self,event): 
     283            self.trigger(found, 'motion', event) 
     284 
     285    def _onClick(self, event): 
    287286        """ 
    288287        Process button click 
     
    322321        # recommendation is that users should define click if they have 
    323322        # drag or release on the artist. 
    324         self.trigger(found,action,event) 
     323        self.trigger(found, action, event) 
    325324        self._hasclick = found 
    326325 
    327     def _onDClick(self,event): 
     326    def _onDClick(self, event): 
    328327        """ 
    329328        Process button double click 
     
    338337        else: 
    339338            found = self._find_current(event) 
    340         self.trigger(found,'dclick',event) 
     339        self.trigger(found, 'dclick', event) 
    341340        self._hasclick = found 
    342341 
    343     def _onRelease(self,event): 
     342    def _onRelease(self, event): 
    344343        """ 
    345344        Process release release 
    346345        """ 
    347         self.trigger(self._hasclick,'release',event) 
     346        self.trigger(self._hasclick, 'release', event) 
    348347        self._hasclick = Selection() 
    349348             
    350     def _onKey(self,event): 
     349    def _onKey(self, event): 
    351350        """ 
    352351        Process key click 
     
    359358        # TODO: architecture a la Tk? 
    360359        # TODO: Do modifiers cause a grab?  Does the artist see the modifiers? 
    361         if event.key in ('alt','meta','control','shift'): 
    362             setattr(self,event.key,True) 
     360        if event.key in ('alt', 'meta', 'control', 'shift'): 
     361            setattr(self, event.key, True) 
    363362            return 
    364363 
     
    367366        else: 
    368367            found = self._find_current(event) 
    369         self.trigger(found,'key',event) 
     368        self.trigger(found, 'key', event) 
    370369        self._haskey = found 
    371370     
    372     def _onKeyRelease(self,event): 
     371    def _onKeyRelease(self, event): 
    373372        """ 
    374373        Process key release 
    375374        """ 
    376         if event.key in ('alt','meta','control','shift'): 
    377             setattr(self,event.key,False) 
     375        if event.key in ('alt', 'meta', 'control', 'shift'): 
     376            setattr(self, event.key, False) 
    378377            return 
    379          
    380378        if self._haskey: 
    381             self.trigger(self._haskey,'keyup',event) 
     379            self.trigger(self._haskey, 'keyup', event) 
    382380        self._haskey = Selection() 
    383381 
    384     def _onScroll(self,event): 
     382    def _onScroll(self, event): 
    385383        """ 
    386384        Process scroll event 
    387385        """ 
    388386        found = self._find_current(event) 
    389         self.trigger(found,'scroll',event) 
    390  
     387        self.trigger(found, 'scroll', event) 
     388 
  • guiframe/local_perspectives/plotting/boxMask.py

    r83f4445 r32c0841  
    33 
    44import math 
    5 import wx 
    6 from copy import deepcopy 
     5#import wx 
     6#from copy import deepcopy 
    77from BaseInteractor import _BaseInteractor 
    8 from boxSum import PointInteractor,VerticalDoubleLine,HorizontalDoubleLine 
    9 from sans.guicomm.events import SlicerParamUpdateEvent 
     8from boxSum import PointInteractor 
     9from boxSum import VerticalDoubleLine 
     10from boxSum import HorizontalDoubleLine 
     11#from sans.guicomm.events import SlicerParamUpdateEvent 
    1012 
    1113 
     
    2426 
    2527    """ 
    26     def __init__(self,base,axes,color='black', zorder=3, side=None,  
     28    def __init__(self, base, axes, color='black', zorder=3, side=None,  
    2729                   x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 
    28          
     30        """ 
     31        """ 
    2932        _BaseInteractor.__init__(self, base, axes, color=color) 
    3033        ## class initialization 
     
    3538        ## connect the artist for the motion 
    3639        self.connect = self.base.connect 
    37         ## when qmax is reached the selected line is reset the its previous value 
     40        ## when qmax is reached the selected line is reset  
     41        #the its previous value 
    3842        self.qmax = min(self.base.data.xmax, self.base.data.xmin) 
    3943        ## Define the box limits 
    40         self.xmin= -1* 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 
    41         self.ymin= -1* 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 
    42         
    43         self.xmax= 0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 
    44         self.ymax=  0.5*min(math.fabs(self.base.data.xmax),math.fabs( self.base.data.xmin)) 
     44        self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 
     45                                 math.fabs(self.base.data.xmin)) 
     46        self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 
     47                                   math.fabs(self.base.data.xmin)) 
     48        self.xmax = 0.5 * min(math.fabs(self.base.data.xmax), 
     49                              math.fabs(self.base.data.xmin)) 
     50        self.ymax =  0.5 * min(math.fabs(self.base.data.xmax), 
     51                               math.fabs(self.base.data.xmin)) 
    4552        ## center of the box 
    46         self.center_x= 0.0002 
    47         self.center_y= 0.0003 
     53        self.center_x = 0.0002 
     54        self.center_y = 0.0003 
    4855        ## Number of points on the plot 
    4956        self.nbins = 20 
    5057        ## Define initial result the summation  
    51         self.count=0 
    52         self.error=0 
     58        self.count = 0 
     59        self.error = 0 
    5360        self.data = self.base.data 
    5461        ## Flag to determine if the current figure has moved 
    5562        ## set to False == no motion , set to True== motion 
    56         self.has_move= False 
     63        self.has_move = False 
    5764        ## Create Box edges  
    58         self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 
     65        self.horizontal_lines = HorizontalDoubleLine(self, 
     66                                                     self.base.subplot, 
     67                                                     color='blue', 
    5968                                                      zorder=zorder, 
    60                                     y= self.ymax, 
    61                                     x= self.xmax, 
    62                                     center_x= self.center_x, 
    63                                     center_y= self.center_y) 
     69                                                      y=self.ymax, 
     70                                                      x=self.xmax, 
     71                                                      center_x=self.center_x, 
     72                                                      center_y=self.center_y) 
    6473        self.horizontal_lines.qmax = self.qmax 
    6574         
    66         self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='grey', 
    67                                                       zorder=zorder, 
    68                                     y= self.ymax, 
    69                                     x= self.xmax, 
    70                                     center_x= self.center_x, 
    71                                     center_y= self.center_y) 
     75        self.vertical_lines = VerticalDoubleLine(self, 
     76                                                self.base.subplot, 
     77                                                color='grey', 
     78                                                zorder=zorder, 
     79                                                y=self.ymax, 
     80                                                x=self.xmax, 
     81                                                center_x=self.center_x, 
     82                                                center_y=self.center_y) 
    7283        self.vertical_lines.qmax = self.qmax 
    7384         
    74         self.center= PointInteractor(self, self.base.subplot,color='grey', 
    75                                                       zorder=zorder, 
    76                                     center_x= self.center_x, 
    77                                     center_y= self.center_y) 
     85        self.center = PointInteractor(self, 
     86                                      self.base.subplot,color='grey', 
     87                                    zorder=zorder, 
     88                                    center_x=self.center_x, 
     89                                    center_y=self.center_y) 
    7890        ## Save the name of the slicer panel associate with this slicer  
    79         self.panel_name=""     
     91        self.panel_name = ""     
    8092        ## Update and post slicer parameters   
    8193        self.update() 
    8294        self._post_data() 
    83          
    84          
     95     
    8596    def clear(self): 
    8697        """ 
     
    99110        resetting the widgets. 
    100111        """ 
    101         ## check if the center point has moved and update the figure accordingly  
     112        # check if the center point has moved and update the figure accordingly  
    102113        if self.center.has_move: 
    103114            self.center.update() 
    104             self.horizontal_lines.update( center= self.center) 
    105             self.vertical_lines.update( center= self.center) 
    106         ## check if the horizontal lines have moved and update the figure accordingly     
     115            self.horizontal_lines.update(center=self.center) 
     116            self.vertical_lines.update(center=self.center) 
     117        ## check if the horizontal lines have moved and update 
     118        # the figure accordingly     
    107119        if self.horizontal_lines.has_move: 
    108120            self.horizontal_lines.update() 
    109121            self.vertical_lines.update(y1=self.horizontal_lines.y1, 
    110122                                       y2=self.horizontal_lines.y2, 
    111                                        height= self.horizontal_lines.half_height ) 
    112         ## check if the vertical lines have moved and update the figure accordingly     
     123                                       height=self.horizontal_lines.half_height) 
     124        ## check if the vertical lines have moved and update 
     125        # the figure accordingly     
    113126        if self.vertical_lines.has_move: 
    114127            self.vertical_lines.update() 
     
    140153        mask = data.mask 
    141154        ## the region of the summation 
    142         x_min= self.horizontal_lines.x2  
    143         x_max= self.horizontal_lines.x1  
    144         y_min= self.vertical_lines.y2 
    145         y_max= self.vertical_lines.y1 
     155        x_min = self.horizontal_lines.x2  
     156        x_max = self.horizontal_lines.x1  
     157        y_min = self.vertical_lines.y2 
     158        y_max = self.vertical_lines.y1 
    146159        mask = Boxcut(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    147160 
    148161        if self.is_inside: 
    149             out = (mask(data)==False) 
     162            out = (mask(data) == False) 
    150163        else: 
    151164            out = (mask(data)) 
     
    187200        """ 
    188201        params = {} 
    189         params["Width"] = math.fabs(self.vertical_lines.half_width)*2 
    190         params["Height"] = math.fabs(self.horizontal_lines.half_height)*2  
     202        params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 
     203        params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2  
    191204        params["center_x"] = self.center.x 
    192         params["center_y"] =self.center.y 
     205        params["center_y"] = self.center.y 
    193206        return params 
    194207     
     
    209222        """ 
    210223        x_max = math.fabs(params["Width"] )/2 
    211         y_max = math.fabs(params["Height"] )/2 
    212          
    213         self.center_x=params["center_x"]  
    214         self.center_y=params["center_y"] 
     224        y_max = math.fabs(params["Height"])/2 
     225         
     226        self.center_x = params["center_x"]  
     227        self.center_y = params["center_y"] 
    215228        #update the slicer given values of params 
    216         self.center.update(center_x=self.center_x,center_y=self.center_y) 
    217         self.horizontal_lines.update(center= self.center, 
     229        self.center.update(center_x=self.center_x, center_y=self.center_y) 
     230        self.horizontal_lines.update(center=self.center, 
    218231                                     width=x_max, 
    219232                                     height=y_max) 
    220         self.vertical_lines.update(center= self.center, 
     233        self.vertical_lines.update(center=self.center, 
    221234                                    width=x_max, 
    222235                                    height=y_max) 
     
    230243        self.base.thaw_axes() 
    231244 
    232  
    233245    def draw(self): 
    234246        self.base.update() 
     
    236248class inner_BoxMask(BoxMask):    
    237249    def __call__(self):      
    238         self.base.data.mask=(self._post_data()==False) 
    239           
     250        self.base.data.mask = (self._post_data()==False) 
     251       
     252    
  • guiframe/local_perspectives/plotting/boxSlicer.py

    rd955bf19 r32c0841  
    22 
    33import wx 
    4 import copy 
    5 from copy import deepcopy 
     4#import copy 
     5#from copy import deepcopy 
    66import math 
    77import numpy 
    8  
    9 from sans.guicomm.events import NewPlotEvent, StatusEvent,SlicerParameterEvent,EVT_SLICER_PARS 
     8from sans.guicomm.events import NewPlotEvent 
     9from sans.guicomm.events import StatusEvent 
     10from sans.guicomm.events import SlicerParameterEvent 
     11from sans.guicomm.events import EVT_SLICER_PARS 
    1012from BaseInteractor import _BaseInteractor 
    1113from sans.guiframe.dataFitting import Data1D 
    12  
    13 import SlicerParameters 
     14#import SlicerParameters 
    1415 
    1516 
     
    1920    in a rectangle area defined by -x, x ,y, -y 
    2021    """ 
    21     def __init__(self,base,axes,color='black', zorder=3): 
     22    def __init__(self, base, axes, color='black', zorder=3): 
    2223        _BaseInteractor.__init__(self, base, axes, color=color) 
    2324        ## Class initialization 
     
    2728        self.connect = self.base.connect 
    2829        ## determine x y  values 
    29         self.x= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    30         self.y= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin))         
     30        self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 
     31                           math.fabs(self.base.data2D.xmin)) 
     32        self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 
     33                           math.fabs(self.base.data2D.xmin))         
    3134        ## when reach qmax reset the graph 
    32         self.qmax = max(self.base.data2D.xmax,self.base.data2D.xmin, 
    33                         self.base.data2D.ymax,self.base.data2D.ymin )    
     35        self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 
     36                        self.base.data2D.ymax, self.base.data2D.ymin)    
    3437        ## Number of points on the plot 
    3538        self.nbins = 30 
    36         ## If True, I(|Q|) will be return, otherwise, negative q-values are allowed 
     39        ## If True, I(|Q|) will be return, otherwise, 
     40        #negative q-values are allowed 
    3741        self.fold = True         
    3842        ## reference of the current  Slab averaging 
    39         self.averager=None 
     43        self.averager = None 
    4044        ## Create vertical and horizaontal lines for the rectangle 
    41         self.vertical_lines = VerticalLines(self, self.base.subplot,color='blue',  
    42                                       zorder=zorder, 
    43                                         y= self.y , 
    44                                         x= self.x) 
     45        self.vertical_lines = VerticalLines(self, 
     46                                            self.base.subplot,  
     47                                            color='blue',  
     48                                            zorder=zorder, 
     49                                            y=self.y , 
     50                                            x=self.x) 
    4551        self.vertical_lines.qmax = self.qmax 
    4652        
    47         self.horizontal_lines= HorizontalLines(self, self.base.subplot,color='green',  
    48                                       zorder=zorder, 
    49                                       x= self.x, 
    50                                       y= self.y) 
    51         self.horizontal_lines.qmax= self.qmax 
     53        self.horizontal_lines = HorizontalLines(self, 
     54                                               self.base.subplot, 
     55                                               color='green',  
     56                                               zorder=zorder, 
     57                                               x=self.x, 
     58                                               y=self.y) 
     59        self.horizontal_lines.qmax = self.qmax 
    5260        ## draw the rectangle and plost the data 1D resulting 
    5361        ## of averaging data2D 
     
    5765        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    5866 
    59  
    6067    def _onEVT_SLICER_PARS(self, event): 
    6168        """ 
     
    6572            attribute 
    6673        """ 
    67         wx.PostEvent(self.base.parent, StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 
     74        wx.PostEvent(self.base.parent, 
     75                     StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 
    6876        event.Skip() 
    6977        if event.type == self.__class__.__name__: 
    7078            self.set_params(event.params) 
    7179            self.base.update() 
    72  
    73  
     80             
    7481    def update_and_post(self): 
    7582        """ 
     
    93100        Clear the slicer and all connected events related to this slicer 
    94101        """ 
    95         self.averager=None 
     102        self.averager = None 
    96103        self.clear_markers() 
    97104        self.horizontal_lines.clear() 
     
    100107        self.base.Unbind(EVT_SLICER_PARS) 
    101108         
    102          
    103109    def update(self): 
    104110        """ 
     
    110116            self.horizontal_lines.update() 
    111117            self.vertical_lines.update(y=self.horizontal_lines.y) 
    112          
    113118        ##Update the slicer if a vertical line is dragged     
    114119        if self.vertical_lines.has_move: 
     
    128133        pass 
    129134         
    130     def post_data(self,new_slab=None , nbins=None, direction =None): 
     135    def post_data(self, new_slab=None, nbins=None, direction=None): 
    131136        """ 
    132137        post data averaging in Qx or Qy given new_slab type 
     
    137142         
    138143        """ 
    139         x_min= -1*math.fabs(self.vertical_lines.x) 
    140         x_max= math.fabs(self.vertical_lines.x) 
    141          
    142         y_min= -1*math.fabs(self.horizontal_lines.y) 
    143         y_max= math.fabs(self.horizontal_lines.y) 
    144          
    145         if nbins !=None: 
    146             self.nbins 
    147         if self.averager==None: 
    148             if new_slab ==None: 
    149                 raise ValueError,"post data:cannot average , averager is empty" 
    150             self.averager= new_slab 
     144        x_min = -1 * math.fabs(self.vertical_lines.x) 
     145        x_max = math.fabs(self.vertical_lines.x) 
     146        y_min = -1 * math.fabs(self.horizontal_lines.y) 
     147        y_max = math.fabs(self.horizontal_lines.y) 
     148         
     149        if nbins != None: 
     150            self.nbins = nbins 
     151        if self.averager == None: 
     152            if new_slab == None: 
     153                msg = "post data:cannot average , averager is empty" 
     154                raise ValueError, msg 
     155            self.averager = new_slab 
    151156        if direction == "X": 
    152             if self.fold: x_low = 0 
    153             else: x_low = math.fabs(x_min) 
    154             bin_width= (x_max + x_low)/self.nbins 
     157            if self.fold: 
     158                x_low = 0 
     159            else: 
     160                x_low = math.fabs(x_min) 
     161            bin_width = (x_max + x_low)/self.nbins 
    155162        else: 
    156             if self.fold: y_low = 0 
    157             else: y_low = math.fabs(y_min) 
    158             bin_width= (y_max + y_low)/self.nbins 
     163            if self.fold: 
     164                y_low = 0 
     165            else: 
     166                y_low = math.fabs(y_min) 
     167            bin_width = (y_max + y_low)/self.nbins 
    159168        ## Average data2D given Qx or Qy 
    160         box = self.averager( x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 
     169        box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 
    161170                         bin_width=bin_width) 
    162171        box.fold = self.fold 
    163172        boxavg = box(self.base.data2D) 
    164173        #3 Create Data1D to plot 
    165          
    166         if hasattr(boxavg,"dxl"): 
    167             dxl= boxavg.dxl 
     174        if hasattr(boxavg, "dxl"): 
     175            dxl = boxavg.dxl 
    168176        else: 
    169             dxl= None 
    170         if hasattr(boxavg,"dxw"): 
    171             dxw=boxavg.dxw 
     177            dxl = None 
     178        if hasattr(boxavg, "dxw"): 
     179            dxw = boxavg.dxw 
    172180        else: 
    173             dxw= None 
    174         
    175         new_plot = Data1D(x=boxavg.x,y=boxavg.y,dy=boxavg.dy) 
     181            dxw = None 
     182        new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 
    176183        new_plot.dxl  = dxl 
    177184        new_plot.dxw  = dxw 
    178         new_plot.name = str(self.averager.__name__) +"("+ self.base.data2D.name+")" 
    179          
    180         new_plot.source=self.base.data2D.source 
     185        new_plot.name = str(self.averager.__name__) + \ 
     186                        "(" + self.base.data2D.name + ")" 
     187        new_plot.source = self.base.data2D.source 
    181188        new_plot.interactive = True 
    182         new_plot.detector =self.base.data2D.detector 
     189        new_plot.detector = self.base.data2D.detector 
    183190        # If the data file does not tell us what the axes are, just assume... 
    184191        new_plot.xaxis("\\rm{Q}", '\\AA^{-1}') 
    185192        new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 
    186         new_plot.group_id = str(self.averager.__name__)+self.base.data2D.name 
     193        new_plot.group_id = str(self.averager.__name__) + self.base.data2D.name 
    187194        new_plot.id = str(self.averager.__name__) 
    188195        #new_plot.is_data= True 
    189          
    190196        wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    191                                                  title=str(self.averager.__name__) )) 
     197                                title=str(self.averager.__name__))) 
    192198           
    193199    def moveend(self, ev): 
     
    230236        """ 
    231237        params = {} 
    232         params["x_max"]= math.fabs(self.vertical_lines.x) 
    233         params["y_max"]= math.fabs(self.horizontal_lines.y) 
    234         params["nbins"]= self.nbins 
     238        params["x_max"] = math.fabs(self.vertical_lines.x) 
     239        params["y_max"] = math.fabs(self.horizontal_lines.y) 
     240        params["nbins"] = self.nbins 
    235241        return params 
    236242     
     
    245251        self.x = float(math.fabs(params["x_max"])) 
    246252        self.y = float(math.fabs(params["y_max"] )) 
    247         self.nbins=params["nbins"] 
    248          
    249         self.horizontal_lines.update(x= self.x, y=  self.y) 
    250         self.vertical_lines.update(x= self.x, y=  self.y) 
    251         self.post_data( nbins=None) 
     253        self.nbins = params["nbins"] 
     254         
     255        self.horizontal_lines.update(x=self.x, y=self.y) 
     256        self.vertical_lines.update(x=self.x, y=self.y) 
     257        self.post_data(nbins=None) 
    252258         
    253259    def freeze_axes(self): 
     
    272278    on the x- direction and in opposite direction 
    273279    """ 
    274     def __init__(self,base,axes,color='black', zorder=5,x=0.5, y=0.5): 
    275          
     280    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): 
     281        """ 
     282        """ 
    276283        _BaseInteractor.__init__(self, base, axes, color=color) 
    277284        ##Class initialization 
     
    279286        self.axes = axes 
    280287        ## Saving the end points of two lines 
    281         self.x= x 
    282         self.save_x= x 
    283          
    284         self.y= y 
    285         self.save_y= y 
     288        self.x = x 
     289        self.save_x = x 
     290         
     291        self.y = y 
     292        self.save_y = y 
    286293        ## Creating a marker 
    287294        try: 
    288295            # Inner circle marker 
    289             self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 
     296            self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    290297                                          marker='s', markersize=10, 
    291298                                          color=self.color, alpha=0.6, 
    292299                                          pickradius=5, label="pick",  
    293                                           zorder=zorder, # Prefer this to other lines 
     300                                          # Prefer this to other lines 
     301                                          zorder=zorder,  
    294302                                          visible=True)[0] 
    295303        except: 
    296             self.inner_marker = self.axes.plot([0],[self.y], linestyle='', 
     304            self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    297305                                          marker='s', markersize=10, 
    298306                                          color=self.color, alpha=0.6, 
    299                                           label="pick",  
    300                                           visible=True)[0] 
    301             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    302             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    303             owner=self.base.base.parent 
    304             wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
    305              
     307                                          label="pick", visible=True)[0] 
     308            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 
     309            message += "OF MATPLOTLIB\n Get the SVN version that" 
     310            message += " is at least as recent as June 1, 2007" 
     311            owner = self.base.base.parent 
     312            wx.PostEvent(owner, 
     313                         StatusEvent(status="AnnulusSlicer: %s" % message)) 
    306314        ## Define 2 horizontal lines 
    307         self.top_line = self.axes.plot([self.x,-self.x], 
    308                                    [self.y,self.y], 
     315        self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 
    309316                                      linestyle='-', marker='', 
    310                                       color=self.color, 
    311                                       visible=True)[0] 
    312         self.bottom_line = self.axes.plot([self.x,-self.x], 
    313                                    [-self.y,-self.y], 
     317                                      color=self.color, visible=True)[0] 
     318        self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 
    314319                                      linestyle='-', marker='', 
    315                                       color=self.color, 
    316                                       visible=True)[0] 
     320                                      color=self.color, visible=True)[0] 
    317321        ## Flag to check the motion of the lines 
    318         self.has_move=False 
     322        self.has_move = False 
    319323        ## Connecting markers to mouse events and draw 
    320324        self.connect_markers([self.top_line, self.inner_marker]) 
    321325        self.update() 
    322  
    323326 
    324327    def set_layer(self, n): 
     
    346349                del self.axes.lines[0] 
    347350    
    348     def update(self,x=None,y=None): 
     351    def update(self, x=None, y=None): 
    349352        """ 
    350353        Draw the new roughness on the graph. 
     
    355358        """ 
    356359        ## Reset x, y- coordinates if send as parameters 
    357         if x!=None: 
    358             self.x = numpy.sign(self.x)*math.fabs(x) 
    359         if y !=None: 
    360             self.y = numpy.sign(self.y)*math.fabs(y) 
     360        if x != None: 
     361            self.x = numpy.sign(self.x) * math.fabs(x) 
     362        if y != None: 
     363            self.y = numpy.sign(self.y) * math.fabs(y) 
    361364        ## Draw lines and markers 
    362         self.inner_marker.set(xdata=[0],ydata=[self.y]) 
    363         self.top_line.set(xdata=[self.x,-self.x], 
    364                        ydata=[self.y,self.y]) 
    365         self.bottom_line.set(xdata=[self.x,-self.x], 
    366                        ydata=[-self.y, -self.y]) 
     365        self.inner_marker.set(xdata=[0], ydata=[self.y]) 
     366        self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 
     367        self.bottom_line.set(xdata=[self.x,-self.x], ydata=[-self.y, -self.y]) 
    367368         
    368369    def save(self, ev): 
     
    371372        can restore on Esc. 
    372373        """ 
    373         self.save_x= self.x 
    374         self.save_y= self.y 
     374        self.save_x = self.x 
     375        self.save_y = self.y 
    375376        self.base.freeze_axes() 
    376377 
     
    380381        to specify the end of dragging motion 
    381382        """ 
    382         self.has_move=False 
     383        self.has_move = False 
    383384        self.base.moveend(ev) 
    384385              
     
    394395        Process move to a new position, making sure that the move is allowed. 
    395396        """ 
    396         self.y= y 
    397         self.has_move=True 
     397        self.y = y 
     398        self.has_move = True 
    398399        self.base.base.update() 
    399400         
     
    403404    Select an annulus through a 2D plot 
    404405    """ 
    405     def __init__(self,base,axes,color='black',zorder=5,x=0.5, y=0.5): 
    406          
     406    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5): 
     407        """ 
     408        """ 
    407409        _BaseInteractor.__init__(self, base, axes, color=color) 
    408410        self.markers = [] 
    409411        self.axes = axes 
    410          
    411         self.x= math.fabs(x) 
    412         self.save_x= self.x 
    413         self.y= math.fabs(y) 
    414         self.save_y= y 
    415          
     412        self.x = math.fabs(x) 
     413        self.save_x = self.x 
     414        self.y = math.fabs(y) 
     415        self.save_y = y 
    416416        try: 
    417417            # Inner circle marker 
    418             self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 
     418            self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    419419                                          marker='s', markersize=10, 
    420420                                          color=self.color, alpha=0.6, 
    421421                                          pickradius=5, label="pick",  
    422                                           zorder=zorder, # Prefer this to other lines 
    423                                           visible=True)[0] 
     422                                          # Prefer this to other lines 
     423                                          zorder=zorder, visible=True)[0] 
    424424        except: 
    425             self.inner_marker = self.axes.plot([self.x],[0], linestyle='', 
     425            self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    426426                                          marker='s', markersize=10, 
    427427                                          color=self.color, alpha=0.6, 
    428                                           label="pick",  
    429                                           visible=True)[0] 
    430             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    431             message += "Get the SVN version that is at least as recent as June 1, 2007" 
     428                                          label="pick", visible=True)[0] 
     429            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
     430            message += " OF MATPLOTLIB\n Get the SVN version that is" 
     431            message += " at least as recent as June 1, 2007" 
    432432             
    433         self.right_line = self.axes.plot([self.x,self.x],[self.y,-self.y], 
     433        self.right_line = self.axes.plot([self.x, self.x], 
     434                                         [self.y , -self.y], 
    434435                                      linestyle='-', marker='', 
    435                                       color=self.color, 
    436                                       visible=True)[0] 
    437         self.left_line = self.axes.plot([-self.x,-self.x],[self.y,-self.y], 
     436                                      color=self.color, visible=True)[0] 
     437        self.left_line = self.axes.plot([-self.x, -self.x], 
     438                                        [self.y, -self.y], 
    438439                                      linestyle='-', marker='', 
    439                                       color=self.color, 
    440                                       visible=True)[0] 
    441        
    442         self.has_move=False 
     440                                      color=self.color, visible=True)[0] 
     441        self.has_move = False 
    443442        self.connect_markers([self.right_line, self.inner_marker]) 
    444443        self.update() 
    445  
    446444 
    447445    def set_layer(self, n): 
     
    469467                del self.axes.lines[0] 
    470468 
    471     def update(self,x=None,y=None): 
     469    def update(self, x=None, y=None): 
    472470        """ 
    473471        Draw the new roughness on the graph. 
     
    478476        """ 
    479477        ## reset x, y -coordinates if given as parameters 
    480         if x!=None: 
    481             self.x = numpy.sign(self.x)*math.fabs(x) 
    482         if y !=None: 
    483             self.y = numpy.sign(self.y)*math.fabs(y) 
     478        if x != None: 
     479            self.x = numpy.sign(self.x) * math.fabs(x) 
     480        if y != None: 
     481            self.y = numpy.sign(self.y) * math.fabs(y) 
    484482        ## draw lines and markers   
    485         self.inner_marker.set(xdata=[self.x],ydata=[0])  
    486         self.left_line.set(xdata=[-self.x,-self.x], 
    487                        ydata=[self.y,-self.y])  
    488         self.right_line.set(xdata=[self.x,self.x], 
    489                        ydata=[self.y,-self.y])  
     483        self.inner_marker.set(xdata=[self.x], ydata=[0])  
     484        self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y])  
     485        self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y])  
    490486     
    491487    def save(self, ev): 
     
    503499        to specify the end of dragging motion 
    504500        """ 
    505         self.has_move=False 
     501        self.has_move = False 
    506502        self.base.moveend(ev) 
    507503                
     
    517513        Process move to a new position, making sure that the move is allowed. 
    518514        """ 
    519         self.has_move=True 
    520         self.x= x 
     515        self.has_move = True 
     516        self.x = x 
    521517        self.base.base.update() 
    522518         
     
    526522    Average in Qx direction 
    527523    """ 
    528     def __init__(self,base,axes,color='black', zorder=3): 
     524    def __init__(self, base, axes, color='black', zorder=3): 
    529525        BoxInteractor.__init__(self, base, axes, color=color) 
    530         self.base=base 
     526        self.base = base 
    531527        self._post_data() 
    532528         
    533          
    534529    def _post_data(self): 
    535530        """ 
     
    537532        """ 
    538533        from DataLoader.manipulations import SlabX 
    539         self.post_data(SlabX, direction ="X")    
     534        self.post_data(SlabX, direction="X")    
    540535         
    541536 
     
    544539    Average in Qy direction 
    545540    """ 
    546     def __init__(self,base,axes,color='black', zorder=3): 
     541    def __init__(self, base, axes, color='black', zorder=3): 
    547542        BoxInteractor.__init__(self, base, axes, color=color) 
    548         self.base=base 
     543        self.base = base 
    549544        self._post_data() 
    550545         
     
    554549        """ 
    555550        from DataLoader.manipulations import SlabY 
    556         self.post_data(SlabY, direction ="Y")    
    557          
    558          
     551        self.post_data(SlabY, direction="Y")    
     552         
     553         
  • guiframe/local_perspectives/plotting/boxSum.py

    r6c0568b r32c0841  
    66from copy import deepcopy 
    77from BaseInteractor import _BaseInteractor 
    8 from sans.guicomm.events import SlicerParamUpdateEvent,EVT_SLICER_PARS,StatusEvent 
     8from sans.guicomm.events import SlicerParamUpdateEvent 
     9from sans.guicomm.events import EVT_SLICER_PARS 
     10from sans.guicomm.events import StatusEvent 
    911 
    1012 
    1113class BoxSum(_BaseInteractor): 
    1214    """ 
    13         Boxsum Class: determine 2 rectangular area to compute the sum of pixel of 
    14         a Data.  
     15        Boxsum Class: determine 2 rectangular area to compute  
     16        the sum of pixel of a Data.  
    1517        Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
    1618        @param zorder:  Artists with lower zorder values are drawn first. 
     
    2123 
    2224    """ 
    23     def __init__(self,base,axes,color='black', zorder=3, x_min=0.008, 
     25    def __init__(self, base, axes, color='black', zorder=3, x_min=0.008, 
    2426                  x_max=0.008, y_min=0.0025, y_max=0.0025): 
    25          
     27        """ 
     28        """ 
    2629        _BaseInteractor.__init__(self, base, axes, color=color) 
    2730        ## class initialization 
     
    3437        self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 
    3538        ## Define the boxsum limits 
    36         self.xmin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    37         self.ymin= -1* 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    38         
    39         self.xmax= 0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
    40         self.ymax=  0.5*min(math.fabs(self.base.data2D.xmax),math.fabs( self.base.data2D.xmin)) 
     39        self.xmin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
     40                                  math.fabs(self.base.data2D.xmin)) 
     41        self.ymin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
     42                                  math.fabs( elf.base.data2D.xmin)) 
     43        self.xmax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
     44                              math.fabs(self.base.data2D.xmin)) 
     45        self.ymax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
     46                              math.fabs(self.base.data2D.xmin)) 
    4147        ## center of the boxSum 
    42         self.center_x= 0.0002 
    43         self.center_y= 0.0003 
     48        self.center_x = 0.0002 
     49        self.center_y = 0.0003 
    4450        ## Number of points on the plot 
    4551        self.nbins = 20 
    4652        ## Define initial result the summation  
    47         self.count=0 
    48         self.error=0 
     53        self.count = 0 
     54        self.error = 0 
    4955        ## Flag to determine if the current figure has moved 
    5056        ## set to False == no motion , set to True== motion 
    51         self.has_move= False 
     57        self.has_move = False 
    5258        ## Create Boxsum edges  
    53         self.horizontal_lines= HorizontalDoubleLine(self, self.base.subplot,color='blue', 
     59        self.horizontal_lines= HorizontalDoubleLine(self, 
     60                                                    self.base.subplot, 
     61                                                    color='blue', 
    5462                                                      zorder=zorder, 
    55                                     y= self.ymax, 
    56                                     x= self.xmax, 
    57                                     center_x= self.center_x, 
    58                                     center_y= self.center_y) 
     63                                                      y=self.ymax, 
     64                                                      x=self.xmax, 
     65                                                      center_x=self.center_x, 
     66                                                      center_y=self.center_y) 
    5967        self.horizontal_lines.qmax = self.qmax 
    6068         
    61         self.vertical_lines= VerticalDoubleLine(self, self.base.subplot,color='black', 
    62                                                       zorder=zorder, 
    63                                     y= self.ymax, 
    64                                     x= self.xmax, 
    65                                     center_x= self.center_x, 
    66                                     center_y= self.center_y) 
     69        self.vertical_lines= VerticalDoubleLine(self, 
     70                                                self.base.subplot, 
     71                                                color='black', 
     72                                                zorder=zorder, 
     73                                                y=self.ymax, 
     74                                                x=self.xmax, 
     75                                                center_x=self.center_x, 
     76                                                center_y=self.center_y) 
    6777        self.vertical_lines.qmax = self.qmax 
    6878         
    69         self.center= PointInteractor(self, self.base.subplot,color='grey', 
    70                                                       zorder=zorder, 
     79        self.center= PointInteractor(self, 
     80                                     self.base.subplot,color='grey', 
     81                                    zorder=zorder, 
    7182                                    center_x= self.center_x, 
    7283                                    center_y= self.center_y) 
    7384        ## Save the name of the slicer panel associate with this slicer  
    74         self.panel_name=""     
     85        self.panel_name = ""     
    7586        ## Update and post slicer parameters   
    7687        self.update() 
     
    7990        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    8091         
    81          
    8292    def set_panel_name(self, name): 
    8393        """ 
     
    8595            @param name: the name of this panel 
    8696        """ 
    87         self.panel_name= name 
    88          
     97        self.panel_name = name 
    8998         
    9099    def _onEVT_SLICER_PARS(self, event): 
     
    95104        """ 
    96105        ## Post e message to declare what kind of event has being received 
    97         wx.PostEvent(self.base.parent, StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 
     106        wx.PostEvent(self.base.parent, 
     107                     StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 
    98108        event.Skip() 
    99109        ## reset the slicer with the values contains the event.params dictionary 
     
    102112            self.base.update() 
    103113 
    104  
    105114    def set_layer(self, n): 
    106115        """ 
    107              Allow adding plot to the same panel 
    108              @param n: the number of layer 
     116        Allow adding plot to the same panel 
     117        :param n: the number of layer 
    109118        """ 
    110119        self.layernum = n 
    111120        self.update() 
    112121         
    113          
    114122    def clear(self): 
    115123        """ 
    116             Clear the slicer and all connected events related to this slicer 
     124        Clear the slicer and all connected events related to this slicer 
    117125        """ 
    118126        self.clear_markers() 
     
    123131        self.base.Unbind(EVT_SLICER_PARS) 
    124132         
    125          
    126133    def update(self): 
    127134        """ 
    128             Respond to changes in the model by recalculating the profiles and 
    129             resetting the widgets. 
     135        Respond to changes in the model by recalculating the profiles and 
     136        resetting the widgets. 
    130137        """ 
    131138        ## check if the center point has moved and update the figure accordingly  
     
    134141            self.horizontal_lines.update( center= self.center) 
    135142            self.vertical_lines.update( center= self.center) 
    136         ## check if the horizontal lines have moved and update the figure accordingly     
     143        ## check if the horizontal lines have moved and  
     144        #update the figure accordingly     
    137145        if self.horizontal_lines.has_move: 
    138146            self.horizontal_lines.update() 
    139147            self.vertical_lines.update(y1=self.horizontal_lines.y1, 
    140148                                       y2=self.horizontal_lines.y2, 
    141                                        height= self.horizontal_lines.half_height ) 
    142         ## check if the vertical lines have moved and update the figure accordingly     
     149                                       height=self.horizontal_lines.half_height) 
     150        ## check if the vertical lines have moved and  
     151        #update the figure accordingly     
    143152        if self.vertical_lines.has_move: 
    144153            self.vertical_lines.update() 
     
    147156                                         width=self.vertical_lines.half_width) 
    148157             
    149  
    150158    def save(self, ev): 
    151159        """ 
     
    160168    def _post_data(self): 
    161169        """ 
    162             Get the limits of the boxsum and compute the sum of the pixel 
    163             contained in that region and the error on that sum 
     170        Get the limits of the boxsum and compute the sum of the pixel 
     171        contained in that region and the error on that sum 
    164172        """ 
    165173        ## Data 2D for which the pixel will be summed 
    166174        data = self.base.data2D 
    167175        ## the region of the summation 
    168         x_min= self.horizontal_lines.x2  
    169         x_max= self.horizontal_lines.x1  
    170         y_min= self.vertical_lines.y2 
    171         y_max= self.vertical_lines.y1 
     176        x_min = self.horizontal_lines.x2  
     177        x_max = self.horizontal_lines.x1  
     178        y_min = self.vertical_lines.y2 
     179        y_max = self.vertical_lines.y1 
    172180        ##computation of the sum and its error 
    173         from DataLoader.manipulations import  Boxavg 
    174         box =  Boxavg (x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
     181        from DataLoader.manipulations import Boxavg 
     182        box =  Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    175183        self.count, self.error = box(self.base.data2D) 
    176  
    177                            
     184         
    178185    def moveend(self, ev): 
    179186        """ 
     
    186193        ## Create and event ( posted to guiframe)that  set the  
    187194        ##current slicer parameter to a panel of name self.panel_name 
    188         self.type= self.__class__.__name__ 
    189         params= self.get_params() 
    190         event = SlicerParamUpdateEvent(type=self.type, params=params, 
    191                                        panel_name= self.panel_name) 
     195        self.type = self.__class__.__name__ 
     196        params = self.get_params() 
     197        event = SlicerParamUpdateEvent(type=self.type, 
     198                                       params=params, 
     199                                       panel_name=self.panel_name) 
    192200        wx.PostEvent(self.base.parent, event) 
    193201         
    194              
    195202    def restore(self): 
    196203        """ 
     
    201208        self.center.restore() 
    202209         
    203          
    204210    def move(self, x, y, ev): 
    205211        """ 
     
    208214        pass 
    209215     
    210      
    211216    def set_cursor(self, x, y): 
     217        """ 
     218        """ 
    212219        pass 
    213220         
    214          
    215221    def get_params(self): 
    216222        """ 
    217             Store a copy of values of parameters of the slicer into a dictionary. 
    218             @return params: the dictionary created 
     223        Store a copy of values of parameters of the slicer into a dictionary. 
     224        :return params: the dictionary created 
    219225        """ 
    220226        params = {} 
    221         params["Width"] = math.fabs(self.vertical_lines.half_width)*2 
    222         params["Height"] = math.fabs(self.horizontal_lines.half_height)*2  
     227        params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 
     228        params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2  
    223229        params["center_x"] = self.center.x 
    224         params["center_y"] =self.center.y 
     230        params["center_y"] = self.center.y 
    225231        params["count"] = self.count 
    226         params["errors"]= self.error 
     232        params["errors"] = self.error 
    227233        return params 
    228234     
    229      
    230235    def get_result(self): 
    231236        """ 
    232237            return the result of box summation 
    233238        """ 
    234         result={} 
     239        result = {} 
    235240        result["count"] = self.count 
    236241        result["error"] = self.error 
    237242        return result 
    238243         
    239          
    240244    def set_params(self, params): 
    241245        """ 
    242             Receive a dictionary and reset the slicer with values contained  
    243             in the values of the dictionary. 
    244             @param params: a dictionary containing name of slicer parameters and  
     246        Receive a dictionary and reset the slicer with values contained  
     247        in the values of the dictionary. 
     248        :param params: a dictionary containing name of slicer parameters and  
    245249            values the user assigned to the slicer. 
    246250        """ 
     
    248252        y_max = math.fabs(params["Height"] )/2 
    249253         
    250         self.center_x=params["center_x"]  
    251         self.center_y=params["center_y"] 
     254        self.center_x = params["center_x"]  
     255        self.center_y = params["center_y"] 
    252256        #update the slicer given values of params 
    253         self.center.update(center_x=self.center_x,center_y=self.center_y) 
    254         self.horizontal_lines.update(center= self.center, 
    255                                      width=x_max, 
    256                                      height=y_max) 
    257         self.vertical_lines.update(center= self.center, 
    258                                     width=x_max, 
    259                                     height=y_max) 
     257        self.center.update(center_x=self.center_x, center_y=self.center_y) 
     258        self.horizontal_lines.update(center=self.center, 
     259                                     width=x_max, height=y_max) 
     260        self.vertical_lines.update(center=self.center, 
     261                                    width=x_max, height=y_max) 
    260262        #compute the new error and sum given values of params 
    261263        self._post_data() 
    262264         
    263         
    264          
    265265    def freeze_axes(self): 
     266        """ 
     267        """ 
    266268        self.base.freeze_axes() 
    267269         
    268          
    269270    def thaw_axes(self): 
     271        """ 
     272        """ 
    270273        self.base.thaw_axes() 
    271274 
    272  
    273275    def draw(self): 
     276        """ 
     277        """ 
    274278        self.base.draw() 
    275279         
     
    278282class PointInteractor(_BaseInteractor): 
    279283    """ 
    280          Draw a point that can be dragged with the marker. 
    281          this class controls the motion the center of the BoxSum  
     284    Draw a point that can be dragged with the marker. 
     285    this class controls the motion the center of the BoxSum  
    282286    """ 
    283     def __init__(self,base,axes,color='black', zorder=5, 
    284                  center_x= 0.0, 
    285                  center_y= 0.0): 
    286          
     287    def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, 
     288                 center_y=0.0): 
     289        """ 
     290        """ 
    287291        _BaseInteractor.__init__(self, base, axes, color=color) 
    288292        ## Initialization the class  
     
    301305                                          color=self.color, alpha=0.6, 
    302306                                          pickradius=5, label="pick",  
    303                                           zorder=zorder, # Prefer this to other lines 
     307                                          # Prefer this to other lines 
     308                                          zorder=zorder,  
    304309                                          visible=True)[0] 
    305310        except: 
     
    309314                                          label="pick",  
    310315                                          visible=True)[0] 
    311             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    312             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    313             owner=self.base.base.parent 
    314             wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
    315              
     316            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
     317            message += " OF MATPLOTLIB.\n Get the SVN version that is " 
     318            message += "at least as recent as June 1, 2007" 
     319            owner = self.base.base.parent 
     320            wx.PostEvent(owner, 
     321                         StatusEvent(status="AnnulusSlicer: %s" % message)) 
    316322        ## Draw a point 
    317         self.center = self.axes.plot([self.x],[self.y], 
     323        self.center = self.axes.plot([self.x], [self.y], 
    318324                                      linestyle='-', marker='', 
    319325                                      color=self.color, 
    320326                                      visible=True)[0] 
    321327        ## Flag to determine the motion this point  
    322         self.has_move=False    
     328        self.has_move = False    
    323329        ## connecting the marker to allow them to move  
    324330        self.connect_markers([self.center_marker]) 
     
    326332        self.update() 
    327333     
    328      
    329334    def set_layer(self, n): 
    330335        """ 
     
    334339        self.layernum = n 
    335340        self.update() 
    336          
    337341         
    338342    def clear(self): 
     
    349353                del self.axes.lines[0] 
    350354   
    351     
    352355    def update(self, center_x=None,center_y=None): 
    353356        """ 
    354357            Draw the new roughness on the graph. 
    355358        """ 
    356         if center_x !=None: self.x= center_x 
    357         if center_y !=None: self.y= center_y 
    358     
     359        if center_x != None: 
     360            self.x = center_x 
     361        if center_y != None: 
     362            self.y = center_y 
    359363        self.center_marker.set(xdata=[self.x], ydata=[self.y]) 
    360364        self.center.set(xdata=[self.x], ydata=[self.y]) 
    361365         
    362          
    363366    def save(self, ev): 
    364367        """ 
     
    366369        can restore on Esc. 
    367370        """ 
    368         self.save_x= self.x 
    369         self.save_y= self.y 
     371        self.save_x = self.x 
     372        self.save_y = self.y 
    370373        self.base.freeze_axes() 
    371  
    372  
     374         
    373375    def moveend(self, ev): 
    374          
     376        """ 
     377        """ 
    375378        self.has_move=False 
    376379        self.base.moveend(ev) 
     
    380383        Restore the roughness for this layer. 
    381384        """ 
    382         self.y= self.save_y 
    383         self.x= self.save_x 
    384          
    385          
     385        self.y = self.save_y 
     386        self.x = self.save_x 
     387     
    386388    def move(self, x, y, ev): 
    387389        """ 
    388390        Process move to a new position, making sure that the move is allowed. 
    389391        """ 
    390         self.x= x 
    391         self.y= y 
    392         
    393         self.has_move=True 
     392        self.x = x 
     393        self.y = y 
     394        self.has_move = True 
    394395        self.base.base.update() 
    395396         
    396          
    397397    def set_cursor(self, x, y): 
     398        """ 
     399        """ 
    398400        self.move(x, y, None) 
    399401        self.update() 
    400          
    401          
     402     
    402403    def get_params(self): 
     404        """ 
     405        """ 
    403406        params = {} 
    404407        params["x"] = self.x 
     
    406409        return params 
    407410     
    408      
    409411    def set_params(self, params): 
     412        """ 
     413        """ 
    410414        center_x = params["x"]  
    411415        center_y = params["y"]  
    412         self.update(center_x=center_x,center_y=center_y) 
     416        self.update(center_x=center_x, center_y=center_y) 
    413417        
    414418         
     
    418422         a point (PointInteractor) 
    419423    """ 
    420     def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 
    421                  center_x= 0.0, 
    422                  center_y= 0.0): 
    423          
     424    def __init__(self, base, axes, color='black', zorder=5, x=0.5,y=0.5, 
     425                 center_x=0.0, center_y=0.0): 
     426        """ 
     427        """ 
    424428        _BaseInteractor.__init__(self, base, axes, color=color) 
    425429        ## Initialization the class  
     
    430434        self.center_y = center_y 
    431435        ## defined end points vertical lignes and their saved values 
    432         self.y1     = y + self.center_y 
     436        self.y1 = y + self.center_y 
    433437        self.save_y1= self.y1 
    434438         
    435         delta= self.y1- self.center_y 
    436         self.y2= self.center_y - delta 
    437         self.save_y2= self.y2 
    438          
    439         self.x1      = x + self.center_x 
     439        delta = self.y1 - self.center_y 
     440        self.y2 = self.center_y - delta 
     441        self.save_y2 = self.y2 
     442         
     443        self.x1 = x + self.center_x 
    440444        self.save_x1 = self.x1 
    441445          
    442         delta= self.x1- self.center_x 
    443         self.x2= self.center_x - delta 
     446        delta = self.x1 - self.center_x 
     447        self.x2 = self.center_x - delta 
    444448        self.save_x2 = self.x2 
    445449        ## save the color of the line 
    446450        self.color = color 
    447451        ## the height of the rectangle 
    448         self.half_height= math.fabs(y) 
    449         self.save_half_height= math.fabs(y) 
     452        self.half_height = math.fabs(y) 
     453        self.save_half_height = math.fabs(y) 
    450454        ## the with of the rectangle 
    451         self.half_width= math.fabs(self.x1- self.x2)/2 
    452         self.save_half_width=math.fabs(self.x1- self.x2)/2 
     455        self.half_width = math.fabs(self.x1- self.x2)/2 
     456        self.save_half_width = math.fabs(self.x1- self.x2)/2 
    453457        ## Create marker  
    454458        try: 
     
    457461                                          color=self.color, alpha=0.6, 
    458462                                          pickradius=5, label="pick",  
    459                                           zorder=zorder, # Prefer this to other lines 
    460                                           visible=True)[0] 
     463                                          # Prefer this to other lines 
     464                                          zorder=zorder, visible=True)[0] 
    461465        except: 
    462466            self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
    463467                                          marker='s', markersize=10, 
    464468                                          color=self.color, alpha=0.6, 
    465                                           label="pick",  
    466                                           visible=True)[0] 
    467             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    468             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    469             owner=self.base.base.parent 
    470             wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     469                                          label="pick", visible=True)[0] 
     470            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST " 
     471            message += "VERSION OF MATPLOTLIB\n Get the SVN version that" 
     472            message += " is at least as recent as June 1, 2007" 
     473            owner = self.base.base.parent 
     474            wx.PostEvent(owner, 
     475                         StatusEvent(status="AnnulusSlicer: %s" % message)) 
    471476             
    472477        ## define the left and right lines of the rectangle 
    473         self.right_line = self.axes.plot([self.x1,self.x1],[self.y1,self.y2], 
     478        self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 
    474479                                      linestyle='-', marker='', 
    475                                       color=self.color, 
    476                                       visible=True)[0] 
    477         self.left_line = self.axes.plot([self.x2,self.x2],[self.y1,self.y2], 
     480                                      color=self.color, visible=True)[0] 
     481        self.left_line = self.axes.plot([self.x2, self.x2], [self.y1, self.y2], 
    478482                                      linestyle='-', marker='', 
    479                                       color=self.color, 
    480                                       visible=True)[0] 
     483                                      color=self.color, visible=True)[0] 
    481484        ## Flag to determine if the lines have moved 
    482         self.has_move=False   
     485        self.has_move = False   
    483486        ## connection the marker and draw the pictures   
    484487        self.connect_markers([self.right_marker]) 
    485488        self.update() 
    486489 
    487  
    488490    def set_layer(self, n): 
    489491        """ 
    490             Allow adding plot to the same panel 
    491             @param n: the number of layer 
     492        Allow adding plot to the same panel 
     493        :param n: the number of layer 
    492494        """ 
    493495        self.layernum = n 
    494496        self.update() 
    495497         
    496          
    497498    def clear(self): 
    498499        """ 
    499             Clear this slicer  and its markers 
     500        Clear this slicer  and its markers 
    500501        """ 
    501502        self.clear_markers() 
     
    509510                del self.axes.lines[0] 
    510511    
    511     
    512     def update(self,x1=None,x2=None, y1=None,y2=None,width=None, height=None, center=None): 
    513         """ 
    514             Draw the new roughness on the graph. 
    515             @param x1: new maximum value of x coordinates 
    516             @param x2: new minimum value of x coordinates 
    517             @param y1: new maximum value of y coordinates 
    518             @param y2: new minimum value of y coordinates 
    519             @param width: is the width of the new rectangle 
    520             @param height: is the height of the new rectangle 
    521             @param center: provided x, y  coordinates of the center point 
     512    def update(self, x1=None, x2=None, y1=None, y2=None,width=None, 
     513                height=None, center=None): 
     514        """ 
     515        Draw the new roughness on the graph. 
     516        :param x1: new maximum value of x coordinates 
     517        :param x2: new minimum value of x coordinates 
     518        :param y1: new maximum value of y coordinates 
     519        :param y2: new minimum value of y coordinates 
     520        :param width: is the width of the new rectangle 
     521        :param height: is the height of the new rectangle 
     522        :param center: provided x, y  coordinates of the center point 
    522523        """ 
    523524        ## save the new height, witdh of the rectangle if given as a param 
    524         if width!=None: 
    525             self.half_width= width 
    526         if height!=None: 
    527             self.half_height= height 
     525        if width != None: 
     526            self.half_width = width 
     527        if height != None: 
     528            self.half_height = height 
    528529        ## If new  center coordinates are given draw the rectangle  
    529530        ##given these value  
    530         if center!=None: 
    531             self.center_x= center.x 
    532             self.center_y= center.y 
    533              
     531        if center != None: 
     532            self.center_x = center.x 
     533            self.center_y = center.y 
    534534            self.x1 = self.half_width + self.center_x 
    535535            self.x2= -self.half_width + self.center_x 
    536              
    537536            self.y1 = self.half_height + self.center_y 
    538537            self.y2= -self.half_height + self.center_y 
    539538          
    540             self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 
    541             self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 
    542             self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 
     539            self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 
     540            self.right_line.set(xdata=[self.x1, self.x1],  
     541                                ydata=[self.y1, self.y2]) 
     542            self.left_line.set(xdata=[self.x2, self.x2], 
     543                               ydata=[self.y1, self.y2]) 
    543544            return  
    544545        ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    545         if x1 !=None:  
    546             self.x1= x1 
    547         if x2 !=None:  
    548             self.x2= x2 
    549         if y1 !=None:  
    550             self.y1= y1 
    551         if y2 !=None:  
    552             self.y2= y2 
     546        if x1 != None:  
     547            self.x1 = x1 
     548        if x2 != None:  
     549            self.x2 = x2 
     550        if y1 != None:  
     551            self.y1 = y1 
     552        if y2 != None:  
     553            self.y2 = y2 
    553554        ## Draw 2 vertical lines and a marker  
    554         self.right_marker.set(xdata=[self.x1],ydata=[self.center_y]) 
    555         self.right_line.set(xdata=[self.x1,self.x1], ydata=[self.y1,self.y2]) 
    556         self.left_line.set(xdata=[self.x2,self.x2], ydata=[self.y1,self.y2]) 
    557          
     555        self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 
     556        self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) 
     557        self.left_line.set(xdata=[self.x2, self.x2], ydata=[self.y1, self.y2]) 
    558558         
    559559    def save(self, ev): 
     
    562562        can restore on Esc. 
    563563        """ 
    564         self.save_x2= self.x2 
    565         self.save_y2= self.y2 
    566          
    567         self.save_x1= self.x1 
    568         self.save_y1= self.y1 
    569          
    570         self.save_half_height= self.half_height 
     564        self.save_x2 = self.x2 
     565        self.save_y2 = self.y2 
     566        self.save_x1 = self.x1 
     567        self.save_y1 = self.y1 
     568        self.save_half_height = self.half_height 
    571569        self.save_half_width = self.half_width 
    572          
    573570        self.base.freeze_axes() 
    574571 
    575  
    576572    def moveend(self, ev): 
    577573        """ 
    578574            After a dragging motion reset the flag self.has_move to False 
    579575        """ 
    580         self.has_move=False 
     576        self.has_move = False 
    581577        self.base.moveend(ev) 
    582578             
    583              
    584579    def restore(self): 
    585580        """ 
    586581        Restore the roughness for this layer. 
    587582        """ 
    588         self.y2= self.save_y2 
    589         self.x2= self.save_x2 
    590          
    591         self.y1= self.save_y1 
    592         self.x1= self.save_x1 
    593          
    594         self.half_height= self.save_half_height 
    595         self.half_width= self.save_half_width 
    596         
     583        self.y2 = self.save_y2 
     584        self.x2 = self.save_x2 
     585        self.y1 = self.save_y1 
     586        self.x1 = self.save_x1 
     587        self.half_height = self.save_half_height 
     588        self.half_width = self.save_half_width 
    597589        
    598590    def move(self, x, y, ev): 
     
    600592        Process move to a new position, making sure that the move is allowed. 
    601593        """ 
    602         self.x1= x 
    603         delta= self.x1- self.center_x 
    604         self.x2= self.center_x - delta 
    605          
    606         self.half_width= math.fabs(self.x1-self.x2)/2 
    607          
    608         self.has_move=True 
     594        self.x1 = x 
     595        delta = self.x1 - self.center_x 
     596        self.x2 = self.center_x - delta 
     597        self.half_width = math.fabs(self.x1 - self.x2)/2 
     598        self.has_move = True 
    609599        self.base.base.update() 
    610600         
    611          
    612601    def set_cursor(self, x, y): 
    613602        """ 
     
    616605        self.move(x, y, None) 
    617606        self.update() 
    618          
    619607         
    620608    def get_params(self): 
     
    626614        params["x"] = self.x1 
    627615        params["y"] = self.y1 
    628          
    629616        return params 
    630617     
     
    638625        x = params["x"]  
    639626        y = params["y"]  
    640         self.update(x=x, y=y, center_x=None,center_y=None) 
     627        self.update(x=x, y=y, center_x=None, center_y=None) 
    641628 
    642629 
     
    645632         Select an annulus through a 2D plot 
    646633    """ 
    647     def __init__(self,base,axes,color='black', zorder=5, x=0.5,y=0.5, 
    648                  center_x= 0.0, 
    649                  center_y= 0.0): 
     634    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 
     635                 center_x=0.0, center_y=0.0): 
    650636         
    651637        _BaseInteractor.__init__(self, base, axes, color=color) 
     
    656642        self.center_x = center_x 
    657643        self.center_y = center_y 
    658          
    659         self.y1     = y + self.center_y 
    660         self.save_y1= self.y1 
    661          
    662         delta= self.y1- self.center_y 
    663         self.y2=  self.center_y - delta 
    664         self.save_y2= self.y2 
    665          
    666         self.x1      = x + self.center_x 
     644        self.y1 = y + self.center_y 
     645        self.save_y1 = self.y1 
     646        delta = self.y1 - self.center_y 
     647        self.y2 = self.center_y - delta 
     648        self.save_y2 = self.y2 
     649        self.x1 = x + self.center_x 
    667650        self.save_x1 = self.x1 
    668          
    669         delta= self.x1- self.center_x 
    670         self.x2=  self.center_x - delta 
     651        delta = self.x1 - self.center_x 
     652        self.x2 = self.center_x - delta 
    671653        self.save_x2 = self.x2 
    672          
    673         self.color=color 
    674          
     654        self.color = color 
    675655        self.half_height= math.fabs(y) 
    676         self.save_half_height= math.fabs(y) 
    677          
    678         self.half_width= math.fabs(x) 
    679         self.save_half_width=math.fabs(x) 
    680      
     656        self.save_half_height = math.fabs(y) 
     657        self.half_width = math.fabs(x) 
     658        self.save_half_width = math.fabs(x) 
    681659        try: 
    682             self.top_marker = self.axes.plot([0],[self.y1], linestyle='', 
     660            self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
    683661                                          marker='s', markersize=10, 
    684662                                          color=self.color, alpha=0.6, 
    685                                           pickradius=5, label="pick",  
    686                                           zorder=zorder, # Prefer this to other lines 
    687                                           visible=True)[0] 
     663                                          pickradius=5, label="pick", 
     664                                          # Prefer this to other lines 
     665                                          zorder=zorder, visible=True)[0] 
    688666        except: 
    689             self.top_marker = self.axes.plot([0],[self.y1], linestyle='', 
     667            self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
    690668                                          marker='s', markersize=10, 
    691669                                          color=self.color, alpha=0.6, 
    692                                           label="pick",  
    693                                           visible=True)[0] 
    694             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION OF MATPLOTLIB\n" 
    695             message += "Get the SVN version that is at least as recent as June 1, 2007" 
    696             owner=self.base.base.parent 
    697             wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s"%message)) 
     670                                          label="pick", visible=True)[0] 
     671            message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 
     672            message += "OF MATPLOTLIB\n Get the SVN version " 
     673            message += "that is at least as recent as June 1, 2007" 
     674            owner = self.base.base.parent 
     675            wx.PostEvent(owner, 
     676                         StatusEvent(status="AnnulusSlicer: %s" % message)) 
    698677             
    699678        # Define 2 horizotnal lines 
    700         self.top_line = self.axes.plot([self.x1,-self.x1],[self.y1,self.y1], 
     679        self.top_line = self.axes.plot([self.x1, -self.x1], [self.y1, self.y1], 
    701680                                      linestyle='-', marker='', 
    702                                       color=self.color, 
    703                                       visible=True)[0] 
    704         self.bottom_line = self.axes.plot([self.x1,-self.x1],[self.y2,self.y2], 
     681                                      color=self.color, visible=True)[0] 
     682        self.bottom_line = self.axes.plot([self.x1, -self.x1],  
     683                                          [self.y2, self.y2], 
    705684                                      linestyle='-', marker='', 
    706                                       color=self.color, 
    707                                       visible=True)[0] 
     685                                      color=self.color, visible=True)[0] 
    708686        ## Flag to determine if the lines have moved 
    709         self.has_move=False     
     687        self.has_move = False     
    710688        ## connection the marker and draw the pictures  
    711689        self.connect_markers([self.top_marker]) 
    712690        self.update() 
    713691 
    714  
    715692    def set_layer(self, n): 
    716693        """ 
     
    720697        self.layernum = n 
    721698        self.update() 
    722          
    723699         
    724700    def clear(self): 
     
    736712                del self.axes.lines[0] 
    737713     
    738     
    739     def update(self,x1=None,x2=None, y1=None,y2=None,width=None,height=None, center=None): 
    740         """ 
    741             Draw the new roughness on the graph. 
    742             @param x1: new maximum value of x coordinates 
    743             @param x2: new minimum value of x coordinates 
    744             @param y1: new maximum value of y coordinates 
    745             @param y2: new minimum value of y coordinates 
    746             @param width: is the width of the new rectangle 
    747             @param height: is the height of the new rectangle 
    748             @param center: provided x, y  coordinates of the center point 
     714    def update(self, x1=None, x2=None, y1=None, y2=None, 
     715               width=None, height=None, center=None): 
     716        """ 
     717        Draw the new roughness on the graph. 
     718        :param x1: new maximum value of x coordinates 
     719        :param x2: new minimum value of x coordinates 
     720        :param y1: new maximum value of y coordinates 
     721        :param y2: new minimum value of y coordinates 
     722        :param width: is the width of the new rectangle 
     723        :param height: is the height of the new rectangle 
     724        :param center: provided x, y  coordinates of the center point 
    749725        """ 
    750726        ## save the new height, witdh of the rectangle if given as a param 
     
    752728            self.half_width = width 
    753729        if height!= None: 
    754             self.half_height= height 
     730            self.half_height = height 
    755731        ## If new  center coordinates are given draw the rectangle  
    756732        ##given these value  
    757         if center!=None: 
    758             self.center_x= center.x 
    759             self.center_y= center.y 
    760              
     733        if center != None: 
     734            self.center_x = center.x 
     735            self.center_y = center.y 
    761736            self.x1 = self.half_width + self.center_x 
    762             self.x2= -self.half_width + self.center_x 
     737            self.x2 = -self.half_width + self.center_x 
    763738             
    764739            self.y1 = self.half_height + self.center_y 
    765             self.y2= -self.half_height + self.center_y 
     740            self.y2 = -self.half_height + self.center_y 
    766741             
    767             self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 
    768             self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 
    769             self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 
     742            self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 
     743            self.top_line.set(xdata=[self.x1, self.x2], 
     744                              ydata=[self.y1, self.y1]) 
     745            self.bottom_line.set(xdata=[self.x1, self.x2], 
     746                                 ydata=[self.y2, self.y2]) 
    770747            return  
    771748        ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    772         if x1 !=None:  
    773             self.x1= x1 
    774         if x2 !=None:  
    775             self.x2= x2 
    776         if y1 !=None:  
    777             self.y1= y1 
    778         if y2 !=None:  
    779             self.y2= y2 
     749        if x1 != None:  
     750            self.x1 = x1 
     751        if x2 != None:  
     752            self.x2 = x2 
     753        if y1 != None:  
     754            self.y1 = y1 
     755        if y2 != None:  
     756            self.y2 = y2 
    780757        ## Draw 2 vertical lines and a marker  
    781         self.top_marker.set(xdata=[self.center_x],ydata=[self.y1]) 
    782         self.top_line.set(xdata=[self.x1,self.x2], ydata=[self.y1,self.y1]) 
    783         self.bottom_line.set(xdata=[self.x1,self.x2], ydata=[self.y2,self.y2]) 
     758        self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 
     759        self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) 
     760        self.bottom_line.set(xdata=[self.x1, self.x2], ydata=[self.y2, self.y2]) 
    784761        
    785          
    786762    def save(self, ev): 
    787763        """ 
     
    789765        can restore on Esc. 
    790766        """ 
    791         self.save_x2= self.x2 
    792         self.save_y2= self.y2 
    793          
    794         self.save_x1= self.x1 
    795         self.save_y1= self.y1 
    796          
    797         self.save_half_height= self.half_height 
     767        self.save_x2 = self.x2 
     768        self.save_y2 = self.y2 
     769        self.save_x1 = self.x1 
     770        self.save_y1 = self.y1 
     771        self.save_half_height = self.half_height 
    798772        self.save_half_width =  self.half_width 
    799773        self.base.freeze_axes() 
    800  
    801  
     774         
    802775    def moveend(self, ev): 
    803776        """ 
    804             After a dragging motion reset the flag self.has_move to False 
    805         """ 
    806         self.has_move=False 
     777        After a dragging motion reset the flag self.has_move to False 
     778        """ 
     779        self.has_move = False 
    807780        self.base.moveend(ev) 
    808781            
    809              
    810782    def restore(self): 
    811783        """ 
    812784        Restore the roughness for this layer. 
    813785        """ 
    814         self.y2= self.save_y2 
    815         self.x2= self.save_x2 
    816          
    817         self.y1= self.save_y1 
    818         self.x1= self.save_x1 
    819         self.half_height= self.save_half_height 
    820         self.half_width= self.save_half_width 
    821          
     786        self.y2 = self.save_y2 
     787        self.x2 = self.save_x2 
     788        self.y1 = self.save_y1 
     789        self.x1 = self.save_x1 
     790        self.half_height = self.save_half_height 
     791        self.half_width = self.save_half_width 
    822792         
    823793    def move(self, x, y, ev): 
     
    825795        Process move to a new position, making sure that the move is allowed. 
    826796        """ 
    827         self.y1= y 
    828         delta= self.y1- self.center_y 
    829         self.y2=  self.center_y - delta 
    830         self.half_height=  math.fabs(self.y1)-self.center_y 
    831         self.has_move=True 
     797        self.y1 = y 
     798        delta = self.y1 - self.center_y 
     799        self.y2 =  self.center_y - delta 
     800        self.half_height = math.fabs(self.y1) - self.center_y 
     801        self.has_move = True 
    832802        self.base.base.update() 
    833          
    834          
     803     
    835804    def set_cursor(self, x, y): 
    836805        """ 
     
    840809        self.update() 
    841810         
    842          
    843811    def get_params(self): 
    844812        """ 
    845             Store a copy of values of parameters of the slicer into a dictionary. 
    846             @return params: the dictionary created 
     813        Store a copy of values of parameters of the slicer into a dictionary. 
     814        :return params: the dictionary created 
    847815        """ 
    848816        params = {} 
     
    851819        return params 
    852820     
    853      
    854821    def set_params(self, params): 
    855822        """ 
    856             Receive a dictionary and reset the slicer with values contained  
    857             in the values of the dictionary. 
    858             @param params: a dictionary containing name of slicer parameters and  
     823        Receive a dictionary and reset the slicer with values contained  
     824        in the values of the dictionary. 
     825        :param params: a dictionary containing name of slicer parameters and  
    859826            values the user assigned to the slicer. 
    860827        """ 
  • guiframe/local_perspectives/plotting/detector_dialog.py

    rd955bf19 r32c0841  
    88import sys 
    99from sans.guiframe.utils import format_number 
    10 from sans.guicomm.events import StatusEvent ,NewPlotEvent 
     10from sans.guicomm.events import StatusEvent  
     11from sans.guicomm.events import NewPlotEvent 
    1112 
    1213import matplotlib  
    1314from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 
    14 from matplotlib import pyplot, mpl, pylab 
     15from matplotlib import pyplot 
     16from matplotlib import mpl 
     17from matplotlib import pylab 
    1518#FONT size  
    16 if sys.platform.count("win32")>0: 
     19if sys.platform.count("win32") > 0: 
    1720    FONT_VARIANT = 0 
    1821else: 
    1922    FONT_VARIANT = 1 
    2023     
    21 DEFAULT_CMAP= pylab.cm.jet 
     24DEFAULT_CMAP = pylab.cm.jet 
    2225 
    2326class DetectorDialog(wx.Dialog): 
     
    2629    """ 
    2730     
    28     def __init__(self,parent,id=1,base=None,dpi = None,cmap=DEFAULT_CMAP, 
    29                  reset_zmin_ctl = None,reset_zmax_ctl = None, *args, **kwds): 
     31    def __init__(self, parent, id=1, base=None, dpi=None, 
     32                 cmap=DEFAULT_CMAP, reset_zmin_ctl = None, 
     33                 reset_zmax_ctl = None, *args, **kwds): 
    3034        """ 
    3135        """ 
    3236        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    33         wx.Dialog.__init__(self,parent,id=1, *args, **kwds) 
    34          
     37        wx.Dialog.__init__(self, parent, id=1, *args, **kwds) 
    3538        self.SetWindowVariant(variant=FONT_VARIANT) 
    36         self.parent=base 
     39        self.parent = base 
    3740        self.dpi = dpi 
    3841        self.cmap = cmap 
    39  
    40         self.reset_zmin_ctl= reset_zmin_ctl 
    41         self.reset_zmax_ctl= reset_zmax_ctl 
    42              
     42        self.reset_zmin_ctl = reset_zmin_ctl 
     43        self.reset_zmax_ctl = reset_zmax_ctl 
    4344        self.label_xnpts = wx.StaticText(self, -1, "Detector width in pixels") 
    4445        self.label_ynpts = wx.StaticText(self, -1, "Detector Height in pixels") 
    4546        self.label_qmax = wx.StaticText(self, -1, "Q max") 
    46         self.label_zmin = wx.StaticText(self, -1, "Min amplitude for color map (optional)") 
    47         self.label_zmax = wx.StaticText(self, -1, "Max amplitude for color map (optional)") 
    48         self.label_beam = wx.StaticText(self, -1, "Beam stop radius in units of q") 
    49          
     47        self.label_zmin = wx.StaticText(self, -1, 
     48                                    "Min amplitude for color map (optional)") 
     49        self.label_zmax = wx.StaticText(self, -1, 
     50                                    "Max amplitude for color map (optional)") 
     51        self.label_beam = wx.StaticText(self, -1, 
     52                                        "Beam stop radius in units of q") 
    5053        self.xnpts_ctl = wx.StaticText(self, -1, "") 
    5154        self.ynpts_ctl = wx.StaticText(self, -1, "") 
    5255        self.qmax_ctl = wx.StaticText(self, -1, "") 
    5356        self.beam_ctl = wx.StaticText(self, -1, "") 
    54          
    55         self.zmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
     57        self.zmin_ctl = wx.TextCtrl(self, -1, size=(60, 20)) 
    5658        self.zmin_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    57         self.zmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) 
     59        self.zmax_ctl = wx.TextCtrl(self, -1, size=(60, 20)) 
    5860        self.zmax_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    59      
    6061        self.static_line_3 = wx.StaticLine(self, -1) 
    61          
    6262        self.button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    63         self.button_reset = wx.Button(self, wx.NewId(),"Reset") 
     63        self.button_reset = wx.Button(self, wx.NewId(), "Reset") 
    6464        self.Bind(wx.EVT_BUTTON, self.resetValues, self.button_reset) 
    6565        self.button_OK = wx.Button(self, wx.ID_OK, "OK") 
    6666        self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_OK) 
    67  
    6867        self.__set_properties() 
    6968        self.__do_layout() 
    70  
    7169        self.Fit() 
    7270         
     
    8078        zmin = 0 
    8179        zmax = 0 
    82         cmap= None 
     80        cmap = None 
    8381        sym4 = False 
    8482     
     
    9088        widget = event.GetEventObject() 
    9189        # Select the whole control, after this event resolves 
    92         wx.CallAfter(widget.SetSelection, -1,-1) 
    93         return 
     90        wx.CallAfter(widget.SetSelection, -1, -1) 
    9491         
    9592    def resetValues(self, event): 
     
    9895        """ 
    9996        try: 
    100             zmin= self.reset_zmin_ctl 
    101             zmax= self.reset_zmax_ctl 
    102             if zmin==None: 
    103                 zmin= "" 
    104             if zmax==None: 
    105                 zmax= ""     
     97            zmin = self.reset_zmin_ctl 
     98            zmax = self.reset_zmax_ctl 
     99            if zmin == None: 
     100                zmin = "" 
     101            if zmax == None: 
     102                zmax = ""     
    106103            self.zmin_ctl.SetValue(str(zmin)) 
    107104            self.zmax_ctl.SetValue(str(zmax)) 
     
    110107            self._on_select_cmap(event=None) 
    111108        except: 
    112             msg ="error occurs while resetting Detector: %s"%sys.exc_value 
    113             wx.PostEvent(self.parent,StatusEvent(status= msg )) 
    114          
     109            msg = "error occurs while resetting Detector: %s" % sys.exc_value 
     110            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    115111         
    116112    def checkValues(self, event): 
     
    121117        flag = True 
    122118        try: 
    123             value=self.zmin_ctl.GetValue() 
    124             if value and float( value)==0.0: 
     119            value = self.zmin_ctl.GetValue() 
     120            if value and float( value) == 0.0: 
    125121                flag = False 
    126                 wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) 
     122                wx.PostEvent(self.parent, 
     123                        StatusEvent(status="Enter number greater than zero")) 
    127124                self.zmin_ctl.SetBackgroundColour("pink") 
    128125                self.zmin_ctl.Refresh() 
     
    136133            self.zmin_ctl.Refresh() 
    137134        try: 
    138             value=self.zmax_ctl.GetValue() 
    139             if value and float(value)==0.0: 
     135            value = self.zmax_ctl.GetValue() 
     136            if value and float(value) == 0.0: 
    140137                flag = False 
    141                 wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) 
     138                wx.PostEvent(self.parent, 
     139                        StatusEvent(status="Enter number greater than zero")) 
    142140                self.zmax_ctl.SetBackgroundColour("pink") 
    143141                self.zmax_ctl.Refresh() 
     
    150148            self.zmax_ctl.SetBackgroundColour("pink") 
    151149            self.zmax_ctl.Refresh() 
    152          
    153150        if flag: 
    154151            event.Skip(True) 
    155152     
    156     def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False): 
     153    def setContent(self, xnpts, ynpts, qmax, beam, 
     154                   zmin=None, zmax=None, sym=False): 
    157155        """ 
    158156        received value and displayed them 
     
    171169        self.qmax_ctl.SetLabel(str(format_number(qmax))) 
    172170        self.beam_ctl.SetLabel(str(format_number(beam))) 
    173      
    174         if zmin !=None: 
     171        if zmin != None: 
    175172            self.zmin_ctl.SetValue(str(format_number(zmin))) 
    176         if zmax !=None: 
     173        if zmax != None: 
    177174            self.zmax_ctl.SetValue(str(format_number(zmax))) 
    178175 
     
    182179        """ 
    183180        event = self.Event() 
    184         
    185181        t_min = self.zmin_ctl.GetValue() 
    186182        t_max = self.zmax_ctl.GetValue() 
    187183        v_min = None 
    188184        v_max = None 
    189          
    190         if len(t_min.lstrip())>0: 
     185        if len(t_min.lstrip()) > 0: 
    191186            try: 
    192187                v_min = float(t_min) 
    193188            except: 
    194189                v_min = None 
    195          
    196         if len(t_max.lstrip())>0: 
     190        if len(t_max.lstrip()) > 0: 
    197191            try: 
    198192                v_max = float(t_max) 
    199193            except: 
    200194                v_max = None 
    201          
    202195        event.zmin = v_min 
    203196        event.zmax = v_max 
    204         event.cmap= self.cmap 
    205          
     197        event.cmap = self.cmap 
    206198        return event 
    207199 
     
    213205        self.SetSize((600, 595)) 
    214206 
    215  
    216207    def __do_layout(self): 
    217208        """ 
     
    220211        sizer_main = wx.BoxSizer(wx.VERTICAL) 
    221212        sizer_button = wx.BoxSizer(wx.HORIZONTAL) 
    222         sizer_params = wx.GridBagSizer(5,5) 
     213        sizer_params = wx.GridBagSizer(5, 5) 
    223214        sizer_colormap = wx.BoxSizer(wx.VERTICAL) 
    224         sizer_selection= wx.BoxSizer(wx.HORIZONTAL) 
     215        sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 
    225216        
    226217        iy = 0 
    227         sizer_params.Add(self.label_xnpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    228         sizer_params.Add(self.xnpts_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    229         iy += 1 
    230         sizer_params.Add(self.label_ynpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    231         sizer_params.Add(self.ynpts_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    232         iy += 1 
    233         sizer_params.Add(self.label_qmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    234         sizer_params.Add(self.qmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    235         iy += 1 
    236         sizer_params.Add(self.label_beam, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    237         sizer_params.Add(self.beam_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    238         iy += 1 
    239         sizer_params.Add(self.label_zmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    240         sizer_params.Add(self.zmin_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    241         iy += 1 
    242         sizer_params.Add(self.label_zmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    243         sizer_params.Add(self.zmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
    244         iy += 1 
    245          
    246         self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4,1)) 
    247         
     218        sizer_params.Add(self.label_xnpts, (iy, 0), (1, 1), 
     219                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     220        sizer_params.Add(self.xnpts_ctl,   (iy, 1), (1, 1), 
     221                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     222        iy += 1 
     223        sizer_params.Add(self.label_ynpts, (iy, 0), (1, 1), 
     224                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     225        sizer_params.Add(self.ynpts_ctl,   (iy, 1), (1, 1), 
     226                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     227        iy += 1 
     228        sizer_params.Add(self.label_qmax, (iy, 0), (1, 1), 
     229                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     230        sizer_params.Add(self.qmax_ctl,   (iy, 1), (1, 1), 
     231                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     232        iy += 1 
     233        sizer_params.Add(self.label_beam, (iy, 0), (1, 1), 
     234                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     235        sizer_params.Add(self.beam_ctl,   (iy, 1), (1, 1), 
     236                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     237        iy += 1 
     238        sizer_params.Add(self.label_zmin, (iy, 0), (1, 1), 
     239                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     240        sizer_params.Add(self.zmin_ctl,   (iy, 1), (1, 1), 
     241                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     242        iy += 1 
     243        sizer_params.Add(self.label_zmax, (iy, 0), (1, 1), 
     244                         wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
     245        sizer_params.Add(self.zmax_ctl,   (iy, 1), (1, 1), 
     246                         wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     247        iy += 1 
     248        self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4, 1)) 
    248249        self.ax1 = self.fig.add_axes([0.05, 0.65, 0.9, 0.15]) 
    249      
    250250        self.norm = mpl.colors.Normalize(vmin=0, vmax=100) 
    251251        self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 
     
    254254        self.cb1.set_label('Detector Colors') 
    255255        self.canvas = Canvas(self, -1, self.fig) 
    256         sizer_colormap.Add(self.canvas,0, wx.LEFT | wx.EXPAND,5) 
    257        
     256        sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND,5) 
    258257        self.cmap_selector = wx.ComboBox(self, -1) 
    259258        self.cmap_selector.SetValue(str(self.cmap.name)) 
    260259        maps = sorted(m for m in pylab.cm.datad if not m.endswith("_r")) 
    261260        
    262         for i,m in enumerate(maps): 
    263              
     261        for i, m in enumerate(maps): 
    264262            self.cmap_selector.Append(str(m), pylab.get_cmap(m)) 
    265263         
    266         wx.EVT_COMBOBOX(self.cmap_selector,-1, self._on_select_cmap) 
    267         sizer_selection.Add(wx.StaticText(self,-1,"Select Cmap: "),0, wx.LEFT|wx.ADJUST_MINSIZE,5)  
     264        wx.EVT_COMBOBOX(self.cmap_selector, -1, self._on_select_cmap) 
     265        sizer_selection.Add(wx.StaticText(self, -1,"Select Cmap: "), 0, 
     266                             wx.LEFT|wx.ADJUST_MINSIZE, 5)  
    268267        sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND|wx.ALL, 10) 
    269          
    270268        sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) 
    271          
    272269        sizer_main.Add(sizer_selection, 0, wx.EXPAND|wx.ALL, 10) 
    273270        sizer_main.Add(sizer_colormap, 1, wx.EXPAND|wx.ALL, 10) 
    274271        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) 
    275          
    276         sizer_button.Add(self.button_reset,0, wx.LEFT|wx.ADJUST_MINSIZE, 100) 
     272        sizer_button.Add(self.button_reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 100) 
    277273        sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    278         sizer_button.Add(self.button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    279      
     274        sizer_button.Add(self.button_Cancel, 0, 
     275                         wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    280276        sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
    281277        self.SetAutoLayout(True) 
     
    289285        display a new cmap  
    290286        """ 
    291         cmap_name= self.cmap_selector.GetCurrentSelection() 
    292         current_cmap= self.cmap_selector.GetClientData( cmap_name ) 
    293         self.cmap= current_cmap 
     287        cmap_name = self.cmap_selector.GetCurrentSelection() 
     288        current_cmap = self.cmap_selector.GetClientData(cmap_name) 
     289        self.cmap = current_cmap 
    294290        self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 
    295                                            norm= self.norm, 
    296                                            orientation='horizontal') 
     291                                     norm=self.norm, orientation='horizontal') 
    297292        self.canvas.draw() 
    298293 
     
    306301        dialog = DetectorDialog(None, -1, "") 
    307302        self.SetTopWindow(dialog) 
    308         dialog.setContent(xnpts=128,ynpts=128, qmax=20, 
    309                            beam=20,zmin=2,zmax=60, sym=False) 
     303        dialog.setContent(xnpts=128, ynpts=128, qmax=20, 
     304                           beam=20, zmin=2, zmax=60, sym=False) 
    310305        print dialog.ShowModal() 
    311306        evt = dialog.getContent() 
    312         if hasattr(evt,"npts"): 
    313             print "number of point: ",evt.npts 
     307        if hasattr(evt, "npts"): 
     308            print "number of point: ", evt.npts 
    314309        if hasattr(evt,"qmax"):  
    315             print "qmax: ",evt.qmax 
     310            print "qmax: ", evt.qmax 
    316311        dialog.Destroy() 
    317312        return 1 
     
    322317    app = MyApp(0) 
    323318    app.MainLoop() 
    324      
    325 ##### end of testing code #####################################################     
     319         
  • guiframe/local_perspectives/plotting/masking.py

    r0aee80d r32c0841  
    1818import wx 
    1919import sys 
    20  
    21 import copy,numpy 
     20import pylab 
     21from pylab import gca 
     22from pylab import gcf 
     23import math 
     24import re 
     25import copy 
     26import numpy 
    2227from danse.common.plottools.PlotPanel import PlotPanel 
    2328from danse.common.plottools.plottables import Graph 
     
    2631from boxMask import BoxMask 
    2732from sectorMask import SectorMask 
    28 from sans.guicomm.events import SlicerEvent, StatusEvent 
    29 (InternalEvent, EVT_INTERNAL)   = wx.lib.newevent.NewEvent() 
    30 from pylab import  gca, gcf 
    31 import math,pylab,re 
    32 DEFAULT_CMAP= pylab.cm.jet 
    33  
     33from sans.guicomm.events import SlicerEvent 
     34from sans.guicomm.events import StatusEvent 
     35(InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 
     36 
     37DEFAULT_CMAP = pylab.cm.jet 
    3438_BOX_WIDTH = 76 
    3539_STATICBOX_WIDTH = 400 
     
    3741 
    3842#SLD panel size  
    39 if sys.platform.count("win32")>0: 
     43if sys.platform.count("win32") > 0: 
    4044    _STATICBOX_WIDTH = 380 
    4145    PANEL_SIZE = 420 
     
    4751     
    4852 
    49              
    5053class MaskPanel(wx.Dialog): 
    5154    """ 
     
    5861    ## Flag to tell the AUI manager to put this panel in the center pane 
    5962    CENTER_PANE = True 
    60     def __init__(self, parent=None,base=None,data =None, id = -1, *args, **kwds): 
     63    def __init__(self, parent=None, base=None,  
     64                 data=None, id=-1, *args, **kwds): 
    6165        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    62         kwds["size"] = wx.Size(_STATICBOX_WIDTH*2,PANEL_SIZE)  
    63         wx.Dialog.__init__(self, parent, id = id,  *args, **kwds) 
     66        kwds["size"] = wx.Size(_STATICBOX_WIDTH * 2, PANEL_SIZE)  
     67        wx.Dialog.__init__(self, parent, id=id,  *args, **kwds) 
     68         
    6469        if data != None: 
    65              
    6670            #Font size  
    67             kwds =[] 
     71            kwds = [] 
    6872            self.SetWindowVariant(variant=FONT_VARIANT) 
    69  
    70             self.SetTitle("Mask Editor for "+ data.name) 
     73            self.SetTitle("Mask Editor for " + data.name) 
    7174            self.parent = base 
    7275            self.data = data 
     
    7982            self.slicer = None 
    8083            self.slicer_z = 5 
    81  
    8284            self.data.interactive = True 
    8385            ## when 2 data have the same id override the 1 st plotted 
    8486            self.name = self.data.name 
    85  
    8687            # Panel for 2D plot 
    87             self.plotpanel    = Maskplotpanel(self, -1, style=wx.TRANSPARENT_WINDOW) 
     88            self.plotpanel = Maskplotpanel(self, -1, 
     89                                           style=wx.TRANSPARENT_WINDOW) 
    8890            self.cmap = DEFAULT_CMAP 
    8991            ## Create Artist and bind it 
    9092            self.subplot = self.plotpanel.subplot 
    9193            self.connect = BindArtist(self.subplot.figure) 
    92  
    9394            self._setup_layout() 
    94             self.newplot=Data2D(image=self.data.data) 
     95            self.newplot = Data2D(image=self.data.data) 
    9596            self.newplot.setValues(self.data) 
    9697            self.plotpanel.add_image(self.newplot)  
     
    108109        mssg += 'The data range can not be completely masked... \n\r' 
    109110        mssg += msg 
    110         wx.MessageBox(mssg, 'Error', wx.OK |  
    111             wx.ICON_ERROR) 
     111        wx.MessageBox(mssg, 'Error', wx.OK | wx.ICON_ERROR) 
    112112     
    113113    def _setup_layout(self): 
     
    116116        """ 
    117117        shape = "Select a Shape for Masking:" 
    118          
    119118        #  panel 
    120         sizer = wx.GridBagSizer(10,10) 
    121  
     119        sizer = wx.GridBagSizer(10, 10) 
    122120        #---------inputs---------------- 
    123121        #inputbox = wx.StaticBox(self, -1, "Draw Mask") 
    124122        shape_txt = wx.StaticText(self, -1, shape)   
    125         sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 
    126                  
     123        sizer.Add(shape_txt, (1, 1), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=5) 
    127124        #innersector_x_txt = wx.StaticText(self, -1, 'Inner Sector') 
    128         self.innersector_rb = wx.RadioButton(self, -1,"Double Wings") 
    129         self.Bind(wx.EVT_RADIOBUTTON,self.onInnerSectorMask , id=self.innersector_rb.GetId()) 
    130         sizer.Add(self.innersector_rb, (2, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
    131          
     125        self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 
     126        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask, 
     127                  id=self.innersector_rb.GetId()) 
     128        sizer.Add(self.innersector_rb, (2, 1),  
     129                  flag=wx.RIGHT|wx.BOTTOM, border=5) 
    132130        #innersector_x_txt = wx.StaticText(self, -1, 'Inner Sector') 
    133         self.innercircle_rb = wx.RadioButton(self, -1,"Circular Disk") 
    134         self.Bind(wx.EVT_RADIOBUTTON,self.onInnerRingMask , id=self.innercircle_rb.GetId()) 
    135         sizer.Add(self.innercircle_rb, (3, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
    136          
    137         self.innerbox_rb = wx.RadioButton(self, -1,"Rectangular Disk") 
    138         self.Bind(wx.EVT_RADIOBUTTON,self.onInnerBoxMask , id=self.innerbox_rb.GetId()) 
    139         sizer.Add(self.innerbox_rb, (4, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
    140  
     131        self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 
     132        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask, 
     133                  id=self.innercircle_rb.GetId()) 
     134        sizer.Add(self.innercircle_rb, (3, 1), 
     135                   flag=wx.RIGHT|wx.BOTTOM, border=5) 
     136         
     137        self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 
     138        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask, 
     139                  id=self.innerbox_rb.GetId()) 
     140        sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 
    141141        #outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 
    142         self.outersector_rb = wx.RadioButton(self, -1,"Double Wing Window") 
    143         self.Bind(wx.EVT_RADIOBUTTON,self.onOuterSectorMask , id=self.outersector_rb.GetId()) 
    144         sizer.Add(self.outersector_rb, (5, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
     142        self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 
     143        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask,  
     144                  id=self.outersector_rb.GetId()) 
     145        sizer.Add(self.outersector_rb, (5, 1), 
     146                  flag=wx.RIGHT|wx.BOTTOM, border=5) 
    145147         
    146148        #outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 
    147         self.outercircle_rb = wx.RadioButton(self, -1,"Circular Window") 
    148         self.Bind(wx.EVT_RADIOBUTTON,self.onOuterRingMask , id=self.outercircle_rb.GetId()) 
    149         sizer.Add(self.outercircle_rb, (6, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
    150          
     149        self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 
     150        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask, 
     151                  id=self.outercircle_rb.GetId()) 
     152        sizer.Add(self.outercircle_rb, (6, 1),  
     153                  flag=wx.RIGHT|wx.BOTTOM, border=5) 
    151154        #outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 
    152         self.outerbox_rb = wx.RadioButton(self, -1,"Rectangular Window") 
    153         self.Bind(wx.EVT_RADIOBUTTON,self.onOuterBoxMask , id=self.outerbox_rb.GetId()) 
    154         sizer.Add(self.outerbox_rb, (7, 1),flag=wx.RIGHT | wx.BOTTOM, border=5) 
    155          
     155        self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 
     156        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask,  
     157                  id=self.outerbox_rb.GetId()) 
     158        sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 
    156159        self.innercircle_rb.SetValue(False) 
    157160        self.outercircle_rb.SetValue(False)         
     
    160163        self.innersector_rb.SetValue(False) 
    161164        self.outersector_rb.SetValue(False) 
    162          
    163         sizer.Add(self.plotpanel,(0, 2), (13, 13), wx.EXPAND | wx.LEFT| wx.RIGHT, 15) 
     165        sizer.Add(self.plotpanel, (0, 2), (13, 13),  
     166                  wx.EXPAND|wx.LEFT|wx.RIGHT, 15) 
    164167 
    165168        #-----Buttons------------1 
    166169        id = wx.NewId() 
    167          
    168170        button_add = wx.Button(self, id, "Add") 
    169171        button_add.SetToolTipString("Add the mask drawn.") 
    170         button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id = button_add.GetId())  
     172        button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId())  
    171173        sizer.Add(button_add, (13, 7)) 
    172          
    173174        id = wx.NewId() 
    174175        button_erase = wx.Button(self, id, "Erase") 
    175176        button_erase.SetToolTipString("Erase the mask drawn.") 
    176         button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, id = button_erase.GetId())  
     177        button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, 
     178                          id=button_erase.GetId())  
    177179        sizer.Add(button_erase, (13, 8)) 
    178          
    179180        id = wx.NewId() 
    180181        button_reset = wx.Button(self, id, "Reset") 
    181182        button_reset.SetToolTipString("Reset the mask.") 
    182         button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, id = button_reset.GetId())  
    183         sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15) 
    184          
     183        button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, 
     184                          id=button_reset.GetId())  
     185        sizer.Add(button_reset, (13, 9), flag=wx.RIGHT|wx.BOTTOM, border=15) 
    185186        id = wx.NewId() 
    186187        button_reset = wx.Button(self, id, "Clear") 
    187188        button_reset.SetToolTipString("Clear all mask.") 
    188         button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, id = button_reset.GetId())  
    189         sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15) 
    190  
     189        button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, 
     190                          id=button_reset.GetId())  
     191        sizer.Add(button_reset, (13, 10), flag=wx.RIGHT|wx.BOTTOM, border=15) 
    191192        sizer.AddGrowableCol(3) 
    192193        sizer.AddGrowableRow(2) 
    193194        self.SetSizerAndFit(sizer) 
    194  
    195195        self.Centre() 
    196196        self.Show(True) 
    197197 
    198  
    199     def onInnerBoxMask(self,event=None): 
     198    def onInnerBoxMask(self, event=None): 
    200199        """ 
    201200        Call Draw Box Slicer and get mask inside of the box 
     
    203202        #get ready for next evt 
    204203        event.Skip()         
    205         from boxMask import BoxMask 
    206         if event !=None: 
    207             self.onClearSlicer(event) 
    208                      
    209         self.slicer_z += 1 
    210         self.slicer =  BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 
    211  
     204        #from boxMask import BoxMask 
     205        if event != None: 
     206            self.onClearSlicer(event)          
     207        self.slicer_z += 1 
     208        self.slicer =  BoxMask(self, self.subplot, 
     209                               zorder=self.slicer_z, side=True) 
    212210        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    213211        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
     
    215213        self.slicer_mask = self.slicer.update() 
    216214         
    217      
    218     def onOuterBoxMask(self,event=None): 
     215    def onOuterBoxMask(self, event=None): 
    219216        """ 
    220217        Call Draw Box Slicer and get mask outside of the box 
    221218        """ 
    222219        event.Skip()         
    223         from boxMask import BoxMask 
    224         if event !=None: 
    225             self.onClearSlicer(event) 
    226                      
    227         self.slicer_z += 1 
    228         self.slicer =  BoxMask(self, self.subplot, zorder=self.slicer_z, side=False) 
    229  
     220        #from boxMask import BoxMask 
     221        if event != None: 
     222            self.onClearSlicer(event)       
     223        self.slicer_z += 1 
     224        self.slicer =  BoxMask(self, self.subplot, 
     225                               zorder=self.slicer_z, side=False) 
    230226        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    231227        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
     
    233229        self.slicer_mask = self.slicer.update() 
    234230 
    235          
    236     def onInnerSectorMask(self,event=None): 
     231    def onInnerSectorMask(self, event=None): 
    237232        """ 
    238233        Call Draw Sector Slicer and get mask inside of the sector 
     
    240235        event.Skip() 
    241236        from sectorMask import SectorMask 
    242         if event !=None: 
     237        if event != None: 
    243238            self.onClearSlicer(event) 
    244  
    245         self.slicer_z += 1 
    246         self.slicer =  SectorMask(self, self.subplot, zorder=self.slicer_z, side=True) 
     239        self.slicer_z += 1 
     240        self.slicer =  SectorMask(self, self.subplot, 
     241                                  zorder=self.slicer_z, side=True) 
    247242        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    248243        self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
    249  
    250244        self.update() 
    251245        self.slicer_mask = self.slicer.update()  
    252246 
    253          
    254247    def onOuterSectorMask(self,event=None): 
    255248        """ 
     
    258251        event.Skip() 
    259252        from sectorMask import SectorMask 
    260         if event !=None: 
     253        if event != None: 
    261254            self.onClearSlicer(event) 
    262  
    263         self.slicer_z += 1 
    264         self.slicer =  SectorMask(self, self.subplot, zorder=self.slicer_z, side=False) 
     255        self.slicer_z += 1 
     256        self.slicer =  SectorMask(self, self.subplot, 
     257                                  zorder=self.slicer_z, side=False) 
    265258        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    266259        self.subplot.set_xlim(self.data.xmin, self.data.xmax)     
    267  
    268260        self.update()      
    269261        self.slicer_mask = self.slicer.update()    
    270262 
    271          
    272263    def onInnerRingMask(self, event=None): 
    273264        """ 
     
    276267        event.Skip() 
    277268        from AnnulusSlicer import CircularMask 
    278         if event !=None: 
     269        if event != None: 
    279270            self.onClearSlicer(event) 
    280          
    281         self.slicer_z += 1 
    282         self.slicer = CircularMask(self,self.subplot, zorder=self.slicer_z, side=True) 
     271        self.slicer_z += 1 
     272        self.slicer = CircularMask(self,self.subplot, 
     273                                  zorder=self.slicer_z, side=True) 
    283274        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    284275        self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
    285  
    286276        self.update() 
    287277        self.slicer_mask = self.slicer.update()  
    288278 
    289          
    290279    def onOuterRingMask(self, event=None): 
    291280        """ 
     
    294283        event.Skip() 
    295284        from AnnulusSlicer import CircularMask 
    296         if event !=None: 
     285        if event != None: 
    297286            self.onClearSlicer(event) 
    298          
    299         self.slicer_z += 1 
    300         self.slicer = CircularMask(self,self.subplot, zorder=self.slicer_z, side=False)    
     287        self.slicer_z += 1 
     288        self.slicer = CircularMask(self,self.subplot, 
     289                                  zorder=self.slicer_z, side=False)    
    301290        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    302291        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
     
    308297        Add new mask to old mask  
    309298        """ 
    310         if not self.slicer==None: 
     299        if not self.slicer == None: 
    311300            data = Data2D() 
    312301            data = self.data 
    313302            self.slicer_mask = self.slicer.update() 
    314303            data.mask = self.data.mask & self.slicer_mask 
    315  
    316304            self._check_display_mask(data.mask, event) 
    317305             
     
    334322            mask = self.data.mask 
    335323            mask[self.slicer_mask==False] = True 
    336  
    337324            self._check_display_mask(mask, event) 
    338325             
     
    342329        """         
    343330        self.slicer_z += 1 
    344         self.slicer =  BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 
     331        self.slicer =  BoxMask(self, self.subplot,  
     332                               zorder=self.slicer_z, side=True) 
    345333        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    346334        self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
    347  
    348335        mask = copy.deepcopy(self.default_mask) 
    349336        self.data.mask = mask 
    350  
    351337        # update mask plot 
    352338        self._check_display_mask(mask, event) 
     
    357343        """             
    358344        self.slicer_z += 1 
    359         self.slicer =  BoxMask(self, self.subplot, zorder=self.slicer_z, side=True) 
     345        self.slicer =  BoxMask(self, self.subplot, 
     346                               zorder=self.slicer_z, side=True) 
    360347        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    361348        self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
    362  
    363349        #mask = copy.deepcopy(self.default_mask) 
    364350        mask = numpy.ones(len(self.data.mask), dtype=bool) 
    365351        self.data.mask = mask 
    366  
    367352        # update mask plot 
    368353        self._check_display_mask(mask, event) 
     
    372357        Clear the slicer on the plot 
    373358        """ 
    374         if not self.slicer==None: 
     359        if not self.slicer == None: 
    375360            self.slicer.clear() 
    376361            self.subplot.figure.canvas.draw() 
     
    396381        self.update() 
    397382        self.slicer.update() 
    398         wx.PostEvent(self.parent, StatusEvent(status=\ 
    399                         "Plotter2D._setSlicer  %s"%self.slicer.__class__.__name__)) 
     383        msg = "Plotter2D._setSlicer  %s"%self.slicer.__class__.__name__ 
     384        wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    400385        # Post slicer event 
    401386        event = self._getEmptySlicerEvent() 
    402387        event.type = self.slicer.__class__.__name__ 
    403          
    404388        event.obj_class = self.slicer.__class__ 
    405389        event.params = self.slicer.get_params() 
     
    424408        """  
    425409        # the case of liitle numbers of True points 
    426         if (len(mask[mask])<10 and self.data !=None): 
     410        if (len(mask[mask]) < 10 and self.data != None): 
    427411            self.ShowMessage() 
    428412            mask = copy.deepcopy(self.mask) 
     
    430414        else: 
    431415            self.mask = mask 
    432  
    433416        # make temperary data to plot 
    434417        temp_mask = numpy.zeros(len(mask)) 
     
    445428            self.slicer.clear() 
    446429            self.slicer = None 
    447          
    448430        # Post slicer None event 
    449431        event = self._getEmptySlicerEvent() 
    450432        wx.PostEvent(self, event) 
    451          
    452         #replot 
    453         ##This method not alway updating the plot(?): use manual plot  
    454         #self.newplot=Data2D(image=temp_data.data) 
    455         #self.newplot.setValues(temp_data) 
    456         #self.plotpanel.add_image(self.newplot) 
    457          
    458433        
    459434        ##use this method 
     
    466441            zmin = min(self.data.data[self.data.data>0]) 
    467442        #plot     
    468         plot = self.plotpanel.image(data= temp_mask, 
     443        plot = self.plotpanel.image(data=temp_mask, 
    469444                       qx_data=self.data.qx_data, 
    470445                       qy_data=self.data.qy_data, 
    471                        xmin= self.data.xmin, 
    472                        xmax= self.data.xmax, 
    473                        ymin= self.data.ymin, 
    474                        ymax= self.data.ymax, 
    475                        zmin= zmin, 
    476                        zmax= zmax, 
    477                        cmap= self.cmap, 
    478                        color=0,symbol=0,label=self.data.name) 
     446                       xmin=self.data.xmin, 
     447                       xmax=self.data.xmax, 
     448                       ymin=self.data.ymin, 
     449                       ymax=self.data.ymax, 
     450                       zmin=zmin, 
     451                       zmax=zmax, 
     452                       cmap=self.cmap, 
     453                       color=0, symbol=0, label=self.data.name) 
    479454        # axis labels 
    480455        self.plotpanel.axes[0].set_xlabel('$\\rm{Q}_{x}(A^{-1})$') 
    481456        self.plotpanel.axes[0].set_ylabel('$\\rm{Q}_{y}(A^{-1})$') 
    482          
    483457        self.plotpanel.render() 
    484458        self.plotpanel.subplot.figure.canvas.draw_idle() 
    485          
    486459         
    487460    def _getEmptySlicerEvent(self): 
     
    495468        self.innercircle_rb.SetValue(False) 
    496469        self.outercircle_rb.SetValue(False) 
    497  
    498470        return SlicerEvent(type=None, 
    499471                           params=None, 
    500472                           obj_class=None)  
    501473              
    502     def _draw_model(self,event): 
     474    def _draw_model(self, event): 
    503475        """ 
    504476         on_close, update the model2d plot 
     
    516488        self.plotpanel.axes_frozen = False        
    517489          
    518     def onMouseMotion(self,event): 
     490    def onMouseMotion(self, event): 
    519491        """ 
    520492        """ 
     
    529501    """ 
    530502    """ 
    531     def __init__(self, parent, id = -1, color = None, dpi = None, **kwargs): 
     503    def __init__(self, parent, id=-1, color=None, dpi=None, **kwargs): 
    532504        """ 
    533505        """ 
     
    604576        """ 
    605577        # Initialize the Frame object 
    606         wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850)) 
    607          
     578        wx.Frame.__init__(self, parent, id, title, 
     579                          wx.DefaultPosition, wx.Size(950, 850)) 
    608580        # Panel for 1D plot 
    609         self.plotpanel    = Maskplotpanel(self, -1, style=wx.RAISED_BORDER) 
     581        self.plotpanel = Maskplotpanel(self, -1, style=wx.RAISED_BORDER) 
    610582 
    611583class ViewApp(wx.App): 
  • guiframe/local_perspectives/plotting/plotting.py

    r4e9583c r32c0841  
    9292        pass 
    9393     
    94      
    9594    def _on_plot_event(self, event): 
    9695        """ 
     
    111110                if hasattr(event.plot, "group_id"): 
    112111                    ## if same group_id used the same panel to plot 
    113                     if not event.plot.group_id==None \ 
    114                         and event.plot.group_id==panel.group_id: 
     112                    if not event.plot.group_id == None \ 
     113                        and event.plot.group_id == panel.group_id: 
    115114                        is_available = True 
    116                          
    117115                        panel._onEVT_1DREPLOT(event) 
    118116                        self.parent.show_panel(panel.uid)    
     
    120118                    # Check that the plot panel has no group ID 
    121119                    ## Use a panel with group_id ==None to plot 
    122                      
    123                     if panel.group_id==None: 
     120                    if panel.group_id == None: 
    124121                        is_available = True 
    125122                        panel._onEVT_1DREPLOT(event) 
    126123                        self.parent.show_panel(panel.uid) 
    127          
    128124        # Create a new plot panel if none was available         
    129125        if not is_available: 
    130126            #print"event.plot",hasattr(event.plot,'data') 
    131             if not hasattr(event.plot,'data'): 
     127            if not hasattr(event.plot, 'data'): 
    132128                from Plotter1D import ModelPanel1D 
    133129                ## get the data representation label of the data to plot 
    134130                ## when even the user select "change scale" 
    135                 if hasattr(event.plot,"xtransform"): 
     131                if hasattr(event.plot, "xtransform"): 
    136132                    xtransform = event.plot.xtransform 
    137133                else: 
    138                     xtransform =None 
     134                    xtransform = None 
    139135                     
    140                 if hasattr(event.plot,"ytransform"): 
    141                     ytransform= event.plot.ytransform 
     136                if hasattr(event.plot, "ytransform"): 
     137                    ytransform = event.plot.ytransform 
    142138                else: 
    143                     ytransform=None 
     139                    ytransform = None 
    144140                ## create a plotpanel for 1D Data 
    145                 new_panel = ModelPanel1D(self.parent, -1,xtransform=xtransform, 
    146                                          ytransform=ytransform, style=wx.RAISED_BORDER) 
    147  
     141                new_panel = ModelPanel1D(self.parent, -1, xtransform=xtransform, 
     142                         ytransform=ytransform, style=wx.RAISED_BORDER) 
    148143            else: 
    149144                ##Create a new plotpanel for 2D data 
    150145                from Plotter2D import ModelPanel2D 
    151                 new_panel = ModelPanel2D(self.parent, id = -1, data2d=event.plot,style=wx.RAISED_BORDER) 
    152              
     146                new_panel = ModelPanel2D(self.parent, id = -1, 
     147                                    data2d=event.plot, style=wx.RAISED_BORDER) 
    153148            ## Set group ID if available 
    154149            ## Assign data properties to the new create panel 
    155150            group_id_str = '' 
    156151            if hasattr(event.plot, "group_id"): 
    157                 if not event.plot.group_id==None: 
     152                if not event.plot.group_id == None: 
    158153                    new_panel.group_id = event.plot.group_id 
    159154                    group_id_str = ' [%s]' % event.plot.group_id 
    160              
    161155            if hasattr(event, "title"): 
    162156                new_panel.window_caption = event.title 
    163157                new_panel.window_name = event.title 
    164                 
    165158            event_id = self.parent.popup_panel(new_panel) 
    166159            #remove the default item in the menu 
    167160            if len(self.plot_panels) == 0: 
    168161                self.menu.RemoveItem(self.menu.FindItemByPosition(0)) 
    169                  
    170162            self.menu.Append(event_id, new_panel.window_caption,  
    171163                             "Show %s plot panel" % new_panel.window_caption) 
  • guiframe/local_perspectives/plotting/sectorMask.py

    rd955bf19 r32c0841  
    22import math 
    33import wx 
    4 from copy import deepcopy 
    5  
     4#from copy import deepcopy 
    65from BaseInteractor import _BaseInteractor 
    7 from SectorSlicer import SideInteractor, LineInteractor 
     6from SectorSlicer import SideInteractor 
     7from SectorSlicer import LineInteractor 
    88from sans.guicomm.events import SlicerParameterEvent 
    99 
     
    1212    Draw a sector slicer.Allow to find the data 2D inside of the sector lines 
    1313    """ 
    14     def __init__(self,base,axes,color='gray', zorder=3, side = False): 
    15          
     14    def __init__(self, base, axes, color='gray', zorder=3, side=False): 
     15        """ 
     16        """ 
    1617        _BaseInteractor.__init__(self, base, axes, color=color) 
    1718        ## Class initialization 
     
    2324         
    2425        ## compute qmax limit to reset the graph      
    25         x = math.pow(max(self.base.data.xmax,math.fabs(self.base.data.xmin)),2) 
    26         y = math.pow(max(self.base.data.ymax,math.fabs(self.base.data.ymin)),2) 
    27         self.qmax= math.sqrt(x + y) 
     26        x = math.pow(max(self.base.data.xmax,  
     27                         math.fabs(self.base.data.xmin)), 2) 
     28        y = math.pow(max(self.base.data.ymax,  
     29                         math.fabs(self.base.data.ymin)), 2) 
     30        self.qmax = math.sqrt(x + y) 
    2831        ## Number of points on the plot 
    2932        self.nbins = 20 
    3033        ## Angle of the middle line 
    31         self.theta2= math.pi/3 
     34        self.theta2 = math.pi/3 
    3235        ## Absolute value of the Angle between the middle line and any side line 
    33         self.phi=math.pi/12 
     36        self.phi = math.pi/12 
    3437         
    3538        ## Middle line 
    36         self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax, 
    37                                            theta= self.theta2) 
     39        self.main_line = LineInteractor(self, self.base.subplot, color='blue', 
     40                                zorder=zorder, r=self.qmax, theta=self.theta2) 
    3841        self.main_line.qmax = self.qmax 
    3942        ## Right Side line 
    40         self.right_line= SideInteractor(self, self.base.subplot,color='gray', zorder=zorder, 
    41                                      r=self.qmax, 
    42                                            phi= -1*self.phi, 
    43                                            theta2=self.theta2) 
     43        self.right_line = SideInteractor(self, self.base.subplot, color='gray', 
     44                            zorder=zorder, r=self.qmax, phi= -1*self.phi, 
     45                                                            theta2=self.theta2) 
    4446        self.right_line.qmax = self.qmax 
    4547        ## Left Side line  
    46         self.left_line= SideInteractor(self, self.base.subplot,color='gray', zorder=zorder, 
    47                                      r=self.qmax, 
    48                                            phi= self.phi, 
    49                                            theta2=self.theta2) 
     48        self.left_line = SideInteractor(self, self.base.subplot, color='gray',  
     49                                    zorder=zorder, r=self.qmax, phi= self.phi, 
     50                                                        theta2=self.theta2) 
    5051        self.left_line.qmax = self.qmax 
    5152        ## draw the sector                
    5253        self.update() 
    5354        self._post_data() 
    54  
    5555         
    5656    def clear(self): 
     
    6565        #self.base.Unbind(EVT_SLICER_PARS) 
    6666         
    67          
    6867    def update(self): 
    6968        """ 
     
    7271        """ 
    7372        # Update locations   
    74         ## Check if the middle line was dragged and update the picture accordingly      
     73        ## Check if the middle line was dragged and  
     74        #update the picture accordingly      
    7575        if self.main_line.has_move: 
    7676            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, 
    80                                    mline= self.main_line.theta ) 
     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, 
     80                                   mline=self.main_line.theta) 
    8181        ## Check if the left side has moved and update the slicer accordingly   
    8282        if self.left_line.has_move: 
    8383            self.main_line.update() 
    84             self.left_line.update( phi=None, delta=None, mline=self.main_line , 
     84            self.left_line.update(phi=None, delta=None, mline=self.main_line , 
    8585                                  side=True, left=True ) 
    86             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 update the slicer accordingly 
     86            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  
     90        #update the slicer accordingly 
    9091        if self.right_line.has_move: 
    9192            self.main_line.update() 
    92             self.right_line.update( phi=None, delta=None, mline=self.main_line, 
    93                                    side=True, left=False, right=True ) 
    94             self.left_line.update( phi=self.right_line.phi, delta=None, 
    95                                     mline=self.main_line, side=True, left=False ) 
     93            self.right_line.update(phi=None, delta=None, mline=self.main_line, 
     94                                   side=True, left=False, right=True) 
     95            self.left_line.update(phi=self.right_line.phi, delta=None, 
     96                                    mline=self.main_line, side=True, left=False) 
    9697        #if self.is_inside != None: 
    9798        out = self._post_data() 
     
    125126        phimax = self.left_line.phi + self.main_line.theta 
    126127          
    127         mask = Sectorcut(phi_min= phimin, phi_max= phimax) 
    128          
     128        mask = Sectorcut(phi_min=phimin, phi_max=phimax) 
    129129        if self.is_inside: 
    130             out = (mask(data)==False) 
     130            out = (mask(data) == False) 
    131131        else: 
    132132            out = (mask(data)) 
     
    147147        self._post_data() 
    148148             
    149              
    150149    def restore(self): 
    151150        """ 
     
    162161        pass 
    163162         
    164          
    165163    def set_cursor(self, x, y): 
    166164        pass 
    167          
    168165         
    169166    def get_params(self): 
     
    178175        ## angle of the middle line 
    179176        if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 
    180             raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 
    181          
     177            msg = "Phi left and phi right are " 
     178            msg += "different %f, %f" % (self.left_line.phi,  
     179                                         self.right_line.phi) 
     180            raise ValueError, msg 
    182181        params["Phi"] = self.main_line.theta 
    183182        params["Delta_Phi"] = math.fabs(self.left_line.phi) 
     
    193192        """ 
    194193        main = params["Phi"]  
    195         phi = math.fabs(params["Delta_Phi"] ) 
    196          
    197         self.main_line.theta= main 
     194        phi = math.fabs(params["Delta_Phi"]) 
     195         
     196        self.main_line.theta = main 
    198197        ## Reset the slicer parameters 
    199198        self.main_line.update() 
    200         self.right_line.update( phi=phi,delta=None, mline=self.main_line, 
    201                                side=True, right=True ) 
    202         self.left_line.update( phi=phi, delta=None, mline=self.main_line, side=True ) 
     199        self.right_line.update(phi=phi, delta=None, mline=self.main_line, 
     200                               side=True, right=True) 
     201        self.left_line.update(phi=phi, delta=None, 
     202                              mline=self.main_line, side=True) 
    203203        ## post the new corresponding data 
    204204        self._post_data() 
  • guiframe/local_perspectives/plotting/slicerpanel.py

    rd955bf19 r32c0841  
    33import wx 
    44import wx.lib.newevent 
    5 from copy import deepcopy 
    6  
     5#from copy import deepcopy 
    76from sans.guiframe.utils import format_number 
    8 from sans.guicomm.events  import SlicerParameterEvent,EVT_SLICER_PARS,EVT_SLICER 
    9  
     7from sans.guicomm.events import SlicerParameterEvent 
     8from sans.guicomm.events import EVT_SLICER_PARS 
     9from sans.guicomm.events import EVT_SLICER 
    1010 
    1111 
     
    2020    ## Title to appear on top of the window 
    2121    window_caption = "Slicer Panel" 
    22      
    2322    CENTER_PANE = False 
    2423     
    25     def __init__(self, parent,id=-1,type=None,base=None, params={}, *args, **kwargs): 
    26         wx.Panel.__init__(self, parent,id, *args, **kwargs) 
     24    def __init__(self, parent, id=-1, type=None, base=None, 
     25                params=None, *args, **kwargs): 
     26        wx.Panel.__init__(self, parent, id, *args, **kwargs) 
    2727        ##  Initialization of the class      
    28         self.base= base 
     28        self.base = base 
     29        if params is None: 
     30            params = {} 
    2931        self.params = params 
    3032        self.parent = parent 
     
    3234        self.listeners = [] 
    3335        self.parameters = [] 
    34          
    35         self.bck = wx.GridBagSizer(5,5) 
     36        self.bck = wx.GridBagSizer(5, 5) 
    3637        self.SetSizer(self.bck) 
    37         if type==None and params==None:       
    38             title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 
    39             self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
     38        if type == None and params == None:   
     39            label = "Right-click on 2D plot for slicer options"   
     40            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 
     41            self.bck.Add(title, (0, 0), (1, 2),  
     42                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    4043        else: 
    41             self.set_slicer( type, params) 
     44            self.set_slicer(type, params) 
    4245        ## Bindings 
    4346        self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) 
    4447        self.parent.Bind(EVT_SLICER_PARS, self.onParamChange) 
    45  
    4648 
    4749    def onEVT_SLICER(self, event): 
     
    5456        """ 
    5557        event.Skip() 
    56         if event.obj_class==None: 
     58        if event.obj_class == None: 
    5759            self.set_slicer(None, None)  
    5860        else: 
     
    6567        self.bck.Clear(True)   
    6668        self.type = type   
    67         if type==None: 
    68             title = wx.StaticText(self, -1, "Right-click on 2D plot for slicer options", style=wx.ALIGN_LEFT) 
    69             self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
     69        if type == None: 
     70            label = "Right-click on 2D plot for slicer options" 
     71            title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 
     72            self.bck.Add(title, (0, 0), (1, 2),  
     73                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    7074        else: 
    71             title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT) 
    72             self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    73              
     75            title = wx.StaticText(self, -1, "Slicer Parameters",  
     76                                  style=wx.ALIGN_LEFT) 
     77            self.bck.Add(title, (0, 0), (1, 2),  
     78                         flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
    7479            n = 1 
    7580            self.parameters = [] 
    7681            keys = params.keys() 
    7782            keys.sort() 
    78             
    7983            for item in keys: 
    80                 if not  item.lower() in ["errors", "count"]: 
     84                if not item.lower() in ["errors", "count"]: 
    8185                    n += 1 
    8286                    text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 
    83                     self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 
    84                     ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 
    85                     ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 
     87                    self.bck.Add(text, (n-1, 0),  
     88                            flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 
     89                    ctl = wx.TextCtrl(self, -1, size=(80, 20),  
     90                                      style=wx.TE_PROCESS_ENTER) 
     91                    hint_msg = "Modify the value of %s to change " 
     92                    hint_msg += "the 2D slicer" % item 
     93                    ctl.SetToolTipString(hint_msg) 
    8694                    ctl.SetValue(str(format_number(params[item]))) 
    87  
    8895                    self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 
    8996                    ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    9097                    ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 
    91                     
    9298                    self.parameters.append([item, ctl]) 
    93                     self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0) 
     99                    self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0) 
    94100            for item in keys: 
    95101                if  item.lower() in ["errors", "count"]: 
    96102                    n += 1 
    97                     text = wx.StaticText(self, -1, item+": ", style=wx.ALIGN_LEFT) 
    98                     self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 
    99                     ctl = wx.StaticText(self, -1, str(format_number(params[item])), style=wx.ALIGN_LEFT) 
     103                    text = wx.StaticText(self, -1, item + ": ",  
     104                                         style=wx.ALIGN_LEFT) 
     105                    self.bck.Add(text, (n-1, 0),  
     106                                 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL,  
     107                                 border=15) 
     108                    ctl = wx.StaticText(self, -1,  
     109                                        str(format_number(params[item])), 
     110                                        style=wx.ALIGN_LEFT) 
    100111                    ctl.SetToolTipString("Result %s" % item) 
    101                     self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0) 
    102                      
     112                    self.bck.Add(ctl, (n-1, 1), flag=wx.TOP|wx.BOTTOM, border=0)        
    103113        self.bck.Layout() 
    104114        #self.bck.Fit(self) 
     
    113123        widget = evt.GetEventObject() 
    114124        # Select the whole control, after this event resolves 
    115         wx.CallAfter(widget.SetSelection, -1,-1) 
     125        wx.CallAfter(widget.SetSelection, -1, -1) 
    116126        return 
    117      
    118127     
    119128    def onParamChange(self, evt): 
     
    145154                item[1].Refresh() 
    146155             
    147         if has_error==False: 
     156        if has_error == False: 
    148157            # Post parameter event 
    149158            ## base is guiframe is this case 
Note: See TracChangeset for help on using the changeset viewer.