Changeset b5de88e in sasview for src/sas/guiframe/local_perspectives/plotting/masking.py
- Timestamp:
- Mar 5, 2015 2:49: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:
- 7d56795
- Parents:
- 824e488
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/masking.py
r79492222 rb5de88e 3 3 """ 4 4 ################################################################################ 5 # This software was developed by the University of Tennessee as part of the6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)7 # project funded by the US National Science Foundation.5 # This software was developed by the University of Tennessee as part of the 6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 # project funded by the US National Science Foundation. 8 8 # 9 # If you use DANSE applications to do scientific research that leads to10 # publication, we ask that you acknowledge the use of the software with the11 # following sentence:9 # If you use DANSE applications to do scientific research that leads to 10 # publication, we ask that you acknowledge the use of the software with the 11 # following sentence: 12 12 # 13 # This work benefited from DANSE software developed under NSF award DMR-0520547.13 # This work benefited from DANSE software developed under NSF award DMR-0520547. 14 14 # 15 # copyright 2008, University of Tennessee15 # copyright 2008, University of Tennessee 16 16 ################################################################################ 17 17 18 18 19 # #Todo: cleaning up, improving the maskplotpanel initialization, and testing.19 # #Todo: cleaning up, improving the maskplotpanel initialization, and testing. 20 20 import wx 21 21 import sys … … 39 39 _STATICBOX_WIDTH = 380 40 40 41 # SLD panel size41 # SLD panel size 42 42 if sys.platform.count("win32") > 0: 43 43 PANEL_SIZE = 350 … … 46 46 PANEL_SIZE = 300 47 47 FONT_VARIANT = 1 48 48 49 49 from sas.data_util.calcthread import CalcThread 50 50 … … 54 54 """ 55 55 def __init__(self, 56 id =-1,57 panel =None,58 image =None,59 completefn =None,60 updatefn =None,61 elapsed =0,62 yieldtime =0.01,63 worktime =0.0156 id=-1, 57 panel=None, 58 image=None, 59 completefn=None, 60 updatefn=None, 61 elapsed=0, 62 yieldtime=0.01, 63 worktime=0.01 64 64 ): 65 65 """ … … 70 70 worktime) 71 71 self.starttime = 0 72 self.id = id 72 self.id = id 73 73 self.panel = panel 74 74 self.image = image 75 76 75 76 77 77 def compute(self): 78 78 """ … … 80 80 """ 81 81 elapsed = time.time() - self.starttime 82 82 83 83 self.complete(panel=self.panel, image=self.image, elapsed=elapsed) 84 85 84 85 86 86 class MaskPanel(wx.Dialog): 87 87 """ 88 88 Provides the Mask Editor GUI. 89 89 """ 90 # # Internal nickname for the window, used by the AUI manager90 # # Internal nickname for the window, used by the AUI manager 91 91 window_name = "Mask Editor" 92 # # Name to appear on the window title bar92 # # Name to appear on the window title bar 93 93 window_caption = "Mask Editor" 94 # # Flag to tell the AUI manager to put this panel in the center pane94 # # Flag to tell the AUI manager to put this panel in the center pane 95 95 CENTER_PANE = True 96 def __init__(self, parent=None, base=None, 96 def __init__(self, parent=None, base=None, 97 97 data=None, id=-1, *args, **kwds): 98 98 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 99 kwds["size"] = wx.Size(_STATICBOX_WIDTH *0.8, PANEL_SIZE)100 wx.Dialog.__init__(self, parent, id=id, 101 99 kwds["size"] = wx.Size(_STATICBOX_WIDTH * 0.8, PANEL_SIZE) 100 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 101 102 102 if data != None: 103 # Font size103 # Font size 104 104 kwds = [] 105 105 self.SetWindowVariant(variant=FONT_VARIANT) … … 108 108 self.data = data 109 109 self.str = self.data.__str__() 110 # # mask for 2D110 # # mask for 2D 111 111 self.mask = data.mask 112 112 self.default_mask = copy.deepcopy(data.mask) 113 # # masked data from GUI113 # # masked data from GUI 114 114 self.slicer_mask = None 115 115 self.slicer = None 116 116 self.slicer_z = 5 117 117 self.data.interactive = True 118 # # when 2 data have the same id override the 1 st plotted118 # # when 2 data have the same id override the 1 st plotted 119 119 self.name = self.data.name 120 120 # Panel for 2D plot … … 122 122 style=wx.TRANSPARENT_WINDOW) 123 123 self.cmap = DEFAULT_CMAP 124 # # Create Artist and bind it124 # # Create Artist and bind it 125 125 self.subplot = self.plotpanel.subplot 126 126 self.connect = BindArtist(self.subplot.figure) … … 128 128 self.newplot = Data2D(image=self.data.data) 129 129 self.newplot.setValues(self.data) 130 self.plotpanel.add_image(self.newplot) 130 self.plotpanel.add_image(self.newplot) 131 131 self._update_mask(self.mask) 132 132 self.Centre() … … 134 134 # bind evt_close to _draw in fitpage 135 135 self.Bind(wx.EVT_CLOSE, self.OnClose) 136 136 137 137 def ShowMessage(self, msg=''): 138 138 """ … … 143 143 mssg += msg 144 144 wx.MessageBox(mssg, 'Error', wx.OK | wx.ICON_ERROR) 145 145 146 146 def _setup_layout(self): 147 147 """ … … 149 149 """ 150 150 note = "Note: This masking applies\n only to %s." % self.data.name 151 note_txt = wx.StaticText(self, -1, note) 151 note_txt = wx.StaticText(self, -1, note) 152 152 note_txt.SetForegroundColour(wx.RED) 153 153 shape = "Select a Shape for Masking:" … … 155 155 sizer = wx.GridBagSizer(10, 10) 156 156 #---------inputs---------------- 157 shape_txt = wx.StaticText(self, -1, shape) 158 sizer.Add(shape_txt, (1, 1), flag=wx.TOP |wx.LEFT|wx.BOTTOM, border=5)157 shape_txt = wx.StaticText(self, -1, shape) 158 sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 159 159 self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 160 160 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask, 161 161 id=self.innersector_rb.GetId()) 162 sizer.Add(self.innersector_rb, (2, 1), 163 flag=wx.RIGHT |wx.BOTTOM, border=5)162 sizer.Add(self.innersector_rb, (2, 1), 163 flag=wx.RIGHT | wx.BOTTOM, border=5) 164 164 self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 165 165 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask, 166 166 id=self.innercircle_rb.GetId()) 167 167 sizer.Add(self.innercircle_rb, (3, 1), 168 flag=wx.RIGHT |wx.BOTTOM, border=5)169 168 flag=wx.RIGHT | wx.BOTTOM, border=5) 169 170 170 self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 171 171 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask, 172 172 id=self.innerbox_rb.GetId()) 173 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)173 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 174 174 175 175 self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 176 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 176 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 177 177 id=self.outersector_rb.GetId()) 178 178 sizer.Add(self.outersector_rb, (5, 1), 179 flag=wx.RIGHT |wx.BOTTOM, border=5)180 181 # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector')179 flag=wx.RIGHT | wx.BOTTOM, border=5) 180 181 # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 182 182 self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 183 183 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask, 184 184 id=self.outercircle_rb.GetId()) 185 sizer.Add(self.outercircle_rb, (6, 1), 186 flag=wx.RIGHT |wx.BOTTOM, border=5)187 # outerbox_txt = wx.StaticText(self, -1, 'Outer Box')185 sizer.Add(self.outercircle_rb, (6, 1), 186 flag=wx.RIGHT | wx.BOTTOM, border=5) 187 # outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 188 188 self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 189 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 189 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 190 190 id=self.outerbox_rb.GetId()) 191 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)192 sizer.Add(note_txt, (8, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)191 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 192 sizer.Add(note_txt, (8, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 193 193 self.innercircle_rb.SetValue(False) 194 self.outercircle_rb.SetValue(False) 194 self.outercircle_rb.SetValue(False) 195 195 self.innerbox_rb.SetValue(False) 196 196 self.outerbox_rb.SetValue(False) 197 197 self.innersector_rb.SetValue(False) 198 198 self.outersector_rb.SetValue(False) 199 sizer.Add(self.plotpanel, (0, 2), (13, 13), 200 wx.EXPAND |wx.LEFT|wx.RIGHT, 15)199 sizer.Add(self.plotpanel, (0, 2), (13, 13), 200 wx.EXPAND | wx.LEFT | wx.RIGHT, 15) 201 201 202 202 #-----Buttons------------1 … … 204 204 button_add = wx.Button(self, id_button, "Add") 205 205 button_add.SetToolTipString("Add the mask drawn.") 206 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 206 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 207 207 sizer.Add(button_add, (13, 7)) 208 208 id_button = wx.NewId() … … 210 210 button_erase.SetToolTipString("Erase the mask drawn.") 211 211 button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, 212 id=button_erase.GetId()) 212 id=button_erase.GetId()) 213 213 sizer.Add(button_erase, (13, 8)) 214 214 id_button = wx.NewId() … … 216 216 button_reset.SetToolTipString("Reset the mask.") 217 217 button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, 218 id=button_reset.GetId()) 219 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT |wx.BOTTOM, border=15)218 id=button_reset.GetId()) 219 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15) 220 220 id_button = wx.NewId() 221 221 button_reset = wx.Button(self, id_button, "Clear") 222 222 button_reset.SetToolTipString("Clear all mask.") 223 223 button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, 224 id=button_reset.GetId()) 225 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT |wx.BOTTOM, border=15)224 id=button_reset.GetId()) 225 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15) 226 226 sizer.AddGrowableCol(3) 227 227 sizer.AddGrowableRow(2) … … 234 234 Call Draw Box Slicer and get mask inside of the box 235 235 """ 236 # get ready for next evt237 event.Skip() 238 # from boxMask import BoxMask236 # get ready for next evt 237 event.Skip() 238 # from boxMask import BoxMask 239 239 if event != None: 240 self.onClearSlicer(event) 240 self.onClearSlicer(event) 241 241 self.slicer_z += 1 242 self.slicer = 242 self.slicer = BoxMask(self, self.subplot, 243 243 zorder=self.slicer_z, side=True) 244 244 self.subplot.set_ylim(self.data.ymin, self.data.ymax) … … 246 246 self.update() 247 247 self.slicer_mask = self.slicer.update() 248 248 249 249 def onOuterBoxMask(self, event=None): 250 250 """ 251 251 Call Draw Box Slicer and get mask outside of the box 252 252 """ 253 event.Skip() 254 # from boxMask import BoxMask253 event.Skip() 254 # from boxMask import BoxMask 255 255 if event != None: 256 self.onClearSlicer(event) 256 self.onClearSlicer(event) 257 257 self.slicer_z += 1 258 self.slicer = 258 self.slicer = BoxMask(self, self.subplot, 259 259 zorder=self.slicer_z, side=False) 260 260 self.subplot.set_ylim(self.data.ymin, self.data.ymax) … … 272 272 self.onClearSlicer(event) 273 273 self.slicer_z += 1 274 self.slicer = 274 self.slicer = SectorMask(self, self.subplot, 275 275 zorder=self.slicer_z, side=True) 276 276 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 277 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 277 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 278 278 self.update() 279 self.slicer_mask = self.slicer.update() 279 self.slicer_mask = self.slicer.update() 280 280 281 281 def onOuterSectorMask(self, event=None): … … 288 288 self.onClearSlicer(event) 289 289 self.slicer_z += 1 290 self.slicer = 290 self.slicer = SectorMask(self, self.subplot, 291 291 zorder=self.slicer_z, side=False) 292 292 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 293 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 294 self.update() 295 self.slicer_mask = self.slicer.update() 293 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 294 self.update() 295 self.slicer_mask = self.slicer.update() 296 296 297 297 def onInnerRingMask(self, event=None): … … 307 307 zorder=self.slicer_z, side=True) 308 308 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 309 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 309 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 310 310 self.update() 311 self.slicer_mask = self.slicer.update() 311 self.slicer_mask = self.slicer.update() 312 312 313 313 def onOuterRingMask(self, event=None): … … 321 321 self.slicer_z += 1 322 322 self.slicer = CircularMask(self, self.subplot, 323 zorder=self.slicer_z, side=False) 323 zorder=self.slicer_z, side=False) 324 324 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 325 325 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 326 326 self.update() 327 self.slicer_mask = self.slicer.update() 328 327 self.slicer_mask = self.slicer.update() 328 329 329 def onAddMask(self, event): 330 330 """ 331 Add new mask to old mask 331 Add new mask to old mask 332 332 """ 333 333 if not self.slicer == None: … … 337 337 data.mask = self.data.mask & self.slicer_mask 338 338 self._check_display_mask(data.mask, event) 339 339 340 340 def _check_display_mask(self, mask, event): 341 341 """ 342 342 check if the mask valid and update the plot 343 343 344 344 :param mask: mask data 345 345 """ 346 # # Redraw the current image346 # # Redraw the current image 347 347 self._update_mask(mask) 348 348 … … 356 356 mask[self.slicer_mask == False] = True 357 357 self._check_display_mask(mask, event) 358 358 359 359 def onResetMask(self, event): 360 360 """ 361 Reset mask to the original mask 362 """ 361 Reset mask to the original mask 362 """ 363 363 self.slicer_z += 1 364 self.slicer = BoxMask(self, self.subplot,364 self.slicer = BoxMask(self, self.subplot, 365 365 zorder=self.slicer_z, side=True) 366 366 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 367 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 367 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 368 368 mask = copy.deepcopy(self.default_mask) 369 369 self.data.mask = mask 370 370 # update mask plot 371 371 self._check_display_mask(mask, event) 372 372 373 373 def onClearMask(self, event): 374 374 """ 375 375 Clear mask 376 """ 376 """ 377 377 self.slicer_z += 1 378 self.slicer = 378 self.slicer = BoxMask(self, self.subplot, 379 379 zorder=self.slicer_z, side=True) 380 380 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 381 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 382 # mask = copy.deepcopy(self.default_mask)381 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 382 # mask = copy.deepcopy(self.default_mask) 383 383 mask = numpy.ones(len(self.data.mask), dtype=bool) 384 384 self.data.mask = mask 385 385 # update mask plot 386 386 self._check_display_mask(mask, event) 387 387 388 388 def onClearSlicer(self, event): 389 389 """ … … 397 397 def update(self, draw=True): 398 398 """ 399 Respond to changes in the model by recalculating the 399 Respond to changes in the model by recalculating the 400 400 profiles and resetting the widgets. 401 401 """ 402 402 self.plotpanel.draw() 403 403 404 404 def _set_mask(self, mask): 405 405 """ … … 407 407 """ 408 408 self.data.mask = mask 409 409 410 410 def set_plot_unfocus(self): 411 411 """ … … 413 413 """ 414 414 pass 415 415 416 416 def _update_mask(self, mask): 417 417 """ 418 418 Respond to changes in masking 419 """ 419 """ 420 420 # the case of liitle numbers of True points 421 421 if (len(mask[mask]) < 10 and self.data != None): … … 430 430 # temp_data default is None 431 431 # This method is to distinguish between masked point and data point = 0. 432 temp_mask = temp_mask /temp_mask432 temp_mask = temp_mask / temp_mask 433 433 temp_mask[mask] = temp_data.data[mask] 434 # set temp_data value for self.mask==True, else still None 435 # temp_mask[mask] = temp_data[mask]436 437 # TODO: refactor this horrible logic434 # set temp_data value for self.mask==True, else still None 435 # temp_mask[mask] = temp_data[mask] 436 437 # TODO: refactor this horrible logic 438 438 temp_data.data[mask == False] = temp_mask[mask == False] 439 439 self.plotpanel.clear() … … 444 444 event = self._getEmptySlicerEvent() 445 445 wx.PostEvent(self, event) 446 447 # #use this method448 # set zmax and zmin to plot: Fix it w/ data.446 447 # #use this method 448 # set zmax and zmin to plot: Fix it w/ data. 449 449 if self.plotpanel.scale == 'log_{10}': 450 zmax = math.log10(max(self.data.data[self.data.data >0]))451 zmin = math.log10(min(self.data.data[self.data.data >0]))450 zmax = math.log10(max(self.data.data[self.data.data > 0])) 451 zmin = math.log10(min(self.data.data[self.data.data > 0])) 452 452 else: 453 zmax = max(self.data.data[self.data.data >0])454 zmin = min(self.data.data[self.data.data >0])455 # plot453 zmax = max(self.data.data[self.data.data > 0]) 454 zmin = min(self.data.data[self.data.data > 0]) 455 # plot 456 456 plot = self.plotpanel.image(data=temp_mask, 457 457 qx_data=self.data.qx_data, … … 470 470 self.plotpanel.render() 471 471 self.plotpanel.subplot.figure.canvas.draw_idle() 472 472 473 473 def _getEmptySlicerEvent(self): 474 474 """ 475 create an empty slicervent 475 create an empty slicervent 476 476 """ 477 477 self.innerbox_rb.SetValue(False) … … 483 483 return SlicerEvent(type=None, 484 484 params=None, 485 obj_class=None) 486 485 obj_class=None) 486 487 487 def _draw_model(self, event): 488 488 """ … … 490 490 """ 491 491 pass 492 492 493 493 def freeze_axes(self): 494 494 """ … … 496 496 """ 497 497 self.plotpanel.axes_frozen = True 498 498 499 499 def thaw_axes(self): 500 500 """ 501 501 thaw axes 502 502 """ 503 self.plotpanel.axes_frozen = False 504 503 self.plotpanel.axes_frozen = False 504 505 505 def onMouseMotion(self, event): 506 506 """ … … 508 508 """ 509 509 pass 510 510 511 511 def onWheel(self, event): 512 512 """ 513 513 on wheel event 514 514 """ 515 pass 516 515 pass 516 517 517 def OnClose(self, event): 518 518 """ … … 524 524 # when called by data panel 525 525 event.Skip() 526 pass 526 pass 527 527 528 528 class FloatPanel(wx.Dialog): … … 530 530 Provides the Mask Editor GUI. 531 531 """ 532 # # Internal nickname for the window, used by the AUI manager532 # # Internal nickname for the window, used by the AUI manager 533 533 window_name = "Plot" 534 # # Name to appear on the window title bar534 # # Name to appear on the window title bar 535 535 window_caption = "Plot" 536 # # Flag to tell the AUI manager to put this panel in the center pane536 # # Flag to tell the AUI manager to put this panel in the center pane 537 537 CENTER_PANE = False 538 538 ID = wx.NewId() 539 def __init__(self, parent=None, base=None, 539 def __init__(self, parent=None, base=None, 540 540 data=None, dimension=1, id=ID, *args, **kwds): 541 541 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 542 kwds["size"] = wx.Size(PANEL_SIZE *1.5, PANEL_SIZE*1.5)543 wx.Dialog.__init__(self, parent, id=id, 544 542 kwds["size"] = wx.Size(PANEL_SIZE * 1.5, PANEL_SIZE * 1.5) 543 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 544 545 545 if data != None: 546 # Font size546 # Font size 547 547 kwds = [] 548 548 self.SetWindowVariant(variant=FONT_VARIANT) … … 551 551 self.data = data 552 552 self.str = self.data.__str__() 553 # # when 2 data have the same id override the 1 st plotted553 # # when 2 data have the same id override the 1 st plotted 554 554 self.name = self.data.name 555 555 self.dimension = dimension … … 560 560 self.plotpanel.prevXtrans = "x" 561 561 self.plotpanel.prevYtrans = "y" 562 562 563 563 self.cmap = DEFAULT_CMAP 564 # # Create Artist and bind it564 # # Create Artist and bind it 565 565 self.subplot = self.plotpanel.subplot 566 566 self._setup_layout() 567 567 if self.dimension == 1: 568 self.newplot = Data1D(x=data.x, y=data.y, 568 self.newplot = Data1D(x=data.x, y=data.y, 569 569 dx=data.dx, dy=data.dy) 570 570 self.newplot.name = data.name 571 else: 571 else: 572 572 self.newplot = Data2D(image=self.data.data) 573 573 self.newplot.setValues(self.data) 574 574 # Compute and get the image plot 575 575 self.get_plot() 576 # self.plotpanel.add_image(self.newplot)576 # self.plotpanel.add_image(self.newplot) 577 577 self.Centre() 578 578 self.Layout() 579 579 580 580 def get_plot(self): 581 581 """ 582 582 Get Plot panel 583 583 """ 584 cal_plot = CalcPlot(panel=self.plotpanel, 585 image=self.newplot, 584 cal_plot = CalcPlot(panel=self.plotpanel, 585 image=self.newplot, 586 586 completefn=self.complete) 587 587 cal_plot.queue() 588 588 589 589 def complete(self, panel, image, elapsed=None): 590 590 """ 591 591 Plot image 592 592 593 593 :param image: newplot [plotpanel] 594 594 """ 595 wx.CallAfter(panel.add_image, image) 596 595 wx.CallAfter(panel.add_image, image) 596 597 597 def _setup_layout(self): 598 598 """ … … 605 605 if len(self.data.data) > 3600: 606 606 note += "Rotation disabled for pixels > 60x60." 607 note_txt = wx.StaticText(self, -1, note) 607 note_txt = wx.StaticText(self, -1, note) 608 608 note_txt.SetForegroundColour(wx.RED) 609 sizer.Add(note_txt, (0, 2), flag=wx.RIGHT |wx.TOP, border=5)610 611 sizer.Add(self.plotpanel, (1, 0), (9, 9), 612 wx.EXPAND |wx.ALL, 15)609 sizer.Add(note_txt, (0, 2), flag=wx.RIGHT | wx.TOP, border=5) 610 611 sizer.Add(self.plotpanel, (1, 0), (9, 9), 612 wx.EXPAND | wx.ALL, 15) 613 613 614 614 sizer.AddGrowableCol(3) 615 615 sizer.AddGrowableRow(2) 616 616 617 617 self.SetSizerAndFit(sizer) 618 618 self.Centre() 619 619 self.Show(True) 620 620 621 621 def set_plot_unfocus(self): 622 622 """ … … 624 624 """ 625 625 pass 626 626 627 627 628 628 def _draw_model(self, event): … … 631 631 """ 632 632 pass 633 633 634 634 def freeze_axes(self): 635 635 """ … … 637 637 """ 638 638 self.plotpanel.axes_frozen = True 639 639 640 640 def thaw_axes(self): 641 641 """ 642 642 thaw axes 643 643 """ 644 self.plotpanel.axes_frozen = False 645 644 self.plotpanel.axes_frozen = False 645 646 646 def OnClose(self, event): 647 647 """ … … 655 655 pass 656 656 657 657 658 658 class Maskplotpanel(PlotPanel): 659 659 """ 660 660 PlotPanel for Quick plot and masking plot 661 661 """ 662 def __init__(self, parent, id=-1, dimension=2, color=None, 662 def __init__(self, parent, id=-1, dimension=2, color=None, 663 663 dpi=None, **kwargs): 664 664 """ 665 665 """ 666 666 PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs) 667 667 668 668 # Keep track of the parent Frame 669 669 self.parent = parent 670 # Internal list of plottable names (because graph 670 # Internal list of plottable names (because graph 671 671 # doesn't have a dictionary of handles for the plottables) 672 672 self.dimension = dimension 673 673 self.plots = {} 674 674 self.graph = Graph() 675 # add axis labels675 # add axis labels 676 676 self.graph.xaxis('\\rm{x} ', '') 677 677 self.graph.yaxis('\\rm{y} ', '') 678 678 679 679 def add_toolbar(self): 680 """ 680 """ 681 681 Add toolbar 682 682 """ 683 683 # Not implemented 684 684 pass 685 685 686 686 def on_set_focus(self, event): 687 687 """ … … 691 691 pass 692 692 else: 693 self.draw() 694 693 self.draw() 694 695 695 def add_image(self, plot): 696 696 """ … … 698 698 """ 699 699 self.plots[plot.name] = plot 700 # init graph700 # init graph 701 701 self.graph = Graph() 702 # add plot702 # add plot 703 703 self.graph.add(plot) 704 # add axes704 # add axes 705 705 if self.dimension == 1: 706 706 self.xaxis_label = '\\rm{x} ' … … 708 708 self.yaxis_label = '\\rm{y} ' 709 709 self.yaxis_unit = '' 710 # draw710 # draw 711 711 # message 712 status_type = 'progress' 712 status_type = 'progress' 713 713 msg = 'Plotting...' 714 714 self._status_info(msg, status_type) 715 status_type = 'stop' 715 status_type = 'stop' 716 716 self.graph.render(self) 717 717 self.subplot.figure.canvas.resizing = False … … 723 723 msg = 'Plotting Completed.' 724 724 self._status_info(msg, status_type) 725 725 726 726 def onMouseMotion(self, event): 727 727 """ … … 729 729 """ 730 730 pass 731 731 732 732 def onWheel(self, event): 733 733 """ 734 734 """ 735 pass 736 735 pass 736 737 737 def onLeftDown(self, event): 738 738 """ … … 740 740 """ 741 741 pass 742 742 743 743 def onPick(self, event): 744 744 """ … … 746 746 """ 747 747 pass 748 748 749 749 def draw(self): 750 750 """ … … 752 752 """ 753 753 # message 754 status_type = 'progress' 754 status_type = 'progress' 755 755 msg = 'Plotting...' 756 756 self._status_info(msg, status_type) 757 status_type = 'stop' 758 757 status_type = 'stop' 758 759 759 if self.dimension == 3: 760 760 pass 761 761 else: 762 self.subplot.figure.canvas.draw_idle() 763 762 self.subplot.figure.canvas.draw_idle() 763 764 764 msg = 'Plotting Completed.' 765 765 self._status_info(msg, status_type) 766 766 767 767 def onContextMenu(self, event): 768 768 """ … … 771 771 # Selective Slicer plot popup menu 772 772 slicerpop = wx.Menu() 773 773 774 774 id = wx.NewId() 775 775 slicerpop.Append(id, '&Print Image', 'Print image') … … 779 779 slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') 780 780 wx.EVT_MENU(self, id, self.OnCopyFigureMenu) 781 781 782 782 if self.dimension == 1: 783 783 id = wx.NewId() … … 789 789 slicerpop.Append(id_cm, '&Toggle Linear/Log scale') 790 790 wx.EVT_MENU(self, id_cm, self._onToggleScale) 791 791 792 792 pos = event.GetPosition() 793 793 pos = self.ScreenToClient(pos) 794 794 self.PopupMenu(slicerpop, pos) 795 796 def _status_info(self, msg = '', type ="update"):795 796 def _status_info(self, msg='', type="update"): 797 797 """ 798 798 Status msg … … 801 801 label = "Plotting..." 802 802 able = True 803 else: 803 else: 804 804 label = "Wait..." 805 805 able = False 806 806 if self.parent.parent.parent != None: 807 wx.PostEvent(self.parent.parent.parent, 808 StatusEvent(status = msg, type = type))807 wx.PostEvent(self.parent.parent.parent, 808 StatusEvent(status=msg, type=type)) 809 809 810 810 class ViewerFrame(wx.Frame): … … 825 825 class ViewApp(wx.App): 826 826 def OnInit(self): 827 frame = ViewerFrame(None, -1, 'testView') 827 frame = ViewerFrame(None, -1, 'testView') 828 828 frame.Show(True) 829 # self.SetTopWindow(frame)830 829 # self.SetTopWindow(frame) 830 831 831 return True 832 833 if __name__ == "__main__": 832 833 if __name__ == "__main__": 834 834 app = ViewApp(0) 835 app.MainLoop() 835 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.