Changeset c416a17 in sasview for src/sas/sasgui/guiframe/local_perspectives
- Timestamp:
- May 26, 2017 7:41:44 AM (7 years ago)
- Branches:
- ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc
- Children:
- c1e380e
- Parents:
- 6964d44 (diff), 7132e49 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- src/sas/sasgui/guiframe/local_perspectives
- Files:
-
- 20 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/sasgui/guiframe/local_perspectives/data_loader/data_loader.py
rfe1eb94 r235f514 7 7 import wx 8 8 import logging 9 10 logger = logging.getLogger(__name__) 9 11 10 12 from sas.sascalc.dataloader.loader import Loader … … 73 75 path = None 74 76 self._default_save_location = self.parent._default_save_location 75 if self._default_save_location ==None:77 if self._default_save_location is None: 76 78 self._default_save_location = os.getcwd() 77 79 … … 90 92 if dlg.ShowModal() == wx.ID_OK: 91 93 file_list = dlg.GetPaths() 92 if len(file_list) >= 0 and not file_list[0] isNone:94 if len(file_list) >= 0 and file_list[0] is not None: 93 95 self._default_save_location = os.path.dirname(file_list[0]) 94 96 path = self._default_save_location … … 114 116 path = None 115 117 self._default_save_location = self.parent._default_save_location 116 if self._default_save_location ==None:118 if self._default_save_location is None: 117 119 self._default_save_location = os.getcwd() 118 120 dlg = wx.DirDialog(self.parent, "Choose a directory", … … 160 162 message += "\tError: {0}\n".format(error_data) 161 163 else: 162 logg ing.error("Loader returned an invalid object:\n %s" % str(item))164 logger.error("Loader returned an invalid object:\n %s" % str(item)) 163 165 data_error = True 164 166 … … 182 184 log_msg += "Please try to open that file from \"open project\"" 183 185 log_msg += "or \"open analysis\" menu." 184 logg ing.info(log_msg)186 logger.info(log_msg) 185 187 file_errors[basename] = [log_msg] 186 188 continue … … 212 214 213 215 except: 214 logg ing.error(sys.exc_value)216 logger.error(sys.exc_value) 215 217 216 218 error_message = "The Data file you selected could not be loaded.\n" -
src/sas/sasgui/guiframe/local_perspectives/plotting/Arc.py
rd85c194 r7432acb 71 71 x = [] 72 72 y = [] 73 if theta1 !=None:73 if theta1 is not None: 74 74 self.theta1 = theta1 75 if theta2 !=None:75 if theta2 is not None: 76 76 self.theta2 = theta2 77 77 while self.theta2 < self.theta1: … … 81 81 npts = int((self.theta2 - self.theta1) / (math.pi / 120)) 82 82 83 if r ==None:83 if r is None: 84 84 self.radius = math.sqrt(math.pow(self._mouse_x, 2) + \ 85 85 math.pow(self._mouse_y, 2)) -
src/sas/sasgui/guiframe/local_perspectives/plotting/Edge.py
rd85c194 r7432acb 63 63 Draw the new roughness on the graph. 64 64 """ 65 if r1 !=None:65 if r1 is not None: 66 66 self.r1 = r1 67 if r2 !=None:67 if r2 is not None: 68 68 self.r2 = r2 69 if theta !=None:69 if theta is not None: 70 70 self.theta = theta 71 71 x1 = self.r1 * math.cos(self.theta) -
src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter1D.py
r9687d58 rc416a17 1 2 1 ################################################################################ 3 2 # This software was developed by the University of Tennessee as part of the … … 14 13 import sys 15 14 import math 16 import numpy 15 import numpy as np 17 16 import logging 18 17 from sas.sasgui.plottools.PlotPanel import PlotPanel … … 24 23 from appearanceDialog import appearanceDialog 25 24 from graphAppearance import graphAppearance 25 26 logger = logging.getLogger(__name__) 26 27 27 28 DEFAULT_QMAX = 0.05 … … 181 182 # So manually recode the size (=x_size) and compare here. 182 183 # Massy code to work around:< 183 if self.parent._mgr !=None:184 if self.parent._mgr is not None: 184 185 max_panel = self.parent._mgr.GetPane(self) 185 186 if max_panel.IsMaximized(): 186 187 self.parent._mgr.RestorePane(max_panel) 187 188 max_panel.Maximize() 188 if self.x_size !=None:189 if self.x_size is not None: 189 190 if self.x_size == self.GetSize(): 190 191 self.resizing = False … … 210 211 On Qmin Qmax vertical line event 211 212 """ 212 if event ==None:213 if event is None: 213 214 return 214 215 event.Skip() 215 216 active_ctrl = event.active 216 if active_ctrl ==None:217 if active_ctrl is None: 217 218 return 218 219 if hasattr(event, 'is_corfunc'): … … 229 230 colors.append('purple') 230 231 values.append(min(x_data.max(), float(ctrl[2].GetValue()))) 231 if self.ly ==None:232 if self.ly is None: 232 233 self.ly = [] 233 234 for c, v in zip(colors, values): … … 239 240 xval = float(active_ctrl.GetValue()) 240 241 position = self.get_data_xy_vals(xval) 241 if position !=None and not self.is_corfunc:242 if position is not None and not self.is_corfunc: 242 243 wx.PostEvent(self.parent, StatusEvent(status=position)) 243 244 except: 244 logg ing.error(sys.exc_value)245 logger.error(sys.exc_value) 245 246 if not event.leftdown: 246 247 # text event … … 255 256 self.canvas.draw() 256 257 except: 257 logg ing.error(sys.exc_value)258 logger.error(sys.exc_value) 258 259 event.Skip() 259 260 return … … 288 289 :Param value: float 289 290 """ 290 idx = (n umpy.abs(array - value)).argmin()291 idx = (np.abs(array - value)).argmin() 291 292 return int(idx) # array.flat[idx] 292 293 … … 334 335 if hasattr(event, "action"): 335 336 dclick = event.action == 'dclick' 336 if ax ==None or dclick:337 if ax is None or dclick: 337 338 # remove the vline 338 339 self._check_zoom_plot() … … 340 341 self.q_ctrl = None 341 342 return 342 if self.ly != None and event.xdata !=None:343 if self.ly is not None and event.xdata is not None: 343 344 # Selecting a new line if cursor lines are displayed already 344 345 dqmin = math.fabs(event.xdata - self.ly[0].get_xdata()) … … 359 360 Move the cursor line to write Q range 360 361 """ 361 if self.q_ctrl ==None:362 if self.q_ctrl is None: 362 363 return 363 364 # release a q range vline 364 if self.ly !=None and not self.leftdown:365 if self.ly is not None and not self.leftdown: 365 366 for ly in self.ly: 366 367 ly.set_alpha(0.7) … … 368 369 return 369 370 ax = event.inaxes 370 if ax ==None or not hasattr(event, 'action'):371 if ax is None or not hasattr(event, 'action'): 371 372 return 372 end_drag = event.action != 'drag' and event.xdata !=None373 end_drag = event.action != 'drag' and event.xdata is not None 373 374 nop = len(self.plots) 374 375 pos_x, _ = float(event.xdata), float(event.ydata) … … 409 410 self.q_ctrl[vl_ind].SetValue(str(pos_x)) 410 411 except: 411 logg ing.error(sys.exc_value)412 logger.error(sys.exc_value) 412 413 413 414 def set_resizing(self, resizing=False): … … 512 513 ax = event.inaxes 513 514 PlotPanel.onLeftDown(self, event) 514 if ax !=None:515 if ax is not None: 515 516 try: 516 517 pos_x = float(event.xdata) # / size_x … … 616 617 # add menu of other plugins 617 618 item_list = self.parent.get_current_context_menu(self) 618 if ( not item_list == None) and (not len(item_list) == 0):619 if (item_list is not None) and (len(item_list)): 619 620 for item, wx_id in zip(item_list, [ids.next() for i in range(len(item_list))]): 620 621 621 try: 622 622 plot_menu.Append(wx_id, item[0], name) … … 682 682 683 683 684 if self.position !=None:684 if self.position is not None: 685 685 wx_id = ids.next() 686 686 self._slicerpop.Append(wx_id, '&Add Text') … … 731 731 self.subplot.set_ylim(y_range) 732 732 self.subplot.figure.canvas.draw_idle() 733 self.is_zoomed = True 733 734 d.Destroy() 734 735 … … 758 759 default_name = default_name.split('.')[0] 759 760 default_name += "_out" 760 if self.parent !=None:761 if self.parent is not None: 761 762 self.parent.save_data1d(data, default_name) 762 763 … … 776 777 default_name = default_name.split('.')[0] 777 778 # default_name += "_out" 778 if self.parent !=None:779 if self.parent is not None: 779 780 self.parent.show_data1d(data, default_name) 780 781 … … 808 809 curr_label = self.appearance_selected_plot.label 809 810 810 if curr_color ==None:811 if curr_color is None: 811 812 curr_color = self._color_labels['Blue'] 812 813 curr_symbol = 13 -
src/sas/sasgui/guiframe/local_perspectives/plotting/Plotter2D.py
rb2b36932 r7432acb 14 14 import sys 15 15 import math 16 import numpy 16 import numpy as np 17 17 import logging 18 18 from sas.sasgui.plottools.PlotPanel import PlotPanel … … 30 30 from graphAppearance import graphAppearance 31 31 (InternalEvent, EVT_INTERNAL) = wx.lib.newevent.NewEvent() 32 33 logger = logging.getLogger(__name__) 32 34 33 35 DEFAULT_QMAX = 0.05 … … 142 144 """ 143 145 # Not implemented 144 if event ==None:146 if event is None: 145 147 return 146 148 event.Skip() … … 154 156 PlotPanel.onLeftDown(self, event) 155 157 ax = event.inaxes 156 if ax !=None:158 if ax is not None: 157 159 # data coordinate position 158 160 pos_x = "%8.3g" % event.xdata … … 225 227 if self._is_changed_legend_label: 226 228 data.label = self.title_label 227 if data.label ==None:229 if data.label is None: 228 230 data.label = data.name 229 231 if not self.title_font: … … 262 264 # control axis labels from the panel itself 263 265 yname, yunits = data.get_yaxis() 264 if self.yaxis_label !=None:266 if self.yaxis_label is not None: 265 267 yname = self.yaxis_label 266 268 yunits = self.yaxis_unit … … 269 271 self.yaxis_unit = yunits 270 272 xname, xunits = data.get_xaxis() 271 if self.xaxis_label !=None:273 if self.xaxis_label is not None: 272 274 xname = self.xaxis_label 273 275 xunits = self.xaxis_unit … … 318 320 if len(self.data2D.detector) <= 1: 319 321 item_list = self.parent.get_current_context_menu(self) 320 if ( not item_list == None) and (not len(item_list) == 0) and\321 self.data2D.name.split(" ")[0] != 'Residuals' :322 if ((item_list is not None) and len(item_list) and 323 self.data2D.name.split(" ")[0] != 'Residuals'): 322 324 for item, wx_id in zip(item_list, [ids.next() for i in range(len(item_list))]): 323 325 try: … … 353 355 slicerpop.Append(wx_id, '&Box Averaging in Qy') 354 356 wx.EVT_MENU(self, wx_id, self.onBoxavgY) 355 if self.slicer !=None:357 if self.slicer is not None: 356 358 wx_id = ids.next() 357 359 slicerpop.Append(wx_id, '&Clear Slicer') … … 432 434 except: 433 435 msg = "Add Text: Error. Check your property values..." 434 logg ing.error(msg)435 if self.parent !=None:436 logger.error(msg) 437 if self.parent is not None: 436 438 wx.PostEvent(self.parent, StatusEvent(status=msg)) 437 439 dial.Destroy() … … 531 533 """ 532 534 ## Clear current slicer 533 if not self.slicer ==None:535 if self.slicer is not None: 534 536 self.slicer.clear() 535 537 ## Create a new slicer … … 567 569 """ 568 570 # Find the best number of bins 569 npt = math.sqrt(len(self.data2D.data[n umpy.isfinite(self.data2D.data)]))571 npt = math.sqrt(len(self.data2D.data[np.isfinite(self.data2D.data)])) 570 572 npt = math.floor(npt) 571 573 from sas.sascalc.dataloader.manipulations import CircularAverage … … 627 629 628 630 """ 629 if self.slicer !=None:631 if self.slicer is not None: 630 632 from SlicerParameters import SlicerParameterPanel 631 633 dialog = SlicerParameterPanel(self, -1, "Slicer Parameters") … … 717 719 Clear the slicer on the plot 718 720 """ 719 if not self.slicer ==None:721 if self.slicer is not None: 720 722 self.slicer.clear() 721 723 self.subplot.figure.canvas.draw() … … 733 735 """ 734 736 event_id = str(evt.GetId()) 735 if self.parent !=None:737 if self.parent is not None: 736 738 self._default_save_location = self.parent._default_save_location 737 739 default_name = self.plots[self.graph.selected_plottable].label … … 757 759 default_name = default_name.split('.')[0] 758 760 #default_name += "_out" 759 if self.parent !=None:761 if self.parent is not None: 760 762 self.parent.show_data2d(data, default_name) 761 763 -
src/sas/sasgui/guiframe/local_perspectives/plotting/SectorSlicer.py
r83eb5208 rc416a17 442 442 self.restore() 443 443 return 444 445 444 self.phi = numpy.fabs(self.theta2 - self.theta) 446 445 if self.phi > numpy.pi: -
src/sas/sasgui/guiframe/local_perspectives/plotting/SimplePlot.py
rb742b2b9 r7432acb 87 87 pos = (pos_x, pos_y + 5) 88 88 self.PopupMenu(slicerpop, pos) 89 if self.scale !=None:89 if self.scale is not None: 90 90 self.parent.scale2d = self.scale 91 91 … … 106 106 self.leftdown = True 107 107 ax = event.inaxes 108 if ax !=None:108 if ax is not None: 109 109 self.xInit, self.yInit = event.xdata, event.ydata 110 110 try: … … 123 123 """ 124 124 self.resizing = False 125 if self.x_size !=None:125 if self.x_size is not None: 126 126 if self.x_size == self.GetSize(): 127 127 self.canvas.set_resizing(self.resizing) … … 161 161 self.plots[plot.name] = plot 162 162 # Axis scales 163 if plot.xtransform !=None:163 if plot.xtransform is not None: 164 164 self.xLabel = plot.xtransform 165 if plot.ytransform !=None:165 if plot.ytransform is not None: 166 166 self.yLabel = plot.ytransform 167 167 # Init graph -
src/sas/sasgui/guiframe/local_perspectives/plotting/SlicerParameters.py
rd85c194 r235f514 46 46 """ 47 47 event.Skip() 48 if event.obj_class ==None:48 if event.obj_class is None: 49 49 self.set_slicer(None, None) 50 50 else: … … 57 57 self.bck.Clear(True) 58 58 self.type = type 59 if type ==None:59 if type is None: 60 60 label = "Right-click on 2D plot for slicer options" 61 61 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) -
src/sas/sasgui/guiframe/local_perspectives/plotting/binder.py
rd85c194 r463e7ffc 4 4 import logging 5 5 import sys 6 7 logger = logging.getLogger(__name__) 6 8 7 9 class Selection(object): … … 70 72 canvas.mpl_disconnect(canvas.scroll_pick_id) 71 73 except: 72 logg ing.error(sys.exc_value)74 logger.error(sys.exc_value) 73 75 self.canvas = canvas 74 76 self.figure = figure -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxMask.py
rd85c194 r7432acb 123 123 x2=self.vertical_lines.x2, 124 124 width=self.vertical_lines.half_width) 125 # if self.is_inside !=None:125 # if self.is_inside is not None: 126 126 out = self._post_data() 127 127 return out -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxSum.py
r83eb5208 rc416a17 362 362 Draw the new roughness on the graph. 363 363 """ 364 if center_x !=None:364 if center_x is not None: 365 365 self.x = center_x 366 if center_y !=None:366 if center_y is not None: 367 367 self.y = center_y 368 368 self.center_marker.set(xdata=[self.x], ydata=[self.y]) -
src/sas/sasgui/guiframe/local_perspectives/plotting/detector_dialog.py
r0783a2e r7432acb 90 90 zmin = self.reset_zmin_ctl 91 91 zmax = self.reset_zmax_ctl 92 if zmin ==None:92 if zmin is None: 93 93 zmin = "" 94 if zmax ==None:94 if zmax is None: 95 95 zmax = "" 96 96 self.zmin_ctl.SetValue(str(zmin)) … … 155 155 self.qmax_ctl.SetLabel(str(format_number(qmax))) 156 156 self.beam_ctl.SetLabel(str(format_number(beam))) 157 if zmin !=None:157 if zmin is not None: 158 158 self.zmin_ctl.SetValue(str(format_number(zmin))) 159 if zmax !=None:159 if zmax is not None: 160 160 self.zmax_ctl.SetValue(str(format_number(zmax))) 161 161 -
src/sas/sasgui/guiframe/local_perspectives/plotting/masking.py
rd85c194 r45dffa69 24 24 import math 25 25 import copy 26 import numpy 26 import numpy as np 27 27 from sas.sasgui.plottools.PlotPanel import PlotPanel 28 28 from sas.sasgui.plottools.plottables import Graph … … 100 100 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 101 101 102 if data !=None:102 if data is not None: 103 103 # Font size 104 104 kwds = [] … … 235 235 event.Skip() 236 236 # from boxMask import BoxMask 237 if event !=None:237 if event is not None: 238 238 self._on_clear_slicer(event) 239 239 self.slicer_z += 1 … … 249 249 Add new mask to old mask 250 250 """ 251 if not self.slicer ==None:251 if self.slicer is not None: 252 252 data = Data2D() 253 253 data = self.data … … 269 269 Erase new mask from old mask 270 270 """ 271 if not self.slicer ==None:271 if self.slicer is not None: 272 272 self.slicer_mask = self.slicer.update() 273 273 mask = self.data.mask … … 298 298 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 299 299 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 300 mask = n umpy.ones(len(self.data.mask), dtype=bool)300 mask = np.ones(len(self.data.mask), dtype=bool) 301 301 self.data.mask = mask 302 302 # update mask plot … … 307 307 Clear the slicer on the plot 308 308 """ 309 if not self.slicer ==None:309 if self.slicer is not None: 310 310 self.slicer.clear() 311 311 self.subplot.figure.canvas.draw() … … 336 336 """ 337 337 # the case of liitle numbers of True points 338 if len(mask[mask]) < 10 and self.data !=None:338 if len(mask[mask]) < 10 and self.data is not None: 339 339 self.ShowMessage() 340 340 mask = copy.deepcopy(self.mask) … … 343 343 self.mask = mask 344 344 # make temperary data to plot 345 temp_mask = n umpy.zeros(len(mask))345 temp_mask = np.zeros(len(mask)) 346 346 temp_data = copy.deepcopy(self.data) 347 347 # temp_data default is None … … 355 355 temp_data.data[mask == False] = temp_mask[mask == False] 356 356 self.plotpanel.clear() 357 if self.slicer !=None:357 if self.slicer is not None: 358 358 self.slicer.clear() 359 359 self.slicer = None … … 460 460 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 461 461 462 if data !=None:462 if data is not None: 463 463 # Font size 464 464 kwds = [] … … 710 710 Status msg 711 711 """ 712 if self.parent.parent.parent !=None:712 if self.parent.parent.parent is not None: 713 713 wx.PostEvent(self.parent.parent.parent, 714 714 StatusEvent(status=msg, type=type)) -
src/sas/sasgui/guiframe/local_perspectives/plotting/plotting.py
r6ffa0dd r235f514 88 88 On Qmin Qmax vertical line event 89 89 """ 90 if event ==None:90 if event is None: 91 91 return 92 92 if event.id in self.plot_panels.keys(): … … 99 99 100 100 def _on_plot_lim(self, event=None): 101 if event ==None:101 if event is None: 102 102 return 103 103 if event.id in self.plot_panels.keys(): … … 134 134 """ 135 135 for group_id in self.plot_panels.keys(): 136 panel = self.plot_panels[group_id] 137 panel.graph.reset() 138 self.hide_panel(group_id) 136 self.clear_panel_by_id(group_id) 139 137 self.plot_panels = {} 140 138 -
src/sas/sasgui/guiframe/local_perspectives/plotting/profile_dialog.py
rd85c194 r7432acb 44 44 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 45 45 46 if data !=None:46 if data is not None: 47 47 #Font size 48 48 kwds = [] … … 284 284 default_name = default_name.split('.')[0] 285 285 default_name += "_out" 286 if self.parent !=None:286 if self.parent is not None: 287 287 # What an ancestor! 288 288 fit_panel = self.parent.parent.parent -
src/sas/sasgui/guiframe/local_perspectives/plotting/sector_mask.py
rd85c194 r7432acb 96 96 self.left_line.update(phi=self.right_line.phi, delta=None, 97 97 mline=self.main_line, side=True, left=False) 98 #if self.is_inside !=None:98 #if self.is_inside is not None: 99 99 out = self._post_data() 100 100 return out … … 117 117 data = self.base.data 118 118 # If we have no data, just return 119 if data ==None:119 if data is None: 120 120 return 121 121 ## Averaging -
src/sas/sasgui/guiframe/local_perspectives/plotting/slicerpanel.py
rd85c194 r7432acb 37 37 self.bck = wx.GridBagSizer(5, 5) 38 38 self.SetSizer(self.bck) 39 if type == None and params ==None:39 if type is None and params is None: 40 40 label = "Right-click on 2D plot for slicer options" 41 41 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) … … 57 57 """ 58 58 event.Skip() 59 if event.obj_class ==None:59 if event.obj_class is None: 60 60 self.set_slicer(None, None) 61 61 else: … … 68 68 self.bck.Clear(True) 69 69 self.type = type 70 if type ==None:70 if type is None: 71 71 label = "Right-click on 2D plot for slicer options" 72 72 title = wx.StaticText(self, -1, label, style=wx.ALIGN_LEFT) … … 114 114 self.Layout() 115 115 psizer = self.parent.GetSizer() 116 if psizer !=None:116 if psizer is not None: 117 117 psizer.Layout() 118 118 -
src/sas/sasgui/guiframe/local_perspectives/plotting/AnnulusSlicer.py
r7432acb r83eb5208 1 # TODO: the line slicer should listen to all 2DREFRESH events, get the data and slice it 2 # before pushing a new 1D data update. 3 4 # 5 # TODO: NEED MAJOR REFACTOR 6 # 7 8 import math 9 import wx 10 # from copy import deepcopy 11 # Debug printout 12 from sas.sasgui.guiframe.events import NewPlotEvent 13 from sas.sasgui.guiframe.events import StatusEvent 14 from sas.sasgui.guiframe.events import SlicerParameterEvent 15 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 1 import numpy 2 from PyQt4 import QtGui 3 from PyQt4 import QtCore 4 16 5 from BaseInteractor import _BaseInteractor 17 6 from sas.sasgui.guiframe.dataFitting import Data1D 18 19 class AnnulusInteractor(_BaseInteractor): 7 import sas.qtgui.Utilities.GuiUtils as GuiUtils 8 from sas.qtgui.Utilities.GuiUtils import formatNumber 9 from sas.qtgui.Plotting.SlicerModel import SlicerModel 10 11 class AnnulusInteractor(_BaseInteractor, SlicerModel): 20 12 """ 21 13 Select an annulus through a 2D plot. … … 24 16 this class is defined by 2 Ringinterators. 25 17 """ 26 def __init__(self, base, axes, color='black', zorder=3):18 def __init__(self, base, axes, item=None, color='black', zorder=3): 27 19 28 20 _BaseInteractor.__init__(self, base, axes, color=color) 21 SlicerModel.__init__(self) 22 29 23 self.markers = [] 30 24 self.axes = axes 31 25 self.base = base 32 self.qmax = min(math.fabs(self.base.data2D.xmax), 33 math.fabs(self.base.data2D.xmin)) # must be positive 26 self._item = item 27 self.qmax = min(numpy.fabs(self.base.data.xmax), 28 numpy.fabs(self.base.data.xmin)) # must be positive 34 29 self.connect = self.base.connect 35 30 36 # #Number of points on the plot31 # Number of points on the plot 37 32 self.nbins = 36 38 33 # Cursor position of Rings (Left(-1) or Right(1)) 39 self.xmaxd = self.base.data 2D.xmax40 self.xmind = self.base.data 2D.xmin34 self.xmaxd = self.base.data.xmax 35 self.xmind = self.base.data.xmin 41 36 42 37 if (self.xmaxd + self.xmind) > 0: … … 45 40 self.sign = -1 46 41 # Inner circle 47 self.inner_circle = RingInteractor(self, self. base.subplot,42 self.inner_circle = RingInteractor(self, self.axes, 48 43 zorder=zorder, 49 44 r=self.qmax / 2.0, sign=self.sign) 50 45 self.inner_circle.qmax = self.qmax 51 self.outer_circle = RingInteractor(self, self. base.subplot,46 self.outer_circle = RingInteractor(self, self.axes, 52 47 zorder=zorder + 1, r=self.qmax / 1.8, 53 48 sign=self.sign) … … 56 51 self._post_data() 57 52 58 # Bind to slice parameter events 59 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 60 61 def _onEVT_SLICER_PARS(self, event): 62 """ 63 receive an event containing parameters values to reset the slicer 64 65 :param event: event of type SlicerParameterEvent with params as 66 attribute 67 68 """ 69 wx.PostEvent(self.base, 70 StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS")) 71 event.Skip() 72 if event.type == self.__class__.__name__: 73 self.set_params(event.params) 74 self.base.update() 53 self.setModelFromParams() 75 54 76 55 def set_layer(self, n): … … 92 71 self.inner_circle.clear() 93 72 self.base.connect.clearall() 94 self.base.Unbind(EVT_SLICER_PARS)95 73 96 74 def update(self): … … 108 86 can restore on Esc. 109 87 """ 110 self.base.freeze_axes()111 88 self.inner_circle.save(ev) 112 89 self.outer_circle.save(ev) … … 120 97 """ 121 98 # Data to average 122 data = self.base.data2D 123 # If we have no data, just return 99 data = self.base.data 124 100 if data is None: 125 101 return 126 102 127 103 from sas.sascalc.dataloader.manipulations import Ring 128 rmin = min( math.fabs(self.inner_circle.get_radius()),129 math.fabs(self.outer_circle.get_radius()))130 rmax = max( math.fabs(self.inner_circle.get_radius()),131 math.fabs(self.outer_circle.get_radius()))132 # if the user does not specify the numbers of points to plot104 rmin = min(numpy.fabs(self.inner_circle.get_radius()), 105 numpy.fabs(self.outer_circle.get_radius())) 106 rmax = max(numpy.fabs(self.inner_circle.get_radius()), 107 numpy.fabs(self.outer_circle.get_radius())) 108 # If the user does not specify the numbers of points to plot 133 109 # the default number will be nbins= 36 134 110 if nbins is None: … … 136 112 else: 137 113 self.nbins = nbins 138 # # create the data1D Q average of data2D114 # Create the data1D Q average of data2D 139 115 sect = Ring(r_min=rmin, r_max=rmax, nbins=self.nbins) 140 sector = sect(self.base.data 2D)116 sector = sect(self.base.data) 141 117 142 118 if hasattr(sector, "dxl"): … … 148 124 else: 149 125 dxw = None 150 new_plot = Data1D(x=(sector.x - math.pi) * 180 / math.pi,126 new_plot = Data1D(x=(sector.x - numpy.pi) * 180 / numpy.pi, 151 127 y=sector.y, dy=sector.dy) 152 128 new_plot.dxl = dxl 153 129 new_plot.dxw = dxw 154 new_plot.name = "AnnulusPhi" + "(" + self.base.data 2D.name + ")"155 156 new_plot.source = self.base.data2D.source 157 # new_plot.info=self.base.data2D.info130 new_plot.name = "AnnulusPhi" + "(" + self.base.data.name + ")" 131 new_plot.title = "AnnulusPhi" + "(" + self.base.data.name + ")" 132 133 new_plot.source = self.base.data.source 158 134 new_plot.interactive = True 159 new_plot.detector = self.base.data 2D.detector135 new_plot.detector = self.base.data.detector 160 136 # If the data file does not tell us what the axes are, just assume... 161 137 new_plot.xaxis("\\rm{\phi}", 'degrees') 162 138 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 163 139 if hasattr(data, "scale") and data.scale == 'linear' and \ 164 self.base.data 2D.name.count("Residuals") > 0:140 self.base.data.name.count("Residuals") > 0: 165 141 new_plot.ytransform = 'y' 166 142 new_plot.yaxis("\\rm{Residuals} ", "/") 167 143 168 new_plot.group_id = "AnnulusPhi" + self.base.data 2D.name169 new_plot.id = "AnnulusPhi" + self.base.data 2D.name144 new_plot.group_id = "AnnulusPhi" + self.base.data.name 145 new_plot.id = "AnnulusPhi" + self.base.data.name 170 146 new_plot.is_data = True 171 147 new_plot.xtransform = "x" 172 148 new_plot.ytransform = "y" 173 self.base.parent.update_theory(data_id=data.id, theory=new_plot) 174 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, title="AnnulusPhi")) 149 variant_plot = QtCore.QVariant(new_plot) 150 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 151 self.base.manager.communicator.plotUpdateSignal.emit([new_plot]) 152 153 if self.update_model: 154 self.setModelFromParams() 155 self.draw() 156 157 def validate(self, param_name, param_value): 158 """ 159 Test the proposed new value "value" for row "row" of parameters 160 """ 161 MIN_DIFFERENCE = 0.01 162 isValid = True 163 164 if param_name == 'inner_radius': 165 # First, check the closeness 166 if numpy.fabs(param_value - self.getParams()['outer_radius']) < MIN_DIFFERENCE: 167 print("Inner and outer radii too close. Please adjust.") 168 isValid = False 169 elif param_value > self.qmax: 170 print("Inner radius exceeds maximum range. Please adjust.") 171 isValid = False 172 elif param_name == 'outer_radius': 173 # First, check the closeness 174 if numpy.fabs(param_value - self.getParams()['inner_radius']) < MIN_DIFFERENCE: 175 print("Inner and outer radii too close. Please adjust.") 176 isValid = False 177 elif param_value > self.qmax: 178 print("Outer radius exceeds maximum range. Please adjust.") 179 isValid = False 180 elif param_name == 'nbins': 181 # Can't be 0 182 if param_value < 1: 183 print("Number of bins cannot be less than or equal to 0. Please adjust.") 184 isValid = False 185 186 return isValid 175 187 176 188 def moveend(self, ev): 177 189 """ 178 190 Called when any dragging motion ends. 179 Post an event (type =SlicerParameterEvent) 180 to plotter 2D with a copy slicer parameters 181 Call _post_data method 182 """ 183 self.base.thaw_axes() 184 # Post parameters to plotter 2D 185 event = SlicerParameterEvent() 186 event.type = self.__class__.__name__ 187 event.params = self.get_params() 188 wx.PostEvent(self.base, event) 191 Redraw the plot with new parameters. 192 """ 193 self._post_data(self.nbins) 189 194 190 195 def restore(self): … … 204 209 pass 205 210 206 def get _params(self):211 def getParams(self): 207 212 """ 208 213 Store a copy of values of parameters of the slicer into a dictionary. 209 210 214 :return params: the dictionary created 211 212 215 """ 213 216 params = {} 214 params["inner_radius"] = math.fabs(self.inner_circle._inner_mouse_x)215 params["outer_radius"] = math.fabs(self.outer_circle._inner_mouse_x)217 params["inner_radius"] = numpy.fabs(self.inner_circle._inner_mouse_x) 218 params["outer_radius"] = numpy.fabs(self.outer_circle._inner_mouse_x) 216 219 params["nbins"] = self.nbins 217 220 return params 218 221 219 def set _params(self, params):222 def setParams(self, params): 220 223 """ 221 224 Receive a dictionary and reset the slicer with values contained … … 224 227 :param params: a dictionary containing name of slicer parameters and 225 228 values the user assigned to the slicer. 226 227 """ 228 inner = math.fabs(params["inner_radius"]) 229 outer = math.fabs(params["outer_radius"]) 229 """ 230 inner = numpy.fabs(params["inner_radius"]) 231 outer = numpy.fabs(params["outer_radius"]) 230 232 self.nbins = int(params["nbins"]) 231 # #Update the picture233 # Update the picture 232 234 self.inner_circle.set_cursor(inner, self.inner_circle._inner_mouse_y) 233 235 self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 234 # #Post the data given the nbins entered by the user236 # Post the data given the nbins entered by the user 235 237 self._post_data(self.nbins) 236 237 def freeze_axes(self):238 """239 """240 self.base.freeze_axes()241 242 def thaw_axes(self):243 """244 """245 self.base.thaw_axes()246 238 247 239 def draw(self): … … 278 270 self.sign = sign 279 271 # # Create a marker 280 try: 281 # Inner circle marker 282 x_value = [self.sign * math.fabs(self._inner_mouse_x)] 283 self.inner_marker = self.axes.plot(x_value, [0], linestyle='', 284 marker='s', markersize=10, 285 color=self.color, alpha=0.6, 286 pickradius=5, label="pick", 287 zorder=zorder, 288 visible=True)[0] 289 except: 290 x_value = [self.sign * math.fabs(self._inner_mouse_x)] 291 self.inner_marker = self.axes.plot(x_value, [0], linestyle='', 292 marker='s', markersize=10, 293 color=self.color, alpha=0.6, 294 label="pick", 295 visible=True)[0] 296 message = "\nTHIS PROTOTYPE NEEDS THE LATEST" 297 message += " VERSION OF MATPLOTLIB\n" 298 message += "Get the SVN version that is at " 299 message += " least as recent as June 1, 2007" 300 301 owner = self.base.base.parent 302 wx.PostEvent(owner, StatusEvent(status="AnnulusSlicer: %s" % message)) 303 272 # Inner circle marker 273 x_value = [self.sign * numpy.fabs(self._inner_mouse_x)] 274 self.inner_marker = self.axes.plot(x_value, [0], linestyle='', 275 marker='s', markersize=10, 276 color=self.color, alpha=0.6, 277 pickradius=5, label="pick", 278 zorder=zorder, 279 visible=True)[0] 304 280 # Draw a circle 305 281 [self.inner_circle] = self.axes.plot([], [], linestyle='-', marker='', color=self.color) 306 # the number of points that make the ring line282 # The number of points that make the ring line 307 283 self.npts = 40 308 284 … … 325 301 """ 326 302 self.clear_markers() 327 try: 328 self.inner_marker.remove() 329 self.inner_circle.remove() 330 except: 331 # Old version of matplotlib 332 for item in range(len(self.axes.lines)): 333 del self.axes.lines[0] 303 self.inner_marker.remove() 304 self.inner_circle.remove() 334 305 335 306 def get_radius(self): … … 347 318 y = [] 348 319 for i in range(self.npts): 349 phi = 2.0 * math.pi / (self.npts - 1) * i350 351 xval = 1.0 * self._inner_mouse_x * math.cos(phi)352 yval = 1.0 * self._inner_mouse_x * math.sin(phi)320 phi = 2.0 * numpy.pi / (self.npts - 1) * i 321 322 xval = 1.0 * self._inner_mouse_x * numpy.cos(phi) 323 yval = 1.0 * self._inner_mouse_x * numpy.sin(phi) 353 324 354 325 x.append(xval) 355 326 y.append(yval) 356 327 357 self.inner_marker.set(xdata=[self.sign * math.fabs(self._inner_mouse_x)],328 self.inner_marker.set(xdata=[self.sign * numpy.fabs(self._inner_mouse_x)], 358 329 ydata=[0]) 359 330 self.inner_circle.set_data(x, y) … … 366 337 self._inner_save_x = self._inner_mouse_x 367 338 self._inner_save_y = self._inner_mouse_y 368 self.base.freeze_axes()369 339 370 340 def moveend(self, ev): … … 396 366 self.update() 397 367 398 399 def get_params(self): 368 def getParams(self): 400 369 """ 401 370 Store a copy of values of parameters of the slicer into a dictionary. 402 403 371 :return params: the dictionary created 404 405 372 """ 406 373 params = {} 407 params["radius"] = math.fabs(self._inner_mouse_x)374 params["radius"] = numpy.fabs(self._inner_mouse_x) 408 375 return params 409 376 410 def set _params(self, params):377 def setParams(self, params): 411 378 """ 412 379 Receive a dictionary and reset the slicer with values contained … … 435 402 self.base = base 436 403 self.is_inside = side 437 self.qmax = min( math.fabs(self.base.data.xmax),438 math.fabs(self.base.data.xmin)) # must be positive404 self.qmax = min(numpy.fabs(self.base.data.xmax), 405 numpy.fabs(self.base.data.xmin)) # must be positive 439 406 self.connect = self.base.connect 440 407 … … 448 415 self.sign = -1 449 416 # Inner circle 450 self.outer_circle = RingInteractor(self, self. base.subplot, 'blue',417 self.outer_circle = RingInteractor(self, self.axes, 'blue', 451 418 zorder=zorder + 1, r=self.qmax / 1.8, 452 419 sign=self.sign) … … 455 422 self._post_data() 456 423 457 # Bind to slice parameter events458 # self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS)459 460 def _onEVT_SLICER_PARS(self, event):461 """462 receive an event containing parameters values to reset the slicer463 464 :param event: event of type SlicerParameterEvent with params as465 attribute466 """467 wx.PostEvent(self.base,468 StatusEvent(status="AnnulusSlicer._onEVT_SLICER_PARS"))469 event.Skip()470 if event.type == self.__class__.__name__:471 self.set_params(event.params)472 self.base.update()473 474 424 def set_layer(self, n): 475 425 """ 476 426 Allow adding plot to the same panel 477 478 427 :param n: the number of layer 479 480 428 """ 481 429 self.layernum = n … … 489 437 self.outer_circle.clear() 490 438 self.base.connect.clearall() 491 # self.base.Unbind(EVT_SLICER_PARS)492 439 493 440 def update(self): … … 498 445 # Update locations 499 446 self.outer_circle.update() 500 # if self.is_inside is not None:447 self._post_data() 501 448 out = self._post_data() 502 449 return out … … 507 454 can restore on Esc. 508 455 """ 509 self.base.freeze_axes()510 456 self.outer_circle.save(ev) 511 457 … … 527 473 528 474 rmin = 0 529 rmax = math.fabs(self.outer_circle.get_radius())530 531 # # create the data1D Q average of data2D475 rmax = numpy.fabs(self.outer_circle.get_radius()) 476 477 # Create the data1D Q average of data2D 532 478 mask = Ringcut(r_min=rmin, r_max=rmax) 533 479 … … 536 482 else: 537 483 out = (mask(data)) 538 # self.base.data.mask=out539 484 return out 540 485 … … 566 511 pass 567 512 568 def get _params(self):513 def getParams(self): 569 514 """ 570 515 Store a copy of values of parameters of the slicer into a dictionary. … … 574 519 """ 575 520 params = {} 576 params["outer_radius"] = math.fabs(self.outer_circle._inner_mouse_x)521 params["outer_radius"] = numpy.fabs(self.outer_circle._inner_mouse_x) 577 522 return params 578 523 579 def set _params(self, params):524 def setParams(self, params): 580 525 """ 581 526 Receive a dictionary and reset the slicer with values contained … … 585 530 values the user assigned to the slicer. 586 531 """ 587 outer = math.fabs(params["outer_radius"])588 # #Update the picture532 outer = numpy.fabs(params["outer_radius"]) 533 # Update the picture 589 534 self.outer_circle.set_cursor(outer, self.outer_circle._inner_mouse_y) 590 # #Post the data given the nbins entered by the user535 # Post the data given the nbins entered by the user 591 536 self._post_data() 592 593 def freeze_axes(self):594 self.base.freeze_axes()595 596 def thaw_axes(self):597 self.base.thaw_axes()598 537 599 538 def draw(self): -
src/sas/sasgui/guiframe/local_perspectives/plotting/AzimutSlicer.py
rd85c194 r161713c 182 182 NewPlotEvent(plot=new_plot, title=str(new_sector.__name__))) 183 183 184 185 def validate(self, param_name, param_value): 186 """ 187 Test the proposed new value "value" for row "row" of parameters 188 """ 189 # Here, always return true 190 return True 191 184 192 def moveend(self, ev): 185 193 #TODO: why is this empty? -
src/sas/sasgui/guiframe/local_perspectives/plotting/boxSlicer.py
r7432acb r83eb5208 1 import wx 2 import math 3 import numpy as np 4 from sas.sasgui.guiframe.events import NewPlotEvent 5 from sas.sasgui.guiframe.events import StatusEvent 6 from sas.sasgui.guiframe.events import SlicerParameterEvent 7 from sas.sasgui.guiframe.events import EVT_SLICER_PARS 1 import numpy 2 from PyQt4 import QtGui 3 from PyQt4 import QtCore 4 8 5 from BaseInteractor import _BaseInteractor 9 6 from sas.sasgui.guiframe.dataFitting import Data1D 10 11 12 class BoxInteractor(_BaseInteractor): 7 import sas.qtgui.Utilities.GuiUtils as GuiUtils 8 from sas.qtgui.Plotting.SlicerModel import SlicerModel 9 10 11 class BoxInteractor(_BaseInteractor, SlicerModel): 13 12 """ 14 13 BoxInteractor define a rectangle that return data1D average of Data2D 15 14 in a rectangle area defined by -x, x ,y, -y 16 15 """ 17 def __init__(self, base, axes, color='black', zorder=3):16 def __init__(self, base, axes, item=None, color='black', zorder=3): 18 17 _BaseInteractor.__init__(self, base, axes, color=color) 19 # # Class initialization 18 SlicerModel.__init__(self) 19 # Class initialization 20 20 self.markers = [] 21 21 self.axes = axes 22 # #connecting artist 22 self._item = item 23 #connecting artist 23 24 self.connect = self.base.connect 24 # #which direction is the preferred interaction direction25 # which direction is the preferred interaction direction 25 26 self.direction = None 26 # #determine x y values27 self.x = 0.5 * min( math.fabs(self.base.data2D.xmax),28 math.fabs(self.base.data2D.xmin))29 self.y = 0.5 * min( math.fabs(self.base.data2D.xmax),30 math.fabs(self.base.data2D.xmin))31 # #when reach qmax reset the graph32 self.qmax = max(self.base.data 2D.xmax, self.base.data2D.xmin,33 self.base.data 2D.ymax, self.base.data2D.ymin)34 # #Number of points on the plot27 # determine x y values 28 self.x = 0.5 * min(numpy.fabs(self.base.data.xmax), 29 numpy.fabs(self.base.data.xmin)) 30 self.y = 0.5 * min(numpy.fabs(self.base.data.xmax), 31 numpy.fabs(self.base.data.xmin)) 32 # when reach qmax reset the graph 33 self.qmax = max(self.base.data.xmax, self.base.data.xmin, 34 self.base.data.ymax, self.base.data.ymin) 35 # Number of points on the plot 35 36 self.nbins = 30 36 # #If True, I(|Q|) will be return, otherwise,37 # If True, I(|Q|) will be return, otherwise, 37 38 # negative q-values are allowed 38 39 self.fold = True 39 # #reference of the current Slab averaging40 # reference of the current Slab averaging 40 41 self.averager = None 41 # #Create vertical and horizaontal lines for the rectangle42 # Create vertical and horizaontal lines for the rectangle 42 43 self.vertical_lines = VerticalLines(self, 43 self. base.subplot,44 self.axes, 44 45 color='blue', 45 46 zorder=zorder, … … 49 50 50 51 self.horizontal_lines = HorizontalLines(self, 51 self. base.subplot,52 self.axes, 52 53 color='green', 53 54 zorder=zorder, … … 55 56 y=self.y) 56 57 self.horizontal_lines.qmax = self.qmax 57 # #draw the rectangle and plost the data 1D resulting58 # #of averaging data2D58 # draw the rectangle and plost the data 1D resulting 59 # of averaging data2D 59 60 self.update() 60 61 self._post_data() 61 # # Bind to slice parameter events 62 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 63 64 def _onEVT_SLICER_PARS(self, event): 65 """ 66 receive an event containing parameters values to reset the slicer 67 68 :param event: event of type SlicerParameterEvent with params as 69 attribute 70 """ 71 wx.PostEvent(self.base.parent, 72 StatusEvent(status="BoxSlicer._onEVT_SLICER_PARS")) 73 event.Skip() 74 if event.type == self.__class__.__name__: 75 self.set_params(event.params) 76 self.base.update() 62 self.setModelFromParams() 77 63 78 64 def update_and_post(self): … … 102 88 self.vertical_lines.clear() 103 89 self.base.connect.clearall() 104 self.base.Unbind(EVT_SLICER_PARS)105 90 106 91 def update(self): … … 123 108 can restore on Esc. 124 109 """ 125 self.base.freeze_axes()126 110 self.vertical_lines.save(ev) 127 111 self.horizontal_lines.save(ev) … … 142 126 self.direction = direction 143 127 144 x_min = -1 * math.fabs(self.vertical_lines.x)145 x_max = math.fabs(self.vertical_lines.x)146 y_min = -1 * math.fabs(self.horizontal_lines.y)147 y_max = math.fabs(self.horizontal_lines.y)128 x_min = -1 * numpy.fabs(self.vertical_lines.x) 129 x_max = numpy.fabs(self.vertical_lines.x) 130 y_min = -1 * numpy.fabs(self.horizontal_lines.y) 131 y_max = numpy.fabs(self.horizontal_lines.y) 148 132 149 133 if nbins is not None: … … 158 142 x_low = 0 159 143 else: 160 x_low = math.fabs(x_min)144 x_low = numpy.fabs(x_min) 161 145 bin_width = (x_max + x_low) / self.nbins 162 146 elif self.direction == "Y": … … 164 148 y_low = 0 165 149 else: 166 y_low = math.fabs(y_min)150 y_low = numpy.fabs(y_min) 167 151 bin_width = (y_max + y_low) / self.nbins 168 152 else: … … 173 157 bin_width=bin_width) 174 158 box.fold = self.fold 175 boxavg = box(self.base.data 2D)159 boxavg = box(self.base.data) 176 160 # 3 Create Data1D to plot 177 161 if hasattr(boxavg, "dxl"): … … 187 171 new_plot.dxw = dxw 188 172 new_plot.name = str(self.averager.__name__) + \ 189 "(" + self.base.data2D.name + ")" 190 new_plot.source = self.base.data2D.source 173 "(" + self.base.data.name + ")" 174 new_plot.title = str(self.averager.__name__) + \ 175 "(" + self.base.data.name + ")" 176 new_plot.source = self.base.data.source 191 177 new_plot.interactive = True 192 new_plot.detector = self.base.data 2D.detector178 new_plot.detector = self.base.data.detector 193 179 # # If the data file does not tell us what the axes are, just assume... 194 180 new_plot.xaxis("\\rm{Q}", "A^{-1}") 195 181 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") 196 182 197 data = self.base.data 2D183 data = self.base.data 198 184 if hasattr(data, "scale") and data.scale == 'linear' and \ 199 self.base.data 2D.name.count("Residuals") > 0:185 self.base.data.name.count("Residuals") > 0: 200 186 new_plot.ytransform = 'y' 201 187 new_plot.yaxis("\\rm{Residuals} ", "/") 202 188 203 new_plot.group_id = "2daverage" + self.base.data 2D.name204 new_plot.id = (self.averager.__name__) + self.base.data 2D.name189 new_plot.group_id = "2daverage" + self.base.data.name 190 new_plot.id = (self.averager.__name__) + self.base.data.name 205 191 new_plot.is_data = True 206 self.base.parent.update_theory(data_id=self.base.data2D.id, \ 207 theory=new_plot) 208 wx.PostEvent(self.base.parent, 209 NewPlotEvent(plot=new_plot, title=str(self.averager.__name__))) 192 variant_plot = QtCore.QVariant(new_plot) 193 GuiUtils.updateModelItemWithPlot(self._item, variant_plot, new_plot.id) 194 195 if self.update_model: 196 self.setModelFromParams() 197 self.draw() 210 198 211 199 def moveend(self, ev): … … 215 203 corresponding to the new average 216 204 """ 217 self.base.thaw_axes()218 # Post paramters219 event = SlicerParameterEvent()220 event.type = self.__class__.__name__221 event.params = self.get_params()222 wx.PostEvent(self.base.parent, event)223 # create the new data1D224 205 self._post_data() 225 206 … … 240 221 pass 241 222 242 def get _params(self):223 def getParams(self): 243 224 """ 244 225 Store a copy of values of parameters of the slicer into a dictionary. … … 248 229 """ 249 230 params = {} 250 params["x_max"] = math.fabs(self.vertical_lines.x)251 params["y_max"] = math.fabs(self.horizontal_lines.y)231 params["x_max"] = numpy.fabs(self.vertical_lines.x) 232 params["y_max"] = numpy.fabs(self.horizontal_lines.y) 252 233 params["nbins"] = self.nbins 253 234 return params 254 235 255 def set _params(self, params):236 def setParams(self, params): 256 237 """ 257 238 Receive a dictionary and reset the slicer with values contained … … 261 242 values the user assigned to the slicer. 262 243 """ 263 self.x = float( math.fabs(params["x_max"]))264 self.y = float( math.fabs(params["y_max"]))244 self.x = float(numpy.fabs(params["x_max"])) 245 self.y = float(numpy.fabs(params["y_max"])) 265 246 self.nbins = params["nbins"] 266 247 … … 269 250 self.post_data(nbins=None) 270 251 271 def freeze_axes(self):272 """273 """274 self.base.freeze_axes()275 276 def thaw_axes(self):277 """278 """279 self.base.thaw_axes()280 281 252 def draw(self): 282 253 """ … … 294 265 """ 295 266 _BaseInteractor.__init__(self, base, axes, color=color) 296 # #Class initialization267 # Class initialization 297 268 self.markers = [] 298 269 self.axes = axes 299 # #Saving the end points of two lines270 # Saving the end points of two lines 300 271 self.x = x 301 272 self.save_x = x … … 303 274 self.y = y 304 275 self.save_y = y 305 # #Creating a marker276 # Creating a marker 306 277 # Inner circle marker 307 278 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', … … 311 282 zorder=zorder, 312 283 visible=True)[0] 313 # #Define 2 horizontal lines284 # Define 2 horizontal lines 314 285 self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 315 286 linestyle='-', marker='', … … 318 289 linestyle='-', marker='', 319 290 color=self.color, visible=True)[0] 320 # #Flag to check the motion of the lines291 # Flag to check the motion of the lines 321 292 self.has_move = False 322 # #Connecting markers to mouse events and draw293 # Connecting markers to mouse events and draw 323 294 self.connect_markers([self.top_line, self.inner_marker]) 324 295 self.update() … … 339 310 """ 340 311 self.clear_markers() 341 try: 342 self.inner_marker.remove() 343 self.top_line.remove() 344 self.bottom_line.remove() 345 except: 346 # Old version of matplotlib 347 for item in range(len(self.axes.lines)): 348 del self.axes.lines[0] 312 self.inner_marker.remove() 313 self.top_line.remove() 314 self.bottom_line.remove() 349 315 350 316 def update(self, x=None, y=None): … … 356 322 357 323 """ 358 # #Reset x, y- coordinates if send as parameters324 # Reset x, y- coordinates if send as parameters 359 325 if x is not None: 360 self.x = n p.sign(self.x) * math.fabs(x)326 self.x = numpy.sign(self.x) * numpy.fabs(x) 361 327 if y is not None: 362 self.y = n p.sign(self.y) * math.fabs(y)363 # #Draw lines and markers328 self.y = numpy.sign(self.y) * numpy.fabs(y) 329 # Draw lines and markers 364 330 self.inner_marker.set(xdata=[0], ydata=[self.y]) 365 331 self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) … … 373 339 self.save_x = self.x 374 340 self.save_y = self.y 375 self.base.freeze_axes()376 341 377 342 def moveend(self, ev): … … 409 374 self.markers = [] 410 375 self.axes = axes 411 self.x = math.fabs(x)376 self.x = numpy.fabs(x) 412 377 self.save_x = self.x 413 self.y = math.fabs(y)378 self.y = numpy.fabs(y) 414 379 self.save_y = y 415 380 # Inner circle marker … … 446 411 """ 447 412 self.clear_markers() 448 try: 449 self.inner_marker.remove() 450 self.left_line.remove() 451 self.right_line.remove() 452 except: 453 # Old version of matplotlib 454 for item in range(len(self.axes.lines)): 455 del self.axes.lines[0] 413 self.inner_marker.remove() 414 self.left_line.remove() 415 self.right_line.remove() 456 416 457 417 def update(self, x=None, y=None): … … 463 423 464 424 """ 465 # # reset x, y -coordinates if given as parameters425 # Reset x, y -coordinates if given as parameters 466 426 if x is not None: 467 self.x = n p.sign(self.x) * math.fabs(x)427 self.x = numpy.sign(self.x) * numpy.fabs(x) 468 428 if y is not None: 469 self.y = n p.sign(self.y) * math.fabs(y)470 # # draw lines and markers429 self.y = numpy.sign(self.y) * numpy.fabs(y) 430 # Draw lines and markers 471 431 self.inner_marker.set(xdata=[self.x], ydata=[0]) 472 432 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) … … 480 440 self.save_x = self.x 481 441 self.save_y = self.y 482 self.base.freeze_axes()483 442 484 443 def moveend(self, ev): … … 510 469 Average in Qx direction 511 470 """ 512 def __init__(self, base, axes, color='black', zorder=3):513 BoxInteractor.__init__(self, base, axes, color=color)471 def __init__(self, base, axes, item=None, color='black', zorder=3): 472 BoxInteractor.__init__(self, base, axes, item=item, color=color) 514 473 self.base = base 515 474 self._post_data() … … 527 486 Average in Qy direction 528 487 """ 529 def __init__(self, base, axes, color='black', zorder=3):530 BoxInteractor.__init__(self, base, axes, color=color)488 def __init__(self, base, axes, item=None, color='black', zorder=3): 489 BoxInteractor.__init__(self, base, axes, item=item, color=color) 531 490 self.base = base 532 491 self._post_data()
Note: See TracChangeset
for help on using the changeset viewer.