Changeset c039589 in sasview
- Timestamp:
- Mar 5, 2015 4:37:00 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:
- b40ad40
- Parents:
- 090e07e
- Location:
- src/sas/guiframe/local_perspectives/plotting
- Files:
-
- 4 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/Plotter2D.py
r79492222 rc039589 3 3 #This software was developed by the University of Tennessee as part of the 4 4 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 5 #project funded by the US National Science Foundation. 5 #project funded by the US National Science Foundation. 6 6 # 7 7 #See the license text in license.txt … … 15 15 import math 16 16 import numpy 17 import logging 17 18 from sas.plottools.PlotPanel import PlotPanel 18 19 from sas.plottools.plottables import Graph 19 20 from sas.plottools.TextDialog import TextDialog 20 from sas.guiframe.events import StatusEvent 21 from sas.guiframe.events import StatusEvent 21 22 from sas.guiframe.events import NewPlotEvent 22 23 from sas.guiframe.events import PanelOnFocusEvent … … 25 26 from sas.guiframe.local_perspectives.plotting.binder import BindArtist 26 27 from Plotter1D import ModelPanel1D 27 from sas.plottools.toolbar import NavigationToolBar 28 from sas.plottools.toolbar import NavigationToolBar 28 29 from matplotlib.font_manager import FontProperties 29 30 from graphAppearance import graphAppearance … … 46 47 def __init__(self, canvas, parent=None): 47 48 NavigationToolBar.__init__(self, canvas=canvas, parent=parent) 48 49 49 50 def delete_option(self): 50 51 """ … … 52 53 """ 53 54 #delete reset button 54 self.DeleteToolByPos(0) 55 self.DeleteToolByPos(0) 55 56 #delete dragging 56 self.DeleteToolByPos(2) 57 self.DeleteToolByPos(2) 57 58 #delete unwanted button that configures subplot parameters 58 59 self.DeleteToolByPos(4) 59 60 60 61 def add_option(self): 61 62 """ … … 65 66 id_context = wx.NewId() 66 67 context_tip = 'Graph Menu' 67 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 68 self.InsertSimpleTool(0, id_context, context, 69 context_tip, context_tip) 70 wx.EVT_TOOL(self, id_context, self.parent.onToolContextMenu) 68 context = wx.ArtProvider.GetBitmap(wx.ART_LIST_VIEW, wx.ART_TOOLBAR) 69 self.InsertSimpleTool(0, id_context, context, context_tip, context_tip) 70 wx.EVT_TOOL(self, id_context, self.parent.onToolContextMenu) 71 71 self.InsertSeparator(1) 72 72 #add print button 73 73 id_print = wx.NewId() 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 75 self.AddSimpleTool(id_print, print_bmp, 76 'Print', 'Activate printing') 74 print_bmp = wx.ArtProvider.GetBitmap(wx.ART_PRINT, wx.ART_TOOLBAR) 75 self.AddSimpleTool(id_print, print_bmp, 'Print', 'Activate printing') 77 76 wx.EVT_TOOL(self, id_print, self.on_print) 78 79 77 78 80 79 class ModelPanel2D(ModelPanel1D): 81 80 """ 82 81 Plot panel for use with the GUI manager 83 82 """ 84 83 85 84 ## Internal name for the AUI manager 86 85 window_name = "plotpanel" … … 92 91 ## Group ID 93 92 group_id = None 94 95 96 def __init__(self, parent, id=-1, data2d=None, color =None,93 94 95 def __init__(self, parent, id=-1, data2d=None, color=None, 97 96 dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 98 97 """ … … 106 105 ## Dictionary containing Plottables 107 106 self.plots = {} 108 ## Save reference of the current plotted 107 ## Save reference of the current plotted 109 108 self.data2D = data2d 110 109 ## Unique ID (from gui_manager) … … 120 119 ## Reference to the current slicer 121 120 self.slicer = None 122 ## event to send slicer info 121 ## event to send slicer info 123 122 self.Bind(EVT_INTERNAL, self._onEVT_INTERNAL) 124 123 125 124 self.axes_frozen = False 126 125 ## panel that contains result from slicer motion (ex: Boxsum info) … … 129 128 self.title_font = None 130 129 self.title_color = 'black' 131 ## Graph 130 ## Graph 132 131 self.graph = Graph() 133 132 self.graph.xaxis("\\rm{Q}", 'A^{-1}') 134 133 self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") 135 134 self.graph.render(self) 136 ## store default value of zmin and zmax 135 ## store default value of zmin and zmax 137 136 self.default_zmin_ctl = self.zmin_2D 138 137 self.default_zmax_ctl = self.zmax_2D … … 145 144 if event == None: 146 145 return 147 event.Skip() 148 149 def onLeftDown(self, event): 146 event.Skip() 147 148 def onLeftDown(self, event): 150 149 """ 151 150 left button down and ready to drag 152 151 153 152 """ 154 153 # Check that the LEFT button was pressed 155 PlotPanel.onLeftDown(self, event) 154 PlotPanel.onLeftDown(self, event) 156 155 ax = event.inaxes 157 156 if ax != None: 158 157 # data coordinate position 159 pos_x = "%8.3g" % event.xdata160 pos_y = "%8.3g" % event.ydata158 pos_x = "%8.3g" % event.xdata 159 pos_y = "%8.3g" % event.ydata 161 160 position = "x: %s y: %s" % (pos_x, pos_y) 162 161 wx.PostEvent(self.parent, StatusEvent(status=position)) … … 164 163 self._manager.set_panel_on_focus(self) 165 164 wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) 166 165 167 166 def add_toolbar(self): 168 167 """ … … 174 173 # On Windows platform, default window size is incorrect, so set 175 174 # toolbar width to figure width. 176 tw, th = self.toolbar.GetSizeTuple()177 fw, fh= self.canvas.GetSizeTuple()175 _, th = self.toolbar.GetSizeTuple() 176 fw, _ = self.canvas.GetSizeTuple() 178 177 self.toolbar.SetSize(wx.Size(fw, th)) 179 self.sizer.Add(self.toolbar, 0, wx.LEFT |wx.EXPAND)178 self.sizer.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND) 180 179 # update the axes menu on the toolbar 181 180 self.toolbar.update() 182 181 183 182 def plot_data(self, data): 184 183 """ 185 184 Data is ready to be displayed 186 185 187 186 :TODO: this name should be changed to something more appropriate 188 187 Don't forget that changing this name will mean changing code 189 188 in plotting.py 190 189 191 190 :param event: data event 192 191 """ 193 192 xlo = None 194 193 xhi = None 195 ylo = None 194 ylo = None 196 195 yhi = None 197 196 if data.__class__.__name__ == 'Data1D': … … 207 206 else: 208 207 self.plots[data.id] = data 209 self.graph.add(self.plots[data.id]) 208 self.graph.add(self.plots[data.id]) 210 209 # update qmax with the new xmax of data plotted 211 self.qmax = data.xmax 210 self.qmax = data.xmax 212 211 self.slicer = None 213 212 # Check axis labels 214 213 #TODO: Should re-factor this 215 ## render the graph with its new content 214 ## render the graph with its new content 216 215 #data2D: put 'Pixel (Number)' for axis title and unit in case of having no detector info and none in _units 217 if len(data.detector) < 1: 216 if len(data.detector) < 1: 218 217 if len(data._xunit) < 1 and len(data._yunit) < 1: 219 218 data._xaxis = '\\rm{x}' … … 224 223 self.graph.xaxis(data._xaxis, data._xunit) 225 224 self.graph.yaxis(data._yaxis, data._yunit) 226 if self._is_changed_legend_label: 227 225 if self._is_changed_legend_label: 226 data.label = self.title_label 228 227 if data.label == None: 229 data.label = data.name 228 data.label = data.name 230 229 if not self.title_font: 231 230 self.graph.title(data.label) … … 240 239 fontproperties=self.title_font, 241 240 color=self.title_color) 242 self.subplot.figure.canvas.draw_idle() 243 ## store default value of zmin and zmax 241 self.subplot.figure.canvas.draw_idle() 242 ## store default value of zmin and zmax 244 243 self.default_zmin_ctl = self.zmin_2D 245 244 self.default_zmax_ctl = self.zmax_2D … … 247 246 return 248 247 # Recover the x,y limits 249 if (xlo and xhi and ylo and yhi) != None:250 if (xlo > data.xmin and xhi < data.xmax and\251 ylo > data.ymin and yhi < data.ymax ):252 self.subplot.set_xlim((xlo, xhi)) 253 self.subplot.set_ylim((ylo, yhi)) 254 else: 248 if xlo and xhi and ylo and yhi: 249 if xlo > data.xmin and xhi < data.xmax and \ 250 ylo > data.ymin and yhi < data.ymax: 251 self.subplot.set_xlim((xlo, xhi)) 252 self.subplot.set_ylim((ylo, yhi)) 253 else: 255 254 self.toolbar.update() 256 255 self.is_zoomed = False … … 276 275 self.xaxis_label = xname 277 276 self.xaxis_unit = xunits 278 self.xaxis(xname, xunits, self.xaxis_font, 277 self.xaxis(xname, xunits, self.xaxis_font, 279 278 self.xaxis_color, self.xaxis_tick) 280 self.yaxis(yname, yunits, self.yaxis_font, 279 self.yaxis(yname, yunits, self.yaxis_font, 281 280 self.yaxis_color, self.yaxis_tick) 282 281 283 282 def onContextMenu(self, event): 284 283 """ 285 284 2D plot context menu 286 285 287 286 :param event: wx context event 288 287 289 288 """ 290 289 slicerpop = PanelMenu() 291 290 slicerpop.set_plots(self.plots) 292 291 slicerpop.set_graph(self.graph) 293 294 id = wx.NewId()295 slicerpop.Append( id, '&Save Image')296 wx.EVT_MENU(self, id, self.onSaveImage)297 298 id = wx.NewId()299 slicerpop.Append( id,'&Print Image', 'Print image')300 wx.EVT_MENU(self, id, self.onPrint)301 302 id = wx.NewId()303 slicerpop.Append( id,'&Print Preview', 'Print preview')304 wx.EVT_MENU(self, id, self.onPrinterPreview)305 306 id = wx.NewId()307 slicerpop.Append( id, '&Copy to Clipboard', 'Copy to the clipboard')308 wx.EVT_MENU(self, id, self.OnCopyFigureMenu)292 293 wx_id = wx.NewId() 294 slicerpop.Append(wx_id, '&Save Image') 295 wx.EVT_MENU(self, wx_id, self.onSaveImage) 296 297 wx_id = wx.NewId() 298 slicerpop.Append(wx_id, '&Print Image', 'Print image') 299 wx.EVT_MENU(self, wx_id, self.onPrint) 300 301 wx_id = wx.NewId() 302 slicerpop.Append(wx_id, '&Print Preview', 'Print preview') 303 wx.EVT_MENU(self, wx_id, self.onPrinterPreview) 304 305 wx_id = wx.NewId() 306 slicerpop.Append(wx_id, '&Copy to Clipboard', 'Copy to the clipboard') 307 wx.EVT_MENU(self, wx_id, self.OnCopyFigureMenu) 309 308 slicerpop.AppendSeparator() 310 309 # saving data 311 310 plot = self.data2D 312 id = wx.NewId() 313 name = plot.name 314 slicerpop.Append(id, "&Data Info" ) 315 wx.EVT_MENU(self, id, self._onDataShow) 316 317 id = wx.NewId() 318 name = plot.name 319 slicerpop.Append(id, "&Save as a File (DAT)" ) 320 self.action_ids[str(id)] = plot 321 wx.EVT_MENU(self, id, self._onSave) 311 wx_id = wx.NewId() 312 slicerpop.Append(wx_id, "&Data Info") 313 wx.EVT_MENU(self, wx_id, self._onDataShow) 314 315 wx_id = wx.NewId() 316 slicerpop.Append(wx_id, "&Save as a File (DAT)") 317 self.action_ids[str(wx_id)] = plot 318 wx.EVT_MENU(self, wx_id, self._onSave) 322 319 323 320 slicerpop.AppendSeparator() 324 if len(self.data2D.detector) == 1: 325 321 if len(self.data2D.detector) == 1: 326 322 item_list = self.parent.get_current_context_menu(self) 327 323 if (not item_list == None) and (not len(item_list) == 0) and\ 328 self.data2D.name.split(" ")[0] != 'Residuals': 324 self.data2D.name.split(" ")[0] != 'Residuals': 329 325 # The line above; Not for trunk 330 326 for item in item_list: 331 327 try: 332 id = wx.NewId()333 slicerpop.Append( id, item[0], item[1])334 wx.EVT_MENU(self, id, item[2])328 wx_id = wx.NewId() 329 slicerpop.Append(wx_id, item[0], item[1]) 330 wx.EVT_MENU(self, wx_id, item[2]) 335 331 except: 336 332 msg = "ModelPanel1D.onContextMenu: " 337 msg += "bad menu item %s" %sys.exc_value333 msg += "bad menu item %s" % sys.exc_value 338 334 wx.PostEvent(self.parent, StatusEvent(status=msg)) 339 pass340 335 slicerpop.AppendSeparator() 341 342 id = wx.NewId()343 slicerpop.Append( id, '&Perform Circular Average')344 wx.EVT_MENU(self, id, self.onCircular) \336 337 wx_id = wx.NewId() 338 slicerpop.Append(wx_id, '&Perform Circular Average') 339 wx.EVT_MENU(self, wx_id, self.onCircular) \ 345 340 # For Masked Data 346 341 if not plot.mask.all(): 347 id = wx.NewId()348 slicerpop.Append( id, '&Masked Circular Average')349 wx.EVT_MENU(self, id, self.onMaskedCircular)350 id = wx.NewId()351 slicerpop.Append( id, '&Sector [Q View]')352 wx.EVT_MENU(self, id, self.onSectorQ)353 id = wx.NewId()354 slicerpop.Append( id, '&Annulus [Phi View ]')355 wx.EVT_MENU(self, id, self.onSectorPhi)356 id = wx.NewId()357 slicerpop.Append( id, '&Box Sum')358 wx.EVT_MENU(self, id, self.onBoxSum)359 id = wx.NewId()360 slicerpop.Append( id, '&Box Averaging in Qx')361 wx.EVT_MENU(self, id, self.onBoxavgX)362 id = wx.NewId()363 slicerpop.Append( id, '&Box Averaging in Qy')364 wx.EVT_MENU(self, id, self.onBoxavgY)342 wx_id = wx.NewId() 343 slicerpop.Append(wx_id, '&Masked Circular Average') 344 wx.EVT_MENU(self, wx_id, self.onMaskedCircular) 345 wx_id = wx.NewId() 346 slicerpop.Append(wx_id, '&Sector [Q View]') 347 wx.EVT_MENU(self, wx_id, self.onSectorQ) 348 wx_id = wx.NewId() 349 slicerpop.Append(wx_id, '&Annulus [Phi View ]') 350 wx.EVT_MENU(self, wx_id, self.onSectorPhi) 351 wx_id = wx.NewId() 352 slicerpop.Append(wx_id, '&Box Sum') 353 wx.EVT_MENU(self, wx_id, self.onBoxSum) 354 wx_id = wx.NewId() 355 slicerpop.Append(wx_id, '&Box Averaging in Qx') 356 wx.EVT_MENU(self, wx_id, self.onBoxavgX) 357 wx_id = wx.NewId() 358 slicerpop.Append(wx_id, '&Box Averaging in Qy') 359 wx.EVT_MENU(self, wx_id, self.onBoxavgY) 365 360 if self.slicer != None: 366 id = wx.NewId()367 slicerpop.Append( id, '&Clear Slicer')368 wx.EVT_MENU(self, id, self.onClearSlicer)369 if self.slicer.__class__.__name__ 370 id = wx.NewId()371 slicerpop.Append( id, '&Edit Slicer Parameters')372 wx.EVT_MENU(self, id, self._onEditSlicer)373 slicerpop.AppendSeparator() 374 375 id = wx.NewId()376 slicerpop.Append( id, '&Edit Graph Label', 'Edit Graph Label')377 wx.EVT_MENU(self, id, self.onEditLabels)361 wx_id = wx.NewId() 362 slicerpop.Append(wx_id, '&Clear Slicer') 363 wx.EVT_MENU(self, wx_id, self.onClearSlicer) 364 if self.slicer.__class__.__name__ != "BoxSum": 365 wx_id = wx.NewId() 366 slicerpop.Append(wx_id, '&Edit Slicer Parameters') 367 wx.EVT_MENU(self, wx_id, self._onEditSlicer) 368 slicerpop.AppendSeparator() 369 370 wx_id = wx.NewId() 371 slicerpop.Append(wx_id, '&Edit Graph Label', 'Edit Graph Label') 372 wx.EVT_MENU(self, wx_id, self.onEditLabels) 378 373 slicerpop.AppendSeparator() 379 374 380 375 # ILL mod here 381 376 382 id = wx.NewId()383 slicerpop.Append( id, '&Modify graph appearance','Modify graph appearance')384 wx.EVT_MENU(self, id, self.modifyGraphAppearance)377 wx_id = wx.NewId() 378 slicerpop.Append(wx_id, '&Modify graph appearance', 'Modify graph appearance') 379 wx.EVT_MENU(self, wx_id, self.modifyGraphAppearance) 385 380 slicerpop.AppendSeparator() 386 381 387 388 389 id = wx.NewId() 390 slicerpop.Append(id, '&2D Color Map') 391 wx.EVT_MENU(self, id, self._onEditDetector) 382 wx_id = wx.NewId() 383 slicerpop.Append(wx_id, '&2D Color Map') 384 wx.EVT_MENU(self, wx_id, self._onEditDetector) 392 385 slicerpop.AppendSeparator() 393 394 id = wx.NewId() 395 slicerpop.Append(id, '&Toggle Linear/Log Scale') 396 wx.EVT_MENU(self, id, self._onToggleScale) 397 398 386 387 wx_id = wx.NewId() 388 slicerpop.Append(wx_id, '&Toggle Linear/Log Scale') 389 wx.EVT_MENU(self, wx_id, self._onToggleScale) 390 399 391 slicerpop.AppendSeparator() 400 id = wx.NewId()401 slicerpop.Append( id, '&Window Title')402 wx.EVT_MENU(self, id, self.onChangeCaption)403 392 wx_id = wx.NewId() 393 slicerpop.Append(wx_id, '&Window Title') 394 wx.EVT_MENU(self, wx_id, self.onChangeCaption) 395 404 396 try: 405 397 pos_evt = event.GetPosition() … … 409 401 pos = (pos_x, pos_y + 5) 410 402 self.PopupMenu(slicerpop, pos) 411 412 403 413 404 def onEditLabels(self, event): 414 405 """ … … 443 434 color=self.title_color) 444 435 self._is_changed_legend_label = True 445 self.subplot.figure.canvas.draw_idle() 436 self.subplot.figure.canvas.draw_idle() 446 437 except: 438 msg = "Add Text: Error. Check your property values..." 439 logging.error(msg) 447 440 if self.parent != None: 448 from sas.guiframe.events import StatusEvent 449 msg= "Add Text: Error. Check your property values..." 450 wx.PostEvent(self.parent, StatusEvent(status = msg )) 451 else: 452 raise 441 wx.PostEvent(self.parent, StatusEvent(status=msg)) 453 442 dial.Destroy() 454 443 455 444 def _onEditDetector(self, event): 456 445 """ 457 446 Allow to view and edits detector parameters 458 447 459 448 :param event: wx.menu event 460 449 461 450 """ 462 451 import detector_dialog 463 dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent,464 reset_zmin_ctl=self.default_zmin_ctl,465 reset_zmax_ctl = self.default_zmax_ctl,cmap=self.cmap)452 dialog = detector_dialog.DetectorDialog(self, -1, base=self.parent, 453 reset_zmin_ctl=self.default_zmin_ctl, 454 reset_zmax_ctl=self.default_zmax_ctl, cmap=self.cmap) 466 455 ## info of current detector and data2D 467 456 xnpts = len(self.data2D.x_bins) … … 470 459 ymax = max(self.data2D.ymin, self.data2D.ymax) 471 460 qmax = math.sqrt(math.pow(xmax, 2) + math.pow(ymax, 2)) 472 beam = self.data2D.xmin473 461 ## set dialog window content 474 dialog.setContent(xnpts=xnpts, ynpts=ynpts,qmax=qmax,475 476 zmin =self.zmin_2D,477 zmax =self.zmax_2D)462 dialog.setContent(xnpts=xnpts, ynpts=ynpts, qmax=qmax, 463 beam=self.data2D.xmin, 464 zmin=self.zmin_2D, 465 zmax=self.zmax_2D) 478 466 if dialog.ShowModal() == wx.ID_OK: 479 467 evt = dialog.getContent() … … 486 474 qx_data=self.data2D.qx_data, 487 475 qy_data=self.data2D.qy_data, 488 xmin= 489 xmax= 490 ymin= 491 ymax= 492 zmin= 493 zmax= 494 cmap= 476 xmin=self.data2D.xmin, 477 xmax=self.data2D.xmax, 478 ymin=self.data2D.ymin, 479 ymax=self.data2D.ymax, 480 zmin=self.zmin_2D, 481 zmax=self.zmax_2D, 482 cmap=self.cmap, 495 483 color=0, symbol=0, label=self.data2D.name) 496 484 self.subplot.figure.canvas.draw_idle() 497 485 498 486 def freeze_axes(self): 499 487 """ 500 488 """ 501 489 self.axes_frozen = True 502 490 503 491 def thaw_axes(self): 504 492 """ 505 493 """ 506 494 self.axes_frozen = False 507 508 def onMouseMotion(self, event):495 496 def onMouseMotion(self, event): 509 497 """ 510 498 """ 511 499 pass 512 500 513 501 def onWheel(self, event): 514 502 """ 515 503 """ 516 pass 517 504 pass 505 518 506 def update(self, draw=True): 519 507 """ 520 Respond to changes in the model by recalculating the 508 Respond to changes in the model by recalculating the 521 509 profiles and resetting the widgets. 522 510 """ 523 511 self.draw_plot() 524 512 525 513 def _getEmptySlicerEvent(self): 526 514 """ 527 create an empty slicervent 515 create an empty slicervent 528 516 """ 529 517 return SlicerEvent(type=None, params=None, obj_class=None) 530 518 531 519 def _onEVT_INTERNAL(self, event): 532 520 """ 533 521 Draw the slicer 534 522 535 523 :param event: wx.lib.newevent (SlicerEvent) containing slicer 536 524 parameter 537 525 538 526 """ 539 527 self._setSlicer(event.slicer) 540 528 541 529 def _setSlicer(self, slicer): 542 530 """ 543 531 Clear the previous slicer and create a new one.Post an internal 544 532 event. 545 533 546 534 :param slicer: slicer class to create 547 535 548 536 """ 549 537 ## Clear current slicer 550 if not self.slicer == None: 551 self.slicer.clear() 552 ## Create a new slicer 538 if not self.slicer == None: 539 self.slicer.clear() 540 ## Create a new slicer 553 541 self.slicer_z += 1 554 542 self.slicer = slicer(self, self.subplot, zorder=self.slicer_z) … … 558 546 self.update() 559 547 self.slicer.update() 560 msg = "Plotter2D._setSlicer %s" %self.slicer.__class__.__name__548 msg = "Plotter2D._setSlicer %s" % self.slicer.__class__.__name__ 561 549 wx.PostEvent(self.parent, StatusEvent(status=msg)) 562 550 # Post slicer event … … 566 554 event.params = self.slicer.get_params() 567 555 wx.PostEvent(self, event) 568 556 569 557 def onMaskedCircular(self, event): 570 558 """ 571 559 perform circular averaging on Data2D with mask if it exists 572 560 573 561 :param event: wx.menu event 574 562 575 563 """ 576 564 self.onCircular(event, True) 577 565 578 566 def onCircular(self, event, ismask=False): 579 567 """ 580 568 perform circular averaging on Data2D 581 569 582 570 :param event: wx.menu event 583 571 584 572 """ 585 573 # Find the best number of bins … … 588 576 from sas.dataloader.manipulations import CircularAverage 589 577 ## compute the maximum radius of data2D 590 self.qmax = max(math.fabs(self.data2D.xmax), 578 self.qmax = max(math.fabs(self.data2D.xmax), 591 579 math.fabs(self.data2D.xmin)) 592 580 self.ymax = max(math.fabs(self.data2D.ymax), 593 581 math.fabs(self.data2D.ymin)) 594 self.radius = math.sqrt(math.pow(self.qmax, 2) + math.pow(self.ymax, 2))582 self.radius = math.sqrt(math.pow(self.qmax, 2) + math.pow(self.ymax, 2)) 595 583 ##Compute beam width 596 bin_width = (self.qmax + self.qmax) /npt584 bin_width = (self.qmax + self.qmax) / npt 597 585 ## Create data1D circular average of data2D 598 Circle = CircularAverage(r_min=0, r_max=self.radius, 586 Circle = CircularAverage(r_min=0, r_max=self.radius, 599 587 bin_width=bin_width) 600 588 circ = Circle(self.data2D, ismask=ismask) … … 617 605 new_plot.interactive = True 618 606 new_plot.detector = self.data2D.detector 619 607 620 608 ## If the data file does not tell us what the axes are, just assume... 621 609 new_plot.xaxis("\\rm{Q}", "A^{-1}") … … 627 615 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 628 616 629 new_plot.group_id = "2daverage" 617 new_plot.group_id = "2daverage" + self.data2D.name 630 618 new_plot.id = "Circ avg " + self.data2D.name 631 619 new_plot.is_data = True 632 620 self.parent.update_theory(data_id=self.data2D.id, \ 633 621 theory=new_plot) 634 wx.PostEvent(self.parent, 622 wx.PostEvent(self.parent, 635 623 NewPlotEvent(plot=new_plot, title=new_plot.name)) 636 624 637 625 def _onEditSlicer(self, event): 638 626 """ 639 Is available only when a slicer is drawn.Create a dialog 627 Is available only when a slicer is drawn.Create a dialog 640 628 window where the user can enter value to reset slicer 641 629 parameters. 642 630 643 631 :param event: wx.menu event 644 632 645 633 """ 646 634 if self.slicer != None: … … 648 636 dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") 649 637 dialog.set_slicer(self.slicer.__class__.__name__, 650 self.slicer.get_params())638 self.slicer.get_params()) 651 639 if dialog.ShowModal() == wx.ID_OK: 652 dialog.Destroy() 653 640 dialog.Destroy() 641 654 642 def onSectorQ(self, event): 655 643 """ … … 659 647 self.onClearSlicer(event) 660 648 wx.PostEvent(self, InternalEvent(slicer=SectorInteractor)) 661 649 662 650 def onSectorPhi(self, event): 663 651 """ … … 667 655 self.onClearSlicer(event) 668 656 wx.PostEvent(self, InternalEvent(slicer=AnnulusInteractor)) 669 657 670 658 def onBoxSum(self, event): 671 659 """ … … 675 663 self.onClearSlicer(event) 676 664 self.slicer_z += 1 677 self.slicer = 665 self.slicer = BoxSum(self, self.subplot, zorder=self.slicer_z) 678 666 self.subplot.set_ylim(self.data2D.ymin, self.data2D.ymax) 679 667 self.subplot.set_xlim(self.data2D.xmin, self.data2D.xmax) … … 681 669 self.slicer.update() 682 670 ## Value used to initially set the slicer panel 683 type = self.slicer.__class__.__name__684 671 params = self.slicer.get_params() 685 672 ## Create a new panel to display results of summation of Data2D … … 687 674 win = MDIFrame(self.parent, None, 'None', (100, 200)) 688 675 new_panel = SlicerPanel(parent=win, id=-1, 689 base=self, type=type,690 691 676 base=self, type=self.slicer.__class__.__name__, 677 params=params, style=wx.RAISED_BORDER) 678 692 679 new_panel.window_caption = self.slicer.__class__.__name__ + " " + \ 693 680 str(self.data2D.name) 694 new_panel.window_name = self.slicer.__class__.__name__ + " " + \681 new_panel.window_name = self.slicer.__class__.__name__ + " " + \ 695 682 str(self.data2D.name) 696 683 ## Store a reference of the new created panel 697 684 698 685 ## save the window_caption of the new panel in the current slicer 699 686 self.slicer.set_panel_name(name=new_panel.window_caption) 700 ## post slicer panel to guiframe to display it 687 ## post slicer panel to guiframe to display it 701 688 from sas.guiframe.events import SlicerPanelEvent 702 689 703 690 win.set_panel(new_panel) 704 691 new_panel.frame = win 705 692 wx.PostEvent(self.parent, SlicerPanelEvent(panel=new_panel, 706 693 main_panel=self)) 707 694 wx.CallAfter(new_panel.frame.Show) 708 695 self.panel_slicer = new_panel 709 710 def onBoxavgX(self, event):696 697 def onBoxavgX(self, event): 711 698 """ 712 699 Perform 2D data averaging on Qx 713 700 Create a new slicer . 714 701 715 702 :param event: wx.menu event 716 703 """ … … 718 705 self.onClearSlicer(event) 719 706 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorX)) 720 721 def onBoxavgY(self, event):707 708 def onBoxavgY(self, event): 722 709 """ 723 710 Perform 2D data averaging on Qy 724 711 Create a new slicer . 725 712 726 713 :param event: wx.menu event 727 714 728 715 """ 729 716 from boxSlicer import BoxInteractorY 730 717 self.onClearSlicer(event) 731 718 wx.PostEvent(self, InternalEvent(slicer=BoxInteractorY)) 732 719 733 720 def onClearSlicer(self, event): 734 721 """ … … 742 729 event = self._getEmptySlicerEvent() 743 730 wx.PostEvent(self, event) 744 731 745 732 def _onSave(self, evt): 746 733 """ 747 734 Save a data set to a dat(text) file 748 735 749 736 :param evt: Menu event 750 751 """ 752 id = str(evt.GetId())737 738 """ 739 event_id = str(evt.GetId()) 753 740 if self.parent != None: 754 741 self._default_save_location = self.parent._default_save_location … … 757 744 default_name = default_name.split('.')[0] 758 745 default_name += "_out" 759 if id in self.action_ids: 760 path = None 746 if event_id in self.action_ids: 761 747 self.parent.save_data2d(self.data2D, default_name) 762 748 763 749 def _onDataShow(self, evt): 764 750 """ 765 751 Show the data set in text 766 752 767 753 :param evt: Menu event 768 754 769 755 """ 770 756 menu = evt.GetEventObject() 771 id = evt.GetId()772 self.set_selected_from_menu(menu, id)757 event_id = evt.GetId() 758 self.set_selected_from_menu(menu, event_id) 773 759 data = self.plots[self.graph.selected_plottable] 774 760 default_name = data.label … … 778 764 if self.parent != None: 779 765 self.parent.show_data2d(data, default_name) 780 781 782 def modifyGraphAppearance(self,e): 783 self.graphApp = graphAppearance(self,'Modify graph appearance', 784 legend=False) 785 786 787 788 self.graphApp.setDefaults(self.grid_on,self.legend_on, 789 self.xaxis_label,self.yaxis_label, 790 self.xaxis_unit,self.yaxis_unit, 791 self.xaxis_font,self.yaxis_font, 792 find_key(self.get_loc_label(),self.legendLoc), 793 self.xcolor,self.ycolor, 794 self.is_xtick, self.is_ytick) 766 767 def modifyGraphAppearance(self, e): 768 self.graphApp = graphAppearance(self, 'Modify graph appearance', legend=False) 769 self.graphApp.setDefaults(self.grid_on, self.legend_on, 770 self.xaxis_label, self.yaxis_label, 771 self.xaxis_unit, self.yaxis_unit, 772 self.xaxis_font, self.yaxis_font, 773 find_key(self.get_loc_label(), self.legendLoc), 774 self.xcolor, self.ycolor, 775 self.is_xtick, self.is_ytick) 795 776 self.graphApp.Bind(wx.EVT_CLOSE, self.on_graphApp_close) 796 797 798 def on_graphApp_close(self,e):799 # gets values from graph appearance dialog and sends them off800 #to modify the plot801 777 778 def on_graphApp_close(self, e): 779 """ 780 Gets values from graph appearance dialog and sends them off 781 to modify the plot 782 """ 802 783 self.onGridOnOff(self.graphApp.get_togglegrid()) 803 804 805 784 self.xaxis_label = self.graphApp.get_xlab() 806 785 self.yaxis_label = self.graphApp.get_ylab() … … 809 788 self.xaxis_font = self.graphApp.get_xfont() 810 789 self.yaxis_font = self.graphApp.get_yfont() 811 self.is_xtick = 812 self.is_ytick = 790 self.is_xtick = self.graphApp.get_xtick_check() 791 self.is_ytick = self.graphApp.get_ytick_check() 813 792 if self.is_xtick: 814 793 self.xaxis_tick = self.xaxis_font … … 816 795 self.yaxis_tick = self.yaxis_font 817 796 818 self.xaxis(self.xaxis_label, self.xaxis_unit, 819 self.graphApp.get_xfont(), self.graphApp.get_xcolor(), 797 self.xaxis(self.xaxis_label, self.xaxis_unit, 798 self.graphApp.get_xfont(), self.graphApp.get_xcolor(), 820 799 self.xaxis_tick) 821 self.yaxis(self.yaxis_label, self.yaxis_unit, 800 self.yaxis(self.yaxis_label, self.yaxis_unit, 822 801 self.graphApp.get_yfont(), self.graphApp.get_ycolor(), 823 802 self.yaxis_tick) -
src/sas/guiframe/local_perspectives/plotting/masking.py
r7d56795 rc039589 30 30 from sas.guiframe.dataFitting import Data1D, Data2D 31 31 from boxMask import BoxMask 32 from sector Mask import SectorMask32 from sector_mask import SectorMask 33 33 from AnnulusSlicer import CircularMask 34 34 -
src/sas/guiframe/local_perspectives/plotting/plotting.py
rb9dbd6b rc039589 5 5 #This software was developed by the University of Tennessee as part of the 6 6 #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 #project funded by the US National Science Foundation. 7 #project funded by the US National Science Foundation. 8 8 # 9 9 #See the license text in license.txt … … 16 16 from sas.guiframe.events import EVT_NEW_PLOT 17 17 from sas.guiframe.events import EVT_PLOT_QRANGE 18 from sas.guiframe.events import StatusEvent19 18 from sas.guiframe.events import DeletePlotPanelEvent 20 19 from sas.guiframe.plugin_base import PluginBase … … 25 24 DEFAULT_MENU_ITEM_ID = wx.NewId() 26 25 27 IS_WIN = True 28 if sys.platform.count("win32") ==0:26 IS_WIN = True 27 if sys.platform.count("win32") == 0: 29 28 if int(str(wx.__version__).split('.')[0]) == 2: 30 29 if int(str(wx.__version__).split('.')[1]) < 9: … … 36 35 Plug-in class to be instantiated by the GUI manager 37 36 """ 38 37 39 38 def __init__(self, standalone=False): 40 39 PluginBase.__init__(self, name="Plotting", standalone=standalone) 41 40 42 41 ## Plot panels 43 42 self.plot_panels = {} … … 47 46 self.menu = None 48 47 49 48 50 49 def set_panel_on_focus(self, panel): 51 50 """ 52 51 """ 53 52 self._panel_on_focus = panel 54 53 55 54 def is_always_active(self): 56 55 """ 57 return True is this plugin is always active even if the user is 56 return True is this plugin is always active even if the user is 58 57 switching between perspectives 59 58 """ 60 59 return True 61 60 62 61 def populate_menu(self, parent): 63 62 """ 64 63 Create a 'Plot' menu to list the panels 65 64 available for displaying 66 65 67 66 :param id: next available unique ID for wx events 68 67 :param parent: parent window 69 68 70 69 """ 71 70 return [] 72 """ 73 self.menu = wx.Menu() 74 self.menu.Append(DEFAULT_MENU_ITEM_ID, DEFAULT_MENU_ITEM_LABEL, 75 "No graph available") 76 self.menu.FindItemByPosition(0).Enable(False) 77 return [(self.menu, "Show")] 78 """ 79 71 80 72 def get_panels(self, parent): 81 73 """ … … 89 81 # We have no initial panels for this plug-in 90 82 return [] 91 92 def _on_plot_qrange(self, event= 83 84 def _on_plot_qrange(self, event=None): 93 85 """ 94 86 On Qmin Qmax vertical line event … … 103 95 return 104 96 panel.on_plot_qrange(event) 105 97 106 98 def _on_show_panel(self, event): 107 99 """show plug-in panel""" 108 100 pass 109 101 110 102 def remove_plot(self, group_id, id): 111 103 """ 112 104 remove plot of ID = id from a panel of group ID =group_id 113 105 """ 114 106 115 107 if group_id in self.plot_panels.keys(): 116 108 panel = self.plot_panels[group_id] 117 109 panel.remove_data_by_id(id=id) 118 110 119 111 return True 120 112 return False 121 113 122 114 def clear_panel(self): 123 115 """ … … 129 121 self.hide_panel(group_id) 130 122 self.plot_panels = {} 131 123 132 124 def clear_panel_by_id(self, group_id): 133 125 """ … … 141 133 return True 142 134 return False 143 135 144 136 def hide_panel(self, group_id): 145 137 """ … … 148 140 # Not implemeted 149 141 return False 150 142 151 143 def create_panel_helper(self, new_panel, data, group_id, title=None): 152 144 """ … … 167 159 new_panel.uid = event_id 168 160 # Ship the plottable to its panel 169 wx.CallAfter(new_panel.plot_data, data) 161 wx.CallAfter(new_panel.plot_data, data) 170 162 #new_panel.canvas.set_resizing(new_panel.resizing) 171 163 self.plot_panels[new_panel.group_id] = new_panel 172 173 # Set Graph menu and help string 174 self.help_string = ' Graph: ' 175 for plot in new_panel.plots.itervalues(): 176 help_string += (' ' + plot.label + ';') 177 #self.menu.AppendCheckItem(event_id, new_panel.window_caption, 178 # helpString) 179 #self.menu.Check(event_id, IS_WIN) 180 #wx.EVT_MENU(self.parent, event_id, self._on_check_menu) 181 182 164 183 165 def create_1d_panel(self, data, group_id): 184 166 """ 185 167 """ 186 # Create a new plot panel if none was available 168 # Create a new plot panel if none was available 187 169 if issubclass(data.__class__, Data1D): 188 170 from Plotter1D import ModelPanel1D … … 194 176 win = MDIFrame(self.parent, None, 'None', (100, 200)) 195 177 new_panel = ModelPanel1D(win, -1, xtransform=xtransform, 196 ytransform=ytransform, style=wx.RAISED_BORDER)178 ytransform=ytransform, style=wx.RAISED_BORDER) 197 179 win.set_panel(new_panel) 198 180 win.Show(False) … … 200 182 #win.Show(True) 201 183 return new_panel 202 184 203 185 msg = "1D Panel of group ID %s could not be created" % str(group_id) 204 186 raise ValueError, msg 205 187 206 188 def create_2d_panel(self, data, group_id): 207 189 """ … … 213 195 win = MDIFrame(self.parent, None, 'None', (200, 150)) 214 196 win.Show(False) 215 new_panel = ModelPanel2D(win, id =-1,216 data2d=data, scale = scale,217 style=wx.RAISED_BORDER)197 new_panel = ModelPanel2D(win, id=-1, 198 data2d=data, scale=scale, 199 style=wx.RAISED_BORDER) 218 200 win.set_panel(new_panel) 219 201 new_panel.frame = win 220 #win.Show(True)221 202 return new_panel 222 203 msg = "2D Panel of group ID %s could not be created" % str(group_id) 223 204 raise ValueError, msg 224 205 225 206 def update_panel(self, data, panel): 226 207 """ … … 228 209 """ 229 210 # Check whether we already have a graph with the same units 230 # as the plottable we just received. 231 _, x_unit = 232 _, y_unit = 211 # as the plottable we just received. 212 _, x_unit = data.get_xaxis() 213 _, y_unit = data.get_yaxis() 233 214 flag_x = (panel.graph.prop["xunit"] is not None) and \ 234 215 (panel.graph.prop["xunit"].strip() != "") and\ … … 237 218 (panel.graph.prop["yunit"].strip() != "") and\ 238 219 (y_unit != panel.graph.prop["yunit"]) and False 239 if (flag_x and flag_y):220 if flag_x and flag_y: 240 221 msg = "Cannot add %s" % str(data.name) 241 222 msg += " to panel %s\n" % str(panel.window_caption) … … 253 234 panel = self.plot_panels[group_id] 254 235 uid = panel.uid 255 wx.PostEvent(self.parent, 236 wx.PostEvent(self.parent, 256 237 DeletePlotPanelEvent(name=panel.window_caption, 257 caption=panel.window_caption)) 258 #remove menu item 259 #self.delete_menu_item(panel.window_caption, panel.uid) 238 caption=panel.window_caption)) 260 239 del self.plot_panels[group_id] 261 240 if uid in self.parent.plot_panels.keys(): … … 265 244 266 245 return False 267 246 268 247 def _on_plot_event(self, event): 269 248 """ … … 271 250 Check whether we have a panel to put in on, or create 272 251 a new one 273 252 274 253 :param event: EVT_NEW_PLOT event 275 254 276 255 """ 277 256 action_check = False … … 285 264 #remove data from panel 286 265 if action_string == 'remove': 287 id = event.id 288 return self.remove_plot(group_id, id) 266 return self.remove_plot(group_id, event.id) 289 267 if action_string == 'hide': 290 268 return self.hide_panel(group_id) … … 295 273 if action_string == "clear": 296 274 return self.clear_panel_by_id(group_id) 297 298 if not hasattr(event, 'plot'): 275 276 if not hasattr(event, 'plot'): 299 277 return 300 278 title = None 301 279 if hasattr(event, 'title'): 302 title = 'Graph' #event.title280 title = 'Graph' #event.title 303 281 data = event.plot 304 group_id = data.group_id 282 group_id = data.group_id 305 283 if group_id in self.plot_panels.keys(): 306 284 if action_check: 307 285 # Check if the plot already exist. if it does, do nothing. 308 286 if data.id in self.plot_panels[group_id].plots.keys(): 309 return 310 #update a panel graph 287 return 288 #update a panel graph 311 289 panel = self.plot_panels[group_id] 312 290 self.update_panel(data, panel) … … 331 309 p_plot.group_id = group_id 332 310 return 333 311 334 312 new_panel = self.create_2d_panel(data, group_id) 335 self.create_panel_helper(new_panel, data, group_id, title) 313 self.create_panel_helper(new_panel, data, group_id, title) 336 314 return 337 frame.Show(True) -
src/sas/guiframe/local_perspectives/plotting/profile_dialog.py
r090e07e rc039589 3 3 """ 4 4 import wx 5 import os6 5 import sys 7 6 from copy import deepcopy … … 10 9 from sas.guiframe.dataFitting import Data1D 11 10 from sas.guiframe.gui_style import GUIFRAME_ID 12 import pylab 13 14 DEFAULT_CMAP = None#pylab.cm.jet 11 12 DEFAULT_CMAP = None #pylab.cm.jet 15 13 _BOX_WIDTH = 76 16 14 _STATICBOX_WIDTH = 400 … … 19 17 _Y_OFF = 0.5 20 18 21 #SLD panel size 19 #SLD panel size 22 20 if sys.platform.count("win32") > 0: 23 21 _STATICBOX_WIDTH = 563 … … 28 26 PANEL_SIZE = 500 29 27 FONT_VARIANT = 1 30 31 28 29 32 30 class SLDPanel(wx.Dialog): 33 31 """ … … 40 38 ## Flag to tell the AUI manager to put this panel in the center pane 41 39 CENTER_PANE = True 42 def __init__(self, parent=None, base=None, data=None, axes =['Radius'],40 def __init__(self, parent=None, base=None, data=None, axes=['Radius'], 43 41 id=-1, *args, **kwds): 44 42 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 45 kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE) 43 kwds["size"] = wx.Size(_STATICBOX_WIDTH, PANEL_SIZE) 46 44 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 47 45 48 46 if data != None: 49 #Font size 47 #Font size 50 48 kwds = [] 51 49 self.SetWindowVariant(variant=FONT_VARIANT) … … 59 57 self.name = self.data.name 60 58 # Panel for plot 61 self.plotpanel = SLDplotpanel(self, axes, -1, 62 59 self.plotpanel = SLDplotpanel(self, axes, -1, 60 style=wx.TRANSPARENT_WINDOW) 63 61 self.cmap = DEFAULT_CMAP 64 62 ## Create Artist and bind it … … 66 64 # layout 67 65 self._setup_layout() 68 66 69 67 # plot 70 68 data_plot = deepcopy(self.data) … … 72 70 # unit increase to M times for users 73 71 data_plot.y = self._set_y_data() 74 72 75 73 self.newplot = Data1D(data_plot.x, data_plot.y, data_plot.dy) 76 74 self.newplot.symbol = GUIFRAME_ID.CURVE_SYMBOL_NUM … … 78 76 self.newplot.name = 'SLD' 79 77 self.newplot.is_data = False 80 78 81 79 self.newplot.id = self.newplot.name 82 self.plotpanel.add_image(self.newplot) 83 80 self.plotpanel.add_image(self.newplot) 81 84 82 self.plotpanel.resizing = False 85 83 self.plotpanel.canvas.set_resizing(self.plotpanel.resizing) 86 87 self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF ,88 89 self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF, 90 84 85 self.plotpanel.subplot.set_ylim(min(data_plot.y) - _Y_OFF, 86 max(data_plot.y) + _Y_OFF) 87 self.plotpanel.subplot.set_xlim(min(data_plot.x) - _X_OFF, 88 max(data_plot.x) + _X_OFF) 91 89 self.plotpanel.graph.render(self.plotpanel) 92 90 self.plotpanel.canvas.draw() 93 91 94 def _set_dy_data(self): 92 def _set_dy_data(self): 95 93 """ 96 94 make fake dy data 97 98 :return dy: 95 96 :return dy: 99 97 """ 100 98 # set dy as zero 101 99 dy = [0 for y in self.data.y] 102 return dy 103 104 def _set_y_data(self): 100 return dy 101 102 def _set_y_data(self): 105 103 """ 106 104 make y data unit Mega times 107 108 :return y_value: 105 106 :return y_value: 109 107 """ 110 108 # changes the unit 111 109 y_value = [yvalue * 1e+006 for yvalue in self.data.y] 112 113 return y_value 114 110 111 return y_value 112 115 113 def _setup_layout(self): 116 114 """ … … 119 117 # panel sizer 120 118 sizer = wx.BoxSizer(wx.VERTICAL) 121 sizer.Add(self.plotpanel, 0, wx.LEFT |wx.RIGHT, 5)122 sizer.Add(wx.StaticLine(self), 0, wx.ALL |wx.EXPAND, 5)119 sizer.Add(self.plotpanel, 0, wx.LEFT | wx.RIGHT, 5) 120 sizer.Add(wx.StaticLine(self), 0, wx.ALL | wx.EXPAND, 5) 123 121 sizer.Add((0, 5)) 124 122 #-----Button------------1 125 id = wx.NewId() 126 button_reset = wx.Button(self, id, "Close") 123 button_reset = wx.Button(self, wx.NewId(), "Close") 127 124 button_reset.SetToolTipString("Close...") 128 button_reset.Bind(wx.EVT_BUTTON, self._close, 129 id=button_reset.GetId()) 130 sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 125 button_reset.Bind(wx.EVT_BUTTON, self._close, 126 id=button_reset.GetId()) 127 sizer.Add(button_reset, 0, wx.LEFT, _STATICBOX_WIDTH - 80) 131 128 sizer.Add((0, 10)) 132 129 self.SetSizerAndFit(sizer) … … 134 131 self.Show(True) 135 132 button_reset.SetFocus() 136 133 137 134 def _close(self, event): 138 135 """ … … 149 146 def get_current_context_menu(self, graph=None): 150 147 """ 151 When the context menu of a plot is rendered, the 152 get_context_menu method will be called to give you a 148 When the context menu of a plot is rendered, the 149 get_context_menu method will be called to give you a 153 150 chance to add a menu item to the context menu. 154 151 :param graph: the Graph object to which we attach the context menu 155 152 156 153 :return: a list of menu items with call-back function 157 154 """ 158 155 return [] 159 156 160 157 def set_schedule_full_draw(self, panel=None, func=None): 161 158 """ … … 164 161 # Not implemented 165 162 pass 166 163 167 164 def set_schedule(self, schedule=False): 168 165 """ … … 171 168 # Not implemented 172 169 pass 173 170 174 171 def set_plot_unfocus(self): 175 172 """ … … 178 175 # NOt implemented 179 176 pass 180 177 181 178 def on_change_caption(self, name, old_caption, new_caption): 182 179 """ 183 180 """ 184 181 self.parent.parent.parent.on_change_caption(name, old_caption, new_caption) 185 182 186 183 def disable_app_menu(self, panel): 187 184 """ … … 190 187 # Not implemented! 191 188 return 192 189 193 190 def show_data1d(self, data, name): 194 191 """ 195 192 Show data dialog 196 """ 193 """ 197 194 self.parent._manager.parent.show_data1d(data, name) 198 195 199 196 class SLDplotpanel(PlotPanel): 200 197 """ 201 198 Panel 202 199 """ 203 def __init__(self, parent, axes=[], id=-1, color=None, dpi=None, 204 **kwargs): 205 """ 206 """ 207 PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 208 color=color, dpi=dpi, 209 size=(_STATICBOX_WIDTH, PANEL_SIZE-100), **kwargs) 200 def __init__(self, parent, axes=[], id=-1, color=None, dpi=None, **kwargs): 201 """ 202 """ 203 PlotPanel.__init__(self, parent, id=id, xtransform='x', ytransform='y', 204 color=color, dpi=dpi, 205 size=(_STATICBOX_WIDTH, PANEL_SIZE - 100), **kwargs) 210 206 211 207 # Keep track of the parent Frame … … 216 212 self.prevYtrans = "y" 217 213 self.viewModel = "--" 218 # Internal list of plottable names (because graph 214 # Internal list of plottable names (because graph 219 215 # doesn't have a dictionary of handles for the plottables) 220 216 self.plots = {} … … 230 226 self.xcolor = 'black' 231 227 self.ycolor = 'black' 232 228 233 229 def add_image(self, plot): 234 230 """ … … 241 237 #add axes 242 238 x1_label = self.axes_label[0] 243 self.xaxis_label = '\\rm{%s} ' % x1_label239 self.xaxis_label = '\\rm{%s} ' % x1_label 244 240 self.xaxis_unit = 'A' 245 241 self.graph.xaxis(self.xaxis_label, self.xaxis_unit) … … 247 243 self.yaxis_unit = '10^{-6}A^{-2}' 248 244 self.graph.yaxis(self.yaxis_label, self.yaxis_unit) 249 #self.subplot.figure.canvas.draw_idle() 250 # For latter scale changes 251 self.plots[plot.id].xaxis('\\rm{%s} '% x1_label, 'A') 245 # For latter scale changes 246 self.plots[plot.id].xaxis('\\rm{%s} ' % x1_label, 'A') 252 247 self.plots[plot.id].yaxis('\\rm{SLD} ', '10^{-6}A^{-2}') 253 #draw 254 #self.graph.render(self) 255 248 256 249 def on_set_focus(self, event): 257 250 """ 258 251 send to the parenet the current panel on focus 259 252 260 253 """ 261 254 #Not implemented … … 265 258 """ 266 259 reset the panel color 267 260 268 261 """ 269 262 #Not implemented 270 263 pass 271 264 272 265 def onChangeCaption(self, event): 273 266 """ … … 275 268 """ 276 269 pass 277 270 278 271 def _onSave(self, evt): 279 272 """ 280 273 Save a data set to a text file 281 274 282 275 :param evt: Menu event 283 276 284 277 """ 285 278 menu = evt.GetEventObject() 286 id = evt.GetId()287 self.set_selected_from_menu(menu, id)279 event_id = evt.GetId() 280 self.set_selected_from_menu(menu, event_id) 288 281 data = self.plots[self.graph.selected_plottable] 289 282 default_name = data.label … … 295 288 fit_panel = self.parent.parent.parent 296 289 fit_panel._manager.parent.save_data1d(data, default_name) 297 290 298 291 class ViewerFrame(wx.Frame): 299 292 """ … … 306 299 """ 307 300 # Initialize the Frame object 308 wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 301 wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, 309 302 wx.Size(_STATICBOX_WIDTH, PANEL_SIZE)) 310 303 # Panel for 1D plot 311 self.plotpanel 304 self.plotpanel = SLDplotpanel(self, -1, style=wx.RAISED_BORDER) 312 305 313 306 class ViewApp(wx.App): 314 307 def OnInit(self): 315 frame = ViewerFrame(None, -1, 'testView') 308 frame = ViewerFrame(None, -1, 'testView') 316 309 frame.Show(True) 317 310 self.SetTopWindow(frame) 318 311 319 312 return True 320 321 if __name__ == "__main__": 313 314 if __name__ == "__main__": 322 315 app = ViewApp(0) 323 app.MainLoop() 316 app.MainLoop() -
src/sas/guiframe/local_perspectives/plotting/sector_mask.py
r79492222 rc039589 1 1 """ 2 Sector mask interactor 3 """ 2 4 import math 3 5 import wx … … 18 20 ## Class initialization 19 21 self.markers = [] 20 self.axes = axes 22 self.axes = axes 21 23 self.is_inside = side 22 ## connect the plot to event 24 ## connect the plot to event 23 25 self.connect = self.base.connect 24 25 ## compute qmax limit to reset the graph 26 x = math.pow(max(self.base.data.xmax, 26 27 ## compute qmax limit to reset the graph 28 x = math.pow(max(self.base.data.xmax, 27 29 math.fabs(self.base.data.xmin)), 2) 28 y = math.pow(max(self.base.data.ymax, 30 y = math.pow(max(self.base.data.ymax, 29 31 math.fabs(self.base.data.ymin)), 2) 30 32 self.qmax = math.sqrt(x + y) … … 32 34 self.nbins = 20 33 35 ## Angle of the middle line 34 self.theta2 = math.pi /336 self.theta2 = math.pi / 3 35 37 ## Absolute value of the Angle between the middle line and any side line 36 self.phi = math.pi /1237 38 self.phi = math.pi / 12 39 38 40 ## Middle line 39 41 self.main_line = LineInteractor(self, self.base.subplot, color='blue', 40 zorder=zorder, r=self.qmax, theta=self.theta2)42 zorder=zorder, r=self.qmax, theta=self.theta2) 41 43 self.main_line.qmax = self.qmax 42 44 ## Right Side line 43 45 self.right_line = SideInteractor(self, self.base.subplot, color='gray', 44 zorder=zorder, r=self.qmax, phi= -1*self.phi,45 46 zorder=zorder, r=self.qmax, phi=-1 * self.phi, 47 theta2=self.theta2) 46 48 self.right_line.qmax = self.qmax 47 ## Left Side line 48 self.left_line = SideInteractor(self, self.base.subplot, color='gray', 49 zorder=zorder, r=self.qmax, phi=self.phi,50 49 ## Left Side line 50 self.left_line = SideInteractor(self, self.base.subplot, color='gray', 51 zorder=zorder, r=self.qmax, phi=self.phi, 52 theta2=self.theta2) 51 53 self.left_line.qmax = self.qmax 52 ## draw the sector 54 ## draw the sector 53 55 self.update() 54 56 self._post_data() 55 57 56 58 def clear(self): 57 59 """ … … 63 65 self.right_line.clear() 64 66 self.base.connect.clearall() 65 #self.base.Unbind(EVT_SLICER_PARS) 66 67 67 68 def update(self): 68 69 """ … … 70 71 resetting the widgets. 71 72 """ 72 # Update locations 73 ## Check if the middle line was dragged and 74 #update the picture accordingly 73 # Update locations 74 ## Check if the middle line was dragged and 75 #update the picture accordingly 75 76 if self.main_line.has_move: 76 77 self.main_line.update() 77 self.right_line.update(delta=-self.left_line.phi/2, 78 mline=self.main_line.theta) 79 self.left_line.update(delta=self.left_line.phi/2, 78 self.right_line.update(delta=-self.left_line.phi / 2, 80 79 mline=self.main_line.theta) 81 ## Check if the left side has moved and update the slicer accordingly 80 self.left_line.update(delta=self.left_line.phi / 2, 81 mline=self.main_line.theta) 82 ## Check if the left side has moved and update the slicer accordingly 82 83 if self.left_line.has_move: 83 84 self.main_line.update() 84 self.left_line.update(phi=None, delta=None, mline=self.main_line 85 side=True, left=True 85 self.left_line.update(phi=None, delta=None, mline=self.main_line, 86 side=True, left=True) 86 87 self.right_line.update(phi=self.left_line.phi, delta=None, 87 88 89 ## Check if the right side line has moved and 88 mline=self.main_line, side=True, 89 left=False, right=True) 90 ## Check if the right side line has moved and 90 91 #update the slicer accordingly 91 92 if self.right_line.has_move: … … 94 95 side=True, left=False, right=True) 95 96 self.left_line.update(phi=self.right_line.phi, delta=None, 96 97 mline=self.main_line, side=True, left=False) 97 98 #if self.is_inside != None: 98 99 out = self._post_data() … … 118 119 if data == None: 119 120 return 120 121 mask = data.mask122 121 ## Averaging 123 122 from sas.dataloader.manipulations import Sectorcut 124 radius = self.qmax 125 phimin = -self.left_line.phi + self.main_line.theta 123 phimin = -self.left_line.phi + self.main_line.theta 126 124 phimax = self.left_line.phi + self.main_line.theta 127 125 128 126 mask = Sectorcut(phi_min=phimin, phi_max=phimax) 129 127 if self.is_inside: … … 131 129 else: 132 130 out = (mask(data)) 133 #self.base.data.mask=out 134 return out 131 return out 135 132 136 133 def moveend(self, ev): 137 134 """ 138 Called a dragging motion ends.Get slicer event 135 Called a dragging motion ends.Get slicer event 139 136 """ 140 137 self.base.thaw_axes() … … 146 143 wx.PostEvent(self.base, event) 147 144 self._post_data() 148 145 149 146 def restore(self): 150 147 """ … … 160 157 """ 161 158 pass 162 159 163 160 def set_cursor(self, x, y): 164 161 pass 165 162 166 163 def get_params(self): 167 164 """ 168 165 Store a copy of values of parameters of the slicer into a dictionary. 169 166 170 167 :return params: the dictionary created 171 168 172 169 """ 173 170 params = {} 174 ## Always make sure that the left and the right line are at phi 171 ## Always make sure that the left and the right line are at phi 175 172 ## angle of the middle line 176 173 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 177 174 msg = "Phi left and phi right are " 178 msg += "different %f, %f" % (self.left_line.phi, 175 msg += "different %f, %f" % (self.left_line.phi, 179 176 self.right_line.phi) 180 177 raise ValueError, msg … … 182 179 params["Delta_Phi"] = math.fabs(self.left_line.phi) 183 180 return params 184 181 185 182 def set_params(self, params): 186 183 """ 187 Receive a dictionary and reset the slicer with values contained 184 Receive a dictionary and reset the slicer with values contained 188 185 in the values of the dictionary. 189 190 :param params: a dictionary containing name of slicer parameters and 186 187 :param params: a dictionary containing name of slicer parameters and 191 188 values the user assigned to the slicer. 192 189 """ 193 main = params["Phi"] 190 main = params["Phi"] 194 191 phi = math.fabs(params["Delta_Phi"]) 195 192 196 193 self.main_line.theta = main 197 194 ## Reset the slicer parameters … … 203 200 ## post the new corresponding data 204 201 self._post_data() 205 202 206 203 def freeze_axes(self): 207 204 """ 208 205 """ 209 206 self.base.freeze_axes() 210 207 211 208 def thaw_axes(self): 212 209 """ … … 218 215 """ 219 216 self.base.update() 220
Note: See TracChangeset
for help on using the changeset viewer.