- Timestamp:
- Mar 5, 2015 4:53:03 PM (10 years ago)
- 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:
- c4f6851
- Parents:
- c039589
- Location:
- src/sas/guiframe/local_perspectives/plotting
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/SectorSlicer.py
r79492222 rb40ad40 1 1 """ 2 Sector interactor 3 """ 2 4 import math 3 5 import wx 4 #from copy import deepcopy5 6 from BaseInteractor import _BaseInteractor 6 7 from sas.guiframe.events import NewPlotEvent … … 16 17 """ 17 18 def __init__(self, base, axes, color='black', zorder=3): 18 19 19 20 _BaseInteractor.__init__(self, base, axes, color=color) 20 21 ## Class initialization 21 22 self.markers = [] 22 self.axes = axes 23 ## connect the plot to event 23 self.axes = axes 24 ## connect the plot to event 24 25 self.connect = self.base.connect 25 26 ## compute qmax limit to reset the graph 27 x = math.pow(max(self.base.data2D.xmax, 26 27 ## compute qmax limit to reset the graph 28 x = math.pow(max(self.base.data2D.xmax, 28 29 math.fabs(self.base.data2D.xmin)), 2) 29 y = math.pow(max(self.base.data2D.ymax, 30 y = math.pow(max(self.base.data2D.ymax, 30 31 math.fabs(self.base.data2D.ymin)), 2) 31 32 self.qmax = math.sqrt(x + y) … … 33 34 self.nbins = 20 34 35 ## Angle of the middle line 35 self.theta2 = math.pi /336 self.theta2 = math.pi / 3 36 37 ## Absolute value of the Angle between the middle line and any side line 37 self.phi = math.pi /1238 self.phi = math.pi / 12 38 39 ## Middle line 39 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 41 zorder=zorder, r=self.qmax, 41 theta=self.theta2)42 theta=self.theta2) 42 43 self.main_line.qmax = self.qmax 43 44 ## Right Side line 44 45 self.right_line = SideInteractor(self, self.base.subplot, color='black', 45 46 phi=-1*self.phi, theta2=self.theta2)46 zorder=zorder, r=self.qmax, 47 phi=-1 * self.phi, theta2=self.theta2) 47 48 self.right_line.qmax = self.qmax 48 ## Left Side line 49 ## Left Side line 49 50 self.left_line = SideInteractor(self, self.base.subplot, color='black', 50 51 zorder=zorder, r=self.qmax, 51 52 phi=self.phi, theta2=self.theta2) 52 53 self.left_line.qmax = self.qmax 53 ## draw the sector 54 ## draw the sector 54 55 self.update() 55 56 self._post_data() … … 60 61 """ 61 62 receive an event containing parameters values to reset the slicer 62 63 :param event: event of type SlicerParameterEvent with params as 63 64 :param event: event of type SlicerParameterEvent with params as 64 65 attribute 65 66 66 67 """ 67 68 wx.PostEvent(self.base.parent, … … 71 72 self.set_params(event.params) 72 73 self.base.update() 73 74 74 75 def set_layer(self, n): 75 76 """ 76 77 Allow adding plot to the same panel 77 78 78 79 :param n: the number of layer 79 80 80 81 """ 81 82 self.layernum = n 82 83 self.update() 83 84 84 85 def clear(self): 85 86 """ … … 92 93 self.base.connect.clearall() 93 94 self.base.Unbind(EVT_SLICER_PARS) 94 95 95 96 def update(self): 96 97 """ … … 98 99 resetting the widgets. 99 100 """ 100 # Update locations 101 ## Check if the middle line was dragged and 102 #update the picture accordingly 101 # Update locations 102 ## Check if the middle line was dragged and 103 #update the picture accordingly 103 104 if self.main_line.has_move: 104 105 self.main_line.update() 105 self.right_line.update(delta=-self.left_line.phi/2, 106 mline=self.main_line.theta) 107 self.left_line.update(delta=self.left_line.phi/2, 106 self.right_line.update(delta=-self.left_line.phi / 2, 108 107 mline=self.main_line.theta) 109 ## Check if the left side has moved and update the slicer accordingly 108 self.left_line.update(delta=self.left_line.phi / 2, 109 mline=self.main_line.theta) 110 ## Check if the left side has moved and update the slicer accordingly 110 111 if self.left_line.has_move: 111 112 self.main_line.update() … … 113 114 side=True, left=True) 114 115 self.right_line.update(phi=self.left_line.phi, delta=None, 115 116 117 ## Check if the right side line has moved and 116 mline=self.main_line, side=True, 117 left=False, right=True) 118 ## Check if the right side line has moved and 118 119 #update the slicer accordingly 119 120 if self.right_line.has_move: … … 122 123 side=True, left=False, right=True) 123 124 self.left_line.update(phi=self.right_line.phi, delta=None, 124 125 125 mline=self.main_line, side=True, left=False) 126 126 127 def save(self, ev): 127 128 """ … … 137 138 """ 138 139 compute sector averaging of data2D into data1D 139 140 140 141 :param nbins: the number of point to plot for the average 1D data 141 142 """ … … 147 148 ## Averaging 148 149 from sas.dataloader.manipulations import SectorQ 149 radius = self.qmax 150 phimin = 150 radius = self.qmax 151 phimin = -self.left_line.phi + self.main_line.theta 151 152 phimax = self.left_line.phi + self.main_line.theta 152 153 if nbins == None: 153 154 nbins = 20 154 155 sect = SectorQ(r_min=0.0, r_max=radius, 155 156 157 156 phi_min=phimin + math.pi, 157 phi_max=phimax + math.pi, nbins=nbins) 158 158 159 sector = sect(self.base.data2D) 159 160 ##Create 1D data resulting from average 160 161 161 162 if hasattr(sector, "dxl"): 162 163 dxl = sector.dxl … … 186 187 new_plot.id = "SectorQ" + self.base.data2D.name 187 188 new_plot.is_data = True 188 self.base.parent.update_theory(data_id=data.id, \ 189 theory=new_plot) 190 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 191 title="SectorQ" + self.base.data2D.name)) 192 189 self.base.parent.update_theory(data_id=data.id, theory=new_plot) 190 wx.PostEvent(self.base.parent, 191 NewPlotEvent(plot=new_plot, title="SectorQ" + self.base.data2D.name)) 192 193 193 def moveend(self, ev): 194 194 """ 195 Called a dragging motion ends.Get slicer event 195 Called a dragging motion ends.Get slicer event 196 196 """ 197 197 self.base.thaw_axes() … … 202 202 ## Send slicer paramers to plotter2D 203 203 wx.PostEvent(self.base, event) 204 204 205 205 def restore(self): 206 206 """ … … 216 216 """ 217 217 pass 218 218 219 219 def set_cursor(self, x, y): 220 220 """ 221 221 """ 222 222 pass 223 223 224 224 def get_params(self): 225 225 """ 226 226 Store a copy of values of parameters of the slicer into a dictionary. 227 227 228 228 :return params: the dictionary created 229 229 230 230 """ 231 231 params = {} 232 ## Always make sure that the left and the right line are at phi 232 ## Always make sure that the left and the right line are at phi 233 233 ## angle of the middle line 234 234 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): … … 236 236 msg += " %f, %f" % (self.left_line.phi, self.right_line.phi) 237 237 raise ValueError, msg 238 params["Phi [deg]"] = self.main_line.theta * 180 /math.pi239 params["Delta_Phi [deg]"] = math.fabs(self.left_line.phi * 180 /math.pi)238 params["Phi [deg]"] = self.main_line.theta * 180 / math.pi 239 params["Delta_Phi [deg]"] = math.fabs(self.left_line.phi * 180 / math.pi) 240 240 params["nbins"] = self.nbins 241 241 return params 242 242 243 243 def set_params(self, params): 244 244 """ 245 Receive a dictionary and reset the slicer with values contained 245 Receive a dictionary and reset the slicer with values contained 246 246 in the values of the dictionary. 247 248 :param params: a dictionary containing name of slicer parameters and 247 248 :param params: a dictionary containing name of slicer parameters and 249 249 values the user assigned to the slicer. 250 250 """ 251 main = params["Phi [deg]"] * math.pi/180252 phi = math.fabs(params["Delta_Phi [deg]"] * math.pi /180)251 main = params["Phi [deg]"] * math.pi / 180 252 phi = math.fabs(params["Delta_Phi [deg]"] * math.pi / 180) 253 253 self.nbins = int(params["nbins"]) 254 254 self.main_line.theta = main … … 257 257 self.right_line.update(phi=phi, delta=None, mline=self.main_line, 258 258 side=True, right=True) 259 self.left_line.update(phi=phi, delta=None, 259 self.left_line.update(phi=phi, delta=None, 260 260 mline=self.main_line, side=True) 261 261 ## post the new corresponding data 262 262 self._post_data(nbins=self.nbins) 263 263 264 264 def freeze_axes(self): 265 265 """ 266 266 """ 267 267 self.base.freeze_axes() 268 268 269 269 def thaw_axes(self): 270 270 """ … … 277 277 self.base.draw() 278 278 279 279 280 280 class SideInteractor(_BaseInteractor): 281 281 """ 282 282 Draw an oblique line 283 283 284 284 :param phi: the phase between the middle line and one side line 285 285 :param theta2: the angle between the middle line and x- axis 286 286 287 287 """ 288 288 def __init__(self, base, axes, color='black', zorder=5, r=1.0, 289 phi=math.pi /4, theta2= math.pi/3):289 phi=math.pi / 4, theta2=math.pi / 3): 290 290 """ 291 291 """ … … 295 295 self.axes = axes 296 296 ## compute the value of the angle between the current line and 297 ## the x-axis 297 ## the x-axis 298 298 self.save_theta = theta2 + phi 299 299 self.theta = theta2 + phi … … 309 309 x2 = -1 * self.radius * math.cos(self.theta) 310 310 y2 = -1 * self.radius * math.sin(self.theta) 311 ## defining a new marker 312 try: 313 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], 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, visible=True)[0] 319 except: 320 self.inner_marker = self.axes.plot([x1/2.5],[y1/2.5], linestyle='', 321 marker='s', markersize=10, 322 color=self.color, alpha=0.6, 323 label="pick", visible=True)[0] 324 message = "\nTHIS PROTOTYPE NEEDS THE LATEST" 325 message += " VERSION OF MATPLOTLIB\n Get the SVN version that" 326 message += " is at least as recent as June 1, 2007" 327 owner = self.base.base.parent 328 wx.PostEvent(owner, 329 StatusEvent(status="sectorSlicer: %s" % message)) 330 311 ## defining a new marker 312 self.inner_marker = self.axes.plot([x1 / 2.5], [y1 / 2.5], linestyle='', 313 marker='s', markersize=10, 314 color=self.color, alpha=0.6, 315 pickradius=5, label="pick", 316 zorder=zorder, visible=True)[0] 317 331 318 ## Defining the current line 332 319 self.line = self.axes.plot([x1, x2], [y1, y2], 333 334 320 linestyle='-', marker='', 321 color=self.color, visible=True)[0] 335 322 ## Flag to differentiate the left line from the right line motion 336 323 self.left_moving = False … … 339 326 ## connecting markers and draw the picture 340 327 self.connect_markers([self.inner_marker, self.line]) 341 328 342 329 def set_layer(self, n): 343 330 """ 344 331 Allow adding plot to the same panel 345 332 346 333 :param n: the number of layer 347 334 348 335 """ 349 336 self.layernum = n 350 337 self.update() 351 338 352 339 def clear(self): 353 340 """ … … 362 349 for item in range(len(self.axes.lines)): 363 350 del self.axes.lines[0] 364 351 365 352 def update(self, phi=None, delta=None, mline=None, 366 side=False, left= 353 side=False, left=False, right=False): 367 354 """ 368 355 Draw oblique line 369 356 370 357 :param phi: the phase between the middle line and the current line 371 358 :param delta: phi/2 applied only when the mline was moved 372 359 373 360 """ 374 361 #print "update left or right ", self.has_move … … 386 373 if side: 387 374 self.theta = mline.theta + self.phi 388 389 if mline != None 375 376 if mline != None: 390 377 if delta != 0: 391 378 self.theta2 = mline + delta … … 400 387 x2 = -1 * self.radius * math.cos(theta3) 401 388 y2 = -1 * self.radius * math.sin(theta3) 402 self.inner_marker.set(xdata=[x1 /2.5], ydata=[y1/2.5])403 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 404 389 self.inner_marker.set(xdata=[x1 / 2.5], ydata=[y1 / 2.5]) 390 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 391 405 392 def save(self, ev): 406 393 """ … … 416 403 self.has_move = False 417 404 self.base.moveend(ev) 418 405 419 406 def restore(self): 420 407 """ … … 433 420 if self.theta2 - self.theta <= 0 and self.theta2 > 0: 434 421 self.restore() 435 return 422 return 436 423 elif self.theta2 < 0 and self.theta < 0 and \ 437 self.theta -self.theta2 >= 0:438 self.restore() 439 return 424 self.theta - self.theta2 >= 0: 425 self.restore() 426 return 440 427 elif self.theta2 < 0 and self.theta > 0 and \ 441 (self.theta2 + 2 * math.pi - self.theta) >= math.pi/2: 442 #print "my theta", self.theta 443 self.restore() 444 return 428 (self.theta2 + 2 * math.pi - self.theta) >= math.pi / 2: 429 self.restore() 430 return 445 431 elif self.theta2 < 0 and self.theta < 0 and \ 446 (self.theta2 - self.theta) >= math.pi/2: 447 #print "my theta", self.theta 448 self.restore() 449 return 450 elif self.theta2 > 0 and (self.theta2-self.theta >= math.pi/2 or \ 451 (self.theta2-self.theta >= math.pi/2)): 452 #print "self theta encore" 453 self.restore() 454 return 432 (self.theta2 - self.theta) >= math.pi / 2: 433 self.restore() 434 return 435 elif self.theta2 > 0 and (self.theta2 - self.theta >= math.pi / 2 or \ 436 (self.theta2 - self.theta >= math.pi / 2)): 437 self.restore() 438 return 455 439 else: 456 #print "left move" 457 if self.theta < 0 and (self.theta + math.pi*2-self.theta2) <= 0: 458 self.restore() 459 return 460 elif self.theta2 < 0 and (self.theta-self.theta2) <= 0: 461 self.restore() 462 return 463 elif self.theta > 0 and self.theta-self.theta2 <= 0: 464 #print "my theta", self.theta 465 self.restore() 466 return 467 elif self.theta-self.theta2 >= math.pi/2 or \ 468 ((self.theta + math.pi * 2 - self.theta2) >= math.pi/2 and \ 440 if self.theta < 0 and (self.theta + math.pi * 2 - self.theta2) <= 0: 441 self.restore() 442 return 443 elif self.theta2 < 0 and (self.theta - self.theta2) <= 0: 444 self.restore() 445 return 446 elif self.theta > 0 and self.theta - self.theta2 <= 0: 447 self.restore() 448 return 449 elif self.theta - self.theta2 >= math.pi / 2 or \ 450 ((self.theta + math.pi * 2 - self.theta2) >= math.pi / 2 and \ 469 451 self.theta < 0 and self.theta2 > 0): 470 #print "self theta encore" 471 self.restore() 472 return 473 452 self.restore() 453 return 454 474 455 self.phi = math.fabs(self.theta2 - self.theta) 475 456 if self.phi > math.pi: 476 457 self.phi = 2 * math.pi - math.fabs(self.theta2 - self.theta) 477 458 self.base.base.update() 478 459 479 460 def set_cursor(self, x, y): 480 461 """ … … 482 463 self.move(x, y, None) 483 464 self.update() 484 465 485 466 def get_params(self): 486 467 """ … … 490 471 params["theta"] = self.theta 491 472 return params 492 473 493 474 def set_params(self, params): 494 475 """ 495 476 """ 496 x = params["radius"] 477 x = params["radius"] 497 478 self.set_cursor(x, None) 498 479 499 480 500 481 class LineInteractor(_BaseInteractor): … … 503 484 """ 504 485 def __init__(self, base, axes, color='black', 505 zorder=5, r=1.0, theta=math.pi /4):486 zorder=5, r=1.0, theta=math.pi / 4): 506 487 """ 507 488 """ 508 489 _BaseInteractor.__init__(self, base, axes, color=color) 509 490 510 491 self.markers = [] 511 492 self.axes = axes 512 self.save_theta = theta 513 self.theta = theta493 self.save_theta = theta 494 self.theta = theta 514 495 self.radius = r 515 496 self.scale = 10.0 … … 517 498 x1 = self.radius * math.cos(self.theta) 518 499 y1 = self.radius * math.sin(self.theta) 519 x2 = -1*self.radius * math.cos(self.theta) 520 y2 = -1*self.radius * math.sin(self.theta) 521 try: 522 # Inner circle marker 523 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 524 marker='s', markersize=10, 525 color=self.color, alpha=0.6, 526 pickradius=5, label="pick", 527 # Prefer this to other lines 528 zorder=zorder, 529 visible=True)[0] 530 except: 531 self.inner_marker = self.axes.plot([x1/2.5], [y1/2.5], linestyle='', 532 marker='s', markersize=10, 533 color=self.color, alpha=0.6, 534 label="pick", 535 visible=True)[0] 536 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 537 message += " OF MATPLOTLIB\n Get the SVN version that is at" 538 message += " least as recent as June 1, 2007" 500 x2 = -1 * self.radius * math.cos(self.theta) 501 y2 = -1 * self.radius * math.sin(self.theta) 502 # Inner circle marker 503 self.inner_marker = self.axes.plot([x1 / 2.5], [y1 / 2.5], linestyle='', 504 marker='s', markersize=10, 505 color=self.color, alpha=0.6, 506 pickradius=5, label="pick", 507 zorder=zorder, 508 visible=True)[0] 539 509 self.line = self.axes.plot([x1, x2], [y1, y2], 540 541 510 linestyle='-', marker='', 511 color=self.color, visible=True)[0] 542 512 self.npts = 20 543 513 self.has_move = False … … 550 520 self.layernum = n 551 521 self.update() 552 522 553 523 def clear(self): 554 524 """ … … 562 532 for item in range(len(self.axes.lines)): 563 533 del self.axes.lines[0] 564 534 565 535 def update(self, theta=None): 566 536 """ 567 537 Draw the new roughness on the graph. 568 538 """ 569 539 570 540 if theta != None: 571 541 self.theta = theta … … 574 544 x2 = -1 * self.radius * math.cos(self.theta) 575 545 y2 = -1 * self.radius * math.sin(self.theta) 576 577 self.inner_marker.set(xdata=[x1 /2.5], ydata=[y1/2.5])578 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 579 546 547 self.inner_marker.set(xdata=[x1 / 2.5], ydata=[y1 / 2.5]) 548 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 549 580 550 def save(self, ev): 581 551 """ … … 583 553 can restore on Esc. 584 554 """ 585 self.save_theta = self.theta555 self.save_theta = self.theta 586 556 self.base.freeze_axes() 587 557 … … 591 561 self.has_move = False 592 562 self.base.moveend(ev) 593 563 594 564 def restore(self): 595 565 """ … … 605 575 self.has_move = True 606 576 self.base.base.update() 607 577 608 578 def set_cursor(self, x, y): 609 579 """ … … 611 581 self.move(x, y, None) 612 582 self.update() 613 583 614 584 def get_params(self): 615 585 """ … … 619 589 params["theta"] = self.theta 620 590 return params 621 591 622 592 def set_params(self, params): 623 593 """ 624 594 """ 625 x = params["radius"] 595 x = params["radius"] 626 596 self.set_cursor(x, None) 627 -
src/sas/guiframe/local_perspectives/plotting/SimplePlot.py
r79492222 rb40ad40 3 3 """ 4 4 import wx 5 from sas.guiframe.local_perspectives.plotting.Plotter2D import ModelPanel2D \ 6 as PlotPanel 5 from sas.guiframe.local_perspectives.plotting.Plotter2D import ModelPanel2D as PlotPanel 7 6 from sas.plottools.toolbar import NavigationToolBar 8 7 from sas.plottools.plottables import Graph 9 8 from sas.guiframe.utils import PanelMenu 10 11 class SimplePlotPanel(PlotPanel): 9 from sas.guiframe.events import StatusEvent 10 11 class SimplePlotPanel(PlotPanel): 12 12 """ 13 13 PlotPanel for 1d and 2d 14 """ 14 """ 15 15 _window_caption = 'Simple Plot' 16 def __init__(self, parent, id=-1, color =None,16 def __init__(self, parent, id=-1, color=None, 17 17 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 18 18 """ … … 22 22 23 23 self.SetColor(wx.WHITE) 24 24 25 25 self.toolbar = NavigationToolBar(parent=self, canvas=self.canvas) 26 26 self.toolbar.Show(False) 27 27 self.scale = parent.scale 28 28 self.window_caption = self._window_caption 29 29 30 30 def draw(self): 31 31 """ … … 34 34 self.canvas.set_resizing(self.resizing) 35 35 self.canvas.draw() 36 36 37 37 def add_toolbar(self): 38 38 """ 39 39 """ 40 pass 41 40 pass 41 42 42 def onContextMenu(self, event): 43 43 """ 44 44 2D plot context menu 45 45 46 46 :param event: wx context event 47 47 48 48 """ 49 49 slicerpop = PanelMenu() 50 50 slicerpop.set_plots(self.plots) 51 51 slicerpop.set_graph(self.graph) 52 53 id = wx.NewId()54 slicerpop.Append( id, '&Save Image')55 wx.EVT_MENU(self, id, self.onSaveImage)56 57 id = wx.NewId()58 slicerpop.Append( id,'&Print Image', 'Print image')59 wx.EVT_MENU(self, id, self.onPrint)60 61 id = wx.NewId()62 slicerpop.Append( id,'&Print Preview', 'Print preview')63 wx.EVT_MENU(self, id, self.onPrinterPreview)64 65 id = wx.NewId()66 slicerpop.Append( id, '&Copy to Clipboard', 'Copy to the clipboard')67 wx.EVT_MENU(self, id, self.OnCopyFigureMenu)52 53 wx_id = wx.NewId() 54 slicerpop.Append(wx_id, '&Save Image') 55 wx.EVT_MENU(self, wx_id, self.onSaveImage) 56 57 wx_id = wx.NewId() 58 slicerpop.Append(wx_id, '&Print Image', 'Print image') 59 wx.EVT_MENU(self, wx_id, self.onPrint) 60 61 wx_id = wx.NewId() 62 slicerpop.Append(wx_id, '&Print Preview', 'Print preview') 63 wx.EVT_MENU(self, wx_id, self.onPrinterPreview) 64 65 wx_id = wx.NewId() 66 slicerpop.Append(wx_id, '&Copy to Clipboard', 'Copy to the clipboard') 67 wx.EVT_MENU(self, wx_id, self.OnCopyFigureMenu) 68 68 69 69 if self.dimension != 3: 70 70 slicerpop.AppendSeparator() 71 id = wx.NewId()72 slicerpop.Append( id, '&Toggle Grid On/Off', 'Toggle Grid On/Off')73 wx.EVT_MENU(self, id, self.on_grid_onoff)71 wx_id = wx.NewId() 72 slicerpop.Append(wx_id, '&Toggle Grid On/Off', 'Toggle Grid On/Off') 73 wx.EVT_MENU(self, wx_id, self.on_grid_onoff) 74 74 75 75 if self.data.__class__.__name__ == 'Data1D': 76 76 slicerpop.AppendSeparator() 77 id = wx.NewId()78 slicerpop.Append( id, '&Change Scale')79 wx.EVT_MENU(self, id, self._onProperties)77 wx_id = wx.NewId() 78 slicerpop.Append(wx_id, '&Change Scale') 79 wx.EVT_MENU(self, wx_id, self._onProperties) 80 80 elif self.data2D.__class__.__name__ == 'Data2D': 81 81 slicerpop.AppendSeparator() 82 id = wx.NewId()83 slicerpop.Append( id, '&Toggle Linear/Log Scale')84 wx.EVT_MENU(self, id, self._onToggleScale)85 82 wx_id = wx.NewId() 83 slicerpop.Append(wx_id, '&Toggle Linear/Log Scale') 84 wx.EVT_MENU(self, wx_id, self._onToggleScale) 85 86 86 try: 87 87 pos_evt = event.GetPosition() … … 92 92 self.PopupMenu(slicerpop, pos) 93 93 if self.scale != None: 94 self.parent.scale2d = self.scale 95 94 self.parent.scale2d = self.scale 95 96 96 def on_grid_onoff(self, event): 97 97 """ … … 99 99 """ 100 100 switch = (not self.grid_on) 101 self.onGridOnOff(switch) 102 101 self.onGridOnOff(switch) 102 103 103 def onLeftDown(self, event): 104 104 """ 105 105 left button down and ready to drag 106 106 107 107 """ 108 108 # Check that the LEFT button was pressed … … 120 120 wx.PostEvent(self.parent, StatusEvent(status=self.position)) 121 121 except: 122 self.position = None 123 124 def _OnReSize(self, event): 122 self.position = None 123 124 def _OnReSize(self, event): 125 125 """ 126 126 On response of the resize of a panel, set axes_visiable False … … 134 134 135 135 # Ready for another event 136 # Do not remove this Skip. 136 # Do not remove this Skip. 137 137 # Otherwise it will get runtime error on wx>=2.9. 138 event.Skip() 138 event.Skip() 139 139 # set the resizing flag 140 140 self.canvas.set_resizing(self.resizing) … … 143 143 self.size, _ = self.GetClientSizeTuple() 144 144 self.SetSizer(self.sizer) 145 145 146 146 def on_set_focus(self, event): 147 147 """ … … 149 149 """ 150 150 pass 151 151 152 152 def on_kill_focus(self, event): 153 153 """ … … 155 155 """ 156 156 pass 157 157 158 158 def show_plot(self, plot): 159 159 """ … … 182 182 self.graph.yaxis(_yaxis, _yunit) 183 183 self.xaxis(_xaxis, _xunit) 184 self.yaxis(_yaxis, _yunit) 184 self.yaxis(_yaxis, _yunit) 185 185 self.set_xscale(self.xscale) 186 self.set_yscale(self.yscale) 187 self.graph.render(self) 188 186 self.set_yscale(self.yscale) 187 self.graph.render(self) 188 189 189 class PlotFrame(wx.Frame): 190 190 """ 191 191 Frame for simple plot 192 192 """ 193 def __init__(self, parent, id, title, scale='log_{10}', 194 size=wx.Size(550, 470)): 193 def __init__(self, parent, id, title, scale='log_{10}', 194 size=wx.Size(550, 470)): 195 195 """ 196 196 comment … … 199 199 # Initialize the Frame object 200 200 wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, size) 201 201 202 202 # Panel for 1D plot 203 203 self.parent = parent … … 214 214 """ 215 215 tsize = (13, 13) 216 save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_TOOLBAR, 217 tsize) 218 quit_bmp = wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, 219 tsize) 220 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, 221 tsize) 222 preview_bmp = wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR, 223 tsize) 224 copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, 225 tsize) 216 save_bmp = wx.ArtProvider.GetBitmap(wx.ART_FILE_SAVE_AS, wx.ART_TOOLBAR, tsize) 217 quit_bmp = wx.ArtProvider.GetBitmap(wx.ART_QUIT, wx.ART_TOOLBAR, tsize) 218 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR, tsize) 219 preview_bmp = wx.ArtProvider.GetBitmap(wx.ART_REPORT_VIEW, wx.ART_TOOLBAR, tsize) 220 copy_bmp = wx.ArtProvider.GetBitmap(wx.ART_COPY, wx.ART_TOOLBAR, tsize) 226 221 menu_bar = wx.MenuBar() 227 228 menu = wx.Menu() 222 223 menu = wx.Menu() 229 224 id = wx.NewId() 230 225 item = wx.MenuItem(menu, id, "&Save Image") … … 244 239 menu.AppendItem(item) 245 240 wx.EVT_MENU(self, id, self.on_print_preview) 246 241 247 242 menu.AppendSeparator() 248 243 id = wx.NewId() … … 253 248 menu_bar.Append(menu, "&File") 254 249 wx.EVT_MENU(self, id, self.on_close) 255 250 256 251 menu_edit = wx.Menu() 257 252 id = wx.NewId() … … 260 255 menu_edit.AppendItem(item) 261 256 wx.EVT_MENU(self, id, self.on_copy_image) 262 257 263 258 menu_bar.Append(menu_edit, "&Edit") 264 259 self.menu_bar = menu_bar … … 269 264 un focusing 270 265 """ 271 pass 272 266 pass 267 273 268 def add_plot(self, plot): 274 269 """ … … 278 273 plotpanel.scale = self.scale 279 274 plotpanel.show_plot(plot) 280 275 281 276 def set_schedule_full_draw(self, panel, func): 282 277 """ 283 278 """ 284 279 self.plotpanel.resizing = False 285 280 286 281 def im_show(self, img): 287 282 """ … … 290 285 """ 291 286 self.plotpanel.subplot.imshow(img) 292 293 def set_schedule(self, schedule=False): 287 288 def set_schedule(self, schedule=False): 294 289 """ 295 290 """ 296 291 #Not implemented 297 292 298 293 def disable_app_menu(self, panel): 299 294 """ 300 295 """ 301 #Not implemented302 303 def get_current_context_menu(self, plotpanel):304 """305 """306 296 #Not implemented 307 297 298 def get_current_context_menu(self, plotpanel): 299 """ 300 """ 301 #Not implemented 302 308 303 def on_save_file(self, event): 309 304 """ … … 317 312 """ 318 313 self.plotpanel.onPrint(event) 319 314 320 315 def on_print_preview(self, event): 321 316 """ … … 329 324 """ 330 325 self.plotpanel.OnCopyFigureMenu(event) 331 326 332 327 def on_close(self, event): 333 328 """ 334 On Close 329 On Close 335 330 """ 336 331 try: … … 339 334 except: 340 335 self.Destroy() 341 336 -
src/sas/guiframe/local_perspectives/plotting/SlicerParameters.py
r79492222 rb40ad40 12 12 class SlicerParameterPanel(wx.Dialog): 13 13 """ 14 Panel class to show the slicer parameters 14 Panel class to show the slicer parameters 15 15 """ 16 16 #TODO: show units 17 17 #TODO: order parameters properly 18 18 19 19 def __init__(self, parent, *args, **kwargs): 20 wx.Dialog.__init__(self, parent, *args, **kwargs)21 20 """ 22 Dialog window that allow to edit parameters slicer 21 Dialog window that allow to edit parameters slicer 23 22 by entering new values 24 23 """ 24 wx.Dialog.__init__(self, parent, *args, **kwargs) 25 25 self.params = {} 26 26 self.parent = parent … … 33 33 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 34 34 self.bck.Add(title, (0, 0), (1, 2), 35 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)35 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 36 36 # Bindings 37 37 self.parent.Bind(EVT_SLICER, self.onEVT_SLICER) … … 42 42 Process EVT_SLICER events 43 43 When the slicer changes, update the panel 44 44 45 45 :param event: EVT_SLICER event 46 46 """ … … 50 50 else: 51 51 self.set_slicer(event.type, event.params) 52 52 53 53 def set_slicer(self, type, params): 54 54 """ 55 55 Rebuild the panel 56 56 """ 57 self.bck.Clear(True) 58 self.type = type 57 self.bck.Clear(True) 58 self.type = type 59 59 if type == None: 60 60 label = "Right-click on 2D plot for slicer options" 61 61 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 62 self.bck.Add(title, (0, 0), (1, 2), 63 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)62 self.bck.Add(title, (0, 0), (1, 2), 63 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 64 64 else: 65 title = wx.StaticText(self, -1, 65 title = wx.StaticText(self, -1, 66 66 "Slicer Parameters", style=wx.ALIGN_LEFT) 67 67 self.bck.Add(title, (0, 0), (1, 2), 68 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)68 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 69 69 ix = 0 70 70 iy = 0 … … 77 77 if not item in ["count", "errors"]: 78 78 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 79 self.bck.Add(text, (iy, ix), (1, 1), 80 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)79 self.bck.Add(text, (iy, ix), (1, 1), 80 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 81 81 ctl = wx.TextCtrl(self, -1, size=(80, 20), 82 82 style=wx.TE_PROCESS_ENTER) … … 88 88 self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 89 89 self.parameters.append([item, ctl]) 90 self.bck.Add(ctl, (iy, ix), (1, 1), 91 wx.EXPAND |wx.ADJUST_MINSIZE, 0)90 self.bck.Add(ctl, (iy, ix), (1, 1), 91 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 92 92 ix = 3 93 self.bck.Add((20, 20), (iy, ix), (1, 1), 94 wx.EXPAND |wx.ADJUST_MINSIZE, 0)93 self.bck.Add((20, 20), (iy, ix), (1, 1), 94 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 95 95 else: 96 text = wx.StaticText(self, -1, item + " : ", 96 text = wx.StaticText(self, -1, item + " : ", 97 97 style=wx.ALIGN_LEFT) 98 self.bck.Add(text, (iy, ix), (1, 1), 99 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)100 ctl = wx.StaticText(self, -1, 101 format_number(str(params[item])),102 style=wx.ALIGN_LEFT)98 self.bck.Add(text, (iy, ix), (1, 1), 99 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 100 ctl = wx.StaticText(self, -1, 101 format_number(str(params[item])), 102 style=wx.ALIGN_LEFT) 103 103 ix = 1 104 self.bck.Add(ctl, (iy, ix), (1, 1), 105 wx.EXPAND |wx.ADJUST_MINSIZE, 0)104 self.bck.Add(ctl, (iy, ix), (1, 1), 105 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 106 106 iy += 1 107 107 ix = 1 108 self.bck.Add((20, 20), (iy, ix), (1, 1), 109 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)108 self.bck.Add((20, 20), (iy, ix), (1, 1), 109 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 110 110 self.bck.Layout() 111 111 self.bck.Fit(self) … … 119 119 evt.Skip() 120 120 if evt.type == "UPDATE": 121 for item in self.parameters: 121 for item in self.parameters: 122 122 if item[0] in evt.params: 123 123 item[1].SetValue("%-5.3g" % evt.params[item[0]]) 124 124 item[1].Refresh() 125 126 def onTextEnter(self, evt): 125 126 def onTextEnter(self, evt): 127 127 """ 128 128 Parameters have changed 129 """ 129 """ 130 130 params = {} 131 131 has_error = False … … 133 133 try: 134 134 params[item[0]] = float(item[1].GetValue()) 135 item[1].SetBackgroundColour( 136 wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) 135 item[1].SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) 137 136 item[1].Refresh() 138 137 except: … … 146 145 event = SlicerParameterEvent(type=self.type, params=params) 147 146 wx.PostEvent(self.parent, event) 148 -
src/sas/guiframe/local_perspectives/plotting/slicerpanel.py
r27ab091 rb40ad40 1 2 3 1 import wx 4 2 import wx.lib.newevent … … 13 11 class SlicerPanel(wx.Panel, PanelBase): 14 12 """ 15 Panel class to show the slicer parameters 13 Panel class to show the slicer parameters 16 14 """ 17 15 #TODO: show units … … 22 20 window_caption = "Slicer Panel" 23 21 CENTER_PANE = False 24 22 25 23 def __init__(self, parent, id=-1, type=None, base=None, 26 params=None, *args, **kwargs):24 params=None, *args, **kwargs): 27 25 wx.Panel.__init__(self, parent, id, *args, **kwargs) 28 26 PanelBase.__init__(self) 29 ## Initialization of the class 27 ## Initialization of the class 30 28 self.base = base 31 29 if params is None: … … 39 37 self.bck = wx.GridBagSizer(5, 5) 40 38 self.SetSizer(self.bck) 41 if type == None and params == None: 42 label = "Right-click on 2D plot for slicer options" 39 if type == None and params == None: 40 label = "Right-click on 2D plot for slicer options" 43 41 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 44 self.bck.Add(title, (0, 0), (1, 2), 45 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)42 self.bck.Add(title, (0, 0), (1, 2), 43 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 46 44 else: 47 45 self.set_slicer(type, params) … … 54 52 Process EVT_SLICER events 55 53 When the slicer changes, update the panel 56 54 57 55 :param event: EVT_SLICER event 58 56 59 57 """ 60 58 event.Skip() 61 59 if event.obj_class == None: 62 self.set_slicer(None, None) 60 self.set_slicer(None, None) 63 61 else: 64 62 self.set_slicer(event.type, event.params) 65 63 66 64 def set_slicer(self, type, params): 67 65 """ 68 66 Rebuild the panel 69 67 """ 70 self.bck.Clear(True) 71 self.type = type 68 self.bck.Clear(True) 69 self.type = type 72 70 if type == None: 73 71 label = "Right-click on 2D plot for slicer options" 74 72 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) 75 self.bck.Add(title, (0, 0), (1, 2), 76 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)73 self.bck.Add(title, (0, 0), (1, 2), 74 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 77 75 else: 78 76 title_text = str(type) + "Parameters" 79 title = wx.StaticText(self, -1, title_text, 77 title = wx.StaticText(self, -1, title_text, 80 78 style=wx.ALIGN_LEFT) 81 self.bck.Add(title, (0, 0), (1, 2), 82 flag=wx.LEFT |wx.ALIGN_CENTER_VERTICAL, border=15)79 self.bck.Add(title, (0, 0), (1, 2), 80 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 83 81 n = 1 84 82 self.parameters = [] … … 86 84 keys.sort() 87 85 for item in keys: 88 if not item.lower() in ["num_points", "avg", "avg_error", "sum", 89 "sum_error"]: 86 if not item.lower() in ["num_points", "avg", "avg_error", "sum", "sum_error"]: 90 87 n += 1 91 88 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 92 self.bck.Add(text, (n -1, 0),93 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15)94 ctl = wx.TextCtrl(self, -1, size=(80, 20), 89 self.bck.Add(text, (n - 1, 0), 90 flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, border=15) 91 ctl = wx.TextCtrl(self, -1, size=(80, 20), 95 92 style=wx.TE_PROCESS_ENTER) 96 93 hint_msg = "Modify the value of %s to change " % item … … 102 99 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 103 100 self.parameters.append([item, ctl]) 104 self.bck.Add(ctl, (n -1, 1), flag=wx.TOP|wx.BOTTOM, border=0)101 self.bck.Add(ctl, (n - 1, 1), flag=wx.TOP | wx.BOTTOM, border=0) 105 102 for item in keys: 106 if item.lower() in ["num_points", "avg", "avg_error", "sum", 107 "sum_error"]: 103 if item.lower() in ["num_points", "avg", "avg_error", "sum", "sum_error"]: 108 104 n += 1 109 text = wx.StaticText(self, -1, item + ": ", 110 style=wx.ALIGN_LEFT) 111 self.bck.Add(text, (n-1, 0), 112 flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, 105 text = wx.StaticText(self, -1, item + ": ", style=wx.ALIGN_LEFT) 106 self.bck.Add(text, (n - 1, 0), flag=wx.LEFT | wx.ALIGN_CENTER_VERTICAL, 113 107 border=15) 114 ctl = wx.StaticText(self, -1, 108 ctl = wx.StaticText(self, -1, 115 109 str(format_number(params[item])), 116 110 style=wx.ALIGN_LEFT) 117 111 ctl.SetToolTipString("Result %s" % item) 118 self.bck.Add(ctl, (n -1, 1), flag=wx.TOP|wx.BOTTOM, border=0)112 self.bck.Add(ctl, (n - 1, 1), flag=wx.TOP | wx.BOTTOM, border=0) 119 113 self.bck.Layout() 120 #self.bck.Fit(self)121 114 self.Layout() 122 115 psizer = self.parent.GetSizer() 123 116 if psizer != None: 124 117 psizer.Layout() 125 118 126 119 def onSetFocus(self, evt): 127 120 """ … … 134 127 wx.CallAfter(widget.SetSelection, -1, -1) 135 128 return 136 129 137 130 def onParamChange(self, evt): 138 131 """ 139 132 Receive and event and reset the text field contained in self.parameters 140 133 141 134 """ 142 135 evt.Skip() 143 for item in self.parameters: 136 for item in self.parameters: 144 137 if item[0] in evt.params: 145 138 item[1].SetValue(format_number(evt.params[item[0]])) 146 139 item[1].Refresh() 147 148 def onTextEnter(self, evt): 140 141 def onTextEnter(self, evt): 149 142 """ 150 143 Parameters have changed … … 156 149 try: 157 150 params[item[0]] = float(item[1].GetValue()) 158 item[1].SetBackgroundColour( 159 wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) 151 item[1].SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) 160 152 item[1].Refresh() 161 153 except: … … 163 155 item[1].SetBackgroundColour("pink") 164 156 item[1].Refresh() 165 157 166 158 if has_error == False: 167 159 # Post parameter event … … 175 167 """ 176 168 ID = self.uid 177 self.parent.delete_panel(ID) 169 self.parent.delete_panel(ID) 178 170 self.frame.Destroy()
Note: See TracChangeset
for help on using the changeset viewer.