Ignore:
Timestamp:
Feb 2, 2017 8:29:07 AM (7 years ago)
Author:
Piotr Rozyczko <rozyczko@…>
Branches:
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
Children:
965fbd8
Parents:
5d89f43
git-author:
Piotr Rozyczko <rozyczko@…> (01/23/17 09:21:03)
git-committer:
Piotr Rozyczko <rozyczko@…> (02/02/17 08:29:07)
Message:

Reimplementation of the slicer functionality

File:
1 edited

Legend:

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

    rd85c194 r3bdbfcc  
    11""" 
     2Boxsum Class: determine 2 rectangular area to compute 
     3the sum of pixel of a Data. 
     4""" 
     5import numpy 
     6from PyQt4 import QtGui 
     7from PyQt4 import QtCore 
     8from sas.qtgui.GuiUtils import formatNumber 
     9 
     10from BaseInteractor import _BaseInteractor 
     11from sas.sascalc.dataloader.manipulations import Boxavg 
     12from sas.sascalc.dataloader.manipulations import Boxsum 
     13 
     14from sas.qtgui.SlicerModel import SlicerModel 
     15 
     16 
     17class BoxSumCalculator(_BaseInteractor): 
     18    """ 
    219    Boxsum Class: determine 2 rectangular area to compute 
    320    the sum of pixel of a Data. 
    4 """ 
    5 import math 
    6 import wx 
    7 from BaseInteractor import _BaseInteractor 
    8 from sas.sasgui.guiframe.events import SlicerParamUpdateEvent 
    9 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 
    10 from sas.sasgui.guiframe.events import StatusEvent 
    11  
    12  
    13 class BoxSum(_BaseInteractor): 
     21    Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
     22    @param zorder:  Artists with lower zorder values are drawn first. 
     23    @param x_min: the minimum value of the x coordinate 
     24    @param x_max: the maximum value of the x coordinate 
     25    @param y_min: the minimum value of the y coordinate 
     26    @param y_max: the maximum value of the y coordinate 
     27 
    1428    """ 
    15         Boxsum Class: determine 2 rectangular area to compute 
    16         the sum of pixel of a Data. 
    17         Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 
    18         @param zorder:  Artists with lower zorder values are drawn first. 
    19         @param x_min: the minimum value of the x coordinate 
    20         @param x_max: the maximum value of the x coordinate 
    21         @param y_min: the minimum value of the y coordinate 
    22         @param y_max: the maximum value of the y coordinate 
    23  
    24     """ 
    25     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): 
    27         """ 
    28         """ 
     29    def __init__(self, base, axes, color='black', zorder=3): 
    2930        _BaseInteractor.__init__(self, base, axes, color=color) 
    30         # # class initialization 
    31         # # list of Boxsmun markers 
     31 
     32        # list of Boxsmun markers 
    3233        self.markers = [] 
    3334        self.axes = axes 
    34         # # connect the artist for the motion 
     35        self._model = None 
     36        self.update_model = False 
     37 
     38        # connect the artist for the motion 
    3539        self.connect = self.base.connect 
    36         # # when qmax is reached the selected line is reset the its previous value 
    37         self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 
    38         # # Define the boxsum limits 
    39         self.xmin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
    40                                    math.fabs(self.base.data2D.xmin)) 
    41         self.ymin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 
    42                                    math.fabs(self.base.data2D.xmin)) 
    43         self.xmax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    44                               math.fabs(self.base.data2D.xmin)) 
    45         self.ymax = 0.5 * min(math.fabs(self.base.data2D.xmax), 
    46                               math.fabs(self.base.data2D.xmin)) 
    47         # # center of the boxSum 
     40 
     41        # when qmax is reached the selected line is reset the its previous value 
     42        self.qmax = min(self.base.data.xmax, self.base.data.xmin) 
     43 
     44        # Define the boxsum limits 
     45        self.xmin = -1 * 0.5 * min(numpy.fabs(self.base.data.xmax), 
     46                                   numpy.fabs(self.base.data.xmin)) 
     47        self.ymin = -1 * 0.5 * min(numpy.fabs(self.base.data.xmax), 
     48                                   numpy.fabs(self.base.data.xmin)) 
     49        self.xmax = 0.5 * min(numpy.fabs(self.base.data.xmax), 
     50                              numpy.fabs(self.base.data.xmin)) 
     51        self.ymax = 0.5 * min(numpy.fabs(self.base.data.xmax), 
     52                              numpy.fabs(self.base.data.xmin)) 
     53        # center of the boxSum 
    4854        self.center_x = 0.0002 
    4955        self.center_y = 0.0003 
    50         # # Number of points on the plot 
     56        # Number of points on the plot 
    5157        self.nbins = 20 
    52         # # Define initial result the summation 
     58        # Define initial result the summation 
    5359        self.count = 0 
    5460        self.error = 0 
     
    5662        self.totalerror = 0 
    5763        self.points = 0 
    58         # # Flag to determine if the current figure has moved 
    59         # # set to False == no motion , set to True== motion 
     64        # Flag to determine if the current figure has moved 
     65        # set to False == no motion , set to True== motion 
    6066        self.has_move = False 
    61         # # Create Boxsum edges 
     67        # Create Boxsum edges 
    6268        self.horizontal_lines = HorizontalDoubleLine(self, 
    63                                                      self.base.subplot, 
     69                                                     self.axes, 
    6470                                                     color='blue', 
    6571                                                     zorder=zorder, 
     
    7177 
    7278        self.vertical_lines = VerticalDoubleLine(self, 
    73                                                  self.base.subplot, 
     79                                                 self.axes, 
    7480                                                 color='black', 
    7581                                                 zorder=zorder, 
     
    8187 
    8288        self.center = PointInteractor(self, 
    83                                       self.base.subplot, color='grey', 
     89                                      self.axes, color='grey', 
    8490                                      zorder=zorder, 
    8591                                      center_x=self.center_x, 
    8692                                      center_y=self.center_y) 
    87         # # Save the name of the slicer panel associate with this slicer 
     93        # Save the name of the slicer panel associate with this slicer 
    8894        self.panel_name = "" 
    89         # # Update and post slicer parameters 
    90         self.update() 
    91         self._post_data() 
    92         # # Bind to slice parameter events 
    93         self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 
    94  
    95     def set_panel_name(self, name): 
    96         """ 
    97             Store the name of the panel associated to this slicer 
    98             @param name: the name of this panel 
     95        # Update and post slicer parameters 
     96        self.update_model = False 
     97        self.update() 
     98        self.postData() 
     99 
     100        # set up the model 
     101        self._model = QtGui.QStandardItemModel(1, 9) 
     102        self.setModelFromParams() 
     103        self.update_model = True 
     104        self._model.itemChanged.connect(self.setParamsFromModel) 
     105 
     106    def setModelFromParams(self): 
     107        """ 
     108        Set up the Qt model for data handling between controls 
     109        """ 
     110        parameters = self.getParams() 
     111        # Crete/overwrite model items 
     112        self._model.setData(self._model.index(0, 0), 
     113                    QtCore.QVariant(formatNumber(parameters['Height']))) 
     114        self._model.setData(self._model.index(0, 1), 
     115                    QtCore.QVariant(formatNumber(parameters['Width']))) 
     116        self._model.setData(self._model.index(0, 2), 
     117                    QtCore.QVariant(formatNumber(parameters['center_x']))) 
     118        self._model.setData(self._model.index(0, 3), 
     119                    QtCore.QVariant(formatNumber(parameters['center_y']))) 
     120 
     121        self.setReadOnlyParametersFromModel() 
     122 
     123    def model(self): 
     124        ''' model accessor ''' 
     125        return self._model 
     126 
     127    def setReadOnlyParametersFromModel(self): 
     128        """ 
     129        Cast model content onto "read-only" subset of parameters 
     130        """ 
     131        parameters = self.getParams() 
     132        self._model.setData(self._model.index(0, 4), 
     133                    QtCore.QVariant(formatNumber(parameters['avg']))) 
     134        self._model.setData(self._model.index(0, 5), 
     135                    QtCore.QVariant(formatNumber(parameters['avg_error']))) 
     136        self._model.setData(self._model.index(0, 6), 
     137                    QtCore.QVariant(formatNumber(parameters['sum']))) 
     138        self._model.setData(self._model.index(0, 7), 
     139                    QtCore.QVariant(formatNumber(parameters['sum_error']))) 
     140        self._model.setData(self._model.index(0, 8), 
     141                    QtCore.QVariant(formatNumber(parameters['num_points']))) 
     142 
     143    def setParamsFromModel(self): 
     144        """ 
     145        Cast model content onto params dict 
     146        """ 
     147        params = {} 
     148        params["Height"] = float(self.model().item(0, 0).text()) 
     149        params["Width"] = float(self.model().item(0, 1).text()) 
     150        params["center_x"] = float(self.model().item(0, 2).text()) 
     151        params["center_y"] = float(self.model().item(0, 3).text()) 
     152        self.update_model = False 
     153        self.setParams(params) 
     154        self.setReadOnlyParametersFromModel() 
     155        self.update_model = True 
     156 
     157    def setPanelName(self, name): 
     158        """ 
     159        Store the name of the panel associated to this slicer 
     160        @param name: the name of this panel 
    99161        """ 
    100162        self.panel_name = name 
    101163 
    102     def _onEVT_SLICER_PARS(self, event): 
    103         """ 
    104             receive an event containing parameters values to reset the slicer 
    105             @param event: event of type SlicerParameterEvent with params as 
    106             attribute 
    107         """ 
    108         # # Post e message to declare what kind of event has being received 
    109         wx.PostEvent(self.base.parent, 
    110                      StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 
    111         event.Skip() 
    112         # # reset the slicer with the values contains the event.params dictionary 
    113         if event.type == self.__class__.__name__: 
    114             self.set_params(event.params) 
    115             self.base.update() 
    116  
    117     def set_layer(self, n): 
     164    def setLayer(self, n): 
    118165        """ 
    119166        Allow adding plot to the same panel 
     
    132179        self.center.clear() 
    133180        self.base.connect.clearall() 
    134         self.base.Unbind(EVT_SLICER_PARS) 
    135181 
    136182    def update(self): 
     
    139185        resetting the widgets. 
    140186        """ 
    141         # # check if the center point has moved and update the figure accordingly 
     187        # check if the center point has moved and update the figure accordingly 
    142188        if self.center.has_move: 
    143189            self.center.update() 
    144190            self.horizontal_lines.update(center=self.center) 
    145191            self.vertical_lines.update(center=self.center) 
    146         # # check if the horizontal lines have moved and 
     192        # check if the horizontal lines have moved and 
    147193        # update the figure accordingly 
    148194        if self.horizontal_lines.has_move: 
     
    151197                                       y2=self.horizontal_lines.y2, 
    152198                                       height=self.horizontal_lines.half_height) 
    153         # # check if the vertical lines have moved and 
     199        # check if the vertical lines have moved and 
    154200        # update the figure accordingly 
    155201        if self.vertical_lines.has_move: 
     
    164210        can restore on Esc. 
    165211        """ 
    166         self.base.freeze_axes() 
    167212        self.horizontal_lines.save(ev) 
    168213        self.vertical_lines.save(ev) 
    169214        self.center.save(ev) 
    170215 
    171     def _post_data(self): 
     216    def postData(self): 
    172217        """ 
    173218        Get the limits of the boxsum and compute the sum of the pixel 
    174219        contained in that region and the error on that sum 
    175220        """ 
    176         # # the region of the summation 
     221        # the region of the summation 
    177222        x_min = self.horizontal_lines.x2 
    178223        x_max = self.horizontal_lines.x1 
    179224        y_min = self.vertical_lines.y2 
    180225        y_max = self.vertical_lines.y1 
    181         # #computation of the sum and its error 
    182         from sas.sascalc.dataloader.manipulations import Boxavg 
     226        #computation of the sum and its error 
    183227        box = Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    184         self.count, self.error = box(self.base.data2D) 
     228        self.count, self.error = box(self.base.data) 
    185229        # Dig out number of points summed, SMK & PDB, 04/03/2013 
    186         from sas.sascalc.dataloader.manipulations import Boxsum 
    187230        boxtotal = Boxsum(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 
    188         self.total, self.totalerror, self.points = boxtotal(self.base.data2D) 
     231        self.total, self.totalerror, self.points = boxtotal(self.base.data) 
     232        if self.update_model: 
     233            self.setModelFromParams() 
     234        self.draw() 
    189235 
    190236    def moveend(self, ev): 
    191237        """ 
    192             After a dragging motion this function is called to compute 
    193             the error and the sum of pixel of a given data 2D 
    194         """ 
    195         self.base.thaw_axes() 
    196         # # compute error an d sum of data's pixel 
    197         self._post_data() 
    198         # # Create and event ( posted to guiframe)that  set the 
    199         # #current slicer parameter to a panel of name self.panel_name 
    200         self.type = self.__class__.__name__ 
    201         params = self.get_params() 
    202         event = SlicerParamUpdateEvent(type=self.type, 
    203                                        params=params, 
    204                                        panel_name=self.panel_name) 
    205         wx.PostEvent(self.base.parent, event) 
     238        After a dragging motion this function is called to compute 
     239        the error and the sum of pixel of a given data 2D 
     240        """ 
     241        # compute error an d sum of data's pixel 
     242        self.postData() 
    206243 
    207244    def restore(self): 
     
    213250        self.center.restore() 
    214251 
    215     def move(self, x, y, ev): 
    216         """ 
    217         Process move to a new position, making sure that the move is allowed. 
    218         """ 
    219         pass 
    220  
    221     def set_cursor(self, x, y): 
    222         """ 
    223         """ 
    224         pass 
    225  
    226     def get_params(self): 
     252    def getParams(self): 
    227253        """ 
    228254        Store a copy of values of parameters of the slicer into a dictionary. 
     
    230256        """ 
    231257        params = {} 
    232         params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 
    233         params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 
     258        params["Width"] = numpy.fabs(self.vertical_lines.half_width) * 2 
     259        params["Height"] = numpy.fabs(self.horizontal_lines.half_height) * 2 
    234260        params["center_x"] = self.center.x 
    235261        params["center_y"] = self.center.y 
     
    241267        return params 
    242268 
    243     def get_result(self): 
    244         """ 
    245             return the result of box summation 
     269    def getResult(self): 
     270        """ 
     271        Return the result of box summation 
    246272        """ 
    247273        result = {} 
     
    253279        return result 
    254280 
    255     def set_params(self, params): 
     281    def setParams(self, params): 
    256282        """ 
    257283        Receive a dictionary and reset the slicer with values contained 
    258284        in the values of the dictionary. 
    259         :param params: a dictionary containing name of slicer parameters and values the user assigned to the slicer. 
    260         """ 
    261         x_max = math.fabs(params["Width"]) / 2 
    262         y_max = math.fabs(params["Height"]) / 2 
     285        :param params: a dictionary containing name of slicer parameters 
     286        and values the user assigned to the slicer. 
     287        """ 
     288        x_max = numpy.fabs(params["Width"]) / 2 
     289        y_max = numpy.fabs(params["Height"]) / 2 
    263290 
    264291        self.center_x = params["center_x"] 
     
    271298                                   width=x_max, height=y_max) 
    272299        # compute the new error and sum given values of params 
    273         self._post_data() 
    274  
    275     def freeze_axes(self): 
    276         """ 
    277         """ 
    278         self.base.freeze_axes() 
    279  
    280     def thaw_axes(self): 
    281         """ 
    282         """ 
    283         self.base.thaw_axes() 
     300        self.postData() 
    284301 
    285302    def draw(self): 
    286         """ 
    287         """ 
     303        """ Redraw canvas""" 
    288304        self.base.draw() 
    289305 
     
    297313    def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, 
    298314                 center_y=0.0): 
    299         """ 
    300         """ 
    301315        _BaseInteractor.__init__(self, base, axes, color=color) 
    302         # # Initialization the class 
     316        # Initialization the class 
    303317        self.markers = [] 
    304318        self.axes = axes 
     
    306320        self.x = center_x 
    307321        self.y = center_y 
    308         # # saved value of the center coordinates 
     322        # saved value of the center coordinates 
    309323        self.save_x = center_x 
    310324        self.save_y = center_y 
    311         # # Create a marker 
     325        # Create a marker 
    312326        self.center_marker = self.axes.plot([self.x], [self.y], linestyle='', 
    313327                                            marker='s', markersize=10, 
     
    316330                                            zorder=zorder, 
    317331                                            visible=True)[0] 
    318         # # Draw a point 
     332        # Draw a point 
    319333        self.center = self.axes.plot([self.x], [self.y], 
    320334                                     linestyle='-', marker='', 
    321335                                     color=self.color, 
    322336                                     visible=True)[0] 
    323         # # Flag to determine the motion this point 
     337        # Flag to determine the motion this point 
    324338        self.has_move = False 
    325         # # connecting the marker to allow them to move 
     339        # connecting the marker to allow them to move 
    326340        self.connect_markers([self.center_marker]) 
    327         # # Update the figure 
    328         self.update() 
    329  
    330     def set_layer(self, n): 
    331         """ 
    332             Allow adding plot to the same panel 
    333             @param n: the number of layer 
     341        # Update the figure 
     342        self.update() 
     343 
     344    def setLayer(self, n): 
     345        """ 
     346        Allow adding plot to the same panel 
     347        @param n: the number of layer 
    334348        """ 
    335349        self.layernum = n 
     
    338352    def clear(self): 
    339353        """ 
    340             Clear this figure and its markers 
     354        Clear this figure and its markers 
    341355        """ 
    342356        self.clear_markers() 
    343         try: 
    344             self.center.remove() 
    345             self.center_marker.remove() 
    346         except: 
    347             # Old version of matplotlib 
    348             for item in range(len(self.axes.lines)): 
    349                 del self.axes.lines[0] 
     357        self.center.remove() 
     358        self.center_marker.remove() 
    350359 
    351360    def update(self, center_x=None, center_y=None): 
    352361        """ 
    353             Draw the new roughness on the graph. 
     362        Draw the new roughness on the graph. 
    354363        """ 
    355364        if center_x != None: 
     
    367376        self.save_x = self.x 
    368377        self.save_y = self.y 
    369         self.base.freeze_axes() 
    370378 
    371379    def moveend(self, ev): 
     
    391399        self.base.base.update() 
    392400 
    393     def set_cursor(self, x, y): 
     401    def setCursor(self, x, y): 
    394402        """ 
    395403        """ 
     
    399407class VerticalDoubleLine(_BaseInteractor): 
    400408    """ 
    401          Draw 2 vertical lines moving in opposite direction and centered on 
    402          a point (PointInteractor) 
     409    Draw 2 vertical lines moving in opposite direction and centered on 
     410    a point (PointInteractor) 
    403411    """ 
    404412    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 
    405413                 center_x=0.0, center_y=0.0): 
    406         """ 
    407         """ 
    408414        _BaseInteractor.__init__(self, base, axes, color=color) 
    409         # # Initialization the class 
     415        # Initialization the class 
    410416        self.markers = [] 
    411417        self.axes = axes 
    412         # # Center coordinates 
     418        # Center coordinates 
    413419        self.center_x = center_x 
    414420        self.center_y = center_y 
    415         # # defined end points vertical lignes and their saved values 
     421        # defined end points vertical lignes and their saved values 
    416422        self.y1 = y + self.center_y 
    417423        self.save_y1 = self.y1 
     
    429435        # # save the color of the line 
    430436        self.color = color 
    431         # # the height of the rectangle 
    432         self.half_height = math.fabs(y) 
    433         self.save_half_height = math.fabs(y) 
    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 
     437        # the height of the rectangle 
     438        self.half_height = numpy.fabs(y) 
     439        self.save_half_height = numpy.fabs(y) 
     440        # the with of the rectangle 
     441        self.half_width = numpy.fabs(self.x1 - self.x2) / 2 
     442        self.save_half_width = numpy.fabs(self.x1 - self.x2) / 2 
     443        # Create marker 
    438444        self.right_marker = self.axes.plot([self.x1], [0], linestyle='', 
    439445                                           marker='s', markersize=10, 
     
    442448                                           zorder=zorder, visible=True)[0] 
    443449 
    444         # # define the left and right lines of the rectangle 
     450        # Define the left and right lines of the rectangle 
    445451        self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 
    446452                                         linestyle='-', marker='', 
     
    449455                                        linestyle='-', marker='', 
    450456                                        color=self.color, visible=True)[0] 
    451         # # Flag to determine if the lines have moved 
     457        # Flag to determine if the lines have moved 
    452458        self.has_move = False 
    453         # # connection the marker and draw the pictures 
     459        # Connection the marker and draw the pictures 
    454460        self.connect_markers([self.right_marker]) 
    455461        self.update() 
    456462 
    457     def set_layer(self, n): 
     463    def setLayer(self, n): 
    458464        """ 
    459465        Allow adding plot to the same panel 
     
    468474        """ 
    469475        self.clear_markers() 
    470         try: 
    471             self.right_marker.remove() 
    472             self.right_line.remove() 
    473             self.left_line.remove() 
    474         except: 
    475             # Old version of matplotlib 
    476             for item in range(len(self.axes.lines)): 
    477                 del self.axes.lines[0] 
     476        self.right_marker.remove() 
     477        self.right_line.remove() 
     478        self.left_line.remove() 
    478479 
    479480    def update(self, x1=None, x2=None, y1=None, y2=None, width=None, 
     
    489490        :param center: provided x, y  coordinates of the center point 
    490491        """ 
    491         # # save the new height, witdh of the rectangle if given as a param 
    492         if width != None: 
     492        # Save the new height, witdh of the rectangle if given as a param 
     493        if width is not None: 
    493494            self.half_width = width 
    494         if height != None: 
     495        if height is not None: 
    495496            self.half_height = height 
    496         # # If new  center coordinates are given draw the rectangle 
    497         # #given these value 
    498         if center != None: 
     497        # If new  center coordinates are given draw the rectangle 
     498        # given these value 
     499        if center is not None: 
    499500            self.center_x = center.x 
    500501            self.center_y = center.y 
     
    510511                               ydata=[self.y1, self.y2]) 
    511512            return 
    512         # # if x1, y1, y2, y3 are given draw the rectangle with this value 
    513         if x1 != None: 
     513        # if x1, y1, y2, y3 are given draw the rectangle with this value 
     514        if x1 is not None: 
    514515            self.x1 = x1 
    515         if x2 != None: 
     516        if x2 is not None: 
    516517            self.x2 = x2 
    517         if y1 != None: 
     518        if y1 is not None: 
    518519            self.y1 = y1 
    519         if y2 != None: 
     520        if y2 is not None: 
    520521            self.y2 = y2 
    521         # # Draw 2 vertical lines and a marker 
     522        # Draw 2 vertical lines and a marker 
    522523        self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 
    523524        self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) 
     
    535536        self.save_half_height = self.half_height 
    536537        self.save_half_width = self.half_width 
    537         self.base.freeze_axes() 
    538538 
    539539    def moveend(self, ev): 
    540540        """ 
    541             After a dragging motion reset the flag self.has_move to False 
     541        After a dragging motion reset the flag self.has_move to False 
    542542        """ 
    543543        self.has_move = False 
     
    562562        delta = self.x1 - self.center_x 
    563563        self.x2 = self.center_x - delta 
    564         self.half_width = math.fabs(self.x1 - self.x2) / 2 
     564        self.half_width = numpy.fabs(self.x1 - self.x2) / 2 
    565565        self.has_move = True 
    566566        self.base.base.update() 
    567567 
    568     def set_cursor(self, x, y): 
    569         """ 
    570             Update the figure given x and y 
     568    def setCursor(self, x, y): 
     569        """ 
     570        Update the figure given x and y 
    571571        """ 
    572572        self.move(x, y, None) 
     
    575575class HorizontalDoubleLine(_BaseInteractor): 
    576576    """ 
    577          Select an annulus through a 2D plot 
     577    Select an annulus through a 2D plot 
    578578    """ 
    579579    def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 
     
    581581 
    582582        _BaseInteractor.__init__(self, base, axes, color=color) 
    583         # # Initialization the class 
     583        # Initialization the class 
    584584        self.markers = [] 
    585585        self.axes = axes 
    586         # # Center coordinates 
     586        # Center coordinates 
    587587        self.center_x = center_x 
    588588        self.center_y = center_y 
     
    598598        self.save_x2 = self.x2 
    599599        self.color = color 
    600         self.half_height = math.fabs(y) 
    601         self.save_half_height = math.fabs(y) 
    602         self.half_width = math.fabs(x) 
    603         self.save_half_width = math.fabs(x) 
     600        self.half_height = numpy.fabs(y) 
     601        self.save_half_height = numpy.fabs(y) 
     602        self.half_width = numpy.fabs(x) 
     603        self.save_half_width = numpy.fabs(x) 
    604604        self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 
    605605                                         marker='s', markersize=10, 
     
    616616                                          linestyle='-', marker='', 
    617617                                          color=self.color, visible=True)[0] 
    618         # # Flag to determine if the lines have moved 
     618        # Flag to determine if the lines have moved 
    619619        self.has_move = False 
    620         # # connection the marker and draw the pictures 
     620        # connection the marker and draw the pictures 
    621621        self.connect_markers([self.top_marker]) 
    622622        self.update() 
    623623 
    624     def set_layer(self, n): 
    625         """ 
    626             Allow adding plot to the same panel 
    627             @param n: the number of layer 
     624    def setLayer(self, n): 
     625        """ 
     626        Allow adding plot to the same panel 
     627        @param n: the number of layer 
    628628        """ 
    629629        self.layernum = n 
     
    632632    def clear(self): 
    633633        """ 
    634             Clear this figure and its markers 
     634        Clear this figure and its markers 
    635635        """ 
    636636        self.clear_markers() 
    637         try: 
    638             self.top_marker.remove() 
    639             self.bottom_line.remove() 
    640             self.top_line.remove() 
    641         except: 
    642             # Old version of matplotlib 
    643             for item in range(len(self.axes.lines)): 
    644                 del self.axes.lines[0] 
     637        self.top_marker.remove() 
     638        self.bottom_line.remove() 
     639        self.top_line.remove() 
    645640 
    646641    def update(self, x1=None, x2=None, y1=None, y2=None, 
     
    656651        :param center: provided x, y  coordinates of the center point 
    657652        """ 
    658         # # save the new height, witdh of the rectangle if given as a param 
    659         if width != None: 
     653        # Save the new height, witdh of the rectangle if given as a param 
     654        if width is not None: 
    660655            self.half_width = width 
    661         if height != None: 
     656        if height is not None: 
    662657            self.half_height = height 
    663         # # If new  center coordinates are given draw the rectangle 
    664         # #given these value 
    665         if center != None: 
     658        # If new  center coordinates are given draw the rectangle 
     659        # given these value 
     660        if center is not None: 
    666661            self.center_x = center.x 
    667662            self.center_y = center.y 
     
    678673                                 ydata=[self.y2, self.y2]) 
    679674            return 
    680         # # if x1, y1, y2, y3 are given draw the rectangle with this value 
    681         if x1 != None: 
     675        # if x1, y1, y2, y3 are given draw the rectangle with this value 
     676        if x1 is not None: 
    682677            self.x1 = x1 
    683         if x2 != None: 
     678        if x2 is not None: 
    684679            self.x2 = x2 
    685         if y1 != None: 
     680        if y1 is not None: 
    686681            self.y1 = y1 
    687         if y2 != None: 
     682        if y2 is not None: 
    688683            self.y2 = y2 
    689         # # Draw 2 vertical lines and a marker 
     684        # Draw 2 vertical lines and a marker 
    690685        self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 
    691686        self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) 
     
    703698        self.save_half_height = self.half_height 
    704699        self.save_half_width = self.half_width 
    705         self.base.freeze_axes() 
    706700 
    707701    def moveend(self, ev): 
     
    730724        delta = self.y1 - self.center_y 
    731725        self.y2 = self.center_y - delta 
    732         self.half_height = math.fabs(self.y1) - self.center_y 
     726        self.half_height = numpy.fabs(self.y1) - self.center_y 
    733727        self.has_move = True 
    734728        self.base.base.update() 
    735729 
    736     def set_cursor(self, x, y): 
    737         """ 
    738             Update the figure given x and y 
     730    def setCursor(self, x, y): 
     731        """ 
     732        Update the figure given x and y 
    739733        """ 
    740734        self.move(x, y, None) 
Note: See TracChangeset for help on using the changeset viewer.