Changeset b5de88e in sasview


Ignore:
Timestamp:
Mar 5, 2015 12:49:03 PM (9 years ago)
Author:
Mathieu Doucet <doucetm@…>
Branches:
master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
Children:
7d56795
Parents:
824e488
Message:

pylint fixes

Location:
src/sas/guiframe/local_perspectives/plotting
Files:
7 edited

Legend:

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

    r79492222 rb5de88e  
     1import math 
     2from BaseInteractor import _BaseInteractor 
    13 
    2 import math 
    3 #import wx   
    4 #from copy import deepcopy 
    5 from BaseInteractor import _BaseInteractor 
    6 #from sas.guiframe.events import NewPlotEvent 
    7 #from sas.guiframe.events import StatusEvent 
    8 #from sas.guiframe.events import SlicerParameterEvent 
    9 #from sas.guiframe.events import EVT_SLICER_PARS 
    10     
    114 
    125class RadiusInteractor(_BaseInteractor): 
     
    158    """ 
    169    def __init__(self, base, axes, color='black', zorder=5, arc1=None, 
    17                  arc2=None, theta=math.pi/8): 
     10                 arc2=None, theta=math.pi / 8): 
    1811        """ 
    1912        """ 
     
    2316        self.r1 = arc1.get_radius() 
    2417        self.r2 = arc2.get_radius() 
    25         #print "radius init", self.r1, self.r2 
    2618        self.theta = theta 
    2719        self.save_theta = theta 
    28         #self.scale = 10.0 
    2920        self.move_stop = False 
    3021        self.theta_left = None 
     
    3223        self.arc1 = arc1 
    3324        self.arc2 = arc2 
    34         #raise "Version error", message 
    3525        x1 = self.r1 * math.cos(self.theta) 
    3626        y1 = self.r1 * math.sin(self.theta) 
     
    3828        y2 = self.r2 * math.sin(self.theta) 
    3929        self.line = self.axes.plot([x1, x2], [y1, y2], 
    40                                       linestyle='-', marker='', 
    41                                       color=self.color, 
    42                                       visible=True)[0] 
     30                                   linestyle='-', marker='', 
     31                                   color=self.color, 
     32                                   visible=True)[0] 
    4333        self.phi = theta 
    4434        self.npts = 20 
     
    4636        self.connect_markers([self.line]) 
    4737        self.update() 
    48          
     38 
    4939    def set_layer(self, n): 
    5040        """ 
     
    5242        self.layernum = n 
    5343        self.update() 
    54          
     44 
    5545    def clear(self): 
    5646        """ 
     
    6353            for item in range(len(self.axes.lines)): 
    6454                del self.axes.lines[0] 
    65      
     55 
    6656    def get_angle(self): 
    6757        """ 
    6858        """ 
    6959        return self.theta 
    70          
     60 
    7161    def update(self, r1=None, r2=None, theta=None): 
    7262        """ 
     
    7969        if theta != None: 
    8070            self.theta = theta 
    81         #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta) 
    8271        x1 = self.r1 * math.cos(self.theta) 
    8372        y1 = self.r1 * math.sin(self.theta) 
    8473        x2 = self.r2 * math.cos(self.theta) 
    85         y2 = self.r2 * math.sin(self.theta)   
     74        y2 = self.r2 * math.sin(self.theta) 
    8675        self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 
    87          
     76 
    8877    def save(self, ev): 
    8978        """ 
     
    9180        can restore on Esc. 
    9281        """ 
    93         self.save_theta = math.atan2(ev.y,ev.x) 
    94         #self.save_theta= self.theta 
     82        self.save_theta = math.atan2(ev.y, ev.x) 
    9583        self.base.freeze_axes() 
    96     
     84 
    9785    def moveend(self, ev): 
    9886        """ 
     
    10088        self.has_move = False 
    10189        self.base.moveend(ev) 
    102              
     90 
    10391    def restore(self, ev): 
    10492        """ 
     
    114102        self.has_move = True 
    115103        self.base.base.update() 
    116          
     104 
    117105    def set_cursor(self, r_min, r_max, theta): 
    118106        """ 
     
    122110        self.r2 = r_max 
    123111        self.update() 
    124          
     112 
    125113    def get_params(self): 
    126114        """ 
     
    131119        params["theta"] = self.theta 
    132120        return params 
    133      
     121 
    134122    def set_params(self, params): 
    135123        """ 
    136124        """ 
    137         #print "when here set curcor arc" 
    138         x1 = params["radius1"]  
    139         x2 = params["radius2"]  
    140         theta= params["theta"] 
     125        x1 = params["radius1"] 
     126        x2 = params["radius2"] 
     127        theta = params["theta"] 
    141128        self.set_cursor(x1, x2, theta) 
    142          
    143      
  • src/sas/guiframe/local_perspectives/plotting/boxMask.py

    r79492222 rb5de88e  
    1  
    2  
    3  
    41import math 
    5 #import wx 
    6 #from copy import deepcopy 
    72from BaseInteractor import _BaseInteractor 
    83from boxSum import PointInteractor 
    94from boxSum import VerticalDoubleLine 
    105from boxSum import HorizontalDoubleLine 
    11 #from sas.guiframe.events import SlicerParamUpdateEvent 
    126 
    137 
     
    159    """ 
    1610    BoxMask Class: determine 2 rectangular area to find the pixel of 
    17     a Data inside of box.  
    18      
     11    a Data inside of box. 
     12 
    1913    Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
    20      
     14 
    2115    :param zorder:  Artists with lower zorder values are drawn first. 
    2216    :param x_min: the minimum value of the x coordinate 
     
    2620 
    2721    """ 
    28     def __init__(self, base, axes, color='black', zorder=3, side=None,  
    29                    x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 
     22    def __init__(self, base, axes, color='black', zorder=3, side=None, 
     23                 x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 
    3024        """ 
    3125        """ 
    3226        _BaseInteractor.__init__(self, base, axes, color=color) 
    33         ## class initialization 
    34         ## list of Boxmask markers 
     27        # # class initialization 
     28        # # list of Boxmask markers 
    3529        self.markers = [] 
    3630        self.axes = axes 
    3731        self.mask = None 
    3832        self.is_inside = side 
    39         ## connect the artist for the motion 
     33        # # connect the artist for the motion 
    4034        self.connect = self.base.connect 
    41         ## when qmax is reached the selected line is reset  
    42         #the its previous value 
     35        # # when qmax is reached the selected line is reset 
     36        # the its previous value 
    4337        self.qmax = min(self.base.data.xmax, self.base.data.xmin) 
    44         ## Define the box limits 
     38        # # Define the box limits 
    4539        self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 
    46                                  math.fabs(self.base.data.xmin)) 
     40                                   math.fabs(self.base.data.xmin)) 
    4741        self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 
    4842                                   math.fabs(self.base.data.xmin)) 
    4943        self.xmax = 0.5 * min(math.fabs(self.base.data.xmax), 
    5044                              math.fabs(self.base.data.xmin)) 
    51         self.ymax =  0.5 * min(math.fabs(self.base.data.xmax), 
    52                                math.fabs(self.base.data.xmin)) 
    53         ## center of the box 
     45        self.ymax = 0.5 * min(math.fabs(self.base.data.xmax), 
     46                              math.fabs(self.base.data.xmin)) 
     47        # # center of the box 
    5448        self.center_x = 0.0002 
    5549        self.center_y = 0.0003 
    56         ## Number of points on the plot 
     50        # # Number of points on the plot 
    5751        self.nbins = 20 
    58         ## Define initial result the summation  
     52        # # Define initial result the summation 
    5953        self.count = 0 
    6054        self.error = 0 
    6155        self.data = self.base.data 
    62         ## Flag to determine if the current figure has moved 
    63         ## set to False == no motion , set to True== motion 
     56        # # Flag to determine if the current figure has moved 
     57        # # set to False == no motion , set to True== motion 
    6458        self.has_move = False 
    65         ## Create Box edges  
     59        # # Create Box edges 
    6660        self.horizontal_lines = HorizontalDoubleLine(self, 
    6761                                                     self.base.subplot, 
    6862                                                     color='blue', 
    69                                                       zorder=zorder, 
    70                                                       y=self.ymax, 
    71                                                       x=self.xmax, 
    72                                                       center_x=self.center_x, 
    73                                                       center_y=self.center_y) 
     63                                                     zorder=zorder, 
     64                                                     y=self.ymax, 
     65                                                     x=self.xmax, 
     66                                                     center_x=self.center_x, 
     67                                                     center_y=self.center_y) 
    7468        self.horizontal_lines.qmax = self.qmax 
    75          
     69 
    7670        self.vertical_lines = VerticalDoubleLine(self, 
    77                                                 self.base.subplot, 
    78                                                 color='grey', 
    79                                                 zorder=zorder, 
    80                                                 y=self.ymax, 
    81                                                 x=self.xmax, 
    82                                                 center_x=self.center_x, 
    83                                                 center_y=self.center_y) 
     71                                                 self.base.subplot, 
     72                                                 color='grey', 
     73                                                 zorder=zorder, 
     74                                                 y=self.ymax, 
     75                                                 x=self.xmax, 
     76                                                 center_x=self.center_x, 
     77                                                 center_y=self.center_y) 
    8478        self.vertical_lines.qmax = self.qmax 
    85          
     79 
    8680        self.center = PointInteractor(self, 
    87                                       self.base.subplot,color='grey', 
    88                                     zorder=zorder, 
    89                                     center_x=self.center_x, 
    90                                     center_y=self.center_y) 
    91         ## Save the name of the slicer panel associate with this slicer  
    92         self.panel_name = ""     
    93         ## Update and post slicer parameters   
     81                                      self.base.subplot, color='grey', 
     82                                      zorder=zorder, 
     83                                      center_x=self.center_x, 
     84                                      center_y=self.center_y) 
     85        # # Save the name of the slicer panel associate with this slicer 
     86        self.panel_name = "" 
     87        # # Update and post slicer parameters 
    9488        self.update() 
    9589        self._post_data() 
    96      
     90 
    9791    def clear(self): 
    9892        """ 
     
    10498        self.center.clear() 
    10599        self.base.connect.clearall() 
    106         #self.base.Unbind(EVT_SLICER_PARS) 
    107      
     100 
    108101    def update(self): 
    109102        """ 
     
    111104        resetting the widgets. 
    112105        """ 
    113         # check if the center point has moved and update the figure accordingly  
     106        # check if the center point has moved and update the figure accordingly 
    114107        if self.center.has_move: 
    115108            self.center.update() 
    116109            self.horizontal_lines.update(center=self.center) 
    117110            self.vertical_lines.update(center=self.center) 
    118         ## check if the horizontal lines have moved and update 
    119         # the figure accordingly     
     111        # # check if the horizontal lines have moved and update 
     112        # the figure accordingly 
    120113        if self.horizontal_lines.has_move: 
    121114            self.horizontal_lines.update() 
     
    123116                                       y2=self.horizontal_lines.y2, 
    124117                                       height=self.horizontal_lines.half_height) 
    125         ## check if the vertical lines have moved and update 
    126         # the figure accordingly     
     118        # # check if the vertical lines have moved and update 
     119        # the figure accordingly 
    127120        if self.vertical_lines.has_move: 
    128121            self.vertical_lines.update() 
     
    130123                                         x2=self.vertical_lines.x2, 
    131124                                         width=self.vertical_lines.half_width) 
    132         #if self.is_inside != None: 
     125        # if self.is_inside != None: 
    133126        out = self._post_data() 
    134127        return out 
    135          
     128 
    136129    def save(self, ev): 
    137130        """ 
     
    143136        self.vertical_lines.save(ev) 
    144137        self.center.save(ev) 
    145          
     138 
    146139    def _post_data(self): 
    147140        """ 
     
    150143        """ 
    151144        from sas.dataloader.manipulations import Boxcut 
    152         ## Data 2D for which the pixel will be summed 
     145        # # Data 2D for which the pixel will be summed 
    153146        data = self.base.data 
    154147        mask = data.mask 
    155         ## the region of the summation 
    156         x_min = self.horizontal_lines.x2  
    157         x_max = self.horizontal_lines.x1  
     148        # # the region of the summation 
     149        x_min = self.horizontal_lines.x2 
     150        x_max = self.horizontal_lines.x1 
    158151        y_min = self.vertical_lines.y2 
    159152        y_max = self.vertical_lines.y1 
     
    164157        else: 
    165158            out = (mask(data)) 
    166         #self.base.data.mask=out 
     159        # self.base.data.mask=out 
    167160        self.mask = mask 
    168         return out   
    169                
     161        return out 
     162 
    170163    def moveend(self, ev): 
    171164        """ 
    172165        After a dragging motion this function is called to compute 
    173         the error and the sum of pixel of a given data 2D  
     166        the error and the sum of pixel of a given data 2D 
    174167        """ 
    175168        self.base.thaw_axes() 
    176         ## post 
     169        # # post 
    177170        self._post_data() 
    178              
     171 
    179172    def restore(self): 
    180173        """ 
     
    184177        self.vertical_lines.restore() 
    185178        self.center.restore() 
    186          
     179 
    187180    def move(self, x, y, ev): 
    188181        """ 
     
    190183        """ 
    191184        pass 
    192      
     185 
    193186    def set_cursor(self, x, y): 
    194187        pass 
    195          
     188 
    196189    def get_params(self): 
    197190        """ 
    198191        Store a copy of values of parameters of the slicer into a dictionary. 
    199          
     192 
    200193        :return params: the dictionary created 
    201          
     194 
    202195        """ 
    203196        params = {} 
    204197        params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 
    205         params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2  
     198        params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 
    206199        params["center_x"] = self.center.x 
    207200        params["center_y"] = self.center.y 
    208201        return params 
    209      
     202 
    210203    def get_mask(self): 
    211204        """ 
     
    214207        mask = self.mask 
    215208        return mask 
    216      
     209 
    217210    def set_params(self, params): 
    218211        """ 
    219         Receive a dictionary and reset the slicer with values contained  
     212        Receive a dictionary and reset the slicer with values contained 
    220213        in the values of the dictionary. 
    221          
    222         :param params: a dictionary containing name of slicer parameters and  
     214 
     215        :param params: a dictionary containing name of slicer parameters and 
    223216           values the user assigned to the slicer. 
    224217        """ 
    225         x_max = math.fabs(params["Width"] )/2 
    226         y_max = math.fabs(params["Height"])/2 
    227          
    228         self.center_x = params["center_x"]  
     218        x_max = math.fabs(params["Width"]) / 2 
     219        y_max = math.fabs(params["Height"]) / 2 
     220 
     221        self.center_x = params["center_x"] 
    229222        self.center_y = params["center_y"] 
    230         #update the slicer given values of params 
     223        # update the slicer given values of params 
    231224        self.center.update(center_x=self.center_x, center_y=self.center_y) 
    232         self.horizontal_lines.update(center=self.center, 
    233                                      width=x_max, 
    234                                      height=y_max) 
    235         self.vertical_lines.update(center=self.center, 
    236                                     width=x_max, 
    237                                     height=y_max) 
    238         #compute the new error and sum given values of params 
     225        self.horizontal_lines.update(center=self.center, width=x_max, height=y_max) 
     226        self.vertical_lines.update(center=self.center, width=x_max, height=y_max) 
     227        # compute the new error and sum given values of params 
    239228        self._post_data() 
    240                 
     229 
    241230    def freeze_axes(self): 
    242231        self.base.freeze_axes() 
    243          
     232 
    244233    def thaw_axes(self): 
    245234        self.base.thaw_axes() 
     
    248237        self.base.update() 
    249238 
    250 class inner_BoxMask(BoxMask):    
    251     def __call__(self):      
    252         self.base.data.mask = (self._post_data()==False) 
    253        
    254     
     239class inner_BoxMask(BoxMask): 
     240    def __call__(self): 
     241        self.base.data.mask = (self._post_data() == False) 
  • src/sas/guiframe/local_perspectives/plotting/boxSlicer.py

    r79492222 rb5de88e  
    1  
    2  
    31import wx 
    4 #import copy 
    5 #from copy import deepcopy 
    62import math 
    73import numpy 
     
    128from BaseInteractor import _BaseInteractor 
    139from sas.guiframe.dataFitting import Data1D 
    14 #import SlicerParameters 
    1510 
    1611 
     
    2217    def __init__(self, base, axes, color='black', zorder=3): 
    2318        _BaseInteractor.__init__(self, base, axes, color=color) 
    24         ## Class initialization 
     19        # # Class initialization 
    2520        self.markers = [] 
    2621        self.axes = axes 
    27         ##connecting artist 
     22        # #connecting artist 
    2823        self.connect = self.base.connect 
    29         ## which direction is the preferred interaction direction 
     24        # # which direction is the preferred interaction direction 
    3025        self.direction = None 
    31         ## determine x y  values 
     26        # # determine x y  values 
    3227        self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    3328                           math.fabs(self.base.data2D.xmin)) 
    3429        self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    35                            math.fabs(self.base.data2D.xmin))         
    36         ## when reach qmax reset the graph 
     30                           math.fabs(self.base.data2D.xmin)) 
     31        # # when reach qmax reset the graph 
    3732        self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 
    38                         self.base.data2D.ymax, self.base.data2D.ymin)    
    39         ## Number of points on the plot 
     33                        self.base.data2D.ymax, self.base.data2D.ymin) 
     34        # # Number of points on the plot 
    4035        self.nbins = 30 
    41         ## If True, I(|Q|) will be return, otherwise, 
    42         #negative q-values are allowed 
    43         self.fold = True         
    44         ## reference of the current  Slab averaging 
     36        # # If True, I(|Q|) will be return, otherwise, 
     37        # negative q-values are allowed 
     38        self.fold = True 
     39        # # reference of the current  Slab averaging 
    4540        self.averager = None 
    46         ## Create vertical and horizaontal lines for the rectangle 
     41        # # Create vertical and horizaontal lines for the rectangle 
    4742        self.vertical_lines = VerticalLines(self, 
    48                                             self.base.subplot,  
    49                                             color='blue',  
     43                                            self.base.subplot, 
     44                                            color='blue', 
    5045                                            zorder=zorder, 
    51                                             y=self.y , 
     46                                            y=self.y, 
    5247                                            x=self.x) 
    5348        self.vertical_lines.qmax = self.qmax 
    54         
     49 
    5550        self.horizontal_lines = HorizontalLines(self, 
    56                                                self.base.subplot, 
    57                                                color='green',  
    58                                                zorder=zorder, 
    59                                                x=self.x, 
    60                                                y=self.y) 
     51                                                self.base.subplot, 
     52                                                color='green', 
     53                                                zorder=zorder, 
     54                                                x=self.x, 
     55                                                y=self.y) 
    6156        self.horizontal_lines.qmax = self.qmax 
    62         ## draw the rectangle and plost the data 1D resulting 
    63         ## of averaging data2D 
     57        # # draw the rectangle and plost the data 1D resulting 
     58        # # of averaging data2D 
    6459        self.update() 
    6560        self._post_data() 
    66         ## Bind to slice parameter events 
     61        # # Bind to slice parameter events 
    6762        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    6863 
     
    7065        """ 
    7166        receive an event containing parameters values to reset the slicer 
    72          
    73         :param event: event of type SlicerParameterEvent with params as  
     67 
     68        :param event: event of type SlicerParameterEvent with params as 
    7469            attribute 
    7570        """ 
     
    8075            self.set_params(event.params) 
    8176            self.base.update() 
    82              
     77 
    8378    def update_and_post(self): 
    8479        """ 
     
    8782        self.update() 
    8883        self._post_data() 
    89          
     84 
    9085    def set_layer(self, n): 
    9186        """ 
    9287        Allow adding plot to the same panel 
    93          
     88 
    9489        :param n: the number of layer 
    95          
     90 
    9691        """ 
    9792        self.layernum = n 
    9893        self.update() 
    99          
     94 
    10095    def clear(self): 
    10196        """ 
     
    108103        self.base.connect.clearall() 
    109104        self.base.Unbind(EVT_SLICER_PARS) 
    110          
     105 
    111106    def update(self): 
    112107        """ 
     
    114109        resetting the widgets. 
    115110        """ 
    116         ##Update the slicer if an horizontal line is dragged    
     111        # #Update the slicer if an horizontal line is dragged 
    117112        if self.horizontal_lines.has_move: 
    118113            self.horizontal_lines.update() 
    119114            self.vertical_lines.update(y=self.horizontal_lines.y) 
    120         ##Update the slicer if a vertical line is dragged     
     115        # #Update the slicer if a vertical line is dragged 
    121116        if self.vertical_lines.has_move: 
    122117            self.vertical_lines.update() 
    123118            self.horizontal_lines.update(x=self.vertical_lines.x) 
    124                   
     119 
    125120    def save(self, ev): 
    126121        """ 
     
    131126        self.vertical_lines.save(ev) 
    132127        self.horizontal_lines.save(ev) 
    133      
     128 
    134129    def _post_data(self): 
    135130        pass 
    136          
     131 
    137132    def post_data(self, new_slab=None, nbins=None, direction=None): 
    138133        """ 
    139134        post data averaging in Qx or Qy given new_slab type 
    140          
     135 
    141136        :param new_slab: slicer that determine with direction to average 
    142137        :param nbins: the number of points plotted when averaging 
    143138        :param direction: the direction of averaging 
    144          
     139 
    145140        """ 
    146141        if self.direction == None: 
    147142            self.direction = direction 
    148              
     143 
    149144        x_min = -1 * math.fabs(self.vertical_lines.x) 
    150145        x_max = math.fabs(self.vertical_lines.x) 
    151146        y_min = -1 * math.fabs(self.horizontal_lines.y) 
    152147        y_max = math.fabs(self.horizontal_lines.y) 
    153          
     148 
    154149        if nbins != None: 
    155150            self.nbins = nbins 
     
    164159            else: 
    165160                x_low = math.fabs(x_min) 
    166             bin_width = (x_max + x_low)/self.nbins 
     161            bin_width = (x_max + x_low) / self.nbins 
    167162        elif self.direction == "Y": 
    168163            if self.fold: 
     
    170165            else: 
    171166                y_low = math.fabs(y_min) 
    172             bin_width = (y_max + y_low)/self.nbins 
     167            bin_width = (y_max + y_low) / self.nbins 
    173168        else: 
    174169            msg = "post data:no Box Average direction was supplied" 
    175170            raise ValueError, msg 
    176         ## Average data2D given Qx or Qy 
     171        # # Average data2D given Qx or Qy 
    177172        box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 
    178                          bin_width=bin_width) 
     173                            bin_width=bin_width) 
    179174        box.fold = self.fold 
    180175        boxavg = box(self.base.data2D) 
    181         #3 Create Data1D to plot 
     176        # 3 Create Data1D to plot 
    182177        if hasattr(boxavg, "dxl"): 
    183178            dxl = boxavg.dxl 
     
    189184            dxw = None 
    190185        new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 
    191         new_plot.dxl  = dxl 
    192         new_plot.dxw  = dxw 
     186        new_plot.dxl = dxl 
     187        new_plot.dxw = dxw 
    193188        new_plot.name = str(self.averager.__name__) + \ 
    194189                        "(" + self.base.data2D.name + ")" 
     
    196191        new_plot.interactive = True 
    197192        new_plot.detector = self.base.data2D.detector 
    198         ## If the data file does not tell us what the axes are, just assume... 
     193        # # If the data file does not tell us what the axes are, just assume... 
    199194        new_plot.xaxis("\\rm{Q}", "A^{-1}") 
    200195        new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 
     
    205200            new_plot.ytransform = 'y' 
    206201            new_plot.yaxis("\\rm{Residuals} ", "/") 
    207              
     202 
    208203        new_plot.group_id = "2daverage" + self.base.data2D.name 
    209204        new_plot.id = (self.averager.__name__) + self.base.data2D.name 
    210         new_plot.is_data= True 
     205        new_plot.is_data = True 
    211206        self.base.parent.update_theory(data_id=self.base.data2D.id, \ 
    212207                                       theory=new_plot) 
    213         wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 
    214                                title=str(self.averager.__name__))) 
    215            
     208        wx.PostEvent(self.base.parent, 
     209                     NewPlotEvent(plot=new_plot, title=str(self.averager.__name__))) 
     210 
    216211    def moveend(self, ev): 
    217212        """ 
    218213        Called after a dragging event. 
    219         Post the slicer new parameters and creates a new Data1D  
     214        Post the slicer new parameters and creates a new Data1D 
    220215        corresponding to the new average 
    221216        """ 
     
    228223        # create the new data1D 
    229224        self._post_data() 
    230              
     225 
    231226    def restore(self): 
    232227        """ 
     
    235230        self.horizontal_lines.restore() 
    236231        self.vertical_lines.restore() 
    237         
     232 
    238233    def move(self, x, y, ev): 
    239234        """ 
     
    241236        """ 
    242237        pass 
    243          
     238 
    244239    def set_cursor(self, x, y): 
    245240        pass 
    246          
     241 
    247242    def get_params(self): 
    248243        """ 
    249244        Store a copy of values of parameters of the slicer into a dictionary. 
    250          
     245 
    251246        :return params: the dictionary created 
    252          
     247 
    253248        """ 
    254249        params = {} 
     
    257252        params["nbins"] = self.nbins 
    258253        return params 
    259      
     254 
    260255    def set_params(self, params): 
    261256        """ 
    262         Receive a dictionary and reset the slicer with values contained  
     257        Receive a dictionary and reset the slicer with values contained 
    263258        in the values of the dictionary. 
    264          
    265         :param params: a dictionary containing name of slicer parameters and  
     259 
     260        :param params: a dictionary containing name of slicer parameters and 
    266261            values the user assigned to the slicer. 
    267262        """ 
    268263        self.x = float(math.fabs(params["x_max"])) 
    269         self.y = float(math.fabs(params["y_max"] )) 
     264        self.y = float(math.fabs(params["y_max"])) 
    270265        self.nbins = params["nbins"] 
    271          
     266 
    272267        self.horizontal_lines.update(x=self.x, y=self.y) 
    273268        self.vertical_lines.update(x=self.x, y=self.y) 
    274269        self.post_data(nbins=None) 
    275          
     270 
    276271    def freeze_axes(self): 
    277272        """ 
    278273        """ 
    279274        self.base.freeze_axes() 
    280          
     275 
    281276    def thaw_axes(self): 
    282277        """ 
     
    292287class HorizontalLines(_BaseInteractor): 
    293288    """ 
    294     Draw 2 Horizontal lines centered on (0,0) that can move  
     289    Draw 2 Horizontal lines centered on (0,0) that can move 
    295290    on the x- direction and in opposite direction 
    296291    """ 
     
    299294        """ 
    300295        _BaseInteractor.__init__(self, base, axes, color=color) 
    301         ##Class initialization 
     296        # #Class initialization 
    302297        self.markers = [] 
    303298        self.axes = axes 
    304         ## Saving the end points of two lines 
     299        # # Saving the end points of two lines 
    305300        self.x = x 
    306301        self.save_x = x 
    307          
     302 
    308303        self.y = y 
    309304        self.save_y = y 
    310         ## Creating a marker 
    311         try: 
    312             # Inner circle marker 
    313             self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    314                                           marker='s', markersize=10, 
    315                                           color=self.color, alpha=0.6, 
    316                                           pickradius=5, label="pick",  
    317                                           # Prefer this to other lines 
    318                                           zorder=zorder,  
    319                                           visible=True)[0] 
    320         except: 
    321             self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
    322                                           marker='s', markersize=10, 
    323                                           color=self.color, alpha=0.6, 
    324                                           label="pick", visible=True)[0] 
    325             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 
    326             message += "OF MATPLOTLIB\n Get the SVN version that" 
    327             message += " is at least as recent as June 1, 2007" 
    328             owner = self.base.base.parent 
    329             wx.PostEvent(owner, 
    330                          StatusEvent(status="AnnulusSlicer: %s" % message)) 
    331         ## Define 2 horizontal lines 
     305        # # Creating a marker 
     306        # Inner circle marker 
     307        self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 
     308                                           marker='s', markersize=10, 
     309                                           color=self.color, alpha=0.6, 
     310                                           pickradius=5, label="pick", 
     311                                           zorder=zorder, 
     312                                           visible=True)[0] 
     313        # # Define 2 horizontal lines 
    332314        self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 
    333                                       linestyle='-', marker='', 
    334                                       color=self.color, visible=True)[0] 
     315                                       linestyle='-', marker='', 
     316                                       color=self.color, visible=True)[0] 
    335317        self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 
    336                                       linestyle='-', marker='', 
    337                                       color=self.color, visible=True)[0] 
    338         ## Flag to check the motion of the lines 
     318                                          linestyle='-', marker='', 
     319                                          color=self.color, visible=True)[0] 
     320        # # Flag to check the motion of the lines 
    339321        self.has_move = False 
    340         ## Connecting markers to mouse events and draw 
     322        # # Connecting markers to mouse events and draw 
    341323        self.connect_markers([self.top_line, self.inner_marker]) 
    342324        self.update() 
     
    345327        """ 
    346328        Allow adding plot to the same panel 
    347          
     329 
    348330        :param n: the number of layer 
    349          
     331 
    350332        """ 
    351333        self.layernum = n 
    352334        self.update() 
    353          
     335 
    354336    def clear(self): 
    355337        """ 
     
    359341        try: 
    360342            self.inner_marker.remove() 
    361             self.top_line.remove()  
     343            self.top_line.remove() 
    362344            self.bottom_line.remove() 
    363345        except: 
     
    365347            for item in range(len(self.axes.lines)): 
    366348                del self.axes.lines[0] 
    367     
     349 
    368350    def update(self, x=None, y=None): 
    369351        """ 
    370352        Draw the new roughness on the graph. 
    371          
     353 
    372354        :param x: x-coordinates to reset current class x 
    373355        :param y: y-coordinates to reset current class y 
    374          
    375         """ 
    376         ## Reset x, y- coordinates if send as parameters 
     356 
     357        """ 
     358        # # Reset x, y- coordinates if send as parameters 
    377359        if x != None: 
    378360            self.x = numpy.sign(self.x) * math.fabs(x) 
    379361        if y != None: 
    380362            self.y = numpy.sign(self.y) * math.fabs(y) 
    381         ## Draw lines and markers 
     363        # # Draw lines and markers 
    382364        self.inner_marker.set(xdata=[0], ydata=[self.y]) 
    383365        self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 
    384         self.bottom_line.set(xdata=[self.x,-self.x], ydata=[-self.y, -self.y]) 
    385          
     366        self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y]) 
     367 
    386368    def save(self, ev): 
    387369        """ 
     
    400382        self.has_move = False 
    401383        self.base.moveend(ev) 
    402               
     384 
    403385    def restore(self): 
    404386        """ 
     
    407389        self.x = self.save_x 
    408390        self.y = self.save_y 
    409          
     391 
    410392    def move(self, x, y, ev): 
    411393        """ 
     
    415397        self.has_move = True 
    416398        self.base.base.update() 
    417          
    418    
     399 
     400 
    419401class VerticalLines(_BaseInteractor): 
    420402    """ 
     
    431413        self.y = math.fabs(y) 
    432414        self.save_y = y 
    433         try: 
    434             # Inner circle marker 
    435             self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    436                                           marker='s', markersize=10, 
    437                                           color=self.color, alpha=0.6, 
    438                                           pickradius=5, label="pick",  
    439                                           # Prefer this to other lines 
    440                                           zorder=zorder, visible=True)[0] 
    441         except: 
    442             self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
    443                                           marker='s', markersize=10, 
    444                                           color=self.color, alpha=0.6, 
    445                                           label="pick", visible=True)[0] 
    446             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
    447             message += " OF MATPLOTLIB\n Get the SVN version that is" 
    448             message += " at least as recent as June 1, 2007" 
    449              
     415        # Inner circle marker 
     416        self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 
     417                                           marker='s', markersize=10, 
     418                                           color=self.color, alpha=0.6, 
     419                                           pickradius=5, label="pick", 
     420                                           zorder=zorder, visible=True)[0] 
    450421        self.right_line = self.axes.plot([self.x, self.x], 
    451                                          [self.y , -self.y], 
    452                                       linestyle='-', marker='', 
    453                                       color=self.color, visible=True)[0] 
     422                                         [self.y, -self.y], 
     423                                         linestyle='-', marker='', 
     424                                         color=self.color, visible=True)[0] 
    454425        self.left_line = self.axes.plot([-self.x, -self.x], 
    455426                                        [self.y, -self.y], 
    456                                       linestyle='-', marker='', 
    457                                       color=self.color, visible=True)[0] 
     427                                        linestyle='-', marker='', 
     428                                        color=self.color, visible=True)[0] 
    458429        self.has_move = False 
    459430        self.connect_markers([self.right_line, self.inner_marker]) 
     
    463434        """ 
    464435        Allow adding plot to the same panel 
    465          
     436 
    466437        :param n: the number of layer 
    467          
     438 
    468439        """ 
    469440        self.layernum = n 
    470441        self.update() 
    471          
     442 
    472443    def clear(self): 
    473444        """ 
     
    487458        """ 
    488459        Draw the new roughness on the graph. 
    489          
     460 
    490461        :param x: x-coordinates to reset current class x 
    491462        :param y: y-coordinates to reset current class y 
    492          
    493         """ 
    494         ## reset x, y -coordinates if given as parameters 
     463 
     464        """ 
     465        # # reset x, y -coordinates if given as parameters 
    495466        if x != None: 
    496467            self.x = numpy.sign(self.x) * math.fabs(x) 
    497468        if y != None: 
    498469            self.y = numpy.sign(self.y) * math.fabs(y) 
    499         ## draw lines and markers   
    500         self.inner_marker.set(xdata=[self.x], ydata=[0])  
    501         self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y])  
    502         self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y])  
    503      
     470        # # draw lines and markers 
     471        self.inner_marker.set(xdata=[self.x], ydata=[0]) 
     472        self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 
     473        self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 
     474 
    504475    def save(self, ev): 
    505476        """ 
     
    510481        self.save_y = self.y 
    511482        self.base.freeze_axes() 
    512          
     483 
    513484    def moveend(self, ev): 
    514485        """ 
     
    518489        self.has_move = False 
    519490        self.base.moveend(ev) 
    520                 
     491 
    521492    def restore(self): 
    522493        """ 
     
    525496        self.x = self.save_x 
    526497        self.y = self.save_y 
    527        
     498 
    528499    def move(self, x, y, ev): 
    529500        """ 
     
    533504        self.x = x 
    534505        self.base.base.update() 
    535          
    536     
     506 
     507 
    537508class BoxInteractorX(BoxInteractor): 
    538509    """ 
     
    543514        self.base = base 
    544515        self._post_data() 
    545          
     516 
    546517    def _post_data(self): 
    547518        """ 
     
    549520        """ 
    550521        from sas.dataloader.manipulations import SlabX 
    551         self.post_data(SlabX, direction="X")    
    552          
     522        self.post_data(SlabX, direction="X") 
     523 
    553524 
    554525class BoxInteractorY(BoxInteractor): 
     
    560531        self.base = base 
    561532        self._post_data() 
    562          
     533 
    563534    def _post_data(self): 
    564535        """ 
     
    566537        """ 
    567538        from sas.dataloader.manipulations import SlabY 
    568         self.post_data(SlabY, direction="Y")    
    569          
    570          
     539        self.post_data(SlabY, direction="Y") 
     540 
  • src/sas/guiframe/local_perspectives/plotting/boxSum.py

    r79492222 rb5de88e  
    11""" 
    2     Boxsum Class: determine 2 rectangular area to compute  
    3     the sum of pixel of a Data.  
     2    Boxsum Class: determine 2 rectangular area to compute 
     3    the sum of pixel of a Data. 
    44""" 
    55import math 
     
    1313class BoxSum(_BaseInteractor): 
    1414    """ 
    15         Boxsum Class: determine 2 rectangular area to compute  
    16         the sum of pixel of a Data.  
     15        Boxsum Class: determine 2 rectangular area to compute 
     16        the sum of pixel of a Data. 
    1717        Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
    1818        @param zorder:  Artists with lower zorder values are drawn first. 
     
    2424    """ 
    2525    def __init__(self, base, axes, color='black', zorder=3, x_min=0.008, 
    26                   x_max=0.008, y_min=0.0025, y_max=0.0025): 
     26                 x_max=0.008, y_min=0.0025, y_max=0.0025): 
    2727        """ 
    2828        """ 
    2929        _BaseInteractor.__init__(self, base, axes, color=color) 
    30         ## class initialization 
    31         ## list of Boxsmun markers 
     30        # # class initialization 
     31        # # list of Boxsmun markers 
    3232        self.markers = [] 
    3333        self.axes = axes 
    34         ## connect the artist for the motion 
     34        # # connect the artist for the motion 
    3535        self.connect = self.base.connect 
    36         ## when qmax is reached the selected line is reset the its previous value 
     36        # # when qmax is reached the selected line is reset the its previous value 
    3737        self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 
    38         ## Define the boxsum limits 
     38        # # Define the boxsum limits 
    3939        self.xmin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
    40                                   math.fabs(self.base.data2D.xmin)) 
     40                                   math.fabs(self.base.data2D.xmin)) 
    4141        self.ymin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
    42                                   math.fabs(self.base.data2D.xmin)) 
     42                                   math.fabs(self.base.data2D.xmin)) 
    4343        self.xmax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    4444                              math.fabs(self.base.data2D.xmin)) 
    4545        self.ymax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    4646                              math.fabs(self.base.data2D.xmin)) 
    47         ## center of the boxSum 
     47        # # center of the boxSum 
    4848        self.center_x = 0.0002 
    4949        self.center_y = 0.0003 
    50         ## Number of points on the plot 
     50        # # Number of points on the plot 
    5151        self.nbins = 20 
    52         ## Define initial result the summation  
     52        # # Define initial result the summation 
    5353        self.count = 0 
    5454        self.error = 0 
     
    5656        self.totalerror = 0 
    5757        self.points = 0 
    58         ## Flag to determine if the current figure has moved 
    59         ## set to False == no motion , set to True== motion 
     58        # # Flag to determine if the current figure has moved 
     59        # # set to False == no motion , set to True== motion 
    6060        self.has_move = False 
    61         ## Create Boxsum edges  
     61        # # Create Boxsum edges 
    6262        self.horizontal_lines = HorizontalDoubleLine(self, 
    63                                                     self.base.subplot, 
    64                                                     color='blue', 
    65                                                       zorder=zorder, 
    66                                                       y=self.ymax, 
    67                                                       x=self.xmax, 
    68                                                       center_x=self.center_x, 
    69                                                       center_y=self.center_y) 
     63                                                     self.base.subplot, 
     64                                                     color='blue', 
     65                                                     zorder=zorder, 
     66                                                     y=self.ymax, 
     67                                                     x=self.xmax, 
     68                                                     center_x=self.center_x, 
     69                                                     center_y=self.center_y) 
    7070        self.horizontal_lines.qmax = self.qmax 
    71          
     71 
    7272        self.vertical_lines = VerticalDoubleLine(self, 
    73                                                 self.base.subplot, 
    74                                                 color='black', 
    75                                                 zorder=zorder, 
    76                                                 y=self.ymax, 
    77                                                 x=self.xmax, 
    78                                                 center_x=self.center_x, 
    79                                                 center_y=self.center_y) 
     73                                                 self.base.subplot, 
     74                                                 color='black', 
     75                                                 zorder=zorder, 
     76                                                 y=self.ymax, 
     77                                                 x=self.xmax, 
     78                                                 center_x=self.center_x, 
     79                                                 center_y=self.center_y) 
    8080        self.vertical_lines.qmax = self.qmax 
    81          
     81 
    8282        self.center = PointInteractor(self, 
    83                                      self.base.subplot,color='grey', 
    84                                     zorder=zorder, 
    85                                     center_x= self.center_x, 
    86                                     center_y= self.center_y) 
    87         ## Save the name of the slicer panel associate with this slicer  
    88         self.panel_name = ""     
    89         ## Update and post slicer parameters   
     83                                      self.base.subplot, color='grey', 
     84                                      zorder=zorder, 
     85                                      center_x=self.center_x, 
     86                                      center_y=self.center_y) 
     87        # # Save the name of the slicer panel associate with this slicer 
     88        self.panel_name = "" 
     89        # # Update and post slicer parameters 
    9090        self.update() 
    9191        self._post_data() 
    92         ## Bind to slice parameter events 
     92        # # Bind to slice parameter events 
    9393        self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    94          
     94 
    9595    def set_panel_name(self, name): 
    9696        """ 
     
    9999        """ 
    100100        self.panel_name = name 
    101          
     101 
    102102    def _onEVT_SLICER_PARS(self, event): 
    103103        """ 
    104104            receive an event containing parameters values to reset the slicer 
    105             @param event: event of type SlicerParameterEvent with params as  
     105            @param event: event of type SlicerParameterEvent with params as 
    106106            attribute 
    107107        """ 
    108         ## Post e message to declare what kind of event has being received 
     108        # # Post e message to declare what kind of event has being received 
    109109        wx.PostEvent(self.base.parent, 
    110110                     StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 
    111111        event.Skip() 
    112         ## reset the slicer with the values contains the event.params dictionary 
     112        # # reset the slicer with the values contains the event.params dictionary 
    113113        if event.type == self.__class__.__name__: 
    114114            self.set_params(event.params) 
     
    122122        self.layernum = n 
    123123        self.update() 
    124          
     124 
    125125    def clear(self): 
    126126        """ 
     
    133133        self.base.connect.clearall() 
    134134        self.base.Unbind(EVT_SLICER_PARS) 
    135          
     135 
    136136    def update(self): 
    137137        """ 
     
    139139        resetting the widgets. 
    140140        """ 
    141         ## check if the center point has moved and update the figure accordingly  
     141        # # check if the center point has moved and update the figure accordingly 
    142142        if self.center.has_move: 
    143143            self.center.update() 
    144             self.horizontal_lines.update( center= self.center) 
    145             self.vertical_lines.update( center= self.center) 
    146         ## check if the horizontal lines have moved and  
    147         #update the figure accordingly     
     144            self.horizontal_lines.update(center=self.center) 
     145            self.vertical_lines.update(center=self.center) 
     146        # # check if the horizontal lines have moved and 
     147        # update the figure accordingly 
    148148        if self.horizontal_lines.has_move: 
    149149            self.horizontal_lines.update() 
     
    151151                                       y2=self.horizontal_lines.y2, 
    152152                                       height=self.horizontal_lines.half_height) 
    153         ## check if the vertical lines have moved and  
    154         #update the figure accordingly     
     153        # # check if the vertical lines have moved and 
     154        # update the figure accordingly 
    155155        if self.vertical_lines.has_move: 
    156156            self.vertical_lines.update() 
     
    158158                                         x2=self.vertical_lines.x2, 
    159159                                         width=self.vertical_lines.half_width) 
    160              
     160 
    161161    def save(self, ev): 
    162162        """ 
     
    168168        self.vertical_lines.save(ev) 
    169169        self.center.save(ev) 
    170          
     170 
    171171    def _post_data(self): 
    172172        """ 
     
    174174        contained in that region and the error on that sum 
    175175        """ 
    176         ## Data 2D for which the pixel will be summed 
    177         data = self.base.data2D 
    178         ## the region of the summation 
    179         x_min = self.horizontal_lines.x2  
    180         x_max = self.horizontal_lines.x1  
     176        # # the region of the summation 
     177        x_min = self.horizontal_lines.x2 
     178        x_max = self.horizontal_lines.x1 
    181179        y_min = self.vertical_lines.y2 
    182180        y_max = self.vertical_lines.y1 
    183         ##computation of the sum and its error 
     181        # #computation of the sum and its error 
    184182        from sas.dataloader.manipulations import Boxavg 
    185         box =  Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
     183        box = Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    186184        self.count, self.error = box(self.base.data2D) 
    187185        # Dig out number of points summed, SMK & PDB, 04/03/2013 
    188186        from sas.dataloader.manipulations import Boxsum 
    189         boxtotal =  Boxsum(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
     187        boxtotal = Boxsum(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    190188        self.total, self.totalerror, self.points = boxtotal(self.base.data2D) 
    191          
     189 
    192190    def moveend(self, ev): 
    193191        """ 
    194192            After a dragging motion this function is called to compute 
    195             the error and the sum of pixel of a given data 2D  
     193            the error and the sum of pixel of a given data 2D 
    196194        """ 
    197195        self.base.thaw_axes() 
    198         ## compute error an d sum of data's pixel 
     196        # # compute error an d sum of data's pixel 
    199197        self._post_data() 
    200         ## Create and event ( posted to guiframe)that  set the  
    201         ##current slicer parameter to a panel of name self.panel_name 
     198        # # Create and event ( posted to guiframe)that  set the 
     199        # #current slicer parameter to a panel of name self.panel_name 
    202200        self.type = self.__class__.__name__ 
    203201        params = self.get_params() 
     
    206204                                       panel_name=self.panel_name) 
    207205        wx.PostEvent(self.base.parent, event) 
    208          
     206 
    209207    def restore(self): 
    210208        """ 
     
    214212        self.vertical_lines.restore() 
    215213        self.center.restore() 
    216          
     214 
    217215    def move(self, x, y, ev): 
    218216        """ 
     
    220218        """ 
    221219        pass 
    222      
     220 
    223221    def set_cursor(self, x, y): 
    224222        """ 
    225223        """ 
    226224        pass 
    227          
     225 
    228226    def get_params(self): 
    229227        """ 
     
    233231        params = {} 
    234232        params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 
    235         params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2  
     233        params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 
    236234        params["center_x"] = self.center.x 
    237235        params["center_y"] = self.center.y 
     
    242240        params["sum_error"] = self.totalerror 
    243241        return params 
    244      
     242 
    245243    def get_result(self): 
    246244        """ 
     
    251249        result["avg"] = self.count 
    252250        result["avg_error"] = self.error 
    253         params["sum"] = self.total 
    254         params["sum_error"] = self.totalerror 
     251        result["sum"] = self.total 
     252        result["sum_error"] = self.totalerror 
    255253        return result 
    256          
     254 
    257255    def set_params(self, params): 
    258256        """ 
    259         Receive a dictionary and reset the slicer with values contained  
     257        Receive a dictionary and reset the slicer with values contained 
    260258        in the values of the dictionary. 
    261259        :param params: a dictionary containing name of slicer parameters and values the user assigned to the slicer. 
    262260        """ 
    263         x_max = math.fabs(params["Width"] )/2 
    264         y_max = math.fabs(params["Height"] )/2 
    265          
    266         self.center_x = params["center_x"]  
     261        x_max = math.fabs(params["Width"]) / 2 
     262        y_max = math.fabs(params["Height"]) / 2 
     263 
     264        self.center_x = params["center_x"] 
    267265        self.center_y = params["center_y"] 
    268         #update the slicer given values of params 
     266        # update the slicer given values of params 
    269267        self.center.update(center_x=self.center_x, center_y=self.center_y) 
    270268        self.horizontal_lines.update(center=self.center, 
    271269                                     width=x_max, height=y_max) 
    272270        self.vertical_lines.update(center=self.center, 
    273                                     width=x_max, height=y_max) 
    274         #compute the new error and sum given values of params 
     271                                   width=x_max, height=y_max) 
     272        # compute the new error and sum given values of params 
    275273        self._post_data() 
    276          
     274 
    277275    def freeze_axes(self): 
    278276        """ 
    279277        """ 
    280278        self.base.freeze_axes() 
    281          
     279 
    282280    def thaw_axes(self): 
    283281        """ 
     
    289287        """ 
    290288        self.base.draw() 
    291          
    292          
    293          
     289 
     290 
     291 
    294292class PointInteractor(_BaseInteractor): 
    295293    """ 
    296294    Draw a point that can be dragged with the marker. 
    297     this class controls the motion the center of the BoxSum  
     295    this class controls the motion the center of the BoxSum 
    298296    """ 
    299297    def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, 
     
    302300        """ 
    303301        _BaseInteractor.__init__(self, base, axes, color=color) 
    304         ## Initialization the class  
     302        # # Initialization the class 
    305303        self.markers = [] 
    306304        self.axes = axes 
     
    308306        self.x = center_x 
    309307        self.y = center_y 
    310         ## saved value of the center coordinates 
     308        # # saved value of the center coordinates 
    311309        self.save_x = center_x 
    312310        self.save_y = center_y 
    313         ## Create a marker  
    314         try: 
    315             self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 
    316                                           marker='s', markersize=10, 
    317                                           color=self.color, alpha=0.6, 
    318                                           pickradius=5, label="pick",  
    319                                           # Prefer this to other lines 
    320                                           zorder=zorder,  
    321                                           visible=True)[0] 
    322         except: 
    323             self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 
    324                                           marker='s', markersize=10, 
    325                                           color=self.color, alpha=0.6, 
    326                                           label="pick",  
    327                                           visible=True)[0] 
    328             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 
    329             message += " OF MATPLOTLIB.\n Get the SVN version that is " 
    330             message += "at least as recent as June 1, 2007" 
    331             owner = self.base.base.parent 
    332             wx.PostEvent(owner, 
    333                          StatusEvent(status="AnnulusSlicer: %s" % message)) 
    334         ## Draw a point 
     311        # # Create a marker 
     312        self.center_marker = self.axes.plot([self.x], [self.y], linestyle='', 
     313                                            marker='s', markersize=10, 
     314                                            color=self.color, alpha=0.6, 
     315                                            pickradius=5, label="pick", 
     316                                            zorder=zorder, 
     317                                            visible=True)[0] 
     318        # # Draw a point 
    335319        self.center = self.axes.plot([self.x], [self.y], 
    336                                       linestyle='-', marker='', 
    337                                       color=self.color, 
    338                                       visible=True)[0] 
    339         ## Flag to determine the motion this point  
    340         self.has_move = False    
    341         ## connecting the marker to allow them to move  
     320                                     linestyle='-', marker='', 
     321                                     color=self.color, 
     322                                     visible=True)[0] 
     323        # # Flag to determine the motion this point 
     324        self.has_move = False 
     325        # # connecting the marker to allow them to move 
    342326        self.connect_markers([self.center_marker]) 
    343         ## Update the figure 
    344         self.update() 
    345      
     327        # # Update the figure 
     328        self.update() 
     329 
    346330    def set_layer(self, n): 
    347331        """ 
     
    351335        self.layernum = n 
    352336        self.update() 
    353          
     337 
    354338    def clear(self): 
    355339        """ 
     
    364348            for item in range(len(self.axes.lines)): 
    365349                del self.axes.lines[0] 
    366    
    367     def update(self, center_x=None,center_y=None): 
     350 
     351    def update(self, center_x=None, center_y=None): 
    368352        """ 
    369353            Draw the new roughness on the graph. 
     
    375359        self.center_marker.set(xdata=[self.x], ydata=[self.y]) 
    376360        self.center.set(xdata=[self.x], ydata=[self.y]) 
    377          
     361 
    378362    def save(self, ev): 
    379363        """ 
     
    384368        self.save_y = self.y 
    385369        self.base.freeze_axes() 
    386          
     370 
    387371    def moveend(self, ev): 
    388372        """ 
    389373        """ 
    390         self.has_move=False 
     374        self.has_move = False 
    391375        self.base.moveend(ev) 
    392              
     376 
    393377    def restore(self): 
    394378        """ 
     
    397381        self.y = self.save_y 
    398382        self.x = self.save_x 
    399      
     383 
    400384    def move(self, x, y, ev): 
    401385        """ 
     
    406390        self.has_move = True 
    407391        self.base.base.update() 
    408          
     392 
    409393    def set_cursor(self, x, y): 
    410394        """ 
     
    412396        self.move(x, y, None) 
    413397        self.update() 
    414          
     398 
    415399class VerticalDoubleLine(_BaseInteractor): 
    416400    """ 
    417          Draw 2 vertical lines moving in opposite direction and centered on  
     401         Draw 2 vertical lines moving in opposite direction and centered on 
    418402         a point (PointInteractor) 
    419403    """ 
    420     def __init__(self, base, axes, color='black', zorder=5, x=0.5,y=0.5, 
     404    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 
    421405                 center_x=0.0, center_y=0.0): 
    422406        """ 
    423407        """ 
    424408        _BaseInteractor.__init__(self, base, axes, color=color) 
    425         ## Initialization the class  
     409        # # Initialization the class 
    426410        self.markers = [] 
    427411        self.axes = axes 
    428         ## Center coordinates 
     412        # # Center coordinates 
    429413        self.center_x = center_x 
    430414        self.center_y = center_y 
    431         ## defined end points vertical lignes and their saved values 
     415        # # defined end points vertical lignes and their saved values 
    432416        self.y1 = y + self.center_y 
    433         self.save_y1= self.y1 
    434          
     417        self.save_y1 = self.y1 
     418 
    435419        delta = self.y1 - self.center_y 
    436420        self.y2 = self.center_y - delta 
    437421        self.save_y2 = self.y2 
    438          
     422 
    439423        self.x1 = x + self.center_x 
    440424        self.save_x1 = self.x1 
    441           
     425 
    442426        delta = self.x1 - self.center_x 
    443427        self.x2 = self.center_x - delta 
    444428        self.save_x2 = self.x2 
    445         ## save the color of the line 
     429        # # save the color of the line 
    446430        self.color = color 
    447         ## the height of the rectangle 
     431        # # the height of the rectangle 
    448432        self.half_height = math.fabs(y) 
    449433        self.save_half_height = math.fabs(y) 
    450         ## 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 
    453         ## Create marker  
    454         try: 
    455             self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
    456                                           marker='s', markersize=10, 
    457                                           color=self.color, alpha=0.6, 
    458                                           pickradius=5, label="pick",  
    459                                           # Prefer this to other lines 
    460                                           zorder=zorder, visible=True)[0] 
    461         except: 
    462             self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 
    463                                           marker='s', markersize=10, 
    464                                           color=self.color, alpha=0.6, 
    465                                           label="pick", visible=True)[0] 
    466             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST " 
    467             message += "VERSION OF MATPLOTLIB\n Get the SVN version that" 
    468             message += " is at least as recent as June 1, 2007" 
    469             owner = self.base.base.parent 
    470             wx.PostEvent(owner, 
    471                          StatusEvent(status="AnnulusSlicer: %s" % message)) 
    472              
    473         ## define the left and right lines of the rectangle 
     434        # # the with of the rectangle 
     435        self.half_width = math.fabs(self.x1 - self.x2) / 2 
     436        self.save_half_width = math.fabs(self.x1 - self.x2) / 2 
     437        # # Create marker 
     438        self.right_marker = self.axes.plot([self.x1], [0], linestyle='', 
     439                                           marker='s', markersize=10, 
     440                                           color=self.color, alpha=0.6, 
     441                                           pickradius=5, label="pick", 
     442                                           zorder=zorder, visible=True)[0] 
     443 
     444        # # define the left and right lines of the rectangle 
    474445        self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 
    475                                       linestyle='-', marker='', 
    476                                       color=self.color, visible=True)[0] 
     446                                         linestyle='-', marker='', 
     447                                         color=self.color, visible=True)[0] 
    477448        self.left_line = self.axes.plot([self.x2, self.x2], [self.y1, self.y2], 
    478                                       linestyle='-', marker='', 
    479                                       color=self.color, visible=True)[0] 
    480         ## Flag to determine if the lines have moved 
    481         self.has_move = False   
    482         ## connection the marker and draw the pictures   
     449                                        linestyle='-', marker='', 
     450                                        color=self.color, visible=True)[0] 
     451        # # Flag to determine if the lines have moved 
     452        self.has_move = False 
     453        # # connection the marker and draw the pictures 
    483454        self.connect_markers([self.right_marker]) 
    484455        self.update() 
     
    491462        self.layernum = n 
    492463        self.update() 
    493          
     464 
    494465    def clear(self): 
    495466        """ 
     
    505476            for item in range(len(self.axes.lines)): 
    506477                del self.axes.lines[0] 
    507     
    508     def update(self, x1=None, x2=None, y1=None, y2=None,width=None, 
    509                 height=None, center=None): 
     478 
     479    def update(self, x1=None, x2=None, y1=None, y2=None, width=None, 
     480               height=None, center=None): 
    510481        """ 
    511482        Draw the new roughness on the graph. 
     
    518489        :param center: provided x, y  coordinates of the center point 
    519490        """ 
    520         ## save the new height, witdh of the rectangle if given as a param 
     491        # # save the new height, witdh of the rectangle if given as a param 
    521492        if width != None: 
    522493            self.half_width = width 
    523494        if height != None: 
    524495            self.half_height = height 
    525         ## If new  center coordinates are given draw the rectangle  
    526         ##given these value  
     496        # # If new  center coordinates are given draw the rectangle 
     497        # #given these value 
    527498        if center != None: 
    528499            self.center_x = center.x 
    529500            self.center_y = center.y 
    530501            self.x1 = self.half_width + self.center_x 
    531             self.x2= -self.half_width + self.center_x 
     502            self.x2 = -self.half_width + self.center_x 
    532503            self.y1 = self.half_height + self.center_y 
    533             self.y2= -self.half_height + self.center_y 
    534           
     504            self.y2 = -self.half_height + self.center_y 
     505 
    535506            self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 
    536             self.right_line.set(xdata=[self.x1, self.x1],  
     507            self.right_line.set(xdata=[self.x1, self.x1], 
    537508                                ydata=[self.y1, self.y2]) 
    538509            self.left_line.set(xdata=[self.x2, self.x2], 
    539510                               ydata=[self.y1, self.y2]) 
    540             return  
    541         ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    542         if x1 != None:  
     511            return 
     512        # # if x1, y1, y2, y3 are given draw the rectangle with this value 
     513        if x1 != None: 
    543514            self.x1 = x1 
    544         if x2 != None:  
     515        if x2 != None: 
    545516            self.x2 = x2 
    546         if y1 != None:  
     517        if y1 != None: 
    547518            self.y1 = y1 
    548         if y2 != None:  
     519        if y2 != None: 
    549520            self.y2 = y2 
    550         ## Draw 2 vertical lines and a marker  
     521        # # Draw 2 vertical lines and a marker 
    551522        self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 
    552523        self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) 
    553524        self.left_line.set(xdata=[self.x2, self.x2], ydata=[self.y1, self.y2]) 
    554          
     525 
    555526    def save(self, ev): 
    556527        """ 
     
    572543        self.has_move = False 
    573544        self.base.moveend(ev) 
    574              
     545 
    575546    def restore(self): 
    576547        """ 
     
    583554        self.half_height = self.save_half_height 
    584555        self.half_width = self.save_half_width 
    585         
     556 
    586557    def move(self, x, y, ev): 
    587558        """ 
     
    591562        delta = self.x1 - self.center_x 
    592563        self.x2 = self.center_x - delta 
    593         self.half_width = math.fabs(self.x1 - self.x2)/2 
     564        self.half_width = math.fabs(self.x1 - self.x2) / 2 
    594565        self.has_move = True 
    595566        self.base.base.update() 
    596          
     567 
    597568    def set_cursor(self, x, y): 
    598569        """ 
    599             Update the figure given x and y  
     570            Update the figure given x and y 
    600571        """ 
    601572        self.move(x, y, None) 
    602573        self.update() 
    603          
     574 
    604575class HorizontalDoubleLine(_BaseInteractor): 
    605576    """ 
     
    608579    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 
    609580                 center_x=0.0, center_y=0.0): 
    610          
     581 
    611582        _BaseInteractor.__init__(self, base, axes, color=color) 
    612         ## Initialization the class  
     583        # # Initialization the class 
    613584        self.markers = [] 
    614585        self.axes = axes 
    615         ## Center coordinates 
     586        # # Center coordinates 
    616587        self.center_x = center_x 
    617588        self.center_y = center_y 
     
    627598        self.save_x2 = self.x2 
    628599        self.color = color 
    629         self.half_height= math.fabs(y) 
     600        self.half_height = math.fabs(y) 
    630601        self.save_half_height = math.fabs(y) 
    631602        self.half_width = math.fabs(x) 
    632603        self.save_half_width = math.fabs(x) 
    633         try: 
    634             self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
    635                                           marker='s', markersize=10, 
    636                                           color=self.color, alpha=0.6, 
    637                                           pickradius=5, label="pick", 
    638                                           # Prefer this to other lines 
    639                                           zorder=zorder, visible=True)[0] 
    640         except: 
    641             self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
    642                                           marker='s', markersize=10, 
    643                                           color=self.color, alpha=0.6, 
    644                                           label="pick", visible=True)[0] 
    645             message  = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 
    646             message += "OF MATPLOTLIB\n Get the SVN version " 
    647             message += "that is at least as recent as June 1, 2007" 
    648             owner = self.base.base.parent 
    649             wx.PostEvent(owner, 
    650                          StatusEvent(status="AnnulusSlicer: %s" % message)) 
    651              
     604        self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
     605                                         marker='s', markersize=10, 
     606                                         color=self.color, alpha=0.6, 
     607                                         pickradius=5, label="pick", 
     608                                         zorder=zorder, visible=True)[0] 
     609 
    652610        # Define 2 horizotnal lines 
    653611        self.top_line = self.axes.plot([self.x1, -self.x1], [self.y1, self.y1], 
    654                                       linestyle='-', marker='', 
    655                                       color=self.color, visible=True)[0] 
    656         self.bottom_line = self.axes.plot([self.x1, -self.x1],  
     612                                       linestyle='-', marker='', 
     613                                       color=self.color, visible=True)[0] 
     614        self.bottom_line = self.axes.plot([self.x1, -self.x1], 
    657615                                          [self.y2, self.y2], 
    658                                       linestyle='-', marker='', 
    659                                       color=self.color, visible=True)[0] 
    660         ## Flag to determine if the lines have moved 
    661         self.has_move = False     
    662         ## connection the marker and draw the pictures  
     616                                          linestyle='-', marker='', 
     617                                          color=self.color, visible=True)[0] 
     618        # # Flag to determine if the lines have moved 
     619        self.has_move = False 
     620        # # connection the marker and draw the pictures 
    663621        self.connect_markers([self.top_marker]) 
    664622        self.update() 
     
    671629        self.layernum = n 
    672630        self.update() 
    673          
     631 
    674632    def clear(self): 
    675633        """ 
     
    685643            for item in range(len(self.axes.lines)): 
    686644                del self.axes.lines[0] 
    687      
     645 
    688646    def update(self, x1=None, x2=None, y1=None, y2=None, 
    689647               width=None, height=None, center=None): 
     
    698656        :param center: provided x, y  coordinates of the center point 
    699657        """ 
    700         ## save the new height, witdh of the rectangle if given as a param 
     658        # # save the new height, witdh of the rectangle if given as a param 
    701659        if width != None: 
    702660            self.half_width = width 
    703         if height!= None: 
     661        if height != None: 
    704662            self.half_height = height 
    705         ## If new  center coordinates are given draw the rectangle  
    706         ##given these value  
     663        # # If new  center coordinates are given draw the rectangle 
     664        # #given these value 
    707665        if center != None: 
    708666            self.center_x = center.x 
     
    710668            self.x1 = self.half_width + self.center_x 
    711669            self.x2 = -self.half_width + self.center_x 
    712              
     670 
    713671            self.y1 = self.half_height + self.center_y 
    714672            self.y2 = -self.half_height + self.center_y 
    715              
     673 
    716674            self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 
    717675            self.top_line.set(xdata=[self.x1, self.x2], 
     
    719677            self.bottom_line.set(xdata=[self.x1, self.x2], 
    720678                                 ydata=[self.y2, self.y2]) 
    721             return  
    722         ## if x1, y1, y2, y3 are given draw the rectangle with this value 
    723         if x1 != None:  
     679            return 
     680        # # if x1, y1, y2, y3 are given draw the rectangle with this value 
     681        if x1 != None: 
    724682            self.x1 = x1 
    725         if x2 != None:  
     683        if x2 != None: 
    726684            self.x2 = x2 
    727         if y1 != None:  
     685        if y1 != None: 
    728686            self.y1 = y1 
    729         if y2 != None:  
     687        if y2 != None: 
    730688            self.y2 = y2 
    731         ## Draw 2 vertical lines and a marker  
     689        # # Draw 2 vertical lines and a marker 
    732690        self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 
    733691        self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) 
    734692        self.bottom_line.set(xdata=[self.x1, self.x2], ydata=[self.y2, self.y2]) 
    735         
     693 
    736694    def save(self, ev): 
    737695        """ 
     
    744702        self.save_y1 = self.y1 
    745703        self.save_half_height = self.half_height 
    746         self.save_half_width =  self.half_width 
     704        self.save_half_width = self.half_width 
    747705        self.base.freeze_axes() 
    748          
     706 
    749707    def moveend(self, ev): 
    750708        """ 
     
    753711        self.has_move = False 
    754712        self.base.moveend(ev) 
    755             
     713 
    756714    def restore(self): 
    757715        """ 
     
    764722        self.half_height = self.save_half_height 
    765723        self.half_width = self.save_half_width 
    766          
     724 
    767725    def move(self, x, y, ev): 
    768726        """ 
     
    771729        self.y1 = y 
    772730        delta = self.y1 - self.center_y 
    773         self.y2 =  self.center_y - delta 
     731        self.y2 = self.center_y - delta 
    774732        self.half_height = math.fabs(self.y1) - self.center_y 
    775733        self.has_move = True 
    776734        self.base.base.update() 
    777      
     735 
    778736    def set_cursor(self, x, y): 
    779737        """ 
    780             Update the figure given x and y  
     738            Update the figure given x and y 
    781739        """ 
    782740        self.move(x, y, None) 
    783741        self.update() 
    784           
  • src/sas/guiframe/local_perspectives/plotting/detector_dialog.py

    r79492222 rb5de88e  
    55import sys 
    66from sas.guiframe.utils import format_number 
    7 from sas.guiframe.events import StatusEvent  
     7from sas.guiframe.events import StatusEvent 
    88from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 
    99from matplotlib import mpl 
    1010from matplotlib import pylab 
    11 #FONT size  
     11# FONT size 
    1212if sys.platform.count("win32") > 0: 
    1313    FONT_VARIANT = 0 
    1414else: 
    1515    FONT_VARIANT = 1 
    16      
     16 
    1717DEFAULT_CMAP = pylab.cm.get_cmap('jet') 
    1818 
     
    2121    Dialog box to let the user edit detector settings 
    2222    """ 
    23      
     23 
    2424    def __init__(self, parent, id=1, base=None, dpi=None, 
    25                  cmap=DEFAULT_CMAP, reset_zmin_ctl = None, 
    26                  reset_zmax_ctl = None, *args, **kwds): 
     25                 cmap=DEFAULT_CMAP, reset_zmin_ctl=None, 
     26                 reset_zmax_ctl=None, *args, **kwds): 
    2727        """ 
    2828        """ 
     
    3939        self.label_qmax = wx.StaticText(self, -1, "Q max") 
    4040        self.label_zmin = wx.StaticText(self, -1, 
    41                                     "Min amplitude for color map (optional)") 
     41                                        "Min amplitude for color map (optional)") 
    4242        self.label_zmax = wx.StaticText(self, -1, 
    43                                     "Max amplitude for color map (optional)") 
     43                                        "Max amplitude for color map (optional)") 
    4444        self.label_beam = wx.StaticText(self, -1, 
    4545                                        "Beam stop radius in units of q") 
     
    5353        self.zmax_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 
    5454        self.static_line_3 = wx.StaticLine(self, -1) 
    55         self.button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
     55        self.button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 
    5656        self.button_reset = wx.Button(self, wx.NewId(), "Reset") 
    5757        self.Bind(wx.EVT_BUTTON, self.resetValues, self.button_reset) 
    58         self.button_OK = wx.Button(self, wx.ID_OK, "OK") 
    59         self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_OK) 
     58        self.button_ok = wx.Button(self, wx.ID_OK, "OK") 
     59        self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_ok) 
    6060        self.__set_properties() 
    6161        self.__do_layout() 
    6262        self.Fit() 
    63          
    64     class Event: 
     63 
     64    class Event(object): 
    6565        """ 
    6666        """ 
     
    7373        cmap = None 
    7474        sym4 = False 
    75      
     75 
    7676    def onSetFocus(self, event): 
    7777        """ 
     
    8282        # Select the whole control, after this event resolves 
    8383        wx.CallAfter(widget.SetSelection, -1, -1) 
    84          
     84 
    8585    def resetValues(self, event): 
    8686        """ 
     
    9393                zmin = "" 
    9494            if zmax == None: 
    95                 zmax = ""     
     95                zmax = "" 
    9696            self.zmin_ctl.SetValue(str(zmin)) 
    9797            self.zmax_ctl.SetValue(str(zmax)) 
     
    102102            msg = "error occurs while resetting Detector: %s" % sys.exc_value 
    103103            wx.PostEvent(self.parent, StatusEvent(status=msg)) 
    104          
     104 
    105105    def checkValues(self, event): 
    106106        """ 
     
    111111        try: 
    112112            value = self.zmin_ctl.GetValue() 
    113             #if value and float( value) == 0.0: 
    114             #    flag = False 
    115             #    wx.PostEvent(self.parent, 
    116             #            StatusEvent(status="Enter number greater than zero")) 
    117             #    self.zmin_ctl.SetBackgroundColour("pink") 
    118             #    self.zmin_ctl.Refresh() 
    119             #else: 
    120113            self.zmin_ctl.SetBackgroundColour(wx.WHITE) 
    121114            self.zmin_ctl.Refresh() 
     
    130123                flag = False 
    131124                wx.PostEvent(self.parent, 
    132                         StatusEvent(status="Enter number greater than zero")) 
     125                             StatusEvent(status="Enter number greater than zero")) 
    133126                self.zmax_ctl.SetBackgroundColour("pink") 
    134127                self.zmax_ctl.Refresh() 
     
    143136        if flag: 
    144137            event.Skip(True) 
    145      
     138 
    146139    def setContent(self, xnpts, ynpts, qmax, beam, 
    147140                   zmin=None, zmax=None, sym=False): 
    148141        """ 
    149142        received value and displayed them 
    150          
     143 
    151144        :param xnpts: the number of point of the x_bins of data 
    152145        :param ynpts: the number of point of the y_bins of data 
     
    156149        :param zmax:  the value to get the maximum color 
    157150        :param sym: 
    158          
     151 
    159152        """ 
    160153        self.xnpts_ctl.SetLabel(str(format_number(xnpts))) 
     
    207200        sizer_colormap = wx.BoxSizer(wx.VERTICAL) 
    208201        sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 
    209         
     202 
    210203        iy = 0 
    211204        sizer_params.Add(self.label_xnpts, (iy, 0), (1, 1), 
    212                           wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    213         sizer_params.Add(self.xnpts_ctl,   (iy, 1), (1, 1), 
    214                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     205                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     206        sizer_params.Add(self.xnpts_ctl, (iy, 1), (1, 1), 
     207                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    215208        iy += 1 
    216209        sizer_params.Add(self.label_ynpts, (iy, 0), (1, 1), 
    217                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    218         sizer_params.Add(self.ynpts_ctl,   (iy, 1), (1, 1), 
    219                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     210                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     211        sizer_params.Add(self.ynpts_ctl, (iy, 1), (1, 1), 
     212                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    220213        iy += 1 
    221214        sizer_params.Add(self.label_qmax, (iy, 0), (1, 1), 
    222                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    223         sizer_params.Add(self.qmax_ctl,   (iy, 1), (1, 1), 
    224                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     215                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     216        sizer_params.Add(self.qmax_ctl, (iy, 1), (1, 1), 
     217                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    225218        iy += 1 
    226219        sizer_params.Add(self.label_beam, (iy, 0), (1, 1), 
    227                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    228         sizer_params.Add(self.beam_ctl,   (iy, 1), (1, 1), 
    229                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     220                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     221        sizer_params.Add(self.beam_ctl, (iy, 1), (1, 1), 
     222                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    230223        iy += 1 
    231224        sizer_params.Add(self.label_zmin, (iy, 0), (1, 1), 
    232                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    233         sizer_params.Add(self.zmin_ctl,   (iy, 1), (1, 1), 
    234                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     225                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     226        sizer_params.Add(self.zmin_ctl, (iy, 1), (1, 1), 
     227                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    235228        iy += 1 
    236229        sizer_params.Add(self.label_zmax, (iy, 0), (1, 1), 
    237                          wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 
    238         sizer_params.Add(self.zmax_ctl,   (iy, 1), (1, 1), 
    239                          wx.EXPAND|wx.ADJUST_MINSIZE, 0) 
     230                         wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 
     231        sizer_params.Add(self.zmax_ctl, (iy, 1), (1, 1), 
     232                         wx.EXPAND | wx.ADJUST_MINSIZE, 0) 
    240233        iy += 1 
    241234        self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4, 1)) 
     
    243236        self.norm = mpl.colors.Normalize(vmin=0, vmax=100) 
    244237        self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 
    245                                            norm= self.norm, 
    246                                            orientation='horizontal') 
     238                                             norm=self.norm, 
     239                                             orientation='horizontal') 
    247240        self.cb1.set_label('Detector Colors') 
    248241        self.canvas = Canvas(self, -1, self.fig) 
    249         sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND,5) 
     242        sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND, 5) 
    250243        self.cmap_selector = wx.ComboBox(self, -1) 
    251244        self.cmap_selector.SetValue(str(self.cmap.name)) 
    252245        maps = sorted(m for m in pylab.cm.datad if not m.endswith("_r")) 
    253         
     246 
    254247        for i, m in enumerate(maps): 
    255248            self.cmap_selector.Append(str(m), pylab.get_cmap(m)) 
    256          
     249 
    257250        wx.EVT_COMBOBOX(self.cmap_selector, -1, self._on_select_cmap) 
    258251        sizer_selection.Add(wx.StaticText(self, -1, "Select Cmap: "), 0, 
    259                              wx.LEFT|wx.ADJUST_MINSIZE, 5)  
    260         sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND|wx.ALL, 10) 
    261         sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 5) 
    262         sizer_main.Add(sizer_selection, 0, wx.EXPAND|wx.ALL, 5) 
    263         note = "   Note: This is one time option. " +\ 
     252                            wx.LEFT | wx.ADJUST_MINSIZE, 5) 
     253        sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND | wx.ALL, 10) 
     254        sizer_main.Add(sizer_params, 0, wx.EXPAND | wx.ALL, 5) 
     255        sizer_main.Add(sizer_selection, 0, wx.EXPAND | wx.ALL, 5) 
     256        note = "   Note: This is one time option. " + \ 
    264257               "It will be reset on updating the image." 
    265258        note_txt = wx.StaticText(self, -1, note) 
    266         sizer_main.Add(note_txt, 0, wx.EXPAND|wx.ALL, 5) 
    267         sizer_main.Add(sizer_colormap, 1, wx.EXPAND|wx.ALL, 5) 
     259        sizer_main.Add(note_txt, 0, wx.EXPAND | wx.ALL, 5) 
     260        sizer_main.Add(sizer_colormap, 1, wx.EXPAND | wx.ALL, 5) 
    268261        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) 
    269         sizer_button.Add(self.button_reset, 0, wx.LEFT|wx.ADJUST_MINSIZE, 100) 
    270         sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) 
    271         sizer_button.Add(self.button_Cancel, 0, 
    272                          wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) 
    273         sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) 
     262        sizer_button.Add(self.button_reset, 0, wx.LEFT | wx.ADJUST_MINSIZE, 100) 
     263        sizer_button.Add(self.button_ok, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 
     264        sizer_button.Add(self.button_cancel, 0, 
     265                         wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 
     266        sizer_main.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 
    274267        self.SetAutoLayout(True) 
    275268        self.SetSizer(sizer_main) 
     
    277270        self.Centre() 
    278271        # end wxGlade 
    279          
     272 
    280273    def _on_select_cmap(self, event): 
    281274        """ 
    282         display a new cmap  
     275        display a new cmap 
    283276        """ 
    284277        cmap_name = self.cmap_selector.GetCurrentSelection() 
     
    286279        self.cmap = current_cmap 
    287280        self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 
    288                                      norm=self.norm, orientation='horizontal') 
     281                                             norm=self.norm, orientation='horizontal') 
    289282        self.canvas.draw() 
  • src/sas/guiframe/local_perspectives/plotting/graphAppearance.py

    r79492222 rb5de88e  
    3939        self.is_ytick = False 
    4040 
    41  
    4241    def InitUI(self): 
    4342 
     
    5352        yhbox2 = wx.BoxSizer(wx.HORIZONTAL) 
    5453 
    55  
    56  
    5754        if self.legend: 
    5855            legendLocText = wx.StaticText(panel, label='Legend location: ') 
    59             self.legend_loc_combo = wx.ComboBox(panel,style = wx.CB_READONLY, size=(180,-1)) 
     56            self.legend_loc_combo = wx.ComboBox(panel, style=wx.CB_READONLY, size=(180, -1)) 
    6057            self.fillLegendLocs() 
    6158        else: 
    6259            self.legend_loc_combo = None 
    6360 
    64  
    6561        if self.legend: 
    6662            self.toggle_legend = wx.CheckBox(panel, label='Toggle legend on/off') 
     
    7066        self.toggle_grid = wx.CheckBox(panel, label='Toggle grid on/off') 
    7167 
    72          
    7368        xstatic_box = wx.StaticBox(panel, -1, 'x-axis label') 
    7469        xstatic_box_sizer = wx.StaticBoxSizer(xstatic_box, wx.VERTICAL) 
     
    7671        ystatic_box_sizer = wx.StaticBoxSizer(ystatic_box, wx.VERTICAL) 
    7772 
    78  
    7973        xaxis_label = wx.StaticText(panel, label='X-axis: ') 
    8074        yaxis_label = wx.StaticText(panel, label='Y-axis: ') 
     
    8276        unitlabel_2 = wx.StaticText(panel, label='Units: ') 
    8377 
    84         self.xaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1)) 
    85         self.yaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1)) 
    86  
    87         self.xaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1)) 
    88         self.yaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1)) 
    89  
    90  
     78        self.xaxis_text = wx.TextCtrl(panel, -1, "", size=(220, -1)) 
     79        self.yaxis_text = wx.TextCtrl(panel, -1, "", size=(220, -1)) 
     80 
     81        self.xaxis_unit_text = wx.TextCtrl(panel, -1, "", size=(100, -1)) 
     82        self.yaxis_unit_text = wx.TextCtrl(panel, -1, "", size=(100, -1)) 
    9183 
    9284        xcolorLabel = wx.StaticText(panel, label='Font color: ') 
     
    9587        self.xfont_color.SetSelection(0) 
    9688        xfont_button = wx.Button(panel, label='Font') 
    97         xfont_button.Bind(wx.EVT_BUTTON, self.onxFont) 
     89        xfont_button.Bind(wx.EVT_BUTTON, self.on_x_font) 
    9890 
    9991        ycolorLabel = wx.StaticText(panel, label='Font color: ') 
    100         self.yfont_color = wx.ComboBox(panel, size=(100, -1),style=wx.CB_READONLY) 
     92        self.yfont_color = wx.ComboBox(panel, size=(100, -1), style=wx.CB_READONLY) 
    10193        self.yfill_colors() 
    10294        self.yfont_color.SetSelection(0) 
    10395        yfont_button = wx.Button(panel, label='Font') 
    104         yfont_button.Bind(wx.EVT_BUTTON, self.onyFont) 
    105  
    106          
     96        yfont_button.Bind(wx.EVT_BUTTON, self.on_y_font) 
    10797 
    10898        self.cancel_button = wx.Button(panel, label='Cancel') 
    10999        self.ok_button = wx.Button(panel, label='OK') 
    110100 
    111         self.cancel_button.Bind(wx.EVT_BUTTON, self.onCancel) 
     101        self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel) 
    112102        self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok) 
    113103 
    114  
    115         xhbox1.Add(xaxis_label, flag= wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10) 
    116         xhbox1.Add(self.xaxis_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10) 
    117         xhbox1.Add(unitlabel_1, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10) 
    118         xhbox1.Add(self.xaxis_unit_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10) 
    119  
    120         yhbox1.Add(yaxis_label, flag= wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10) 
    121         yhbox1.Add(self.yaxis_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_LEFT, border=10) 
    122         yhbox1.Add(unitlabel_2, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10) 
    123         yhbox1.Add(self.yaxis_unit_text, flag=wx.ALL | wx.EXPAND  | wx.ALIGN_RIGHT, border=10) 
     104        xhbox1.Add(xaxis_label, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 
     105        xhbox1.Add(self.xaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 
     106        xhbox1.Add(unitlabel_1, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 
     107        xhbox1.Add(self.xaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 
     108 
     109        yhbox1.Add(yaxis_label, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 
     110        yhbox1.Add(self.yaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 
     111        yhbox1.Add(unitlabel_2, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 
     112        yhbox1.Add(self.yaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 
    124113 
    125114        xhbox2.Add(xcolorLabel, flag=wx.ALL | wx.ALIGN_RIGHT, border=10) 
     
    132121 
    133122        if self.legend: 
    134             hbox1.Add(legendLocText, flag =  wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
    135             hbox1.Add(self.legend_loc_combo, flag =  wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
     123            hbox1.Add(legendLocText, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
     124            hbox1.Add(self.legend_loc_combo, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
    136125 
    137126        if self.legend: 
    138127            hbox1.Add((5, -1)) 
    139             hbox1.Add(self.toggle_legend, flag = wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
    140  
    141         hbox2.Add(self.ok_button, flag = wx.ALL | wx.ALIGN_RIGHT, border=5) 
    142         hbox2.Add(self.cancel_button, flag = wx.ALL | wx.ALIGN_RIGHT, border=5) 
     128            hbox1.Add(self.toggle_legend, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 
     129 
     130        hbox2.Add(self.ok_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 
     131        hbox2.Add(self.cancel_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 
    143132        hbox2.Add((15, -1)) 
    144133 
    145         xstatic_box_sizer.Add(xhbox1, flag= wx.EXPAND , border=5) 
     134        xstatic_box_sizer.Add(xhbox1, flag=wx.EXPAND, border=5) 
    146135        xstatic_box_sizer.Add(xhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 
    147         ystatic_box_sizer.Add(yhbox1, flag= wx.EXPAND, border=5) 
     136        ystatic_box_sizer.Add(yhbox1, flag=wx.EXPAND, border=5) 
    148137        ystatic_box_sizer.Add(yhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 
    149138 
    150139        vbox.Add((-1, 20)) 
    151         vbox.Add(hbox1, flag = wx.EXPAND | wx.ALL, border=5) 
    152         vbox.Add(xstatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10) 
    153         vbox.Add(ystatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10) 
    154  
    155         vbox.Add(self.toggle_grid, flag = wx.ALIGN_RIGHT | wx.RIGHT, border=20) 
    156         vbox.Add(hbox2, flag = wx.ALIGN_RIGHT | wx.ALL , border=5) 
    157  
     140        vbox.Add(hbox1, flag=wx.EXPAND | wx.ALL, border=5) 
     141        vbox.Add(xstatic_box_sizer, flag=wx.ALL | wx.EXPAND, border=10) 
     142        vbox.Add(ystatic_box_sizer, flag=wx.ALL | wx.EXPAND, border=10) 
     143 
     144        vbox.Add(self.toggle_grid, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20) 
     145        vbox.Add(hbox2, flag=wx.ALIGN_RIGHT | wx.ALL, border=5) 
    158146 
    159147        panel.SetSizer(vbox) 
     
    169157            self.yfont_color.Append(c_list[idx], idx) 
    170158 
    171     def onxFont(self, e): 
     159    def on_x_font(self, e): 
    172160        title = 'Modify x axis font' 
    173161 
     
    175163        fonty.set_default_font(self.xfont) 
    176164        fonty.set_ticklabel_check(self.is_xtick) 
    177         if(fonty.ShowModal() == wx.ID_OK): 
     165        if fonty.ShowModal() == wx.ID_OK: 
    178166            self.xfont = fonty.get_font() 
    179167            self.is_xtick = fonty.get_ticklabel_check() 
    180168 
    181     def onyFont(self, e): 
     169    def on_y_font(self, e): 
    182170        title = 'Modify y axis font' 
    183171        fonty = SimpleFont(self, wx.NewId(), title) 
    184172        fonty.set_default_font(self.yfont) 
    185173        fonty.set_ticklabel_check(self.is_ytick) 
    186         if(fonty.ShowModal() == wx.ID_OK): 
     174        if fonty.ShowModal() == wx.ID_OK: 
    187175            self.yfont = fonty.get_font() 
    188176            self.is_ytick = fonty.get_ticklabel_check() 
     
    191179        self.Close() 
    192180 
    193     def onCancel(self, e): 
     181    def on_cancel(self, e): 
    194182        self.Destroy() 
    195183 
     
    237225 
    238226 
    239     def setDefaults(self,grid,legend,xlab,ylab,xunit,yunit, 
    240                     xaxis_font,yaxis_font,legend_loc, 
    241                     xcolor,ycolor, is_xtick, is_ytick): 
     227    def setDefaults(self, grid, legend, xlab, ylab, xunit, yunit, 
     228                    xaxis_font, yaxis_font, legend_loc, 
     229                    xcolor, ycolor, is_xtick, is_ytick): 
    242230        self.toggle_grid.SetValue(grid) 
    243231        if self.legend: 
     
    261249        else: 
    262250            self.yfont_color.SetStringSelection(ycolor) 
    263              
     251 
    264252 
    265253        if self.legend: 
     
    310298    def get_yfont(self): 
    311299        return self.yfont 
    312      
     300 
    313301    def get_xtick_check(self): 
    314302        return self.is_xtick 
     
    316304    def get_ytick_check(self): 
    317305        return self.is_ytick 
    318      
     306 
    319307 
    320308if __name__ == '__main__': 
    321309 
    322310    app = wx.App() 
    323     graphD = graphAppearance(None,title='Modify graph appearance') 
     311    graphD = graphAppearance(None, title='Modify graph appearance') 
    324312    app.MainLoop() 
    325313 
  • src/sas/guiframe/local_perspectives/plotting/masking.py

    r79492222 rb5de88e  
    33""" 
    44################################################################################ 
    5 #This software was developed by the University of Tennessee as part of the 
    6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
    7 #project funded by the US National Science Foundation.  
     5# This software was developed by the University of Tennessee as part of the 
     6# Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 
     7# project funded by the US National Science Foundation. 
    88# 
    9 #If you use DANSE applications to do scientific research that leads to  
    10 #publication, we ask that you acknowledge the use of the software with the  
    11 #following sentence: 
     9# If you use DANSE applications to do scientific research that leads to 
     10# publication, we ask that you acknowledge the use of the software with the 
     11# following sentence: 
    1212# 
    13 #This work benefited from DANSE software developed under NSF award DMR-0520547.  
     13# This work benefited from DANSE software developed under NSF award DMR-0520547. 
    1414# 
    15 #copyright 2008, University of Tennessee 
     15# copyright 2008, University of Tennessee 
    1616################################################################################ 
    1717 
    1818 
    19 ##Todo: cleaning up, improving the maskplotpanel initialization, and testing. 
     19# #Todo: cleaning up, improving the maskplotpanel initialization, and testing. 
    2020import wx 
    2121import sys 
     
    3939_STATICBOX_WIDTH = 380 
    4040 
    41 #SLD panel size  
     41# SLD panel size 
    4242if sys.platform.count("win32") > 0: 
    4343    PANEL_SIZE = 350 
     
    4646    PANEL_SIZE = 300 
    4747    FONT_VARIANT = 1 
    48      
     48 
    4949from sas.data_util.calcthread import CalcThread 
    5050 
     
    5454    """ 
    5555    def __init__(self, 
    56                  id = -1, 
    57                  panel = None, 
    58                  image = None, 
    59                  completefn = None, 
    60                  updatefn   = None, 
    61                  elapsed = 0, 
    62                  yieldtime  = 0.01, 
    63                  worktime   = 0.01 
     56                 id=-1, 
     57                 panel=None, 
     58                 image=None, 
     59                 completefn=None, 
     60                 updatefn=None, 
     61                 elapsed=0, 
     62                 yieldtime=0.01, 
     63                 worktime=0.01 
    6464                 ): 
    6565        """ 
     
    7070                 worktime) 
    7171        self.starttime = 0 
    72         self.id = id  
     72        self.id = id 
    7373        self.panel = panel 
    7474        self.image = image 
    75          
    76          
     75 
     76 
    7777    def compute(self): 
    7878        """ 
     
    8080        """ 
    8181        elapsed = time.time() - self.starttime 
    82         
     82 
    8383        self.complete(panel=self.panel, image=self.image, elapsed=elapsed) 
    84          
    85          
     84 
     85 
    8686class MaskPanel(wx.Dialog): 
    8787    """ 
    8888    Provides the Mask Editor GUI. 
    8989    """ 
    90     ## Internal nickname for the window, used by the AUI manager 
     90    # # Internal nickname for the window, used by the AUI manager 
    9191    window_name = "Mask Editor" 
    92     ## Name to appear on the window title bar 
     92    # # Name to appear on the window title bar 
    9393    window_caption = "Mask Editor" 
    94     ## Flag to tell the AUI manager to put this panel in the center pane 
     94    # # Flag to tell the AUI manager to put this panel in the center pane 
    9595    CENTER_PANE = True 
    96     def __init__(self, parent=None, base=None,  
     96    def __init__(self, parent=None, base=None, 
    9797                 data=None, id=-1, *args, **kwds): 
    9898        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    99         kwds["size"] = wx.Size(_STATICBOX_WIDTH*0.8, PANEL_SIZE)  
    100         wx.Dialog.__init__(self, parent, id=id,  *args, **kwds) 
    101          
     99        kwds["size"] = wx.Size(_STATICBOX_WIDTH * 0.8, PANEL_SIZE) 
     100        wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 
     101 
    102102        if data != None: 
    103             #Font size  
     103            # Font size 
    104104            kwds = [] 
    105105            self.SetWindowVariant(variant=FONT_VARIANT) 
     
    108108            self.data = data 
    109109            self.str = self.data.__str__() 
    110             ## mask for 2D 
     110            # # mask for 2D 
    111111            self.mask = data.mask 
    112112            self.default_mask = copy.deepcopy(data.mask) 
    113             ## masked data from GUI 
     113            # # masked data from GUI 
    114114            self.slicer_mask = None 
    115115            self.slicer = None 
    116116            self.slicer_z = 5 
    117117            self.data.interactive = True 
    118             ## when 2 data have the same id override the 1 st plotted 
     118            # # when 2 data have the same id override the 1 st plotted 
    119119            self.name = self.data.name 
    120120            # Panel for 2D plot 
     
    122122                                           style=wx.TRANSPARENT_WINDOW) 
    123123            self.cmap = DEFAULT_CMAP 
    124             ## Create Artist and bind it 
     124            # # Create Artist and bind it 
    125125            self.subplot = self.plotpanel.subplot 
    126126            self.connect = BindArtist(self.subplot.figure) 
     
    128128            self.newplot = Data2D(image=self.data.data) 
    129129            self.newplot.setValues(self.data) 
    130             self.plotpanel.add_image(self.newplot)  
     130            self.plotpanel.add_image(self.newplot) 
    131131            self._update_mask(self.mask) 
    132132            self.Centre() 
     
    134134            # bind evt_close to _draw in fitpage 
    135135            self.Bind(wx.EVT_CLOSE, self.OnClose) 
    136              
     136 
    137137    def ShowMessage(self, msg=''): 
    138138        """ 
     
    143143        mssg += msg 
    144144        wx.MessageBox(mssg, 'Error', wx.OK | wx.ICON_ERROR) 
    145      
     145 
    146146    def _setup_layout(self): 
    147147        """ 
     
    149149        """ 
    150150        note = "Note: This masking applies\n     only to %s." % self.data.name 
    151         note_txt = wx.StaticText(self, -1, note)  
     151        note_txt = wx.StaticText(self, -1, note) 
    152152        note_txt.SetForegroundColour(wx.RED) 
    153153        shape = "Select a Shape for Masking:" 
     
    155155        sizer = wx.GridBagSizer(10, 10) 
    156156        #---------inputs---------------- 
    157         shape_txt = wx.StaticText(self, -1, shape)   
    158         sizer.Add(shape_txt, (1, 1), flag=wx.TOP|wx.LEFT|wx.BOTTOM, border=5) 
     157        shape_txt = wx.StaticText(self, -1, shape) 
     158        sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 
    159159        self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 
    160160        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask, 
    161161                  id=self.innersector_rb.GetId()) 
    162         sizer.Add(self.innersector_rb, (2, 1),  
    163                   flag=wx.RIGHT|wx.BOTTOM, border=5) 
     162        sizer.Add(self.innersector_rb, (2, 1), 
     163                  flag=wx.RIGHT | wx.BOTTOM, border=5) 
    164164        self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 
    165165        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask, 
    166166                  id=self.innercircle_rb.GetId()) 
    167167        sizer.Add(self.innercircle_rb, (3, 1), 
    168                    flag=wx.RIGHT|wx.BOTTOM, border=5) 
    169          
     168                   flag=wx.RIGHT | wx.BOTTOM, border=5) 
     169 
    170170        self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 
    171171        self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask, 
    172172                  id=self.innerbox_rb.GetId()) 
    173         sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 
     173        sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 
    174174 
    175175        self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 
    176         self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask,  
     176        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 
    177177                  id=self.outersector_rb.GetId()) 
    178178        sizer.Add(self.outersector_rb, (5, 1), 
    179                   flag=wx.RIGHT|wx.BOTTOM, border=5) 
    180          
    181         #outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 
     179                  flag=wx.RIGHT | wx.BOTTOM, border=5) 
     180 
     181        # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 
    182182        self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 
    183183        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask, 
    184184                  id=self.outercircle_rb.GetId()) 
    185         sizer.Add(self.outercircle_rb, (6, 1),  
    186                   flag=wx.RIGHT|wx.BOTTOM, border=5) 
    187         #outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 
     185        sizer.Add(self.outercircle_rb, (6, 1), 
     186                  flag=wx.RIGHT | wx.BOTTOM, border=5) 
     187        # outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 
    188188        self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 
    189         self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask,  
     189        self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 
    190190                  id=self.outerbox_rb.GetId()) 
    191         sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 
    192         sizer.Add(note_txt, (8, 1), flag=wx.RIGHT|wx.BOTTOM, border=5) 
     191        sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 
     192        sizer.Add(note_txt, (8, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 
    193193        self.innercircle_rb.SetValue(False) 
    194         self.outercircle_rb.SetValue(False)         
     194        self.outercircle_rb.SetValue(False) 
    195195        self.innerbox_rb.SetValue(False) 
    196196        self.outerbox_rb.SetValue(False) 
    197197        self.innersector_rb.SetValue(False) 
    198198        self.outersector_rb.SetValue(False) 
    199         sizer.Add(self.plotpanel, (0, 2), (13, 13),  
    200                   wx.EXPAND|wx.LEFT|wx.RIGHT, 15) 
     199        sizer.Add(self.plotpanel, (0, 2), (13, 13), 
     200                  wx.EXPAND | wx.LEFT | wx.RIGHT, 15) 
    201201 
    202202        #-----Buttons------------1 
     
    204204        button_add = wx.Button(self, id_button, "Add") 
    205205        button_add.SetToolTipString("Add the mask drawn.") 
    206         button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId())  
     206        button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 
    207207        sizer.Add(button_add, (13, 7)) 
    208208        id_button = wx.NewId() 
     
    210210        button_erase.SetToolTipString("Erase the mask drawn.") 
    211211        button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, 
    212                           id=button_erase.GetId())  
     212                          id=button_erase.GetId()) 
    213213        sizer.Add(button_erase, (13, 8)) 
    214214        id_button = wx.NewId() 
     
    216216        button_reset.SetToolTipString("Reset the mask.") 
    217217        button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, 
    218                           id=button_reset.GetId())  
    219         sizer.Add(button_reset, (13, 9), flag=wx.RIGHT|wx.BOTTOM, border=15) 
     218                          id=button_reset.GetId()) 
     219        sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15) 
    220220        id_button = wx.NewId() 
    221221        button_reset = wx.Button(self, id_button, "Clear") 
    222222        button_reset.SetToolTipString("Clear all mask.") 
    223223        button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, 
    224                           id=button_reset.GetId())  
    225         sizer.Add(button_reset, (13, 10), flag=wx.RIGHT|wx.BOTTOM, border=15) 
     224                          id=button_reset.GetId()) 
     225        sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15) 
    226226        sizer.AddGrowableCol(3) 
    227227        sizer.AddGrowableRow(2) 
     
    234234        Call Draw Box Slicer and get mask inside of the box 
    235235        """ 
    236         #get ready for next evt 
    237         event.Skip()         
    238         #from boxMask import BoxMask 
     236        # get ready for next evt 
     237        event.Skip() 
     238        # from boxMask import BoxMask 
    239239        if event != None: 
    240             self.onClearSlicer(event)          
     240            self.onClearSlicer(event) 
    241241        self.slicer_z += 1 
    242         self.slicer =  BoxMask(self, self.subplot, 
     242        self.slicer = BoxMask(self, self.subplot, 
    243243                               zorder=self.slicer_z, side=True) 
    244244        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
     
    246246        self.update() 
    247247        self.slicer_mask = self.slicer.update() 
    248          
     248 
    249249    def onOuterBoxMask(self, event=None): 
    250250        """ 
    251251        Call Draw Box Slicer and get mask outside of the box 
    252252        """ 
    253         event.Skip()         
    254         #from boxMask import BoxMask 
     253        event.Skip() 
     254        # from boxMask import BoxMask 
    255255        if event != None: 
    256             self.onClearSlicer(event)       
     256            self.onClearSlicer(event) 
    257257        self.slicer_z += 1 
    258         self.slicer =  BoxMask(self, self.subplot, 
     258        self.slicer = BoxMask(self, self.subplot, 
    259259                               zorder=self.slicer_z, side=False) 
    260260        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
     
    272272            self.onClearSlicer(event) 
    273273        self.slicer_z += 1 
    274         self.slicer =  SectorMask(self, self.subplot, 
     274        self.slicer = SectorMask(self, self.subplot, 
    275275                                  zorder=self.slicer_z, side=True) 
    276276        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    277         self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
     277        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
    278278        self.update() 
    279         self.slicer_mask = self.slicer.update()  
     279        self.slicer_mask = self.slicer.update() 
    280280 
    281281    def onOuterSectorMask(self, event=None): 
     
    288288            self.onClearSlicer(event) 
    289289        self.slicer_z += 1 
    290         self.slicer =  SectorMask(self, self.subplot, 
     290        self.slicer = SectorMask(self, self.subplot, 
    291291                                  zorder=self.slicer_z, side=False) 
    292292        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    293         self.subplot.set_xlim(self.data.xmin, self.data.xmax)     
    294         self.update()      
    295         self.slicer_mask = self.slicer.update()    
     293        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
     294        self.update() 
     295        self.slicer_mask = self.slicer.update() 
    296296 
    297297    def onInnerRingMask(self, event=None): 
     
    307307                                   zorder=self.slicer_z, side=True) 
    308308        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    309         self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
     309        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
    310310        self.update() 
    311         self.slicer_mask = self.slicer.update()  
     311        self.slicer_mask = self.slicer.update() 
    312312 
    313313    def onOuterRingMask(self, event=None): 
     
    321321        self.slicer_z += 1 
    322322        self.slicer = CircularMask(self, self.subplot, 
    323                                    zorder=self.slicer_z, side=False)    
     323                                   zorder=self.slicer_z, side=False) 
    324324        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    325325        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
    326326        self.update() 
    327         self.slicer_mask = self.slicer.update()      
    328          
     327        self.slicer_mask = self.slicer.update() 
     328 
    329329    def onAddMask(self, event): 
    330330        """ 
    331         Add new mask to old mask  
     331        Add new mask to old mask 
    332332        """ 
    333333        if not self.slicer == None: 
     
    337337            data.mask = self.data.mask & self.slicer_mask 
    338338            self._check_display_mask(data.mask, event) 
    339              
     339 
    340340    def _check_display_mask(self, mask, event): 
    341341        """ 
    342342        check if the mask valid and update the plot 
    343          
     343 
    344344        :param mask: mask data 
    345345        """ 
    346         ## Redraw the current image 
     346        # # Redraw the current image 
    347347        self._update_mask(mask) 
    348348 
     
    356356            mask[self.slicer_mask == False] = True 
    357357            self._check_display_mask(mask, event) 
    358              
     358 
    359359    def onResetMask(self, event): 
    360360        """ 
    361         Reset mask to the original mask  
    362         """         
     361        Reset mask to the original mask 
     362        """ 
    363363        self.slicer_z += 1 
    364         self.slicer =  BoxMask(self, self.subplot,  
     364        self.slicer = BoxMask(self, self.subplot, 
    365365                               zorder=self.slicer_z, side=True) 
    366366        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    367         self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
     367        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
    368368        mask = copy.deepcopy(self.default_mask) 
    369369        self.data.mask = mask 
    370370        # update mask plot 
    371371        self._check_display_mask(mask, event) 
    372          
     372 
    373373    def onClearMask(self, event): 
    374374        """ 
    375375        Clear mask 
    376         """             
     376        """ 
    377377        self.slicer_z += 1 
    378         self.slicer =  BoxMask(self, self.subplot, 
     378        self.slicer = BoxMask(self, self.subplot, 
    379379                               zorder=self.slicer_z, side=True) 
    380380        self.subplot.set_ylim(self.data.ymin, self.data.ymax) 
    381         self.subplot.set_xlim(self.data.xmin, self.data.xmax)    
    382         #mask = copy.deepcopy(self.default_mask) 
     381        self.subplot.set_xlim(self.data.xmin, self.data.xmax) 
     382        # mask = copy.deepcopy(self.default_mask) 
    383383        mask = numpy.ones(len(self.data.mask), dtype=bool) 
    384384        self.data.mask = mask 
    385385        # update mask plot 
    386386        self._check_display_mask(mask, event) 
    387          
     387 
    388388    def onClearSlicer(self, event): 
    389389        """ 
     
    397397    def update(self, draw=True): 
    398398        """ 
    399         Respond to changes in the model by recalculating the  
     399        Respond to changes in the model by recalculating the 
    400400        profiles and resetting the widgets. 
    401401        """ 
    402402        self.plotpanel.draw() 
    403          
     403 
    404404    def _set_mask(self, mask): 
    405405        """ 
     
    407407        """ 
    408408        self.data.mask = mask 
    409          
     409 
    410410    def set_plot_unfocus(self): 
    411411        """ 
     
    413413        """ 
    414414        pass 
    415      
     415 
    416416    def _update_mask(self, mask): 
    417417        """ 
    418418        Respond to changes in masking 
    419         """  
     419        """ 
    420420        # the case of liitle numbers of True points 
    421421        if (len(mask[mask]) < 10 and self.data != None): 
     
    430430        # temp_data default is None 
    431431        # This method is to distinguish between masked point and data point = 0. 
    432         temp_mask = temp_mask/temp_mask 
     432        temp_mask = temp_mask / temp_mask 
    433433        temp_mask[mask] = temp_data.data[mask] 
    434         # set temp_data value for self.mask==True, else still None  
    435         #temp_mask[mask] = temp_data[mask] 
    436          
    437         #TODO: refactor this horrible logic  
     434        # set temp_data value for self.mask==True, else still None 
     435        # temp_mask[mask] = temp_data[mask] 
     436 
     437        # TODO: refactor this horrible logic 
    438438        temp_data.data[mask == False] = temp_mask[mask == False] 
    439439        self.plotpanel.clear() 
     
    444444        event = self._getEmptySlicerEvent() 
    445445        wx.PostEvent(self, event) 
    446         
    447         ##use this method 
    448         #set zmax and zmin to plot: Fix it w/ data. 
     446 
     447        # #use this method 
     448        # set zmax and zmin to plot: Fix it w/ data. 
    449449        if self.plotpanel.scale == 'log_{10}': 
    450             zmax = math.log10(max(self.data.data[self.data.data>0])) 
    451             zmin = math.log10(min(self.data.data[self.data.data>0])) 
     450            zmax = math.log10(max(self.data.data[self.data.data > 0])) 
     451            zmin = math.log10(min(self.data.data[self.data.data > 0])) 
    452452        else: 
    453             zmax = max(self.data.data[self.data.data>0]) 
    454             zmin = min(self.data.data[self.data.data>0]) 
    455         #plot     
     453            zmax = max(self.data.data[self.data.data > 0]) 
     454            zmin = min(self.data.data[self.data.data > 0]) 
     455        # plot 
    456456        plot = self.plotpanel.image(data=temp_mask, 
    457457                       qx_data=self.data.qx_data, 
     
    470470        self.plotpanel.render() 
    471471        self.plotpanel.subplot.figure.canvas.draw_idle() 
    472          
     472 
    473473    def _getEmptySlicerEvent(self): 
    474474        """ 
    475         create an empty slicervent  
     475        create an empty slicervent 
    476476        """ 
    477477        self.innerbox_rb.SetValue(False) 
     
    483483        return SlicerEvent(type=None, 
    484484                           params=None, 
    485                            obj_class=None)  
    486               
     485                           obj_class=None) 
     486 
    487487    def _draw_model(self, event): 
    488488        """ 
     
    490490        """ 
    491491        pass 
    492          
     492 
    493493    def freeze_axes(self): 
    494494        """ 
     
    496496        """ 
    497497        self.plotpanel.axes_frozen = True 
    498          
     498 
    499499    def thaw_axes(self): 
    500500        """ 
    501501        thaw axes 
    502502        """ 
    503         self.plotpanel.axes_frozen = False        
    504           
     503        self.plotpanel.axes_frozen = False 
     504 
    505505    def onMouseMotion(self, event): 
    506506        """ 
     
    508508        """ 
    509509        pass 
    510      
     510 
    511511    def onWheel(self, event): 
    512512        """ 
    513513        on wheel event 
    514514        """ 
    515         pass   
    516      
     515        pass 
     516 
    517517    def OnClose(self, event): 
    518518        """ 
     
    524524            # when called by data panel 
    525525            event.Skip() 
    526             pass    
     526            pass 
    527527 
    528528class FloatPanel(wx.Dialog): 
     
    530530    Provides the Mask Editor GUI. 
    531531    """ 
    532     ## Internal nickname for the window, used by the AUI manager 
     532    # # Internal nickname for the window, used by the AUI manager 
    533533    window_name = "Plot" 
    534     ## Name to appear on the window title bar 
     534    # # Name to appear on the window title bar 
    535535    window_caption = "Plot" 
    536     ## Flag to tell the AUI manager to put this panel in the center pane 
     536    # # Flag to tell the AUI manager to put this panel in the center pane 
    537537    CENTER_PANE = False 
    538538    ID = wx.NewId() 
    539     def __init__(self, parent=None, base=None,  
     539    def __init__(self, parent=None, base=None, 
    540540                 data=None, dimension=1, id=ID, *args, **kwds): 
    541541        kwds["style"] = wx.DEFAULT_DIALOG_STYLE 
    542         kwds["size"] = wx.Size(PANEL_SIZE*1.5, PANEL_SIZE*1.5)  
    543         wx.Dialog.__init__(self, parent, id=id,  *args, **kwds) 
    544          
     542        kwds["size"] = wx.Size(PANEL_SIZE * 1.5, PANEL_SIZE * 1.5) 
     543        wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 
     544 
    545545        if data != None: 
    546             #Font size  
     546            # Font size 
    547547            kwds = [] 
    548548            self.SetWindowVariant(variant=FONT_VARIANT) 
     
    551551            self.data = data 
    552552            self.str = self.data.__str__() 
    553             ## when 2 data have the same id override the 1 st plotted 
     553            # # when 2 data have the same id override the 1 st plotted 
    554554            self.name = self.data.name 
    555555            self.dimension = dimension 
     
    560560            self.plotpanel.prevXtrans = "x" 
    561561            self.plotpanel.prevYtrans = "y" 
    562              
     562 
    563563            self.cmap = DEFAULT_CMAP 
    564             ## Create Artist and bind it 
     564            # # Create Artist and bind it 
    565565            self.subplot = self.plotpanel.subplot 
    566566            self._setup_layout() 
    567567            if self.dimension == 1: 
    568                 self.newplot = Data1D(x=data.x, y=data.y,  
     568                self.newplot = Data1D(x=data.x, y=data.y, 
    569569                                      dx=data.dx, dy=data.dy) 
    570570                self.newplot.name = data.name 
    571             else:     
     571            else: 
    572572                self.newplot = Data2D(image=self.data.data) 
    573573                self.newplot.setValues(self.data) 
    574574                    # Compute and get the image plot 
    575575            self.get_plot() 
    576             #self.plotpanel.add_image(self.newplot)  
     576            # self.plotpanel.add_image(self.newplot) 
    577577            self.Centre() 
    578578            self.Layout() 
    579      
     579 
    580580    def get_plot(self): 
    581581        """ 
    582582        Get Plot panel 
    583583        """ 
    584         cal_plot = CalcPlot(panel=self.plotpanel,  
    585                                    image=self.newplot,  
     584        cal_plot = CalcPlot(panel=self.plotpanel, 
     585                                   image=self.newplot, 
    586586                                   completefn=self.complete) 
    587587        cal_plot.queue() 
    588      
     588 
    589589    def complete(self, panel, image, elapsed=None): 
    590590        """ 
    591591        Plot image 
    592          
     592 
    593593        :param image: newplot [plotpanel] 
    594594        """ 
    595         wx.CallAfter(panel.add_image, image)  
    596          
     595        wx.CallAfter(panel.add_image, image) 
     596 
    597597    def _setup_layout(self): 
    598598        """ 
     
    605605            if len(self.data.data) > 3600: 
    606606                note += "Rotation disabled for pixels > 60x60." 
    607             note_txt = wx.StaticText(self, -1, note)  
     607            note_txt = wx.StaticText(self, -1, note) 
    608608            note_txt.SetForegroundColour(wx.RED) 
    609             sizer.Add(note_txt, (0, 2), flag=wx.RIGHT|wx.TOP, border=5) 
    610          
    611         sizer.Add(self.plotpanel, (1, 0), (9, 9),  
    612                   wx.EXPAND|wx.ALL, 15) 
     609            sizer.Add(note_txt, (0, 2), flag=wx.RIGHT | wx.TOP, border=5) 
     610 
     611        sizer.Add(self.plotpanel, (1, 0), (9, 9), 
     612                  wx.EXPAND | wx.ALL, 15) 
    613613 
    614614        sizer.AddGrowableCol(3) 
    615615        sizer.AddGrowableRow(2) 
    616          
     616 
    617617        self.SetSizerAndFit(sizer) 
    618618        self.Centre() 
    619619        self.Show(True) 
    620          
     620 
    621621    def set_plot_unfocus(self): 
    622622        """ 
     
    624624        """ 
    625625        pass 
    626      
     626 
    627627 
    628628    def _draw_model(self, event): 
     
    631631        """ 
    632632        pass 
    633          
     633 
    634634    def freeze_axes(self): 
    635635        """ 
     
    637637        """ 
    638638        self.plotpanel.axes_frozen = True 
    639          
     639 
    640640    def thaw_axes(self): 
    641641        """ 
    642642        thaw axes 
    643643        """ 
    644         self.plotpanel.axes_frozen = False        
    645      
     644        self.plotpanel.axes_frozen = False 
     645 
    646646    def OnClose(self, event): 
    647647        """ 
     
    655655            pass 
    656656 
    657                  
     657 
    658658class Maskplotpanel(PlotPanel): 
    659659    """ 
    660660    PlotPanel for Quick plot and masking plot 
    661661    """ 
    662     def __init__(self, parent, id=-1, dimension=2, color=None,  
     662    def __init__(self, parent, id=-1, dimension=2, color=None, 
    663663                                            dpi=None, **kwargs): 
    664664        """ 
    665665        """ 
    666666        PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs) 
    667          
     667 
    668668        # Keep track of the parent Frame 
    669669        self.parent = parent 
    670         # Internal list of plottable names (because graph  
     670        # Internal list of plottable names (because graph 
    671671        # doesn't have a dictionary of handles for the plottables) 
    672672        self.dimension = dimension 
    673673        self.plots = {} 
    674674        self.graph = Graph() 
    675         #add axis labels 
     675        # add axis labels 
    676676        self.graph.xaxis('\\rm{x} ', '') 
    677677        self.graph.yaxis('\\rm{y} ', '') 
    678          
     678 
    679679    def add_toolbar(self): 
    680         """  
     680        """ 
    681681        Add toolbar 
    682682        """ 
    683683        # Not implemented 
    684684        pass 
    685      
     685 
    686686    def on_set_focus(self, event): 
    687687        """ 
     
    691691            pass 
    692692        else: 
    693             self.draw()    
    694           
     693            self.draw() 
     694 
    695695    def add_image(self, plot): 
    696696        """ 
     
    698698        """ 
    699699        self.plots[plot.name] = plot 
    700         #init graph 
     700        # init graph 
    701701        self.graph = Graph() 
    702         #add plot 
     702        # add plot 
    703703        self.graph.add(plot) 
    704         #add axes 
     704        # add axes 
    705705        if self.dimension == 1: 
    706706            self.xaxis_label = '\\rm{x} ' 
     
    708708            self.yaxis_label = '\\rm{y} ' 
    709709            self.yaxis_unit = '' 
    710         #draw 
     710        # draw 
    711711        # message 
    712         status_type = 'progress'  
     712        status_type = 'progress' 
    713713        msg = 'Plotting...' 
    714714        self._status_info(msg, status_type) 
    715         status_type = 'stop'            
     715        status_type = 'stop' 
    716716        self.graph.render(self) 
    717717        self.subplot.figure.canvas.resizing = False 
     
    723723        msg = 'Plotting Completed.' 
    724724        self._status_info(msg, status_type) 
    725          
     725 
    726726    def onMouseMotion(self, event): 
    727727        """ 
     
    729729        """ 
    730730        pass 
    731      
     731 
    732732    def onWheel(self, event): 
    733733        """ 
    734734        """ 
    735         pass  
    736       
     735        pass 
     736 
    737737    def onLeftDown(self, event): 
    738738        """ 
     
    740740        """ 
    741741        pass 
    742      
     742 
    743743    def onPick(self, event): 
    744744        """ 
     
    746746        """ 
    747747        pass 
    748      
     748 
    749749    def draw(self): 
    750750        """ 
     
    752752        """ 
    753753        # message 
    754         status_type = 'progress'  
     754        status_type = 'progress' 
    755755        msg = 'Plotting...' 
    756756        self._status_info(msg, status_type) 
    757         status_type = 'stop'            
    758          
     757        status_type = 'stop' 
     758 
    759759        if self.dimension == 3: 
    760760            pass 
    761761        else: 
    762             self.subplot.figure.canvas.draw_idle()  
    763          
     762            self.subplot.figure.canvas.draw_idle() 
     763 
    764764        msg = 'Plotting Completed.' 
    765765        self._status_info(msg, status_type) 
    766         
     766 
    767767    def onContextMenu(self, event): 
    768768        """ 
     
    771771        # Selective Slicer plot popup menu 
    772772        slicerpop = wx.Menu() 
    773          
     773 
    774774        id = wx.NewId() 
    775775        slicerpop.Append(id, '&Print Image', 'Print image') 
     
    779779        slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') 
    780780        wx.EVT_MENU(self, id, self.OnCopyFigureMenu) 
    781          
     781 
    782782        if self.dimension == 1: 
    783783            id = wx.NewId() 
     
    789789            slicerpop.Append(id_cm, '&Toggle Linear/Log scale') 
    790790            wx.EVT_MENU(self, id_cm, self._onToggleScale) 
    791                 
     791 
    792792        pos = event.GetPosition() 
    793793        pos = self.ScreenToClient(pos) 
    794794        self.PopupMenu(slicerpop, pos) 
    795          
    796     def _status_info(self, msg = '', type = "update"): 
     795 
     796    def _status_info(self, msg='', type="update"): 
    797797        """ 
    798798        Status msg 
     
    801801            label = "Plotting..." 
    802802            able = True 
    803         else:    
     803        else: 
    804804            label = "Wait..." 
    805805            able = False 
    806806        if self.parent.parent.parent != None: 
    807                 wx.PostEvent(self.parent.parent.parent,  
    808                              StatusEvent(status = msg, type = type )) 
     807                wx.PostEvent(self.parent.parent.parent, 
     808                             StatusEvent(status=msg, type=type)) 
    809809 
    810810class ViewerFrame(wx.Frame): 
     
    825825class ViewApp(wx.App): 
    826826    def OnInit(self): 
    827         frame = ViewerFrame(None, -1, 'testView')     
     827        frame = ViewerFrame(None, -1, 'testView') 
    828828        frame.Show(True) 
    829         #self.SetTopWindow(frame) 
    830          
     829        # self.SetTopWindow(frame) 
     830 
    831831        return True 
    832                 
    833 if __name__ == "__main__":  
     832 
     833if __name__ == "__main__": 
    834834    app = ViewApp(0) 
    835     app.MainLoop()      
     835    app.MainLoop() 
Note: See TracChangeset for help on using the changeset viewer.