- Timestamp:
- Mar 5, 2015 2:49:03 PM (10 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 7d56795
- Parents:
- 824e488
- Location:
- src/sas/guiframe/local_perspectives/plotting
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sas/guiframe/local_perspectives/plotting/Edge.py
r79492222 rb5de88e 1 import math 2 from BaseInteractor import _BaseInteractor 1 3 2 import math3 #import wx4 #from copy import deepcopy5 from BaseInteractor import _BaseInteractor6 #from sas.guiframe.events import NewPlotEvent7 #from sas.guiframe.events import StatusEvent8 #from sas.guiframe.events import SlicerParameterEvent9 #from sas.guiframe.events import EVT_SLICER_PARS10 11 4 12 5 class RadiusInteractor(_BaseInteractor): … … 15 8 """ 16 9 def __init__(self, base, axes, color='black', zorder=5, arc1=None, 17 arc2=None, theta=math.pi /8):10 arc2=None, theta=math.pi / 8): 18 11 """ 19 12 """ … … 23 16 self.r1 = arc1.get_radius() 24 17 self.r2 = arc2.get_radius() 25 #print "radius init", self.r1, self.r226 18 self.theta = theta 27 19 self.save_theta = theta 28 #self.scale = 10.029 20 self.move_stop = False 30 21 self.theta_left = None … … 32 23 self.arc1 = arc1 33 24 self.arc2 = arc2 34 #raise "Version error", message35 25 x1 = self.r1 * math.cos(self.theta) 36 26 y1 = self.r1 * math.sin(self.theta) … … 38 28 y2 = self.r2 * math.sin(self.theta) 39 29 self.line = self.axes.plot([x1, x2], [y1, y2], 40 41 42 30 linestyle='-', marker='', 31 color=self.color, 32 visible=True)[0] 43 33 self.phi = theta 44 34 self.npts = 20 … … 46 36 self.connect_markers([self.line]) 47 37 self.update() 48 38 49 39 def set_layer(self, n): 50 40 """ … … 52 42 self.layernum = n 53 43 self.update() 54 44 55 45 def clear(self): 56 46 """ … … 63 53 for item in range(len(self.axes.lines)): 64 54 del self.axes.lines[0] 65 55 66 56 def get_angle(self): 67 57 """ 68 58 """ 69 59 return self.theta 70 60 71 61 def update(self, r1=None, r2=None, theta=None): 72 62 """ … … 79 69 if theta != None: 80 70 self.theta = theta 81 #print "in the edge r1, r2",self.r1,self.r2,math.degrees(self.theta)82 71 x1 = self.r1 * math.cos(self.theta) 83 72 y1 = self.r1 * math.sin(self.theta) 84 73 x2 = self.r2 * math.cos(self.theta) 85 y2 = self.r2 * math.sin(self.theta) 74 y2 = self.r2 * math.sin(self.theta) 86 75 self.line.set(xdata=[x1, x2], ydata=[y1, y2]) 87 76 88 77 def save(self, ev): 89 78 """ … … 91 80 can restore on Esc. 92 81 """ 93 self.save_theta = math.atan2(ev.y,ev.x) 94 #self.save_theta= self.theta 82 self.save_theta = math.atan2(ev.y, ev.x) 95 83 self.base.freeze_axes() 96 84 97 85 def moveend(self, ev): 98 86 """ … … 100 88 self.has_move = False 101 89 self.base.moveend(ev) 102 90 103 91 def restore(self, ev): 104 92 """ … … 114 102 self.has_move = True 115 103 self.base.base.update() 116 104 117 105 def set_cursor(self, r_min, r_max, theta): 118 106 """ … … 122 110 self.r2 = r_max 123 111 self.update() 124 112 125 113 def get_params(self): 126 114 """ … … 131 119 params["theta"] = self.theta 132 120 return params 133 121 134 122 def set_params(self, params): 135 123 """ 136 124 """ 137 #print "when here set curcor arc" 138 x1 = params["radius1"] 139 x2 = params["radius2"] 140 theta= params["theta"] 125 x1 = params["radius1"] 126 x2 = params["radius2"] 127 theta = params["theta"] 141 128 self.set_cursor(x1, x2, theta) 142 143 -
src/sas/guiframe/local_perspectives/plotting/boxMask.py
r79492222 rb5de88e 1 2 3 4 1 import math 5 #import wx6 #from copy import deepcopy7 2 from BaseInteractor import _BaseInteractor 8 3 from boxSum import PointInteractor 9 4 from boxSum import VerticalDoubleLine 10 5 from boxSum import HorizontalDoubleLine 11 #from sas.guiframe.events import SlicerParamUpdateEvent12 6 13 7 … … 15 9 """ 16 10 BoxMask Class: determine 2 rectangular area to find the pixel of 17 a Data inside of box. 18 11 a Data inside of box. 12 19 13 Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 20 14 21 15 :param zorder: Artists with lower zorder values are drawn first. 22 16 :param x_min: the minimum value of the x coordinate … … 26 20 27 21 """ 28 def __init__(self, base, axes, color='black', zorder=3, side=None, 29 22 def __init__(self, base, axes, color='black', zorder=3, side=None, 23 x_min=0.008, x_max=0.008, y_min=0.0025, y_max=0.0025): 30 24 """ 31 25 """ 32 26 _BaseInteractor.__init__(self, base, axes, color=color) 33 # # class initialization34 # # list of Boxmask markers27 # # class initialization 28 # # list of Boxmask markers 35 29 self.markers = [] 36 30 self.axes = axes 37 31 self.mask = None 38 32 self.is_inside = side 39 # # connect the artist for the motion33 # # connect the artist for the motion 40 34 self.connect = self.base.connect 41 # # when qmax is reached the selected line is reset42 # the its previous value35 # # when qmax is reached the selected line is reset 36 # the its previous value 43 37 self.qmax = min(self.base.data.xmax, self.base.data.xmin) 44 # # Define the box limits38 # # Define the box limits 45 39 self.xmin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 46 math.fabs(self.base.data.xmin))40 math.fabs(self.base.data.xmin)) 47 41 self.ymin = -1 * 0.5 * min(math.fabs(self.base.data.xmax), 48 42 math.fabs(self.base.data.xmin)) 49 43 self.xmax = 0.5 * min(math.fabs(self.base.data.xmax), 50 44 math.fabs(self.base.data.xmin)) 51 self.ymax = 52 53 # # center of the box45 self.ymax = 0.5 * min(math.fabs(self.base.data.xmax), 46 math.fabs(self.base.data.xmin)) 47 # # center of the box 54 48 self.center_x = 0.0002 55 49 self.center_y = 0.0003 56 # # Number of points on the plot50 # # Number of points on the plot 57 51 self.nbins = 20 58 # # Define initial result the summation52 # # Define initial result the summation 59 53 self.count = 0 60 54 self.error = 0 61 55 self.data = self.base.data 62 # # Flag to determine if the current figure has moved63 # # set to False == no motion , set to True== motion56 # # Flag to determine if the current figure has moved 57 # # set to False == no motion , set to True== motion 64 58 self.has_move = False 65 # # Create Box edges59 # # Create Box edges 66 60 self.horizontal_lines = HorizontalDoubleLine(self, 67 61 self.base.subplot, 68 62 color='blue', 69 70 71 72 73 63 zorder=zorder, 64 y=self.ymax, 65 x=self.xmax, 66 center_x=self.center_x, 67 center_y=self.center_y) 74 68 self.horizontal_lines.qmax = self.qmax 75 69 76 70 self.vertical_lines = VerticalDoubleLine(self, 77 self.base.subplot,78 color='grey',79 zorder=zorder,80 y=self.ymax,81 x=self.xmax,82 center_x=self.center_x,83 center_y=self.center_y)71 self.base.subplot, 72 color='grey', 73 zorder=zorder, 74 y=self.ymax, 75 x=self.xmax, 76 center_x=self.center_x, 77 center_y=self.center_y) 84 78 self.vertical_lines.qmax = self.qmax 85 79 86 80 self.center = PointInteractor(self, 87 self.base.subplot, color='grey',88 zorder=zorder,89 center_x=self.center_x,90 center_y=self.center_y)91 # # Save the name of the slicer panel associate with this slicer92 self.panel_name = "" 93 # # Update and post slicer parameters81 self.base.subplot, color='grey', 82 zorder=zorder, 83 center_x=self.center_x, 84 center_y=self.center_y) 85 # # Save the name of the slicer panel associate with this slicer 86 self.panel_name = "" 87 # # Update and post slicer parameters 94 88 self.update() 95 89 self._post_data() 96 90 97 91 def clear(self): 98 92 """ … … 104 98 self.center.clear() 105 99 self.base.connect.clearall() 106 #self.base.Unbind(EVT_SLICER_PARS) 107 100 108 101 def update(self): 109 102 """ … … 111 104 resetting the widgets. 112 105 """ 113 # check if the center point has moved and update the figure accordingly 106 # check if the center point has moved and update the figure accordingly 114 107 if self.center.has_move: 115 108 self.center.update() 116 109 self.horizontal_lines.update(center=self.center) 117 110 self.vertical_lines.update(center=self.center) 118 # # check if the horizontal lines have moved and update119 # the figure accordingly 111 # # check if the horizontal lines have moved and update 112 # the figure accordingly 120 113 if self.horizontal_lines.has_move: 121 114 self.horizontal_lines.update() … … 123 116 y2=self.horizontal_lines.y2, 124 117 height=self.horizontal_lines.half_height) 125 # # check if the vertical lines have moved and update126 # the figure accordingly 118 # # check if the vertical lines have moved and update 119 # the figure accordingly 127 120 if self.vertical_lines.has_move: 128 121 self.vertical_lines.update() … … 130 123 x2=self.vertical_lines.x2, 131 124 width=self.vertical_lines.half_width) 132 # if self.is_inside != None:125 # if self.is_inside != None: 133 126 out = self._post_data() 134 127 return out 135 128 136 129 def save(self, ev): 137 130 """ … … 143 136 self.vertical_lines.save(ev) 144 137 self.center.save(ev) 145 138 146 139 def _post_data(self): 147 140 """ … … 150 143 """ 151 144 from sas.dataloader.manipulations import Boxcut 152 # # Data 2D for which the pixel will be summed145 # # Data 2D for which the pixel will be summed 153 146 data = self.base.data 154 147 mask = data.mask 155 # # the region of the summation156 x_min = self.horizontal_lines.x2 157 x_max = self.horizontal_lines.x1 148 # # the region of the summation 149 x_min = self.horizontal_lines.x2 150 x_max = self.horizontal_lines.x1 158 151 y_min = self.vertical_lines.y2 159 152 y_max = self.vertical_lines.y1 … … 164 157 else: 165 158 out = (mask(data)) 166 # self.base.data.mask=out159 # self.base.data.mask=out 167 160 self.mask = mask 168 return out 169 161 return out 162 170 163 def moveend(self, ev): 171 164 """ 172 165 After a dragging motion this function is called to compute 173 the error and the sum of pixel of a given data 2D 166 the error and the sum of pixel of a given data 2D 174 167 """ 175 168 self.base.thaw_axes() 176 # # post169 # # post 177 170 self._post_data() 178 171 179 172 def restore(self): 180 173 """ … … 184 177 self.vertical_lines.restore() 185 178 self.center.restore() 186 179 187 180 def move(self, x, y, ev): 188 181 """ … … 190 183 """ 191 184 pass 192 185 193 186 def set_cursor(self, x, y): 194 187 pass 195 188 196 189 def get_params(self): 197 190 """ 198 191 Store a copy of values of parameters of the slicer into a dictionary. 199 192 200 193 :return params: the dictionary created 201 194 202 195 """ 203 196 params = {} 204 197 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 205 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 198 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 206 199 params["center_x"] = self.center.x 207 200 params["center_y"] = self.center.y 208 201 return params 209 202 210 203 def get_mask(self): 211 204 """ … … 214 207 mask = self.mask 215 208 return mask 216 209 217 210 def set_params(self, params): 218 211 """ 219 Receive a dictionary and reset the slicer with values contained 212 Receive a dictionary and reset the slicer with values contained 220 213 in the values of the dictionary. 221 222 :param params: a dictionary containing name of slicer parameters and 214 215 :param params: a dictionary containing name of slicer parameters and 223 216 values the user assigned to the slicer. 224 217 """ 225 x_max = math.fabs(params["Width"] )/2226 y_max = math.fabs(params["Height"]) /2227 228 self.center_x = params["center_x"] 218 x_max = math.fabs(params["Width"]) / 2 219 y_max = math.fabs(params["Height"]) / 2 220 221 self.center_x = params["center_x"] 229 222 self.center_y = params["center_y"] 230 # update the slicer given values of params223 # update the slicer given values of params 231 224 self.center.update(center_x=self.center_x, center_y=self.center_y) 232 self.horizontal_lines.update(center=self.center, 233 width=x_max, 234 height=y_max) 235 self.vertical_lines.update(center=self.center, 236 width=x_max, 237 height=y_max) 238 #compute the new error and sum given values of params 225 self.horizontal_lines.update(center=self.center, width=x_max, height=y_max) 226 self.vertical_lines.update(center=self.center, width=x_max, height=y_max) 227 # compute the new error and sum given values of params 239 228 self._post_data() 240 229 241 230 def freeze_axes(self): 242 231 self.base.freeze_axes() 243 232 244 233 def thaw_axes(self): 245 234 self.base.thaw_axes() … … 248 237 self.base.update() 249 238 250 class inner_BoxMask(BoxMask): 251 def __call__(self): 252 self.base.data.mask = (self._post_data()==False) 253 254 239 class inner_BoxMask(BoxMask): 240 def __call__(self): 241 self.base.data.mask = (self._post_data() == False) -
src/sas/guiframe/local_perspectives/plotting/boxSlicer.py
r79492222 rb5de88e 1 2 3 1 import wx 4 #import copy5 #from copy import deepcopy6 2 import math 7 3 import numpy … … 12 8 from BaseInteractor import _BaseInteractor 13 9 from sas.guiframe.dataFitting import Data1D 14 #import SlicerParameters15 10 16 11 … … 22 17 def __init__(self, base, axes, color='black', zorder=3): 23 18 _BaseInteractor.__init__(self, base, axes, color=color) 24 # # Class initialization19 # # Class initialization 25 20 self.markers = [] 26 21 self.axes = axes 27 # #connecting artist22 # #connecting artist 28 23 self.connect = self.base.connect 29 # # which direction is the preferred interaction direction24 # # which direction is the preferred interaction direction 30 25 self.direction = None 31 # # determine x y values26 # # determine x y values 32 27 self.x = 0.5 * min(math.fabs(self.base.data2D.xmax), 33 28 math.fabs(self.base.data2D.xmin)) 34 29 self.y = 0.5 * min(math.fabs(self.base.data2D.xmax), 35 math.fabs(self.base.data2D.xmin)) 36 # # when reach qmax reset the graph30 math.fabs(self.base.data2D.xmin)) 31 # # when reach qmax reset the graph 37 32 self.qmax = max(self.base.data2D.xmax, self.base.data2D.xmin, 38 self.base.data2D.ymax, self.base.data2D.ymin) 39 # # Number of points on the plot33 self.base.data2D.ymax, self.base.data2D.ymin) 34 # # Number of points on the plot 40 35 self.nbins = 30 41 # # If True, I(|Q|) will be return, otherwise,42 # negative q-values are allowed43 self.fold = True 44 # # reference of the current Slab averaging36 # # If True, I(|Q|) will be return, otherwise, 37 # negative q-values are allowed 38 self.fold = True 39 # # reference of the current Slab averaging 45 40 self.averager = None 46 # # Create vertical and horizaontal lines for the rectangle41 # # Create vertical and horizaontal lines for the rectangle 47 42 self.vertical_lines = VerticalLines(self, 48 self.base.subplot, 49 color='blue', 43 self.base.subplot, 44 color='blue', 50 45 zorder=zorder, 51 y=self.y 46 y=self.y, 52 47 x=self.x) 53 48 self.vertical_lines.qmax = self.qmax 54 49 55 50 self.horizontal_lines = HorizontalLines(self, 56 self.base.subplot,57 color='green',58 zorder=zorder,59 x=self.x,60 y=self.y)51 self.base.subplot, 52 color='green', 53 zorder=zorder, 54 x=self.x, 55 y=self.y) 61 56 self.horizontal_lines.qmax = self.qmax 62 # # draw the rectangle and plost the data 1D resulting63 # # of averaging data2D57 # # draw the rectangle and plost the data 1D resulting 58 # # of averaging data2D 64 59 self.update() 65 60 self._post_data() 66 # # Bind to slice parameter events61 # # Bind to slice parameter events 67 62 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 68 63 … … 70 65 """ 71 66 receive an event containing parameters values to reset the slicer 72 73 :param event: event of type SlicerParameterEvent with params as 67 68 :param event: event of type SlicerParameterEvent with params as 74 69 attribute 75 70 """ … … 80 75 self.set_params(event.params) 81 76 self.base.update() 82 77 83 78 def update_and_post(self): 84 79 """ … … 87 82 self.update() 88 83 self._post_data() 89 84 90 85 def set_layer(self, n): 91 86 """ 92 87 Allow adding plot to the same panel 93 88 94 89 :param n: the number of layer 95 90 96 91 """ 97 92 self.layernum = n 98 93 self.update() 99 94 100 95 def clear(self): 101 96 """ … … 108 103 self.base.connect.clearall() 109 104 self.base.Unbind(EVT_SLICER_PARS) 110 105 111 106 def update(self): 112 107 """ … … 114 109 resetting the widgets. 115 110 """ 116 # #Update the slicer if an horizontal line is dragged111 # #Update the slicer if an horizontal line is dragged 117 112 if self.horizontal_lines.has_move: 118 113 self.horizontal_lines.update() 119 114 self.vertical_lines.update(y=self.horizontal_lines.y) 120 # #Update the slicer if a vertical line is dragged115 # #Update the slicer if a vertical line is dragged 121 116 if self.vertical_lines.has_move: 122 117 self.vertical_lines.update() 123 118 self.horizontal_lines.update(x=self.vertical_lines.x) 124 119 125 120 def save(self, ev): 126 121 """ … … 131 126 self.vertical_lines.save(ev) 132 127 self.horizontal_lines.save(ev) 133 128 134 129 def _post_data(self): 135 130 pass 136 131 137 132 def post_data(self, new_slab=None, nbins=None, direction=None): 138 133 """ 139 134 post data averaging in Qx or Qy given new_slab type 140 135 141 136 :param new_slab: slicer that determine with direction to average 142 137 :param nbins: the number of points plotted when averaging 143 138 :param direction: the direction of averaging 144 139 145 140 """ 146 141 if self.direction == None: 147 142 self.direction = direction 148 143 149 144 x_min = -1 * math.fabs(self.vertical_lines.x) 150 145 x_max = math.fabs(self.vertical_lines.x) 151 146 y_min = -1 * math.fabs(self.horizontal_lines.y) 152 147 y_max = math.fabs(self.horizontal_lines.y) 153 148 154 149 if nbins != None: 155 150 self.nbins = nbins … … 164 159 else: 165 160 x_low = math.fabs(x_min) 166 bin_width = (x_max + x_low) /self.nbins161 bin_width = (x_max + x_low) / self.nbins 167 162 elif self.direction == "Y": 168 163 if self.fold: … … 170 165 else: 171 166 y_low = math.fabs(y_min) 172 bin_width = (y_max + y_low) /self.nbins167 bin_width = (y_max + y_low) / self.nbins 173 168 else: 174 169 msg = "post data:no Box Average direction was supplied" 175 170 raise ValueError, msg 176 # # Average data2D given Qx or Qy171 # # Average data2D given Qx or Qy 177 172 box = self.averager(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max, 178 bin_width=bin_width)173 bin_width=bin_width) 179 174 box.fold = self.fold 180 175 boxavg = box(self.base.data2D) 181 # 3 Create Data1D to plot176 # 3 Create Data1D to plot 182 177 if hasattr(boxavg, "dxl"): 183 178 dxl = boxavg.dxl … … 189 184 dxw = None 190 185 new_plot = Data1D(x=boxavg.x, y=boxavg.y, dy=boxavg.dy) 191 new_plot.dxl 192 new_plot.dxw 186 new_plot.dxl = dxl 187 new_plot.dxw = dxw 193 188 new_plot.name = str(self.averager.__name__) + \ 194 189 "(" + self.base.data2D.name + ")" … … 196 191 new_plot.interactive = True 197 192 new_plot.detector = self.base.data2D.detector 198 # # If the data file does not tell us what the axes are, just assume...193 # # If the data file does not tell us what the axes are, just assume... 199 194 new_plot.xaxis("\\rm{Q}", "A^{-1}") 200 195 new_plot.yaxis("\\rm{Intensity} ", "cm^{-1}") … … 205 200 new_plot.ytransform = 'y' 206 201 new_plot.yaxis("\\rm{Residuals} ", "/") 207 202 208 203 new_plot.group_id = "2daverage" + self.base.data2D.name 209 204 new_plot.id = (self.averager.__name__) + self.base.data2D.name 210 new_plot.is_data = True205 new_plot.is_data = True 211 206 self.base.parent.update_theory(data_id=self.base.data2D.id, \ 212 207 theory=new_plot) 213 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot,214 215 208 wx.PostEvent(self.base.parent, 209 NewPlotEvent(plot=new_plot, title=str(self.averager.__name__))) 210 216 211 def moveend(self, ev): 217 212 """ 218 213 Called after a dragging event. 219 Post the slicer new parameters and creates a new Data1D 214 Post the slicer new parameters and creates a new Data1D 220 215 corresponding to the new average 221 216 """ … … 228 223 # create the new data1D 229 224 self._post_data() 230 225 231 226 def restore(self): 232 227 """ … … 235 230 self.horizontal_lines.restore() 236 231 self.vertical_lines.restore() 237 232 238 233 def move(self, x, y, ev): 239 234 """ … … 241 236 """ 242 237 pass 243 238 244 239 def set_cursor(self, x, y): 245 240 pass 246 241 247 242 def get_params(self): 248 243 """ 249 244 Store a copy of values of parameters of the slicer into a dictionary. 250 245 251 246 :return params: the dictionary created 252 247 253 248 """ 254 249 params = {} … … 257 252 params["nbins"] = self.nbins 258 253 return params 259 254 260 255 def set_params(self, params): 261 256 """ 262 Receive a dictionary and reset the slicer with values contained 257 Receive a dictionary and reset the slicer with values contained 263 258 in the values of the dictionary. 264 265 :param params: a dictionary containing name of slicer parameters and 259 260 :param params: a dictionary containing name of slicer parameters and 266 261 values the user assigned to the slicer. 267 262 """ 268 263 self.x = float(math.fabs(params["x_max"])) 269 self.y = float(math.fabs(params["y_max"] 264 self.y = float(math.fabs(params["y_max"])) 270 265 self.nbins = params["nbins"] 271 266 272 267 self.horizontal_lines.update(x=self.x, y=self.y) 273 268 self.vertical_lines.update(x=self.x, y=self.y) 274 269 self.post_data(nbins=None) 275 270 276 271 def freeze_axes(self): 277 272 """ 278 273 """ 279 274 self.base.freeze_axes() 280 275 281 276 def thaw_axes(self): 282 277 """ … … 292 287 class HorizontalLines(_BaseInteractor): 293 288 """ 294 Draw 2 Horizontal lines centered on (0,0) that can move 289 Draw 2 Horizontal lines centered on (0,0) that can move 295 290 on the x- direction and in opposite direction 296 291 """ … … 299 294 """ 300 295 _BaseInteractor.__init__(self, base, axes, color=color) 301 # #Class initialization296 # #Class initialization 302 297 self.markers = [] 303 298 self.axes = axes 304 # # Saving the end points of two lines299 # # Saving the end points of two lines 305 300 self.x = x 306 301 self.save_x = x 307 302 308 303 self.y = y 309 304 self.save_y = y 310 ## Creating a marker 311 try: 312 # Inner circle marker 313 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 314 marker='s', markersize=10, 315 color=self.color, alpha=0.6, 316 pickradius=5, label="pick", 317 # Prefer this to other lines 318 zorder=zorder, 319 visible=True)[0] 320 except: 321 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 322 marker='s', markersize=10, 323 color=self.color, alpha=0.6, 324 label="pick", visible=True)[0] 325 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 326 message += "OF MATPLOTLIB\n Get the SVN version that" 327 message += " is at least as recent as June 1, 2007" 328 owner = self.base.base.parent 329 wx.PostEvent(owner, 330 StatusEvent(status="AnnulusSlicer: %s" % message)) 331 ## Define 2 horizontal lines 305 # # Creating a marker 306 # Inner circle marker 307 self.inner_marker = self.axes.plot([0], [self.y], linestyle='', 308 marker='s', markersize=10, 309 color=self.color, alpha=0.6, 310 pickradius=5, label="pick", 311 zorder=zorder, 312 visible=True)[0] 313 # # Define 2 horizontal lines 332 314 self.top_line = self.axes.plot([self.x, -self.x], [self.y, self.y], 333 linestyle='-', marker='',334 color=self.color, visible=True)[0]315 linestyle='-', marker='', 316 color=self.color, visible=True)[0] 335 317 self.bottom_line = self.axes.plot([self.x, -self.x], [-self.y, -self.y], 336 linestyle='-', marker='',337 color=self.color, visible=True)[0]338 # # Flag to check the motion of the lines318 linestyle='-', marker='', 319 color=self.color, visible=True)[0] 320 # # Flag to check the motion of the lines 339 321 self.has_move = False 340 # # Connecting markers to mouse events and draw322 # # Connecting markers to mouse events and draw 341 323 self.connect_markers([self.top_line, self.inner_marker]) 342 324 self.update() … … 345 327 """ 346 328 Allow adding plot to the same panel 347 329 348 330 :param n: the number of layer 349 331 350 332 """ 351 333 self.layernum = n 352 334 self.update() 353 335 354 336 def clear(self): 355 337 """ … … 359 341 try: 360 342 self.inner_marker.remove() 361 self.top_line.remove() 343 self.top_line.remove() 362 344 self.bottom_line.remove() 363 345 except: … … 365 347 for item in range(len(self.axes.lines)): 366 348 del self.axes.lines[0] 367 349 368 350 def update(self, x=None, y=None): 369 351 """ 370 352 Draw the new roughness on the graph. 371 353 372 354 :param x: x-coordinates to reset current class x 373 355 :param y: y-coordinates to reset current class y 374 375 """ 376 # # Reset x, y- coordinates if send as parameters356 357 """ 358 # # Reset x, y- coordinates if send as parameters 377 359 if x != None: 378 360 self.x = numpy.sign(self.x) * math.fabs(x) 379 361 if y != None: 380 362 self.y = numpy.sign(self.y) * math.fabs(y) 381 # # Draw lines and markers363 # # Draw lines and markers 382 364 self.inner_marker.set(xdata=[0], ydata=[self.y]) 383 365 self.top_line.set(xdata=[self.x, -self.x], ydata=[self.y, self.y]) 384 self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y])385 366 self.bottom_line.set(xdata=[self.x, -self.x], ydata=[-self.y, -self.y]) 367 386 368 def save(self, ev): 387 369 """ … … 400 382 self.has_move = False 401 383 self.base.moveend(ev) 402 384 403 385 def restore(self): 404 386 """ … … 407 389 self.x = self.save_x 408 390 self.y = self.save_y 409 391 410 392 def move(self, x, y, ev): 411 393 """ … … 415 397 self.has_move = True 416 398 self.base.base.update() 417 418 399 400 419 401 class VerticalLines(_BaseInteractor): 420 402 """ … … 431 413 self.y = math.fabs(y) 432 414 self.save_y = y 433 try: 434 # Inner circle marker 435 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 436 marker='s', markersize=10, 437 color=self.color, alpha=0.6, 438 pickradius=5, label="pick", 439 # Prefer this to other lines 440 zorder=zorder, visible=True)[0] 441 except: 442 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 443 marker='s', markersize=10, 444 color=self.color, alpha=0.6, 445 label="pick", visible=True)[0] 446 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 447 message += " OF MATPLOTLIB\n Get the SVN version that is" 448 message += " at least as recent as June 1, 2007" 449 415 # Inner circle marker 416 self.inner_marker = self.axes.plot([self.x], [0], linestyle='', 417 marker='s', markersize=10, 418 color=self.color, alpha=0.6, 419 pickradius=5, label="pick", 420 zorder=zorder, visible=True)[0] 450 421 self.right_line = self.axes.plot([self.x, self.x], 451 [self.y 452 linestyle='-', marker='',453 color=self.color, visible=True)[0]422 [self.y, -self.y], 423 linestyle='-', marker='', 424 color=self.color, visible=True)[0] 454 425 self.left_line = self.axes.plot([-self.x, -self.x], 455 426 [self.y, -self.y], 456 linestyle='-', marker='',457 color=self.color, visible=True)[0]427 linestyle='-', marker='', 428 color=self.color, visible=True)[0] 458 429 self.has_move = False 459 430 self.connect_markers([self.right_line, self.inner_marker]) … … 463 434 """ 464 435 Allow adding plot to the same panel 465 436 466 437 :param n: the number of layer 467 438 468 439 """ 469 440 self.layernum = n 470 441 self.update() 471 442 472 443 def clear(self): 473 444 """ … … 487 458 """ 488 459 Draw the new roughness on the graph. 489 460 490 461 :param x: x-coordinates to reset current class x 491 462 :param y: y-coordinates to reset current class y 492 493 """ 494 # # reset x, y -coordinates if given as parameters463 464 """ 465 # # reset x, y -coordinates if given as parameters 495 466 if x != None: 496 467 self.x = numpy.sign(self.x) * math.fabs(x) 497 468 if y != None: 498 469 self.y = numpy.sign(self.y) * math.fabs(y) 499 # # draw lines and markers500 self.inner_marker.set(xdata=[self.x], ydata=[0]) 501 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 502 self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 503 470 # # draw lines and markers 471 self.inner_marker.set(xdata=[self.x], ydata=[0]) 472 self.left_line.set(xdata=[-self.x, -self.x], ydata=[self.y, -self.y]) 473 self.right_line.set(xdata=[self.x, self.x], ydata=[self.y, -self.y]) 474 504 475 def save(self, ev): 505 476 """ … … 510 481 self.save_y = self.y 511 482 self.base.freeze_axes() 512 483 513 484 def moveend(self, ev): 514 485 """ … … 518 489 self.has_move = False 519 490 self.base.moveend(ev) 520 491 521 492 def restore(self): 522 493 """ … … 525 496 self.x = self.save_x 526 497 self.y = self.save_y 527 498 528 499 def move(self, x, y, ev): 529 500 """ … … 533 504 self.x = x 534 505 self.base.base.update() 535 536 506 507 537 508 class BoxInteractorX(BoxInteractor): 538 509 """ … … 543 514 self.base = base 544 515 self._post_data() 545 516 546 517 def _post_data(self): 547 518 """ … … 549 520 """ 550 521 from sas.dataloader.manipulations import SlabX 551 self.post_data(SlabX, direction="X") 552 522 self.post_data(SlabX, direction="X") 523 553 524 554 525 class BoxInteractorY(BoxInteractor): … … 560 531 self.base = base 561 532 self._post_data() 562 533 563 534 def _post_data(self): 564 535 """ … … 566 537 """ 567 538 from sas.dataloader.manipulations import SlabY 568 self.post_data(SlabY, direction="Y") 569 570 539 self.post_data(SlabY, direction="Y") 540 -
src/sas/guiframe/local_perspectives/plotting/boxSum.py
r79492222 rb5de88e 1 1 """ 2 Boxsum Class: determine 2 rectangular area to compute 3 the sum of pixel of a Data. 2 Boxsum Class: determine 2 rectangular area to compute 3 the sum of pixel of a Data. 4 4 """ 5 5 import math … … 13 13 class BoxSum(_BaseInteractor): 14 14 """ 15 Boxsum Class: determine 2 rectangular area to compute 16 the sum of pixel of a Data. 15 Boxsum Class: determine 2 rectangular area to compute 16 the sum of pixel of a Data. 17 17 Uses PointerInteractor , VerticalDoubleLine,HorizontalDoubleLine. 18 18 @param zorder: Artists with lower zorder values are drawn first. … … 24 24 """ 25 25 def __init__(self, base, axes, color='black', zorder=3, x_min=0.008, 26 26 x_max=0.008, y_min=0.0025, y_max=0.0025): 27 27 """ 28 28 """ 29 29 _BaseInteractor.__init__(self, base, axes, color=color) 30 # # class initialization31 # # list of Boxsmun markers30 # # class initialization 31 # # list of Boxsmun markers 32 32 self.markers = [] 33 33 self.axes = axes 34 # # connect the artist for the motion34 # # connect the artist for the motion 35 35 self.connect = self.base.connect 36 # # when qmax is reached the selected line is reset the its previous value36 # # when qmax is reached the selected line is reset the its previous value 37 37 self.qmax = min(self.base.data2D.xmax, self.base.data2D.xmin) 38 # # Define the boxsum limits38 # # Define the boxsum limits 39 39 self.xmin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 40 math.fabs(self.base.data2D.xmin))40 math.fabs(self.base.data2D.xmin)) 41 41 self.ymin = -1 * 0.5 * min(math.fabs(self.base.data2D.xmax), 42 math.fabs(self.base.data2D.xmin))42 math.fabs(self.base.data2D.xmin)) 43 43 self.xmax = 0.5 * min(math.fabs(self.base.data2D.xmax), 44 44 math.fabs(self.base.data2D.xmin)) 45 45 self.ymax = 0.5 * min(math.fabs(self.base.data2D.xmax), 46 46 math.fabs(self.base.data2D.xmin)) 47 # # center of the boxSum47 # # center of the boxSum 48 48 self.center_x = 0.0002 49 49 self.center_y = 0.0003 50 # # Number of points on the plot50 # # Number of points on the plot 51 51 self.nbins = 20 52 # # Define initial result the summation52 # # Define initial result the summation 53 53 self.count = 0 54 54 self.error = 0 … … 56 56 self.totalerror = 0 57 57 self.points = 0 58 # # Flag to determine if the current figure has moved59 # # set to False == no motion , set to True== motion58 # # Flag to determine if the current figure has moved 59 # # set to False == no motion , set to True== motion 60 60 self.has_move = False 61 # # Create Boxsum edges61 # # Create Boxsum edges 62 62 self.horizontal_lines = HorizontalDoubleLine(self, 63 self.base.subplot,64 color='blue',65 66 67 68 69 63 self.base.subplot, 64 color='blue', 65 zorder=zorder, 66 y=self.ymax, 67 x=self.xmax, 68 center_x=self.center_x, 69 center_y=self.center_y) 70 70 self.horizontal_lines.qmax = self.qmax 71 71 72 72 self.vertical_lines = VerticalDoubleLine(self, 73 self.base.subplot,74 color='black',75 zorder=zorder,76 y=self.ymax,77 x=self.xmax,78 center_x=self.center_x,79 center_y=self.center_y)73 self.base.subplot, 74 color='black', 75 zorder=zorder, 76 y=self.ymax, 77 x=self.xmax, 78 center_x=self.center_x, 79 center_y=self.center_y) 80 80 self.vertical_lines.qmax = self.qmax 81 81 82 82 self.center = PointInteractor(self, 83 self.base.subplot,color='grey',84 zorder=zorder,85 center_x=self.center_x,86 center_y=self.center_y)87 # # Save the name of the slicer panel associate with this slicer88 self.panel_name = "" 89 # # Update and post slicer parameters83 self.base.subplot, color='grey', 84 zorder=zorder, 85 center_x=self.center_x, 86 center_y=self.center_y) 87 # # Save the name of the slicer panel associate with this slicer 88 self.panel_name = "" 89 # # Update and post slicer parameters 90 90 self.update() 91 91 self._post_data() 92 # # Bind to slice parameter events92 # # Bind to slice parameter events 93 93 self.base.Bind(EVT_SLICER_PARS, self._onEVT_SLICER_PARS) 94 94 95 95 def set_panel_name(self, name): 96 96 """ … … 99 99 """ 100 100 self.panel_name = name 101 101 102 102 def _onEVT_SLICER_PARS(self, event): 103 103 """ 104 104 receive an event containing parameters values to reset the slicer 105 @param event: event of type SlicerParameterEvent with params as 105 @param event: event of type SlicerParameterEvent with params as 106 106 attribute 107 107 """ 108 # # Post e message to declare what kind of event has being received108 # # Post e message to declare what kind of event has being received 109 109 wx.PostEvent(self.base.parent, 110 110 StatusEvent(status="Boxsum._onEVT_SLICER_PARS")) 111 111 event.Skip() 112 # # reset the slicer with the values contains the event.params dictionary112 # # reset the slicer with the values contains the event.params dictionary 113 113 if event.type == self.__class__.__name__: 114 114 self.set_params(event.params) … … 122 122 self.layernum = n 123 123 self.update() 124 124 125 125 def clear(self): 126 126 """ … … 133 133 self.base.connect.clearall() 134 134 self.base.Unbind(EVT_SLICER_PARS) 135 135 136 136 def update(self): 137 137 """ … … 139 139 resetting the widgets. 140 140 """ 141 # # check if the center point has moved and update the figure accordingly141 # # check if the center point has moved and update the figure accordingly 142 142 if self.center.has_move: 143 143 self.center.update() 144 self.horizontal_lines.update( center=self.center)145 self.vertical_lines.update( center=self.center)146 # # check if the horizontal lines have moved and147 # update the figure accordingly144 self.horizontal_lines.update(center=self.center) 145 self.vertical_lines.update(center=self.center) 146 # # check if the horizontal lines have moved and 147 # update the figure accordingly 148 148 if self.horizontal_lines.has_move: 149 149 self.horizontal_lines.update() … … 151 151 y2=self.horizontal_lines.y2, 152 152 height=self.horizontal_lines.half_height) 153 # # check if the vertical lines have moved and154 # update the figure accordingly153 # # check if the vertical lines have moved and 154 # update the figure accordingly 155 155 if self.vertical_lines.has_move: 156 156 self.vertical_lines.update() … … 158 158 x2=self.vertical_lines.x2, 159 159 width=self.vertical_lines.half_width) 160 160 161 161 def save(self, ev): 162 162 """ … … 168 168 self.vertical_lines.save(ev) 169 169 self.center.save(ev) 170 170 171 171 def _post_data(self): 172 172 """ … … 174 174 contained in that region and the error on that sum 175 175 """ 176 ## Data 2D for which the pixel will be summed 177 data = self.base.data2D 178 ## the region of the summation 179 x_min = self.horizontal_lines.x2 180 x_max = self.horizontal_lines.x1 176 # # the region of the summation 177 x_min = self.horizontal_lines.x2 178 x_max = self.horizontal_lines.x1 181 179 y_min = self.vertical_lines.y2 182 180 y_max = self.vertical_lines.y1 183 # #computation of the sum and its error181 # #computation of the sum and its error 184 182 from sas.dataloader.manipulations import Boxavg 185 box = 183 box = Boxavg(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 186 184 self.count, self.error = box(self.base.data2D) 187 185 # Dig out number of points summed, SMK & PDB, 04/03/2013 188 186 from sas.dataloader.manipulations import Boxsum 189 boxtotal = 187 boxtotal = Boxsum(x_min=x_min, x_max=x_max, y_min=y_min, y_max=y_max) 190 188 self.total, self.totalerror, self.points = boxtotal(self.base.data2D) 191 189 192 190 def moveend(self, ev): 193 191 """ 194 192 After a dragging motion this function is called to compute 195 the error and the sum of pixel of a given data 2D 193 the error and the sum of pixel of a given data 2D 196 194 """ 197 195 self.base.thaw_axes() 198 # # compute error an d sum of data's pixel196 # # compute error an d sum of data's pixel 199 197 self._post_data() 200 # # Create and event ( posted to guiframe)that set the201 # #current slicer parameter to a panel of name self.panel_name198 # # Create and event ( posted to guiframe)that set the 199 # #current slicer parameter to a panel of name self.panel_name 202 200 self.type = self.__class__.__name__ 203 201 params = self.get_params() … … 206 204 panel_name=self.panel_name) 207 205 wx.PostEvent(self.base.parent, event) 208 206 209 207 def restore(self): 210 208 """ … … 214 212 self.vertical_lines.restore() 215 213 self.center.restore() 216 214 217 215 def move(self, x, y, ev): 218 216 """ … … 220 218 """ 221 219 pass 222 220 223 221 def set_cursor(self, x, y): 224 222 """ 225 223 """ 226 224 pass 227 225 228 226 def get_params(self): 229 227 """ … … 233 231 params = {} 234 232 params["Width"] = math.fabs(self.vertical_lines.half_width) * 2 235 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 233 params["Height"] = math.fabs(self.horizontal_lines.half_height) * 2 236 234 params["center_x"] = self.center.x 237 235 params["center_y"] = self.center.y … … 242 240 params["sum_error"] = self.totalerror 243 241 return params 244 242 245 243 def get_result(self): 246 244 """ … … 251 249 result["avg"] = self.count 252 250 result["avg_error"] = self.error 253 params["sum"] = self.total254 params["sum_error"] = self.totalerror251 result["sum"] = self.total 252 result["sum_error"] = self.totalerror 255 253 return result 256 254 257 255 def set_params(self, params): 258 256 """ 259 Receive a dictionary and reset the slicer with values contained 257 Receive a dictionary and reset the slicer with values contained 260 258 in the values of the dictionary. 261 259 :param params: a dictionary containing name of slicer parameters and values the user assigned to the slicer. 262 260 """ 263 x_max = math.fabs(params["Width"] )/2264 y_max = math.fabs(params["Height"] )/2265 266 self.center_x = params["center_x"] 261 x_max = math.fabs(params["Width"]) / 2 262 y_max = math.fabs(params["Height"]) / 2 263 264 self.center_x = params["center_x"] 267 265 self.center_y = params["center_y"] 268 # update the slicer given values of params266 # update the slicer given values of params 269 267 self.center.update(center_x=self.center_x, center_y=self.center_y) 270 268 self.horizontal_lines.update(center=self.center, 271 269 width=x_max, height=y_max) 272 270 self.vertical_lines.update(center=self.center, 273 274 # compute the new error and sum given values of params271 width=x_max, height=y_max) 272 # compute the new error and sum given values of params 275 273 self._post_data() 276 274 277 275 def freeze_axes(self): 278 276 """ 279 277 """ 280 278 self.base.freeze_axes() 281 279 282 280 def thaw_axes(self): 283 281 """ … … 289 287 """ 290 288 self.base.draw() 291 292 293 289 290 291 294 292 class PointInteractor(_BaseInteractor): 295 293 """ 296 294 Draw a point that can be dragged with the marker. 297 this class controls the motion the center of the BoxSum 295 this class controls the motion the center of the BoxSum 298 296 """ 299 297 def __init__(self, base, axes, color='black', zorder=5, center_x=0.0, … … 302 300 """ 303 301 _BaseInteractor.__init__(self, base, axes, color=color) 304 # # Initialization the class302 # # Initialization the class 305 303 self.markers = [] 306 304 self.axes = axes … … 308 306 self.x = center_x 309 307 self.y = center_y 310 # # saved value of the center coordinates308 # # saved value of the center coordinates 311 309 self.save_x = center_x 312 310 self.save_y = center_y 313 ## Create a marker 314 try: 315 self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 316 marker='s', markersize=10, 317 color=self.color, alpha=0.6, 318 pickradius=5, label="pick", 319 # Prefer this to other lines 320 zorder=zorder, 321 visible=True)[0] 322 except: 323 self.center_marker = self.axes.plot([self.x],[self.y], linestyle='', 324 marker='s', markersize=10, 325 color=self.color, alpha=0.6, 326 label="pick", 327 visible=True)[0] 328 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION" 329 message += " OF MATPLOTLIB.\n Get the SVN version that is " 330 message += "at least as recent as June 1, 2007" 331 owner = self.base.base.parent 332 wx.PostEvent(owner, 333 StatusEvent(status="AnnulusSlicer: %s" % message)) 334 ## Draw a point 311 # # Create a marker 312 self.center_marker = self.axes.plot([self.x], [self.y], linestyle='', 313 marker='s', markersize=10, 314 color=self.color, alpha=0.6, 315 pickradius=5, label="pick", 316 zorder=zorder, 317 visible=True)[0] 318 # # Draw a point 335 319 self.center = self.axes.plot([self.x], [self.y], 336 337 338 339 # # Flag to determine the motion this point340 self.has_move = False 341 # # connecting the marker to allow them to move320 linestyle='-', marker='', 321 color=self.color, 322 visible=True)[0] 323 # # Flag to determine the motion this point 324 self.has_move = False 325 # # connecting the marker to allow them to move 342 326 self.connect_markers([self.center_marker]) 343 # # Update the figure344 self.update() 345 327 # # Update the figure 328 self.update() 329 346 330 def set_layer(self, n): 347 331 """ … … 351 335 self.layernum = n 352 336 self.update() 353 337 354 338 def clear(self): 355 339 """ … … 364 348 for item in range(len(self.axes.lines)): 365 349 del self.axes.lines[0] 366 367 def update(self, center_x=None, center_y=None):350 351 def update(self, center_x=None, center_y=None): 368 352 """ 369 353 Draw the new roughness on the graph. … … 375 359 self.center_marker.set(xdata=[self.x], ydata=[self.y]) 376 360 self.center.set(xdata=[self.x], ydata=[self.y]) 377 361 378 362 def save(self, ev): 379 363 """ … … 384 368 self.save_y = self.y 385 369 self.base.freeze_axes() 386 370 387 371 def moveend(self, ev): 388 372 """ 389 373 """ 390 self.has_move =False374 self.has_move = False 391 375 self.base.moveend(ev) 392 376 393 377 def restore(self): 394 378 """ … … 397 381 self.y = self.save_y 398 382 self.x = self.save_x 399 383 400 384 def move(self, x, y, ev): 401 385 """ … … 406 390 self.has_move = True 407 391 self.base.base.update() 408 392 409 393 def set_cursor(self, x, y): 410 394 """ … … 412 396 self.move(x, y, None) 413 397 self.update() 414 398 415 399 class VerticalDoubleLine(_BaseInteractor): 416 400 """ 417 Draw 2 vertical lines moving in opposite direction and centered on 401 Draw 2 vertical lines moving in opposite direction and centered on 418 402 a point (PointInteractor) 419 403 """ 420 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5,404 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 421 405 center_x=0.0, center_y=0.0): 422 406 """ 423 407 """ 424 408 _BaseInteractor.__init__(self, base, axes, color=color) 425 # # Initialization the class409 # # Initialization the class 426 410 self.markers = [] 427 411 self.axes = axes 428 # # Center coordinates412 # # Center coordinates 429 413 self.center_x = center_x 430 414 self.center_y = center_y 431 # # defined end points vertical lignes and their saved values415 # # defined end points vertical lignes and their saved values 432 416 self.y1 = y + self.center_y 433 self.save_y1 = self.y1434 417 self.save_y1 = self.y1 418 435 419 delta = self.y1 - self.center_y 436 420 self.y2 = self.center_y - delta 437 421 self.save_y2 = self.y2 438 422 439 423 self.x1 = x + self.center_x 440 424 self.save_x1 = self.x1 441 425 442 426 delta = self.x1 - self.center_x 443 427 self.x2 = self.center_x - delta 444 428 self.save_x2 = self.x2 445 # # save the color of the line429 # # save the color of the line 446 430 self.color = color 447 # # the height of the rectangle431 # # the height of the rectangle 448 432 self.half_height = math.fabs(y) 449 433 self.save_half_height = math.fabs(y) 450 ## the with of the rectangle 451 self.half_width = math.fabs(self.x1- self.x2)/2 452 self.save_half_width = math.fabs(self.x1- self.x2)/2 453 ## Create marker 454 try: 455 self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 456 marker='s', markersize=10, 457 color=self.color, alpha=0.6, 458 pickradius=5, label="pick", 459 # Prefer this to other lines 460 zorder=zorder, visible=True)[0] 461 except: 462 self.right_marker = self.axes.plot([self.x1],[0], linestyle='', 463 marker='s', markersize=10, 464 color=self.color, alpha=0.6, 465 label="pick", visible=True)[0] 466 message = "\nTHIS PROTOTYPE NEEDS THE LATEST " 467 message += "VERSION OF MATPLOTLIB\n Get the SVN version that" 468 message += " is at least as recent as June 1, 2007" 469 owner = self.base.base.parent 470 wx.PostEvent(owner, 471 StatusEvent(status="AnnulusSlicer: %s" % message)) 472 473 ## define the left and right lines of the rectangle 434 # # the with of the rectangle 435 self.half_width = math.fabs(self.x1 - self.x2) / 2 436 self.save_half_width = math.fabs(self.x1 - self.x2) / 2 437 # # Create marker 438 self.right_marker = self.axes.plot([self.x1], [0], linestyle='', 439 marker='s', markersize=10, 440 color=self.color, alpha=0.6, 441 pickradius=5, label="pick", 442 zorder=zorder, visible=True)[0] 443 444 # # define the left and right lines of the rectangle 474 445 self.right_line = self.axes.plot([self.x1, self.x1], [self.y1, self.y2], 475 linestyle='-', marker='',476 color=self.color, visible=True)[0]446 linestyle='-', marker='', 447 color=self.color, visible=True)[0] 477 448 self.left_line = self.axes.plot([self.x2, self.x2], [self.y1, self.y2], 478 linestyle='-', marker='',479 color=self.color, visible=True)[0]480 # # Flag to determine if the lines have moved481 self.has_move = False 482 # # connection the marker and draw the pictures449 linestyle='-', marker='', 450 color=self.color, visible=True)[0] 451 # # Flag to determine if the lines have moved 452 self.has_move = False 453 # # connection the marker and draw the pictures 483 454 self.connect_markers([self.right_marker]) 484 455 self.update() … … 491 462 self.layernum = n 492 463 self.update() 493 464 494 465 def clear(self): 495 466 """ … … 505 476 for item in range(len(self.axes.lines)): 506 477 del self.axes.lines[0] 507 508 def update(self, x1=None, x2=None, y1=None, y2=None, width=None,509 478 479 def update(self, x1=None, x2=None, y1=None, y2=None, width=None, 480 height=None, center=None): 510 481 """ 511 482 Draw the new roughness on the graph. … … 518 489 :param center: provided x, y coordinates of the center point 519 490 """ 520 # # save the new height, witdh of the rectangle if given as a param491 # # save the new height, witdh of the rectangle if given as a param 521 492 if width != None: 522 493 self.half_width = width 523 494 if height != None: 524 495 self.half_height = height 525 # # If new center coordinates are given draw the rectangle526 # #given these value496 # # If new center coordinates are given draw the rectangle 497 # #given these value 527 498 if center != None: 528 499 self.center_x = center.x 529 500 self.center_y = center.y 530 501 self.x1 = self.half_width + self.center_x 531 self.x2 = -self.half_width + self.center_x502 self.x2 = -self.half_width + self.center_x 532 503 self.y1 = self.half_height + self.center_y 533 self.y2 = -self.half_height + self.center_y534 504 self.y2 = -self.half_height + self.center_y 505 535 506 self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 536 self.right_line.set(xdata=[self.x1, self.x1], 507 self.right_line.set(xdata=[self.x1, self.x1], 537 508 ydata=[self.y1, self.y2]) 538 509 self.left_line.set(xdata=[self.x2, self.x2], 539 510 ydata=[self.y1, self.y2]) 540 return 541 # # if x1, y1, y2, y3 are given draw the rectangle with this value542 if x1 != None: 511 return 512 # # if x1, y1, y2, y3 are given draw the rectangle with this value 513 if x1 != None: 543 514 self.x1 = x1 544 if x2 != None: 515 if x2 != None: 545 516 self.x2 = x2 546 if y1 != None: 517 if y1 != None: 547 518 self.y1 = y1 548 if y2 != None: 519 if y2 != None: 549 520 self.y2 = y2 550 # # Draw 2 vertical lines and a marker521 # # Draw 2 vertical lines and a marker 551 522 self.right_marker.set(xdata=[self.x1], ydata=[self.center_y]) 552 523 self.right_line.set(xdata=[self.x1, self.x1], ydata=[self.y1, self.y2]) 553 524 self.left_line.set(xdata=[self.x2, self.x2], ydata=[self.y1, self.y2]) 554 525 555 526 def save(self, ev): 556 527 """ … … 572 543 self.has_move = False 573 544 self.base.moveend(ev) 574 545 575 546 def restore(self): 576 547 """ … … 583 554 self.half_height = self.save_half_height 584 555 self.half_width = self.save_half_width 585 556 586 557 def move(self, x, y, ev): 587 558 """ … … 591 562 delta = self.x1 - self.center_x 592 563 self.x2 = self.center_x - delta 593 self.half_width = math.fabs(self.x1 - self.x2) /2564 self.half_width = math.fabs(self.x1 - self.x2) / 2 594 565 self.has_move = True 595 566 self.base.base.update() 596 567 597 568 def set_cursor(self, x, y): 598 569 """ 599 Update the figure given x and y 570 Update the figure given x and y 600 571 """ 601 572 self.move(x, y, None) 602 573 self.update() 603 574 604 575 class HorizontalDoubleLine(_BaseInteractor): 605 576 """ … … 608 579 def __init__(self, base, axes, color='black', zorder=5, x=0.5, y=0.5, 609 580 center_x=0.0, center_y=0.0): 610 581 611 582 _BaseInteractor.__init__(self, base, axes, color=color) 612 # # Initialization the class583 # # Initialization the class 613 584 self.markers = [] 614 585 self.axes = axes 615 # # Center coordinates586 # # Center coordinates 616 587 self.center_x = center_x 617 588 self.center_y = center_y … … 627 598 self.save_x2 = self.x2 628 599 self.color = color 629 self.half_height = math.fabs(y)600 self.half_height = math.fabs(y) 630 601 self.save_half_height = math.fabs(y) 631 602 self.half_width = math.fabs(x) 632 603 self.save_half_width = math.fabs(x) 633 try: 634 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 635 marker='s', markersize=10, 636 color=self.color, alpha=0.6, 637 pickradius=5, label="pick", 638 # Prefer this to other lines 639 zorder=zorder, visible=True)[0] 640 except: 641 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 642 marker='s', markersize=10, 643 color=self.color, alpha=0.6, 644 label="pick", visible=True)[0] 645 message = "\nTHIS PROTOTYPE NEEDS THE LATEST VERSION " 646 message += "OF MATPLOTLIB\n Get the SVN version " 647 message += "that is at least as recent as June 1, 2007" 648 owner = self.base.base.parent 649 wx.PostEvent(owner, 650 StatusEvent(status="AnnulusSlicer: %s" % message)) 651 604 self.top_marker = self.axes.plot([0], [self.y1], linestyle='', 605 marker='s', markersize=10, 606 color=self.color, alpha=0.6, 607 pickradius=5, label="pick", 608 zorder=zorder, visible=True)[0] 609 652 610 # Define 2 horizotnal lines 653 611 self.top_line = self.axes.plot([self.x1, -self.x1], [self.y1, self.y1], 654 linestyle='-', marker='',655 color=self.color, visible=True)[0]656 self.bottom_line = self.axes.plot([self.x1, -self.x1], 612 linestyle='-', marker='', 613 color=self.color, visible=True)[0] 614 self.bottom_line = self.axes.plot([self.x1, -self.x1], 657 615 [self.y2, self.y2], 658 linestyle='-', marker='',659 color=self.color, visible=True)[0]660 # # Flag to determine if the lines have moved661 self.has_move = False 662 # # connection the marker and draw the pictures616 linestyle='-', marker='', 617 color=self.color, visible=True)[0] 618 # # Flag to determine if the lines have moved 619 self.has_move = False 620 # # connection the marker and draw the pictures 663 621 self.connect_markers([self.top_marker]) 664 622 self.update() … … 671 629 self.layernum = n 672 630 self.update() 673 631 674 632 def clear(self): 675 633 """ … … 685 643 for item in range(len(self.axes.lines)): 686 644 del self.axes.lines[0] 687 645 688 646 def update(self, x1=None, x2=None, y1=None, y2=None, 689 647 width=None, height=None, center=None): … … 698 656 :param center: provided x, y coordinates of the center point 699 657 """ 700 # # save the new height, witdh of the rectangle if given as a param658 # # save the new height, witdh of the rectangle if given as a param 701 659 if width != None: 702 660 self.half_width = width 703 if height != None:661 if height != None: 704 662 self.half_height = height 705 # # If new center coordinates are given draw the rectangle706 # #given these value663 # # If new center coordinates are given draw the rectangle 664 # #given these value 707 665 if center != None: 708 666 self.center_x = center.x … … 710 668 self.x1 = self.half_width + self.center_x 711 669 self.x2 = -self.half_width + self.center_x 712 670 713 671 self.y1 = self.half_height + self.center_y 714 672 self.y2 = -self.half_height + self.center_y 715 673 716 674 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 717 675 self.top_line.set(xdata=[self.x1, self.x2], … … 719 677 self.bottom_line.set(xdata=[self.x1, self.x2], 720 678 ydata=[self.y2, self.y2]) 721 return 722 # # if x1, y1, y2, y3 are given draw the rectangle with this value723 if x1 != None: 679 return 680 # # if x1, y1, y2, y3 are given draw the rectangle with this value 681 if x1 != None: 724 682 self.x1 = x1 725 if x2 != None: 683 if x2 != None: 726 684 self.x2 = x2 727 if y1 != None: 685 if y1 != None: 728 686 self.y1 = y1 729 if y2 != None: 687 if y2 != None: 730 688 self.y2 = y2 731 # # Draw 2 vertical lines and a marker689 # # Draw 2 vertical lines and a marker 732 690 self.top_marker.set(xdata=[self.center_x], ydata=[self.y1]) 733 691 self.top_line.set(xdata=[self.x1, self.x2], ydata=[self.y1, self.y1]) 734 692 self.bottom_line.set(xdata=[self.x1, self.x2], ydata=[self.y2, self.y2]) 735 693 736 694 def save(self, ev): 737 695 """ … … 744 702 self.save_y1 = self.y1 745 703 self.save_half_height = self.half_height 746 self.save_half_width = 704 self.save_half_width = self.half_width 747 705 self.base.freeze_axes() 748 706 749 707 def moveend(self, ev): 750 708 """ … … 753 711 self.has_move = False 754 712 self.base.moveend(ev) 755 713 756 714 def restore(self): 757 715 """ … … 764 722 self.half_height = self.save_half_height 765 723 self.half_width = self.save_half_width 766 724 767 725 def move(self, x, y, ev): 768 726 """ … … 771 729 self.y1 = y 772 730 delta = self.y1 - self.center_y 773 self.y2 = 731 self.y2 = self.center_y - delta 774 732 self.half_height = math.fabs(self.y1) - self.center_y 775 733 self.has_move = True 776 734 self.base.base.update() 777 735 778 736 def set_cursor(self, x, y): 779 737 """ 780 Update the figure given x and y 738 Update the figure given x and y 781 739 """ 782 740 self.move(x, y, None) 783 741 self.update() 784 -
src/sas/guiframe/local_perspectives/plotting/detector_dialog.py
r79492222 rb5de88e 5 5 import sys 6 6 from sas.guiframe.utils import format_number 7 from sas.guiframe.events import StatusEvent 7 from sas.guiframe.events import StatusEvent 8 8 from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas 9 9 from matplotlib import mpl 10 10 from matplotlib import pylab 11 # FONT size11 # FONT size 12 12 if sys.platform.count("win32") > 0: 13 13 FONT_VARIANT = 0 14 14 else: 15 15 FONT_VARIANT = 1 16 16 17 17 DEFAULT_CMAP = pylab.cm.get_cmap('jet') 18 18 … … 21 21 Dialog box to let the user edit detector settings 22 22 """ 23 23 24 24 def __init__(self, parent, id=1, base=None, dpi=None, 25 cmap=DEFAULT_CMAP, reset_zmin_ctl =None,26 reset_zmax_ctl =None, *args, **kwds):25 cmap=DEFAULT_CMAP, reset_zmin_ctl=None, 26 reset_zmax_ctl=None, *args, **kwds): 27 27 """ 28 28 """ … … 39 39 self.label_qmax = wx.StaticText(self, -1, "Q max") 40 40 self.label_zmin = wx.StaticText(self, -1, 41 "Min amplitude for color map (optional)")41 "Min amplitude for color map (optional)") 42 42 self.label_zmax = wx.StaticText(self, -1, 43 "Max amplitude for color map (optional)")43 "Max amplitude for color map (optional)") 44 44 self.label_beam = wx.StaticText(self, -1, 45 45 "Beam stop radius in units of q") … … 53 53 self.zmax_ctl.Bind(wx.EVT_SET_FOCUS, self.onSetFocus) 54 54 self.static_line_3 = wx.StaticLine(self, -1) 55 self.button_ Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel")55 self.button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") 56 56 self.button_reset = wx.Button(self, wx.NewId(), "Reset") 57 57 self.Bind(wx.EVT_BUTTON, self.resetValues, self.button_reset) 58 self.button_ OK= wx.Button(self, wx.ID_OK, "OK")59 self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_ OK)58 self.button_ok = wx.Button(self, wx.ID_OK, "OK") 59 self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_ok) 60 60 self.__set_properties() 61 61 self.__do_layout() 62 62 self.Fit() 63 64 class Event :63 64 class Event(object): 65 65 """ 66 66 """ … … 73 73 cmap = None 74 74 sym4 = False 75 75 76 76 def onSetFocus(self, event): 77 77 """ … … 82 82 # Select the whole control, after this event resolves 83 83 wx.CallAfter(widget.SetSelection, -1, -1) 84 84 85 85 def resetValues(self, event): 86 86 """ … … 93 93 zmin = "" 94 94 if zmax == None: 95 zmax = "" 95 zmax = "" 96 96 self.zmin_ctl.SetValue(str(zmin)) 97 97 self.zmax_ctl.SetValue(str(zmax)) … … 102 102 msg = "error occurs while resetting Detector: %s" % sys.exc_value 103 103 wx.PostEvent(self.parent, StatusEvent(status=msg)) 104 104 105 105 def checkValues(self, event): 106 106 """ … … 111 111 try: 112 112 value = self.zmin_ctl.GetValue() 113 #if value and float( value) == 0.0:114 # flag = False115 # wx.PostEvent(self.parent,116 # StatusEvent(status="Enter number greater than zero"))117 # self.zmin_ctl.SetBackgroundColour("pink")118 # self.zmin_ctl.Refresh()119 #else:120 113 self.zmin_ctl.SetBackgroundColour(wx.WHITE) 121 114 self.zmin_ctl.Refresh() … … 130 123 flag = False 131 124 wx.PostEvent(self.parent, 132 StatusEvent(status="Enter number greater than zero"))125 StatusEvent(status="Enter number greater than zero")) 133 126 self.zmax_ctl.SetBackgroundColour("pink") 134 127 self.zmax_ctl.Refresh() … … 143 136 if flag: 144 137 event.Skip(True) 145 138 146 139 def setContent(self, xnpts, ynpts, qmax, beam, 147 140 zmin=None, zmax=None, sym=False): 148 141 """ 149 142 received value and displayed them 150 143 151 144 :param xnpts: the number of point of the x_bins of data 152 145 :param ynpts: the number of point of the y_bins of data … … 156 149 :param zmax: the value to get the maximum color 157 150 :param sym: 158 151 159 152 """ 160 153 self.xnpts_ctl.SetLabel(str(format_number(xnpts))) … … 207 200 sizer_colormap = wx.BoxSizer(wx.VERTICAL) 208 201 sizer_selection = wx.BoxSizer(wx.HORIZONTAL) 209 202 210 203 iy = 0 211 204 sizer_params.Add(self.label_xnpts, (iy, 0), (1, 1), 212 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)213 sizer_params.Add(self.xnpts_ctl, 214 wx.EXPAND |wx.ADJUST_MINSIZE, 0)205 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 206 sizer_params.Add(self.xnpts_ctl, (iy, 1), (1, 1), 207 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 215 208 iy += 1 216 209 sizer_params.Add(self.label_ynpts, (iy, 0), (1, 1), 217 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)218 sizer_params.Add(self.ynpts_ctl, 219 wx.EXPAND |wx.ADJUST_MINSIZE, 0)210 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 211 sizer_params.Add(self.ynpts_ctl, (iy, 1), (1, 1), 212 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 220 213 iy += 1 221 214 sizer_params.Add(self.label_qmax, (iy, 0), (1, 1), 222 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)223 sizer_params.Add(self.qmax_ctl, 224 wx.EXPAND |wx.ADJUST_MINSIZE, 0)215 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 216 sizer_params.Add(self.qmax_ctl, (iy, 1), (1, 1), 217 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 225 218 iy += 1 226 219 sizer_params.Add(self.label_beam, (iy, 0), (1, 1), 227 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)228 sizer_params.Add(self.beam_ctl, 229 wx.EXPAND |wx.ADJUST_MINSIZE, 0)220 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 221 sizer_params.Add(self.beam_ctl, (iy, 1), (1, 1), 222 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 230 223 iy += 1 231 224 sizer_params.Add(self.label_zmin, (iy, 0), (1, 1), 232 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)233 sizer_params.Add(self.zmin_ctl, 234 wx.EXPAND |wx.ADJUST_MINSIZE, 0)225 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 226 sizer_params.Add(self.zmin_ctl, (iy, 1), (1, 1), 227 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 235 228 iy += 1 236 229 sizer_params.Add(self.label_zmax, (iy, 0), (1, 1), 237 wx.LEFT |wx.EXPAND|wx.ADJUST_MINSIZE, 15)238 sizer_params.Add(self.zmax_ctl, 239 wx.EXPAND |wx.ADJUST_MINSIZE, 0)230 wx.LEFT | wx.EXPAND | wx.ADJUST_MINSIZE, 15) 231 sizer_params.Add(self.zmax_ctl, (iy, 1), (1, 1), 232 wx.EXPAND | wx.ADJUST_MINSIZE, 0) 240 233 iy += 1 241 234 self.fig = mpl.figure.Figure(dpi=self.dpi, figsize=(4, 1)) … … 243 236 self.norm = mpl.colors.Normalize(vmin=0, vmax=100) 244 237 self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 245 norm=self.norm,246 orientation='horizontal')238 norm=self.norm, 239 orientation='horizontal') 247 240 self.cb1.set_label('Detector Colors') 248 241 self.canvas = Canvas(self, -1, self.fig) 249 sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND, 5)242 sizer_colormap.Add(self.canvas, 0, wx.LEFT | wx.EXPAND, 5) 250 243 self.cmap_selector = wx.ComboBox(self, -1) 251 244 self.cmap_selector.SetValue(str(self.cmap.name)) 252 245 maps = sorted(m for m in pylab.cm.datad if not m.endswith("_r")) 253 246 254 247 for i, m in enumerate(maps): 255 248 self.cmap_selector.Append(str(m), pylab.get_cmap(m)) 256 249 257 250 wx.EVT_COMBOBOX(self.cmap_selector, -1, self._on_select_cmap) 258 251 sizer_selection.Add(wx.StaticText(self, -1, "Select Cmap: "), 0, 259 wx.LEFT|wx.ADJUST_MINSIZE, 5)260 sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND |wx.ALL, 10)261 sizer_main.Add(sizer_params, 0, wx.EXPAND |wx.ALL, 5)262 sizer_main.Add(sizer_selection, 0, wx.EXPAND |wx.ALL, 5)263 note = " Note: This is one time option. " + \252 wx.LEFT | wx.ADJUST_MINSIZE, 5) 253 sizer_selection.Add(self.cmap_selector, 0, wx.EXPAND | wx.ALL, 10) 254 sizer_main.Add(sizer_params, 0, wx.EXPAND | wx.ALL, 5) 255 sizer_main.Add(sizer_selection, 0, wx.EXPAND | wx.ALL, 5) 256 note = " Note: This is one time option. " + \ 264 257 "It will be reset on updating the image." 265 258 note_txt = wx.StaticText(self, -1, note) 266 sizer_main.Add(note_txt, 0, wx.EXPAND |wx.ALL, 5)267 sizer_main.Add(sizer_colormap, 1, wx.EXPAND |wx.ALL, 5)259 sizer_main.Add(note_txt, 0, wx.EXPAND | wx.ALL, 5) 260 sizer_main.Add(sizer_colormap, 1, wx.EXPAND | wx.ALL, 5) 268 261 sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) 269 sizer_button.Add(self.button_reset, 0, wx.LEFT |wx.ADJUST_MINSIZE, 100)270 sizer_button.Add(self.button_ OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10)271 sizer_button.Add(self.button_ Cancel, 0,272 wx.LEFT |wx.RIGHT|wx.ADJUST_MINSIZE, 10)273 sizer_main.Add(sizer_button, 0, wx.EXPAND |wx.BOTTOM|wx.TOP, 10)262 sizer_button.Add(self.button_reset, 0, wx.LEFT | wx.ADJUST_MINSIZE, 100) 263 sizer_button.Add(self.button_ok, 0, wx.LEFT | wx.ADJUST_MINSIZE, 10) 264 sizer_button.Add(self.button_cancel, 0, 265 wx.LEFT | wx.RIGHT | wx.ADJUST_MINSIZE, 10) 266 sizer_main.Add(sizer_button, 0, wx.EXPAND | wx.BOTTOM | wx.TOP, 10) 274 267 self.SetAutoLayout(True) 275 268 self.SetSizer(sizer_main) … … 277 270 self.Centre() 278 271 # end wxGlade 279 272 280 273 def _on_select_cmap(self, event): 281 274 """ 282 display a new cmap 275 display a new cmap 283 276 """ 284 277 cmap_name = self.cmap_selector.GetCurrentSelection() … … 286 279 self.cmap = current_cmap 287 280 self.cb1 = mpl.colorbar.ColorbarBase(self.ax1, cmap=self.cmap, 288 norm=self.norm, orientation='horizontal')281 norm=self.norm, orientation='horizontal') 289 282 self.canvas.draw() -
src/sas/guiframe/local_perspectives/plotting/graphAppearance.py
r79492222 rb5de88e 39 39 self.is_ytick = False 40 40 41 42 41 def InitUI(self): 43 42 … … 53 52 yhbox2 = wx.BoxSizer(wx.HORIZONTAL) 54 53 55 56 57 54 if self.legend: 58 55 legendLocText = wx.StaticText(panel, label='Legend location: ') 59 self.legend_loc_combo = wx.ComboBox(panel, style = wx.CB_READONLY, size=(180,-1))56 self.legend_loc_combo = wx.ComboBox(panel, style=wx.CB_READONLY, size=(180, -1)) 60 57 self.fillLegendLocs() 61 58 else: 62 59 self.legend_loc_combo = None 63 60 64 65 61 if self.legend: 66 62 self.toggle_legend = wx.CheckBox(panel, label='Toggle legend on/off') … … 70 66 self.toggle_grid = wx.CheckBox(panel, label='Toggle grid on/off') 71 67 72 73 68 xstatic_box = wx.StaticBox(panel, -1, 'x-axis label') 74 69 xstatic_box_sizer = wx.StaticBoxSizer(xstatic_box, wx.VERTICAL) … … 76 71 ystatic_box_sizer = wx.StaticBoxSizer(ystatic_box, wx.VERTICAL) 77 72 78 79 73 xaxis_label = wx.StaticText(panel, label='X-axis: ') 80 74 yaxis_label = wx.StaticText(panel, label='Y-axis: ') … … 82 76 unitlabel_2 = wx.StaticText(panel, label='Units: ') 83 77 84 self.xaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1)) 85 self.yaxis_text = wx.TextCtrl(panel, -1, "",size=(220, -1)) 86 87 self.xaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1)) 88 self.yaxis_unit_text = wx.TextCtrl(panel, -1,"",size=(100, -1)) 89 90 78 self.xaxis_text = wx.TextCtrl(panel, -1, "", size=(220, -1)) 79 self.yaxis_text = wx.TextCtrl(panel, -1, "", size=(220, -1)) 80 81 self.xaxis_unit_text = wx.TextCtrl(panel, -1, "", size=(100, -1)) 82 self.yaxis_unit_text = wx.TextCtrl(panel, -1, "", size=(100, -1)) 91 83 92 84 xcolorLabel = wx.StaticText(panel, label='Font color: ') … … 95 87 self.xfont_color.SetSelection(0) 96 88 xfont_button = wx.Button(panel, label='Font') 97 xfont_button.Bind(wx.EVT_BUTTON, self.on xFont)89 xfont_button.Bind(wx.EVT_BUTTON, self.on_x_font) 98 90 99 91 ycolorLabel = wx.StaticText(panel, label='Font color: ') 100 self.yfont_color = wx.ComboBox(panel, size=(100, -1), style=wx.CB_READONLY)92 self.yfont_color = wx.ComboBox(panel, size=(100, -1), style=wx.CB_READONLY) 101 93 self.yfill_colors() 102 94 self.yfont_color.SetSelection(0) 103 95 yfont_button = wx.Button(panel, label='Font') 104 yfont_button.Bind(wx.EVT_BUTTON, self.onyFont) 105 106 96 yfont_button.Bind(wx.EVT_BUTTON, self.on_y_font) 107 97 108 98 self.cancel_button = wx.Button(panel, label='Cancel') 109 99 self.ok_button = wx.Button(panel, label='OK') 110 100 111 self.cancel_button.Bind(wx.EVT_BUTTON, self.on Cancel)101 self.cancel_button.Bind(wx.EVT_BUTTON, self.on_cancel) 112 102 self.ok_button.Bind(wx.EVT_BUTTON, self.on_ok) 113 103 114 115 xhbox1.Add(xaxis_label, flag= wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 116 xhbox1.Add(self.xaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 117 xhbox1.Add(unitlabel_1, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 118 xhbox1.Add(self.xaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 119 120 yhbox1.Add(yaxis_label, flag= wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 121 yhbox1.Add(self.yaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 122 yhbox1.Add(unitlabel_2, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 123 yhbox1.Add(self.yaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 104 xhbox1.Add(xaxis_label, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 105 xhbox1.Add(self.xaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 106 xhbox1.Add(unitlabel_1, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 107 xhbox1.Add(self.xaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 108 109 yhbox1.Add(yaxis_label, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 110 yhbox1.Add(self.yaxis_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=10) 111 yhbox1.Add(unitlabel_2, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 112 yhbox1.Add(self.yaxis_unit_text, flag=wx.ALL | wx.EXPAND | wx.ALIGN_RIGHT, border=10) 124 113 125 114 xhbox2.Add(xcolorLabel, flag=wx.ALL | wx.ALIGN_RIGHT, border=10) … … 132 121 133 122 if self.legend: 134 hbox1.Add(legendLocText, flag = wx.ALL | wx.EXPAND| wx.ALIGN_LEFT, border=5)135 hbox1.Add(self.legend_loc_combo, flag = wx.ALL | wx.EXPAND| wx.ALIGN_LEFT, border=5)123 hbox1.Add(legendLocText, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 124 hbox1.Add(self.legend_loc_combo, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 136 125 137 126 if self.legend: 138 127 hbox1.Add((5, -1)) 139 hbox1.Add(self.toggle_legend, flag = wx.ALL | wx.EXPAND| wx.ALIGN_LEFT, border=5)140 141 hbox2.Add(self.ok_button, flag =wx.ALL | wx.ALIGN_RIGHT, border=5)142 hbox2.Add(self.cancel_button, flag =wx.ALL | wx.ALIGN_RIGHT, border=5)128 hbox1.Add(self.toggle_legend, flag=wx.ALL | wx.EXPAND | wx.ALIGN_LEFT, border=5) 129 130 hbox2.Add(self.ok_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 131 hbox2.Add(self.cancel_button, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 143 132 hbox2.Add((15, -1)) 144 133 145 xstatic_box_sizer.Add(xhbox1, flag= wx.EXPAND, border=5)134 xstatic_box_sizer.Add(xhbox1, flag=wx.EXPAND, border=5) 146 135 xstatic_box_sizer.Add(xhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 147 ystatic_box_sizer.Add(yhbox1, flag= 136 ystatic_box_sizer.Add(yhbox1, flag=wx.EXPAND, border=5) 148 137 ystatic_box_sizer.Add(yhbox2, flag=wx.ALL | wx.ALIGN_RIGHT, border=5) 149 138 150 139 vbox.Add((-1, 20)) 151 vbox.Add(hbox1, flag = wx.EXPAND | wx.ALL, border=5) 152 vbox.Add(xstatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10) 153 vbox.Add(ystatic_box_sizer, flag = wx.ALL | wx.EXPAND, border=10) 154 155 vbox.Add(self.toggle_grid, flag = wx.ALIGN_RIGHT | wx.RIGHT, border=20) 156 vbox.Add(hbox2, flag = wx.ALIGN_RIGHT | wx.ALL , border=5) 157 140 vbox.Add(hbox1, flag=wx.EXPAND | wx.ALL, border=5) 141 vbox.Add(xstatic_box_sizer, flag=wx.ALL | wx.EXPAND, border=10) 142 vbox.Add(ystatic_box_sizer, flag=wx.ALL | wx.EXPAND, border=10) 143 144 vbox.Add(self.toggle_grid, flag=wx.ALIGN_RIGHT | wx.RIGHT, border=20) 145 vbox.Add(hbox2, flag=wx.ALIGN_RIGHT | wx.ALL, border=5) 158 146 159 147 panel.SetSizer(vbox) … … 169 157 self.yfont_color.Append(c_list[idx], idx) 170 158 171 def on xFont(self, e):159 def on_x_font(self, e): 172 160 title = 'Modify x axis font' 173 161 … … 175 163 fonty.set_default_font(self.xfont) 176 164 fonty.set_ticklabel_check(self.is_xtick) 177 if (fonty.ShowModal() == wx.ID_OK):165 if fonty.ShowModal() == wx.ID_OK: 178 166 self.xfont = fonty.get_font() 179 167 self.is_xtick = fonty.get_ticklabel_check() 180 168 181 def on yFont(self, e):169 def on_y_font(self, e): 182 170 title = 'Modify y axis font' 183 171 fonty = SimpleFont(self, wx.NewId(), title) 184 172 fonty.set_default_font(self.yfont) 185 173 fonty.set_ticklabel_check(self.is_ytick) 186 if (fonty.ShowModal() == wx.ID_OK):174 if fonty.ShowModal() == wx.ID_OK: 187 175 self.yfont = fonty.get_font() 188 176 self.is_ytick = fonty.get_ticklabel_check() … … 191 179 self.Close() 192 180 193 def on Cancel(self, e):181 def on_cancel(self, e): 194 182 self.Destroy() 195 183 … … 237 225 238 226 239 def setDefaults(self, grid,legend,xlab,ylab,xunit,yunit,240 xaxis_font, yaxis_font,legend_loc,241 xcolor, ycolor, is_xtick, is_ytick):227 def setDefaults(self, grid, legend, xlab, ylab, xunit, yunit, 228 xaxis_font, yaxis_font, legend_loc, 229 xcolor, ycolor, is_xtick, is_ytick): 242 230 self.toggle_grid.SetValue(grid) 243 231 if self.legend: … … 261 249 else: 262 250 self.yfont_color.SetStringSelection(ycolor) 263 251 264 252 265 253 if self.legend: … … 310 298 def get_yfont(self): 311 299 return self.yfont 312 300 313 301 def get_xtick_check(self): 314 302 return self.is_xtick … … 316 304 def get_ytick_check(self): 317 305 return self.is_ytick 318 306 319 307 320 308 if __name__ == '__main__': 321 309 322 310 app = wx.App() 323 graphD = graphAppearance(None, title='Modify graph appearance')311 graphD = graphAppearance(None, title='Modify graph appearance') 324 312 app.MainLoop() 325 313 -
src/sas/guiframe/local_perspectives/plotting/masking.py
r79492222 rb5de88e 3 3 """ 4 4 ################################################################################ 5 # This software was developed by the University of Tennessee as part of the6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE)7 # project funded by the US National Science Foundation.5 # This software was developed by the University of Tennessee as part of the 6 # Distributed Data Analysis of Neutron Scattering Experiments (DANSE) 7 # project funded by the US National Science Foundation. 8 8 # 9 # If you use DANSE applications to do scientific research that leads to10 # publication, we ask that you acknowledge the use of the software with the11 # following sentence:9 # If you use DANSE applications to do scientific research that leads to 10 # publication, we ask that you acknowledge the use of the software with the 11 # following sentence: 12 12 # 13 # This work benefited from DANSE software developed under NSF award DMR-0520547.13 # This work benefited from DANSE software developed under NSF award DMR-0520547. 14 14 # 15 # copyright 2008, University of Tennessee15 # copyright 2008, University of Tennessee 16 16 ################################################################################ 17 17 18 18 19 # #Todo: cleaning up, improving the maskplotpanel initialization, and testing.19 # #Todo: cleaning up, improving the maskplotpanel initialization, and testing. 20 20 import wx 21 21 import sys … … 39 39 _STATICBOX_WIDTH = 380 40 40 41 # SLD panel size41 # SLD panel size 42 42 if sys.platform.count("win32") > 0: 43 43 PANEL_SIZE = 350 … … 46 46 PANEL_SIZE = 300 47 47 FONT_VARIANT = 1 48 48 49 49 from sas.data_util.calcthread import CalcThread 50 50 … … 54 54 """ 55 55 def __init__(self, 56 id =-1,57 panel =None,58 image =None,59 completefn =None,60 updatefn =None,61 elapsed =0,62 yieldtime =0.01,63 worktime =0.0156 id=-1, 57 panel=None, 58 image=None, 59 completefn=None, 60 updatefn=None, 61 elapsed=0, 62 yieldtime=0.01, 63 worktime=0.01 64 64 ): 65 65 """ … … 70 70 worktime) 71 71 self.starttime = 0 72 self.id = id 72 self.id = id 73 73 self.panel = panel 74 74 self.image = image 75 76 75 76 77 77 def compute(self): 78 78 """ … … 80 80 """ 81 81 elapsed = time.time() - self.starttime 82 82 83 83 self.complete(panel=self.panel, image=self.image, elapsed=elapsed) 84 85 84 85 86 86 class MaskPanel(wx.Dialog): 87 87 """ 88 88 Provides the Mask Editor GUI. 89 89 """ 90 # # Internal nickname for the window, used by the AUI manager90 # # Internal nickname for the window, used by the AUI manager 91 91 window_name = "Mask Editor" 92 # # Name to appear on the window title bar92 # # Name to appear on the window title bar 93 93 window_caption = "Mask Editor" 94 # # Flag to tell the AUI manager to put this panel in the center pane94 # # Flag to tell the AUI manager to put this panel in the center pane 95 95 CENTER_PANE = True 96 def __init__(self, parent=None, base=None, 96 def __init__(self, parent=None, base=None, 97 97 data=None, id=-1, *args, **kwds): 98 98 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 99 kwds["size"] = wx.Size(_STATICBOX_WIDTH *0.8, PANEL_SIZE)100 wx.Dialog.__init__(self, parent, id=id, 101 99 kwds["size"] = wx.Size(_STATICBOX_WIDTH * 0.8, PANEL_SIZE) 100 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 101 102 102 if data != None: 103 # Font size103 # Font size 104 104 kwds = [] 105 105 self.SetWindowVariant(variant=FONT_VARIANT) … … 108 108 self.data = data 109 109 self.str = self.data.__str__() 110 # # mask for 2D110 # # mask for 2D 111 111 self.mask = data.mask 112 112 self.default_mask = copy.deepcopy(data.mask) 113 # # masked data from GUI113 # # masked data from GUI 114 114 self.slicer_mask = None 115 115 self.slicer = None 116 116 self.slicer_z = 5 117 117 self.data.interactive = True 118 # # when 2 data have the same id override the 1 st plotted118 # # when 2 data have the same id override the 1 st plotted 119 119 self.name = self.data.name 120 120 # Panel for 2D plot … … 122 122 style=wx.TRANSPARENT_WINDOW) 123 123 self.cmap = DEFAULT_CMAP 124 # # Create Artist and bind it124 # # Create Artist and bind it 125 125 self.subplot = self.plotpanel.subplot 126 126 self.connect = BindArtist(self.subplot.figure) … … 128 128 self.newplot = Data2D(image=self.data.data) 129 129 self.newplot.setValues(self.data) 130 self.plotpanel.add_image(self.newplot) 130 self.plotpanel.add_image(self.newplot) 131 131 self._update_mask(self.mask) 132 132 self.Centre() … … 134 134 # bind evt_close to _draw in fitpage 135 135 self.Bind(wx.EVT_CLOSE, self.OnClose) 136 136 137 137 def ShowMessage(self, msg=''): 138 138 """ … … 143 143 mssg += msg 144 144 wx.MessageBox(mssg, 'Error', wx.OK | wx.ICON_ERROR) 145 145 146 146 def _setup_layout(self): 147 147 """ … … 149 149 """ 150 150 note = "Note: This masking applies\n only to %s." % self.data.name 151 note_txt = wx.StaticText(self, -1, note) 151 note_txt = wx.StaticText(self, -1, note) 152 152 note_txt.SetForegroundColour(wx.RED) 153 153 shape = "Select a Shape for Masking:" … … 155 155 sizer = wx.GridBagSizer(10, 10) 156 156 #---------inputs---------------- 157 shape_txt = wx.StaticText(self, -1, shape) 158 sizer.Add(shape_txt, (1, 1), flag=wx.TOP |wx.LEFT|wx.BOTTOM, border=5)157 shape_txt = wx.StaticText(self, -1, shape) 158 sizer.Add(shape_txt, (1, 1), flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=5) 159 159 self.innersector_rb = wx.RadioButton(self, -1, "Double Wings") 160 160 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerSectorMask, 161 161 id=self.innersector_rb.GetId()) 162 sizer.Add(self.innersector_rb, (2, 1), 163 flag=wx.RIGHT |wx.BOTTOM, border=5)162 sizer.Add(self.innersector_rb, (2, 1), 163 flag=wx.RIGHT | wx.BOTTOM, border=5) 164 164 self.innercircle_rb = wx.RadioButton(self, -1, "Circular Disk") 165 165 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerRingMask, 166 166 id=self.innercircle_rb.GetId()) 167 167 sizer.Add(self.innercircle_rb, (3, 1), 168 flag=wx.RIGHT |wx.BOTTOM, border=5)169 168 flag=wx.RIGHT | wx.BOTTOM, border=5) 169 170 170 self.innerbox_rb = wx.RadioButton(self, -1, "Rectangular Disk") 171 171 self.Bind(wx.EVT_RADIOBUTTON, self.onInnerBoxMask, 172 172 id=self.innerbox_rb.GetId()) 173 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)173 sizer.Add(self.innerbox_rb, (4, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 174 174 175 175 self.outersector_rb = wx.RadioButton(self, -1, "Double Wing Window") 176 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 176 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterSectorMask, 177 177 id=self.outersector_rb.GetId()) 178 178 sizer.Add(self.outersector_rb, (5, 1), 179 flag=wx.RIGHT |wx.BOTTOM, border=5)180 181 # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector')179 flag=wx.RIGHT | wx.BOTTOM, border=5) 180 181 # outersector_y_txt = wx.StaticText(self, -1, 'Outer Sector') 182 182 self.outercircle_rb = wx.RadioButton(self, -1, "Circular Window") 183 183 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterRingMask, 184 184 id=self.outercircle_rb.GetId()) 185 sizer.Add(self.outercircle_rb, (6, 1), 186 flag=wx.RIGHT |wx.BOTTOM, border=5)187 # outerbox_txt = wx.StaticText(self, -1, 'Outer Box')185 sizer.Add(self.outercircle_rb, (6, 1), 186 flag=wx.RIGHT | wx.BOTTOM, border=5) 187 # outerbox_txt = wx.StaticText(self, -1, 'Outer Box') 188 188 self.outerbox_rb = wx.RadioButton(self, -1, "Rectangular Window") 189 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 189 self.Bind(wx.EVT_RADIOBUTTON, self.onOuterBoxMask, 190 190 id=self.outerbox_rb.GetId()) 191 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)192 sizer.Add(note_txt, (8, 1), flag=wx.RIGHT |wx.BOTTOM, border=5)191 sizer.Add(self.outerbox_rb, (7, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 192 sizer.Add(note_txt, (8, 1), flag=wx.RIGHT | wx.BOTTOM, border=5) 193 193 self.innercircle_rb.SetValue(False) 194 self.outercircle_rb.SetValue(False) 194 self.outercircle_rb.SetValue(False) 195 195 self.innerbox_rb.SetValue(False) 196 196 self.outerbox_rb.SetValue(False) 197 197 self.innersector_rb.SetValue(False) 198 198 self.outersector_rb.SetValue(False) 199 sizer.Add(self.plotpanel, (0, 2), (13, 13), 200 wx.EXPAND |wx.LEFT|wx.RIGHT, 15)199 sizer.Add(self.plotpanel, (0, 2), (13, 13), 200 wx.EXPAND | wx.LEFT | wx.RIGHT, 15) 201 201 202 202 #-----Buttons------------1 … … 204 204 button_add = wx.Button(self, id_button, "Add") 205 205 button_add.SetToolTipString("Add the mask drawn.") 206 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 206 button_add.Bind(wx.EVT_BUTTON, self.onAddMask, id=button_add.GetId()) 207 207 sizer.Add(button_add, (13, 7)) 208 208 id_button = wx.NewId() … … 210 210 button_erase.SetToolTipString("Erase the mask drawn.") 211 211 button_erase.Bind(wx.EVT_BUTTON, self.onEraseMask, 212 id=button_erase.GetId()) 212 id=button_erase.GetId()) 213 213 sizer.Add(button_erase, (13, 8)) 214 214 id_button = wx.NewId() … … 216 216 button_reset.SetToolTipString("Reset the mask.") 217 217 button_reset.Bind(wx.EVT_BUTTON, self.onResetMask, 218 id=button_reset.GetId()) 219 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT |wx.BOTTOM, border=15)218 id=button_reset.GetId()) 219 sizer.Add(button_reset, (13, 9), flag=wx.RIGHT | wx.BOTTOM, border=15) 220 220 id_button = wx.NewId() 221 221 button_reset = wx.Button(self, id_button, "Clear") 222 222 button_reset.SetToolTipString("Clear all mask.") 223 223 button_reset.Bind(wx.EVT_BUTTON, self.onClearMask, 224 id=button_reset.GetId()) 225 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT |wx.BOTTOM, border=15)224 id=button_reset.GetId()) 225 sizer.Add(button_reset, (13, 10), flag=wx.RIGHT | wx.BOTTOM, border=15) 226 226 sizer.AddGrowableCol(3) 227 227 sizer.AddGrowableRow(2) … … 234 234 Call Draw Box Slicer and get mask inside of the box 235 235 """ 236 # get ready for next evt237 event.Skip() 238 # from boxMask import BoxMask236 # get ready for next evt 237 event.Skip() 238 # from boxMask import BoxMask 239 239 if event != None: 240 self.onClearSlicer(event) 240 self.onClearSlicer(event) 241 241 self.slicer_z += 1 242 self.slicer = 242 self.slicer = BoxMask(self, self.subplot, 243 243 zorder=self.slicer_z, side=True) 244 244 self.subplot.set_ylim(self.data.ymin, self.data.ymax) … … 246 246 self.update() 247 247 self.slicer_mask = self.slicer.update() 248 248 249 249 def onOuterBoxMask(self, event=None): 250 250 """ 251 251 Call Draw Box Slicer and get mask outside of the box 252 252 """ 253 event.Skip() 254 # from boxMask import BoxMask253 event.Skip() 254 # from boxMask import BoxMask 255 255 if event != None: 256 self.onClearSlicer(event) 256 self.onClearSlicer(event) 257 257 self.slicer_z += 1 258 self.slicer = 258 self.slicer = BoxMask(self, self.subplot, 259 259 zorder=self.slicer_z, side=False) 260 260 self.subplot.set_ylim(self.data.ymin, self.data.ymax) … … 272 272 self.onClearSlicer(event) 273 273 self.slicer_z += 1 274 self.slicer = 274 self.slicer = SectorMask(self, self.subplot, 275 275 zorder=self.slicer_z, side=True) 276 276 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 277 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 277 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 278 278 self.update() 279 self.slicer_mask = self.slicer.update() 279 self.slicer_mask = self.slicer.update() 280 280 281 281 def onOuterSectorMask(self, event=None): … … 288 288 self.onClearSlicer(event) 289 289 self.slicer_z += 1 290 self.slicer = 290 self.slicer = SectorMask(self, self.subplot, 291 291 zorder=self.slicer_z, side=False) 292 292 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 293 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 294 self.update() 295 self.slicer_mask = self.slicer.update() 293 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 294 self.update() 295 self.slicer_mask = self.slicer.update() 296 296 297 297 def onInnerRingMask(self, event=None): … … 307 307 zorder=self.slicer_z, side=True) 308 308 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 309 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 309 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 310 310 self.update() 311 self.slicer_mask = self.slicer.update() 311 self.slicer_mask = self.slicer.update() 312 312 313 313 def onOuterRingMask(self, event=None): … … 321 321 self.slicer_z += 1 322 322 self.slicer = CircularMask(self, self.subplot, 323 zorder=self.slicer_z, side=False) 323 zorder=self.slicer_z, side=False) 324 324 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 325 325 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 326 326 self.update() 327 self.slicer_mask = self.slicer.update() 328 327 self.slicer_mask = self.slicer.update() 328 329 329 def onAddMask(self, event): 330 330 """ 331 Add new mask to old mask 331 Add new mask to old mask 332 332 """ 333 333 if not self.slicer == None: … … 337 337 data.mask = self.data.mask & self.slicer_mask 338 338 self._check_display_mask(data.mask, event) 339 339 340 340 def _check_display_mask(self, mask, event): 341 341 """ 342 342 check if the mask valid and update the plot 343 343 344 344 :param mask: mask data 345 345 """ 346 # # Redraw the current image346 # # Redraw the current image 347 347 self._update_mask(mask) 348 348 … … 356 356 mask[self.slicer_mask == False] = True 357 357 self._check_display_mask(mask, event) 358 358 359 359 def onResetMask(self, event): 360 360 """ 361 Reset mask to the original mask 362 """ 361 Reset mask to the original mask 362 """ 363 363 self.slicer_z += 1 364 self.slicer = BoxMask(self, self.subplot,364 self.slicer = BoxMask(self, self.subplot, 365 365 zorder=self.slicer_z, side=True) 366 366 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 367 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 367 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 368 368 mask = copy.deepcopy(self.default_mask) 369 369 self.data.mask = mask 370 370 # update mask plot 371 371 self._check_display_mask(mask, event) 372 372 373 373 def onClearMask(self, event): 374 374 """ 375 375 Clear mask 376 """ 376 """ 377 377 self.slicer_z += 1 378 self.slicer = 378 self.slicer = BoxMask(self, self.subplot, 379 379 zorder=self.slicer_z, side=True) 380 380 self.subplot.set_ylim(self.data.ymin, self.data.ymax) 381 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 382 # mask = copy.deepcopy(self.default_mask)381 self.subplot.set_xlim(self.data.xmin, self.data.xmax) 382 # mask = copy.deepcopy(self.default_mask) 383 383 mask = numpy.ones(len(self.data.mask), dtype=bool) 384 384 self.data.mask = mask 385 385 # update mask plot 386 386 self._check_display_mask(mask, event) 387 387 388 388 def onClearSlicer(self, event): 389 389 """ … … 397 397 def update(self, draw=True): 398 398 """ 399 Respond to changes in the model by recalculating the 399 Respond to changes in the model by recalculating the 400 400 profiles and resetting the widgets. 401 401 """ 402 402 self.plotpanel.draw() 403 403 404 404 def _set_mask(self, mask): 405 405 """ … … 407 407 """ 408 408 self.data.mask = mask 409 409 410 410 def set_plot_unfocus(self): 411 411 """ … … 413 413 """ 414 414 pass 415 415 416 416 def _update_mask(self, mask): 417 417 """ 418 418 Respond to changes in masking 419 """ 419 """ 420 420 # the case of liitle numbers of True points 421 421 if (len(mask[mask]) < 10 and self.data != None): … … 430 430 # temp_data default is None 431 431 # This method is to distinguish between masked point and data point = 0. 432 temp_mask = temp_mask /temp_mask432 temp_mask = temp_mask / temp_mask 433 433 temp_mask[mask] = temp_data.data[mask] 434 # set temp_data value for self.mask==True, else still None 435 # temp_mask[mask] = temp_data[mask]436 437 # TODO: refactor this horrible logic434 # set temp_data value for self.mask==True, else still None 435 # temp_mask[mask] = temp_data[mask] 436 437 # TODO: refactor this horrible logic 438 438 temp_data.data[mask == False] = temp_mask[mask == False] 439 439 self.plotpanel.clear() … … 444 444 event = self._getEmptySlicerEvent() 445 445 wx.PostEvent(self, event) 446 447 # #use this method448 # set zmax and zmin to plot: Fix it w/ data.446 447 # #use this method 448 # set zmax and zmin to plot: Fix it w/ data. 449 449 if self.plotpanel.scale == 'log_{10}': 450 zmax = math.log10(max(self.data.data[self.data.data >0]))451 zmin = math.log10(min(self.data.data[self.data.data >0]))450 zmax = math.log10(max(self.data.data[self.data.data > 0])) 451 zmin = math.log10(min(self.data.data[self.data.data > 0])) 452 452 else: 453 zmax = max(self.data.data[self.data.data >0])454 zmin = min(self.data.data[self.data.data >0])455 # plot453 zmax = max(self.data.data[self.data.data > 0]) 454 zmin = min(self.data.data[self.data.data > 0]) 455 # plot 456 456 plot = self.plotpanel.image(data=temp_mask, 457 457 qx_data=self.data.qx_data, … … 470 470 self.plotpanel.render() 471 471 self.plotpanel.subplot.figure.canvas.draw_idle() 472 472 473 473 def _getEmptySlicerEvent(self): 474 474 """ 475 create an empty slicervent 475 create an empty slicervent 476 476 """ 477 477 self.innerbox_rb.SetValue(False) … … 483 483 return SlicerEvent(type=None, 484 484 params=None, 485 obj_class=None) 486 485 obj_class=None) 486 487 487 def _draw_model(self, event): 488 488 """ … … 490 490 """ 491 491 pass 492 492 493 493 def freeze_axes(self): 494 494 """ … … 496 496 """ 497 497 self.plotpanel.axes_frozen = True 498 498 499 499 def thaw_axes(self): 500 500 """ 501 501 thaw axes 502 502 """ 503 self.plotpanel.axes_frozen = False 504 503 self.plotpanel.axes_frozen = False 504 505 505 def onMouseMotion(self, event): 506 506 """ … … 508 508 """ 509 509 pass 510 510 511 511 def onWheel(self, event): 512 512 """ 513 513 on wheel event 514 514 """ 515 pass 516 515 pass 516 517 517 def OnClose(self, event): 518 518 """ … … 524 524 # when called by data panel 525 525 event.Skip() 526 pass 526 pass 527 527 528 528 class FloatPanel(wx.Dialog): … … 530 530 Provides the Mask Editor GUI. 531 531 """ 532 # # Internal nickname for the window, used by the AUI manager532 # # Internal nickname for the window, used by the AUI manager 533 533 window_name = "Plot" 534 # # Name to appear on the window title bar534 # # Name to appear on the window title bar 535 535 window_caption = "Plot" 536 # # Flag to tell the AUI manager to put this panel in the center pane536 # # Flag to tell the AUI manager to put this panel in the center pane 537 537 CENTER_PANE = False 538 538 ID = wx.NewId() 539 def __init__(self, parent=None, base=None, 539 def __init__(self, parent=None, base=None, 540 540 data=None, dimension=1, id=ID, *args, **kwds): 541 541 kwds["style"] = wx.DEFAULT_DIALOG_STYLE 542 kwds["size"] = wx.Size(PANEL_SIZE *1.5, PANEL_SIZE*1.5)543 wx.Dialog.__init__(self, parent, id=id, 544 542 kwds["size"] = wx.Size(PANEL_SIZE * 1.5, PANEL_SIZE * 1.5) 543 wx.Dialog.__init__(self, parent, id=id, *args, **kwds) 544 545 545 if data != None: 546 # Font size546 # Font size 547 547 kwds = [] 548 548 self.SetWindowVariant(variant=FONT_VARIANT) … … 551 551 self.data = data 552 552 self.str = self.data.__str__() 553 # # when 2 data have the same id override the 1 st plotted553 # # when 2 data have the same id override the 1 st plotted 554 554 self.name = self.data.name 555 555 self.dimension = dimension … … 560 560 self.plotpanel.prevXtrans = "x" 561 561 self.plotpanel.prevYtrans = "y" 562 562 563 563 self.cmap = DEFAULT_CMAP 564 # # Create Artist and bind it564 # # Create Artist and bind it 565 565 self.subplot = self.plotpanel.subplot 566 566 self._setup_layout() 567 567 if self.dimension == 1: 568 self.newplot = Data1D(x=data.x, y=data.y, 568 self.newplot = Data1D(x=data.x, y=data.y, 569 569 dx=data.dx, dy=data.dy) 570 570 self.newplot.name = data.name 571 else: 571 else: 572 572 self.newplot = Data2D(image=self.data.data) 573 573 self.newplot.setValues(self.data) 574 574 # Compute and get the image plot 575 575 self.get_plot() 576 # self.plotpanel.add_image(self.newplot)576 # self.plotpanel.add_image(self.newplot) 577 577 self.Centre() 578 578 self.Layout() 579 579 580 580 def get_plot(self): 581 581 """ 582 582 Get Plot panel 583 583 """ 584 cal_plot = CalcPlot(panel=self.plotpanel, 585 image=self.newplot, 584 cal_plot = CalcPlot(panel=self.plotpanel, 585 image=self.newplot, 586 586 completefn=self.complete) 587 587 cal_plot.queue() 588 588 589 589 def complete(self, panel, image, elapsed=None): 590 590 """ 591 591 Plot image 592 592 593 593 :param image: newplot [plotpanel] 594 594 """ 595 wx.CallAfter(panel.add_image, image) 596 595 wx.CallAfter(panel.add_image, image) 596 597 597 def _setup_layout(self): 598 598 """ … … 605 605 if len(self.data.data) > 3600: 606 606 note += "Rotation disabled for pixels > 60x60." 607 note_txt = wx.StaticText(self, -1, note) 607 note_txt = wx.StaticText(self, -1, note) 608 608 note_txt.SetForegroundColour(wx.RED) 609 sizer.Add(note_txt, (0, 2), flag=wx.RIGHT |wx.TOP, border=5)610 611 sizer.Add(self.plotpanel, (1, 0), (9, 9), 612 wx.EXPAND |wx.ALL, 15)609 sizer.Add(note_txt, (0, 2), flag=wx.RIGHT | wx.TOP, border=5) 610 611 sizer.Add(self.plotpanel, (1, 0), (9, 9), 612 wx.EXPAND | wx.ALL, 15) 613 613 614 614 sizer.AddGrowableCol(3) 615 615 sizer.AddGrowableRow(2) 616 616 617 617 self.SetSizerAndFit(sizer) 618 618 self.Centre() 619 619 self.Show(True) 620 620 621 621 def set_plot_unfocus(self): 622 622 """ … … 624 624 """ 625 625 pass 626 626 627 627 628 628 def _draw_model(self, event): … … 631 631 """ 632 632 pass 633 633 634 634 def freeze_axes(self): 635 635 """ … … 637 637 """ 638 638 self.plotpanel.axes_frozen = True 639 639 640 640 def thaw_axes(self): 641 641 """ 642 642 thaw axes 643 643 """ 644 self.plotpanel.axes_frozen = False 645 644 self.plotpanel.axes_frozen = False 645 646 646 def OnClose(self, event): 647 647 """ … … 655 655 pass 656 656 657 657 658 658 class Maskplotpanel(PlotPanel): 659 659 """ 660 660 PlotPanel for Quick plot and masking plot 661 661 """ 662 def __init__(self, parent, id=-1, dimension=2, color=None, 662 def __init__(self, parent, id=-1, dimension=2, color=None, 663 663 dpi=None, **kwargs): 664 664 """ 665 665 """ 666 666 PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs) 667 667 668 668 # Keep track of the parent Frame 669 669 self.parent = parent 670 # Internal list of plottable names (because graph 670 # Internal list of plottable names (because graph 671 671 # doesn't have a dictionary of handles for the plottables) 672 672 self.dimension = dimension 673 673 self.plots = {} 674 674 self.graph = Graph() 675 # add axis labels675 # add axis labels 676 676 self.graph.xaxis('\\rm{x} ', '') 677 677 self.graph.yaxis('\\rm{y} ', '') 678 678 679 679 def add_toolbar(self): 680 """ 680 """ 681 681 Add toolbar 682 682 """ 683 683 # Not implemented 684 684 pass 685 685 686 686 def on_set_focus(self, event): 687 687 """ … … 691 691 pass 692 692 else: 693 self.draw() 694 693 self.draw() 694 695 695 def add_image(self, plot): 696 696 """ … … 698 698 """ 699 699 self.plots[plot.name] = plot 700 # init graph700 # init graph 701 701 self.graph = Graph() 702 # add plot702 # add plot 703 703 self.graph.add(plot) 704 # add axes704 # add axes 705 705 if self.dimension == 1: 706 706 self.xaxis_label = '\\rm{x} ' … … 708 708 self.yaxis_label = '\\rm{y} ' 709 709 self.yaxis_unit = '' 710 # draw710 # draw 711 711 # message 712 status_type = 'progress' 712 status_type = 'progress' 713 713 msg = 'Plotting...' 714 714 self._status_info(msg, status_type) 715 status_type = 'stop' 715 status_type = 'stop' 716 716 self.graph.render(self) 717 717 self.subplot.figure.canvas.resizing = False … … 723 723 msg = 'Plotting Completed.' 724 724 self._status_info(msg, status_type) 725 725 726 726 def onMouseMotion(self, event): 727 727 """ … … 729 729 """ 730 730 pass 731 731 732 732 def onWheel(self, event): 733 733 """ 734 734 """ 735 pass 736 735 pass 736 737 737 def onLeftDown(self, event): 738 738 """ … … 740 740 """ 741 741 pass 742 742 743 743 def onPick(self, event): 744 744 """ … … 746 746 """ 747 747 pass 748 748 749 749 def draw(self): 750 750 """ … … 752 752 """ 753 753 # message 754 status_type = 'progress' 754 status_type = 'progress' 755 755 msg = 'Plotting...' 756 756 self._status_info(msg, status_type) 757 status_type = 'stop' 758 757 status_type = 'stop' 758 759 759 if self.dimension == 3: 760 760 pass 761 761 else: 762 self.subplot.figure.canvas.draw_idle() 763 762 self.subplot.figure.canvas.draw_idle() 763 764 764 msg = 'Plotting Completed.' 765 765 self._status_info(msg, status_type) 766 766 767 767 def onContextMenu(self, event): 768 768 """ … … 771 771 # Selective Slicer plot popup menu 772 772 slicerpop = wx.Menu() 773 773 774 774 id = wx.NewId() 775 775 slicerpop.Append(id, '&Print Image', 'Print image') … … 779 779 slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') 780 780 wx.EVT_MENU(self, id, self.OnCopyFigureMenu) 781 781 782 782 if self.dimension == 1: 783 783 id = wx.NewId() … … 789 789 slicerpop.Append(id_cm, '&Toggle Linear/Log scale') 790 790 wx.EVT_MENU(self, id_cm, self._onToggleScale) 791 791 792 792 pos = event.GetPosition() 793 793 pos = self.ScreenToClient(pos) 794 794 self.PopupMenu(slicerpop, pos) 795 796 def _status_info(self, msg = '', type ="update"):795 796 def _status_info(self, msg='', type="update"): 797 797 """ 798 798 Status msg … … 801 801 label = "Plotting..." 802 802 able = True 803 else: 803 else: 804 804 label = "Wait..." 805 805 able = False 806 806 if self.parent.parent.parent != None: 807 wx.PostEvent(self.parent.parent.parent, 808 StatusEvent(status = msg, type = type))807 wx.PostEvent(self.parent.parent.parent, 808 StatusEvent(status=msg, type=type)) 809 809 810 810 class ViewerFrame(wx.Frame): … … 825 825 class ViewApp(wx.App): 826 826 def OnInit(self): 827 frame = ViewerFrame(None, -1, 'testView') 827 frame = ViewerFrame(None, -1, 'testView') 828 828 frame.Show(True) 829 # self.SetTopWindow(frame)830 829 # self.SetTopWindow(frame) 830 831 831 return True 832 833 if __name__ == "__main__": 832 833 if __name__ == "__main__": 834 834 app = ViewApp(0) 835 app.MainLoop() 835 app.MainLoop()
Note: See TracChangeset
for help on using the changeset viewer.