Changeset 3bdbfcc in sasview for src/sas/sasgui/guiframe/local_perspectives/plotting/boxSum.py
- Timestamp:
- Feb 2, 2017 8:29:07 AM (8 years ago)
- 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)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/plotting/boxSum.py
rd85c194 r3bdbfcc 1 1 """ 2 Boxsum Class: determine 2 rectangular area to compute 3 the sum of pixel of a Data. 4 """ 5 import numpy 6 from PyQt4 import QtGui 7 from PyQt4 import QtCore 8 from sas.qtgui.GuiUtils import formatNumber 9 10 from BaseInteractor import _BaseInteractor 11 from sas.sascalc.dataloader.manipulations import Boxavg 12 from sas.sascalc.dataloader.manipulations import Boxsum 13 14 from sas.qtgui.SlicerModel import SlicerModel 15 16 17 class BoxSumCalculator(_BaseInteractor): 18 """ 2 19 Boxsum Class: determine 2 rectangular area to compute 3 20 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 14 28 """ 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): 29 30 _BaseInteractor.__init__(self, base, axes, color=color) 30 # # class initialization 31 # #list of Boxsmun markers31 32 # list of Boxsmun markers 32 33 self.markers = [] 33 34 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 35 39 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 48 54 self.center_x = 0.0002 49 55 self.center_y = 0.0003 50 # #Number of points on the plot56 # Number of points on the plot 51 57 self.nbins = 20 52 # #Define initial result the summation58 # Define initial result the summation 53 59 self.count = 0 54 60 self.error = 0 … … 56 62 self.totalerror = 0 57 63 self.points = 0 58 # #Flag to determine if the current figure has moved59 # #set to False == no motion , set to True== motion64 # Flag to determine if the current figure has moved 65 # set to False == no motion , set to True== motion 60 66 self.has_move = False 61 # #Create Boxsum edges67 # Create Boxsum edges 62 68 self.horizontal_lines = HorizontalDoubleLine(self, 63 self. base.subplot,69 self.axes, 64 70 color='blue', 65 71 zorder=zorder, … … 71 77 72 78 self.vertical_lines = VerticalDoubleLine(self, 73 self. base.subplot,79 self.axes, 74 80 color='black', 75 81 zorder=zorder, … … 81 87 82 88 self.center = PointInteractor(self, 83 self. base.subplot, color='grey',89 self.axes, color='grey', 84 90 zorder=zorder, 85 91 center_x=self.center_x, 86 92 center_y=self.center_y) 87 # #Save the name of the slicer panel associate with this slicer93 # Save the name of the slicer panel associate with this slicer 88 94 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 99 161 """ 100 162 self.panel_name = name 101 163 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): 118 165 """ 119 166 Allow adding plot to the same panel … … 132 179 self.center.clear() 133 180 self.base.connect.clearall() 134 self.base.Unbind(EVT_SLICER_PARS)135 181 136 182 def update(self): … … 139 185 resetting the widgets. 140 186 """ 141 # #check if the center point has moved and update the figure accordingly187 # check if the center point has moved and update the figure accordingly 142 188 if self.center.has_move: 143 189 self.center.update() 144 190 self.horizontal_lines.update(center=self.center) 145 191 self.vertical_lines.update(center=self.center) 146 # #check if the horizontal lines have moved and192 # check if the horizontal lines have moved and 147 193 # update the figure accordingly 148 194 if self.horizontal_lines.has_move: … … 151 197 y2=self.horizontal_lines.y2, 152 198 height=self.horizontal_lines.half_height) 153 # #check if the vertical lines have moved and199 # check if the vertical lines have moved and 154 200 # update the figure accordingly 155 201 if self.vertical_lines.has_move: … … 164 210 can restore on Esc. 165 211 """ 166 self.base.freeze_axes()167 212 self.horizontal_lines.save(ev) 168 213 self.vertical_lines.save(ev) 169 214 self.center.save(ev) 170 215 171 def _post_data(self):216 def postData(self): 172 217 """ 173 218 Get the limits of the boxsum and compute the sum of the pixel 174 219 contained in that region and the error on that sum 175 220 """ 176 # #the region of the summation221 # the region of the summation 177 222 x_min = self.horizontal_lines.x2 178 223 x_max = self.horizontal_lines.x1 179 224 y_min = self.vertical_lines.y2 180 225 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 183 227 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.data 2D)228 self.count, self.error = box(self.base.data) 185 229 # Dig out number of points summed, SMK & PDB, 04/03/2013 186 from sas.sascalc.dataloader.manipulations import Boxsum187 230 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() 189 235 190 236 def moveend(self, ev): 191 237 """ 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() 206 243 207 244 def restore(self): … … 213 250 self.center.restore() 214 251 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): 227 253 """ 228 254 Store a copy of values of parameters of the slicer into a dictionary. … … 230 256 """ 231 257 params = {} 232 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2233 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2258 params["Width"] = numpy.fabs(self.vertical_lines.half_width) * 2 259 params["Height"] = numpy.fabs(self.horizontal_lines.half_height) * 2 234 260 params["center_x"] = self.center.x 235 261 params["center_y"] = self.center.y … … 241 267 return params 242 268 243 def get _result(self):244 """ 245 return the result of box summation269 def getResult(self): 270 """ 271 Return the result of box summation 246 272 """ 247 273 result = {} … … 253 279 return result 254 280 255 def set _params(self, params):281 def setParams(self, params): 256 282 """ 257 283 Receive a dictionary and reset the slicer with values contained 258 284 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 263 290 264 291 self.center_x = params["center_x"] … … 271 298 width=x_max, height=y_max) 272 299 # 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() 284 301 285 302 def draw(self): 286 """ 287 """ 303 """ Redraw canvas""" 288 304 self.base.draw() 289 305 … … 297 313 def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, 298 314 center_y=0.0): 299 """300 """301 315 _BaseInteractor.__init__(self, base, axes, color=color) 302 # #Initialization the class316 # Initialization the class 303 317 self.markers = [] 304 318 self.axes = axes … … 306 320 self.x = center_x 307 321 self.y = center_y 308 # #saved value of the center coordinates322 # saved value of the center coordinates 309 323 self.save_x = center_x 310 324 self.save_y = center_y 311 # #Create a marker325 # Create a marker 312 326 self.center_marker = self.axes.plot([self.x], [self.y], linestyle='', 313 327 marker='s', markersize=10, … … 316 330 zorder=zorder, 317 331 visible=True)[0] 318 # #Draw a point332 # Draw a point 319 333 self.center = self.axes.plot([self.x], [self.y], 320 334 linestyle='-', marker='', 321 335 color=self.color, 322 336 visible=True)[0] 323 # #Flag to determine the motion this point337 # Flag to determine the motion this point 324 338 self.has_move = False 325 # #connecting the marker to allow them to move339 # connecting the marker to allow them to move 326 340 self.connect_markers([self.center_marker]) 327 # #Update the figure328 self.update() 329 330 def set _layer(self, n):331 """ 332 333 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 334 348 """ 335 349 self.layernum = n … … 338 352 def clear(self): 339 353 """ 340 354 Clear this figure and its markers 341 355 """ 342 356 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() 350 359 351 360 def update(self, center_x=None, center_y=None): 352 361 """ 353 362 Draw the new roughness on the graph. 354 363 """ 355 364 if center_x != None: … … 367 376 self.save_x = self.x 368 377 self.save_y = self.y 369 self.base.freeze_axes()370 378 371 379 def moveend(self, ev): … … 391 399 self.base.base.update() 392 400 393 def set _cursor(self, x, y):401 def setCursor(self, x, y): 394 402 """ 395 403 """ … … 399 407 class VerticalDoubleLine(_BaseInteractor): 400 408 """ 401 402 409 Draw 2 vertical lines moving in opposite direction and centered on 410 a point (PointInteractor) 403 411 """ 404 412 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 405 413 center_x=0.0, center_y=0.0): 406 """407 """408 414 _BaseInteractor.__init__(self, base, axes, color=color) 409 # #Initialization the class415 # Initialization the class 410 416 self.markers = [] 411 417 self.axes = axes 412 # #Center coordinates418 # Center coordinates 413 419 self.center_x = center_x 414 420 self.center_y = center_y 415 # #defined end points vertical lignes and their saved values421 # defined end points vertical lignes and their saved values 416 422 self.y1 = y + self.center_y 417 423 self.save_y1 = self.y1 … … 429 435 # # save the color of the line 430 436 self.color = color 431 # #the height of the rectangle432 self.half_height = math.fabs(y)433 self.save_half_height = math.fabs(y)434 # #the with of the rectangle435 self.half_width = math.fabs(self.x1 - self.x2) / 2436 self.save_half_width = math.fabs(self.x1 - self.x2) / 2437 # #Create marker437 # 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 438 444 self.right_marker = self.axes.plot([self.x1], [0], linestyle='', 439 445 marker='s', markersize=10, … … 442 448 zorder=zorder, visible=True)[0] 443 449 444 # # define the left and right lines of the rectangle450 # Define the left and right lines of the rectangle 445 451 self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 446 452 linestyle='-', marker='', … … 449 455 linestyle='-', marker='', 450 456 color=self.color, visible=True)[0] 451 # #Flag to determine if the lines have moved457 # Flag to determine if the lines have moved 452 458 self.has_move = False 453 # # connection the marker and draw the pictures459 # Connection the marker and draw the pictures 454 460 self.connect_markers([self.right_marker]) 455 461 self.update() 456 462 457 def set _layer(self, n):463 def setLayer(self, n): 458 464 """ 459 465 Allow adding plot to the same panel … … 468 474 """ 469 475 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() 478 479 479 480 def update(self, x1=None, x2=None, y1=None, y2=None, width=None, … … 489 490 :param center: provided x, y coordinates of the center point 490 491 """ 491 # # save the new height, witdh of the rectangle if given as a param492 if width !=None:492 # Save the new height, witdh of the rectangle if given as a param 493 if width is not None: 493 494 self.half_width = width 494 if height !=None:495 if height is not None: 495 496 self.half_height = height 496 # #If new center coordinates are given draw the rectangle497 # #given these value498 if center !=None:497 # If new center coordinates are given draw the rectangle 498 # given these value 499 if center is not None: 499 500 self.center_x = center.x 500 501 self.center_y = center.y … … 510 511 ydata=[self.y1, self.y2]) 511 512 return 512 # #if x1, y1, y2, y3 are given draw the rectangle with this value513 if x1 !=None:513 # if x1, y1, y2, y3 are given draw the rectangle with this value 514 if x1 is not None: 514 515 self.x1 = x1 515 if x2 !=None:516 if x2 is not None: 516 517 self.x2 = x2 517 if y1 !=None:518 if y1 is not None: 518 519 self.y1 = y1 519 if y2 !=None:520 if y2 is not None: 520 521 self.y2 = y2 521 # #Draw 2 vertical lines and a marker522 # Draw 2 vertical lines and a marker 522 523 self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 523 524 self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) … … 535 536 self.save_half_height = self.half_height 536 537 self.save_half_width = self.half_width 537 self.base.freeze_axes()538 538 539 539 def moveend(self, ev): 540 540 """ 541 541 After a dragging motion reset the flag self.has_move to False 542 542 """ 543 543 self.has_move = False … … 562 562 delta = self.x1 - self.center_x 563 563 self.x2 = self.center_x - delta 564 self.half_width = math.fabs(self.x1 - self.x2) / 2564 self.half_width = numpy.fabs(self.x1 - self.x2) / 2 565 565 self.has_move = True 566 566 self.base.base.update() 567 567 568 def set _cursor(self, x, y):569 """ 570 568 def setCursor(self, x, y): 569 """ 570 Update the figure given x and y 571 571 """ 572 572 self.move(x, y, None) … … 575 575 class HorizontalDoubleLine(_BaseInteractor): 576 576 """ 577 577 Select an annulus through a 2D plot 578 578 """ 579 579 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, … … 581 581 582 582 _BaseInteractor.__init__(self, base, axes, color=color) 583 # #Initialization the class583 # Initialization the class 584 584 self.markers = [] 585 585 self.axes = axes 586 # #Center coordinates586 # Center coordinates 587 587 self.center_x = center_x 588 588 self.center_y = center_y … … 598 598 self.save_x2 = self.x2 599 599 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) 604 604 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 605 605 marker='s', markersize=10, … … 616 616 linestyle='-', marker='', 617 617 color=self.color, visible=True)[0] 618 # #Flag to determine if the lines have moved618 # Flag to determine if the lines have moved 619 619 self.has_move = False 620 # #connection the marker and draw the pictures620 # connection the marker and draw the pictures 621 621 self.connect_markers([self.top_marker]) 622 622 self.update() 623 623 624 def set _layer(self, n):625 """ 626 627 624 def setLayer(self, n): 625 """ 626 Allow adding plot to the same panel 627 @param n: the number of layer 628 628 """ 629 629 self.layernum = n … … 632 632 def clear(self): 633 633 """ 634 634 Clear this figure and its markers 635 635 """ 636 636 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() 645 640 646 641 def update(self, x1=None, x2=None, y1=None, y2=None, … … 656 651 :param center: provided x, y coordinates of the center point 657 652 """ 658 # # save the new height, witdh of the rectangle if given as a param659 if width !=None:653 # Save the new height, witdh of the rectangle if given as a param 654 if width is not None: 660 655 self.half_width = width 661 if height !=None:656 if height is not None: 662 657 self.half_height = height 663 # #If new center coordinates are given draw the rectangle664 # #given these value665 if center !=None:658 # If new center coordinates are given draw the rectangle 659 # given these value 660 if center is not None: 666 661 self.center_x = center.x 667 662 self.center_y = center.y … … 678 673 ydata=[self.y2, self.y2]) 679 674 return 680 # #if x1, y1, y2, y3 are given draw the rectangle with this value681 if x1 !=None:675 # if x1, y1, y2, y3 are given draw the rectangle with this value 676 if x1 is not None: 682 677 self.x1 = x1 683 if x2 !=None:678 if x2 is not None: 684 679 self.x2 = x2 685 if y1 !=None:680 if y1 is not None: 686 681 self.y1 = y1 687 if y2 !=None:682 if y2 is not None: 688 683 self.y2 = y2 689 # #Draw 2 vertical lines and a marker684 # Draw 2 vertical lines and a marker 690 685 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 691 686 self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) … … 703 698 self.save_half_height = self.half_height 704 699 self.save_half_width = self.half_width 705 self.base.freeze_axes()706 700 707 701 def moveend(self, ev): … … 730 724 delta = self.y1 - self.center_y 731 725 self.y2 = self.center_y - delta 732 self.half_height = math.fabs(self.y1) - self.center_y726 self.half_height = numpy.fabs(self.y1) - self.center_y 733 727 self.has_move = True 734 728 self.base.base.update() 735 729 736 def set _cursor(self, x, y):737 """ 738 730 def setCursor(self, x, y): 731 """ 732 Update the figure given x and y 739 733 """ 740 734 self.move(x, y, None)
Note: See TracChangeset
for help on using the changeset viewer.