Changeset ef0c170 in sasview for guiframe/local_perspectives
- Timestamp:
- Dec 18, 2008 5:26:36 PM (16 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:
- f2eee4a
- Parents:
- ab8f936
- Location:
- guiframe/local_perspectives/plotting
- Files:
-
- 3 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/Plotter1D.py
rab8f936 ref0c170 140 140 141 141 # Set the view scale for all plots 142 142 143 self._onEVT_FUNC_PROPERTY() 143 144 144 145 self.graph.render(self) 145 146 self.subplot.figure.canvas.draw_idle() -
guiframe/local_perspectives/plotting/Plotter2D.py
rab8f936 ref0c170 29 29 DEFAULT_QSTEP = 0.001 30 30 DEFAULT_BEAM = 0.005 31 BIN_WIDTH = 131 BIN_WIDTH = 1.0 32 32 import pylab 33 33 from Plotter1D import PanelMenu … … 81 81 #self.radius = math.sqrt(data2d.) 82 82 self.qstep = DEFAULT_QSTEP 83 print "panel2D qmax",self.qmax, 83 #print "panel2D qmax",self.qmax, 84 84 85 self.x = pylab.arange(-1*self.qmax, self.qmax+self.qstep*0.01, self.qstep) 85 86 self.y = pylab.arange(-1*self.imax, self.imax+self.qstep*0.01, self.qstep) … … 112 113 if hasattr(event, "reset"): 113 114 self._reset() 114 print "model2 d event",event.plot.name, event.plot.id, event.plot.group_id115 print "plottable list ",self.plots.keys()116 print self.plots115 #print "model2 d event",event.plot.name, event.plot.id, event.plot.group_id 116 #print "plottable list ",self.plots.keys() 117 #print self.plots 117 118 is_new = True 118 119 if event.plot.name in self.plots.keys(): … … 129 130 if is_new: 130 131 # a new plottable overwrites a plotted one using the same id 131 print "went here",self.plots.itervalues()132 #print "went here",self.plots.itervalues() 132 133 for plottable in self.plots.itervalues(): 133 134 if event.plot.id==plottable.id : … … 195 196 196 197 id = wx.NewId() 197 slicerpop.Append(id, '&Sector Q')198 slicerpop.Append(id, '&Sector [Q view]') 198 199 wx.EVT_MENU(self, id, self.onSectorQ) 199 200 200 201 id = wx.NewId() 201 slicerpop.Append(id, '& Sector Phi')202 slicerpop.Append(id, '&Annulus [Phi view ]') 202 203 wx.EVT_MENU(self, id, self.onSectorPhi) 203 204 … … 306 307 307 308 from DataLoader.manipulations import CircularAverage 308 Circle = CircularAverage( r_min= 0, r_max= self.qmax, bin_width=BIN_WIDTH ) 309 import math 310 self.radius= math.sqrt( math.pow(self.qmax,2)+math.pow(self.qmax,2)) 311 print "radius?",self.radius 312 Circle = CircularAverage( r_min=0, r_max=self.radius, bin_width=0.001) 313 #Circle = CircularAverage( r_min=0, r_max=13705.0, bin_width=BIN_WIDTH ) 309 314 #Circle = CircularAverage( r_min= -1, r_max= 1, bin_width=0.001 ) 315 #Circle = CircularAverage( r_min= -1*self.radius, r_max= self.radius, bin_width=0.001 ) 310 316 circ = Circle(self.data2D) 311 317 from sans.guiframe.dataFitting import Data1D … … 318 324 else: 319 325 dxw= None 320 326 321 327 new_plot = Data1D(x=circ.x,y=circ.y,dy=circ.dy,dxl=dxl,dxw=dxw) 322 328 new_plot.name = "Circ avg "+ self.data2D.name … … 332 338 new_plot.group_id = "Circ avg "+ self.data2D.name 333 339 self.scale = 'log' 340 334 341 wx.PostEvent(self.parent, NewPlotEvent(plot=new_plot, title=new_plot.name)) 335 336 342 337 343 def _onEditSlicer(self, event): 338 344 if self.slicer !=None: … … 349 355 """ 350 356 351 from SectorSlicer import SectorInteractor Q357 from SectorSlicer import SectorInteractor 352 358 self.onClearSlicer(event) 353 wx.PostEvent(self.parent, InternalEvent(slicer= SectorInteractor Q))359 wx.PostEvent(self.parent, InternalEvent(slicer= SectorInteractor)) 354 360 355 361 def onSectorPhi(self, event): … … 357 363 Perform sector averaging on Phi 358 364 """ 359 from SectorSlicer import SectorInteractorPhi365 from AnnulusSlicer import AnnulusInteractor 360 366 self.onClearSlicer(event) 361 wx.PostEvent(self.parent, InternalEvent(slicer= SectorInteractorPhi))367 wx.PostEvent(self.parent, InternalEvent(slicer= AnnulusInteractor)) 362 368 363 369 -
guiframe/local_perspectives/plotting/SectorSlicer.py
rcd84dca ref0c170 8 8 9 9 # Debug printout 10 10 from sans.guicomm.events import StatusEvent 11 from sans.guicomm.events import NewPlotEvent 11 12 from BaseInteractor import _BaseInteractor 12 13 from copy import deepcopy 13 14 import math 14 15 15 from sans.guicomm.events import NewPlotEvent, StatusEvent 16 16 17 import SlicerParameters 17 18 import wx … … 31 32 ## Number of points on the plot 32 33 self.nbins = 20 33 theta1=math.pi/8 34 theta2=math.pi/2 35 theta1=2*math.pi/3 36 theta2=-2*math.pi/3 37 r1=self.qmax/2.0 38 r2=self.qmax/1.8 39 34 self.theta1= math.pi/4 35 self.theta2= math.pi/3 36 self.phi=math.pi/12 37 #self.theta3= 2*self.theta2 -self.theta1 40 38 # Inner circle 41 from Arc import ArcInteractor 42 self.inner_circle = ArcInteractor(self, self.base.subplot, zorder=zorder, r=self.qmax/2.0,theta1= theta1, 43 theta2=theta2) 44 self.inner_circle.qmax = self.base.qmax 45 self.outer_circle = ArcInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax/1.8,theta1= theta1, 46 theta2=theta2) 47 self.outer_circle.qmax = self.base.qmax*1.2 39 self.main_line = LineInteractor(self, self.base.subplot,color='blue', zorder=zorder, r=self.qmax, 40 theta= self.theta2) 41 self.main_line.qmax = self.base.qmax 42 #self.left_line = SectionInteractor(self, self.base.subplot, zorder=zorder+1, r=self.qmax, 43 # theta1= self.theta1, theta2= self.theta2) 44 #self.left_line.qmax = self.base.qmax 45 self.right_line= SideInteractor(self, self.base.subplot,color='black', zorder=zorder, 46 r=self.qmax, 47 phi= -1*self.phi, 48 theta2=self.theta2) 49 self.right_line.qmax = self.base.qmax 50 self.left_line= SideInteractor(self, self.base.subplot,color='green', zorder=zorder, 51 r=self.qmax, 52 phi= self.phi, 53 theta2=self.theta2) 54 self.left_line.qmax = self.base.qmax 48 55 #self.outer_circle.set_cursor(self.base.qmax/1.8, 0) 49 from Edge import RadiusInteractor 50 self.right_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 51 arc1=self.inner_circle, 52 arc2=self.outer_circle, 53 theta=theta1) 54 self.left_edge= RadiusInteractor(self, self.base.subplot, zorder=zorder+1, 55 arc1=self.inner_circle, 56 arc2=self.outer_circle, 57 theta=theta2) 56 57 58 58 self.update() 59 59 self._post_data() 60 60 61 # Bind to slice parameter events 61 62 self.base.parent.Bind(SlicerParameters.EVT_SLICER_PARS, self._onEVT_SLICER_PARS) … … 63 64 64 65 def _onEVT_SLICER_PARS(self, event): 65 #printEVT("AnnulusSlicer._onEVT_SLICER_PARS")66 wx.PostEvent(self.base.parent, StatusEvent(status="SectorSlicer._onEVT_SLICER_PARS")) 66 67 event.Skip() 67 68 if event.type == self.__class__.__name__: … … 69 70 self.base.update() 70 71 71 """72 72 def update_and_post(self): 73 73 self.update() 74 self._post_data() 75 76 """ 74 #self._post_data() 75 77 76 def save_data(self, path, image, x, y): 78 77 output = open(path, 'w') … … 91 90 def clear(self): 92 91 self.clear_markers() 93 self.outer_circle.clear() 94 self.inner_circle.clear() 95 self.right_edge.clear() 96 self.left_edge.clear() 92 self.main_line.clear() 93 self.left_line.clear() 94 self.right_line.clear() 97 95 #self.base.connect.disconnect() 98 96 self.base.parent.Unbind(SlicerParameters.EVT_SLICER_PARS) … … 103 101 resetting the widgets. 104 102 """ 105 # Update locations 106 if self.inner_circle.has_move: 107 print "inner circle has moved" 108 self.inner_circle.update() 109 r1=self.inner_circle.get_radius() 110 r2=self.outer_circle.get_radius() 111 self.right_edge.update(r1,r2) 112 self.left_edge.update(r1,r2) 113 if self.outer_circle.has_move: 114 print "outer circle has moved" 115 self.outer_circle.update() 116 r1=self.inner_circle.get_radius() 117 r2=self.outer_circle.get_radius() 118 self.left_edge.update(r1,r2) 119 self.right_edge.update(r1,r2) 120 if self.right_edge.has_move: 121 print "right edge has moved" 122 self.right_edge.update() 123 self.inner_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 124 self.outer_circle.update(theta1=self.right_edge.get_angle(), theta2=None) 125 if self.left_edge.has_move: 126 print "left Edge has moved" 127 self.left_edge.update() 128 self.inner_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 129 self.outer_circle.update(theta1=None, theta2=self.left_edge.get_angle()) 130 131 103 # Update locations 104 105 #if self.main_line.has_move: 106 #self.main_line.update() 107 #self.right_line.update() 108 #self.left_line.update() 109 if self.main_line.has_move: 110 self.main_line.update() 111 self.right_line.update( delta = self.main_line.get_radius(),mline= self.main_line) 112 self.left_line.update( delta = self.main_line.get_radius() ,mline= self.main_line) 113 print "Main line has moved ---> phi right",math.degrees(self.main_line.theta-self.right_line.theta) 114 print "Main line has moved ---> phi left",math.degrees(self.main_line.theta-self.left_line.theta) 115 if self.left_line.has_move: 116 print "left line has moved --->" 117 self.main_line.update() 118 self.left_line.update(phi=None,delta=None, mline=self.main_line,side=True) 119 #self.right_line.update(-1*delta,linem=self.main_line,linel=self.left_line) 120 self.right_line.update(phi=-1*self.left_line.phi,delta=None, mline=self.main_line,side=True) 121 if self.right_line.has_move: 122 print "right line has moved --->" 123 124 self.main_line.update() 125 self.right_line.update(phi=None,delta=None, mline=self.main_line,side=True) 126 #self.right_line.update(-1*delta,linem=self.main_line,linel=self.left_line) 127 self.left_line.update(phi=-1*self.right_line.phi,delta=None, mline=self.main_line,side=True) 128 129 130 131 132 132 def save(self, ev): 133 133 """ … … 138 138 self.inner_circle.save(ev) 139 139 self.outer_circle.save(ev) 140 self.right_edge.save(ev) 141 self.left_edge.save(ev) 142 143 def _post_data(self): 144 pass 145 146 def post_data(self,new_sector ): 147 """ post data averaging in Q""" 148 if self.inner_circle.get_radius() < self.outer_circle.get_radius(): 149 rmin=self.inner_circle.get_radius() 150 rmax=self.outer_circle.get_radius() 151 else: 152 rmin=self.outer_circle.get_radius() 153 rmax=self.inner_circle.get_radius() 154 if self.right_edge.get_angle() < self.left_edge.get_angle(): 155 phimin=self.right_edge.get_angle() 156 phimax=self.left_edge.get_angle() 157 else: 158 phimin=self.left_edge.get_angle() 159 phimax=self.right_edge.get_angle() 160 161 print "phimin, phimax, rmin ,rmax",math.degrees(phimin), math.degrees(phimax), rmin ,rmax 162 #from DataLoader.manipulations import SectorQ 163 164 sect = new_sector(r_min=rmin, r_max=rmax, phi_min=phimin, phi_max=phimax) 140 141 def _post_data(self, nbins=None): 142 # Compute data 143 data = self.base.data2D 144 # If we have no data, just return 145 if data == None: 146 return 147 148 name = "Sector " 149 from DataLoader.manipulations import SectorQ 150 radius = math.sqrt(math.pow(self.qmax,2)+math.pow(self.qmax,2)) 151 phimin = self.right_line.theta 152 phimax = self.left_line.theta 153 sect = SectorQ(r_min=-1*radius , r_max= radius , phi_min=phimin, phi_max=phimax) 154 if nbins!=None: 155 sect.nbins = nbins 156 165 157 sector = sect(self.base.data2D) 166 158 … … 176 168 177 169 new_plot = Data1D(x=sector.x,y=sector.y,dy=sector.dy,dxl=dxl,dxw=dxw) 178 new_plot.name = str(new_sector.__name__)+"("+ self.base.data2D.name+")"170 new_plot.name = "SectorQ" +"("+ self.base.data2D.name+")" 179 171 180 172 … … 188 180 new_plot.xaxis("\\rm{Q}", 'rad') 189 181 new_plot.yaxis("\\rm{Intensity} ","cm^{-1}") 190 new_plot.group_id = str(new_sector.__name__)+self.base.data2D.name182 new_plot.group_id = "SectorQ"+self.base.data2D.name 191 183 wx.PostEvent(self.base.parent, NewPlotEvent(plot=new_plot, 192 title=str(new_sector.__name__) )) 193 184 title="SectorQ" )) 185 186 194 187 195 188 def moveend(self, ev): 196 #self.base.thaw_axes() 197 198 # Post paramters 199 #event = SlicerParameters.SlicerParameterEvent() 200 #event.type = self.__class__.__name__ 201 #event.params = self.get_params() 202 #print "main moveend ", event.params 203 #wx.PostEvent(self.base.parent, event) 189 self.base.thaw_axes() 190 191 # Post paramters 192 event = SlicerParameters.SlicerParameterEvent() 193 event.type = self.__class__.__name__ 194 event.params = self.get_params() 195 wx.PostEvent(self.base.parent, event) 204 196 self._post_data() 205 197 … … 208 200 Restore the roughness for this layer. 209 201 """ 210 self.inner_circle.restore() 211 self.outer_circle.restore() 212 self.right_edge.restore() 213 self.left_edge.restore() 202 self.main_line.restore() 203 self.left_line.restore() 204 self.right_line.restore() 214 205 215 206 def move(self, x, y, ev): … … 224 215 def get_params(self): 225 216 params = {} 226 params[" r_min"] = self.inner_circle.get_radius()227 params["r_max"] = self.outer_circle.get_radius()228 params["phi_min"] = self.right_edge.get_angle()229 params[" phi_max"] = self.left_edge.get_angle()217 params["main_phi"] = self.main_line.theta 218 if math.fabs(self.left_line.phi) != math.fabs(self.right_line.phi): 219 raise ValueError,"Phi left and phi right are different %f, %f"%(self.left_line.phi, self.right_line.phi) 220 params["left_phi"] = self.left_line.phi 230 221 params["nbins"] = self.nbins 231 222 return params 232 223 233 224 def set_params(self, params): 234 print "setparams on main slicer ",params 235 inner = params["r_min"] 236 outer = params["r_max"] 237 phi_min= params["phi_min"] 238 phi_max=params["phi_max"] 225 226 main = params["main_phi"] 227 phi = params["left_phi"] 239 228 self.nbins = int(params["nbins"]) 240 241 242 self. inner_circle.set_cursor(inner, phi_min, phi_max,self.nbins)243 self. outer_circle.set_cursor(outer, phi_min, phi_max, self.nbins)244 self. right_edge.set_cursor(inner, outer, phi_min)245 self.left_edge.set_cursor(inner, outer, phi_max)246 self._post_data( )229 self.main_line.theta= main 230 231 self.main_line.update() 232 self.right_line.update(phi=-1*phi,delta=None, mline=self.main_line,side=True) 233 self.left_line.update(phi=phi,delta=None, mline=self.main_line,side=True) 234 235 self._post_data(nbins=self.nbins) 247 236 248 237 def freeze_axes(self): … … 255 244 self.base.draw() 256 245 257 class SectorInteractorQ(SectorInteractor): 258 def __init__(self,base,axes,color='black', zorder=3): 259 SectorInteractor.__init__(self, base, axes, color=color) 260 self.base=base 261 self._post_data() 262 def _post_data(self): 263 from DataLoader.manipulations import SectorQ 264 self.post_data(SectorQ ) 265 266 267 class SectorInteractorPhi(SectorInteractor): 268 def __init__(self,base,axes,color='black', zorder=3): 269 SectorInteractor.__init__(self, base, axes, color=color) 270 self.base=base 271 self._post_data() 272 def _post_data(self): 273 from DataLoader.manipulations import SectorPhi 274 self.post_data(SectorPhi ) 275 276 246 247 class SideInteractor(_BaseInteractor): 248 """ 249 Select an annulus through a 2D plot 250 """ 251 def __init__(self,base,axes,color='black', zorder=5, r=1.0,phi=math.pi/4, theta2= math.pi/3): 252 253 _BaseInteractor.__init__(self, base, axes, color=color) 254 self.markers = [] 255 self.axes = axes 256 257 self.save_theta = theta2 + phi 258 self.theta= theta2 + phi 259 self.theta2 = theta2 260 self.radius = r 261 self.phi = phi 262 self.scale = 10.0 263 #print "init for line side theta2, phi, theta",math.degrees(theta2),math.degrees(phi),math.degrees(self.theta) 264 #raise "Version error", message 265 266 # Inner circle 267 x1= self.radius*math.cos(self.theta) 268 y1= self.radius*math.sin(self.theta) 269 x2= -1*self.radius*math.cos(self.theta) 270 y2= -1*self.radius*math.sin(self.theta) 271 272 self.line = self.axes.plot([x1,x2],[y1,y2], 273 linestyle='-', marker='', 274 color=self.color, 275 visible=True)[0] 276 277 self.npts = 20 278 self.has_move=False 279 self.connect_markers([self.line]) 280 #self.update() 281 282 def set_layer(self, n): 283 self.layernum = n 284 self.update() 285 286 def clear(self): 287 self.clear_markers() 288 try: 289 290 self.line.remove() 291 except: 292 # Old version of matplotlib 293 for item in range(len(self.axes.lines)): 294 del self.axes.lines[0] 295 296 297 298 def get_radius(self): 299 300 return self.theta - self.save_theta 301 302 def update(self,phi=None,delta=None, mline=None,side=False): 303 """ 304 Draw the new roughness on the graph. 305 """ 306 #print "update left or right ", self.has_move 307 308 if phi !=None: 309 self.phi = phi 310 if delta==None: 311 delta = 0 312 if side== True: 313 self.theta= mline.theta + self.phi 314 if mline!=None: 315 self.theta2 = mline.theta 316 #print "U:for line side theta2, phi, theta",math.degrees(self.theta2),math.degrees(self.phi),math.degrees(self.theta) 317 #if self.theta2 >= self.theta and self.theta>=0: 318 # print "between 0-pi",math.degrees(self.theta) 319 320 x1= self.radius*math.cos(self.theta + delta) 321 y1= self.radius*math.sin(self.theta + delta) 322 x2= -1*self.radius*math.cos(self.theta + delta) 323 y2= -1*self.radius*math.sin(self.theta + delta) 324 325 326 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 327 328 329 330 331 def save(self, ev): 332 """ 333 Remember the roughness for this layer and the next so that we 334 can restore on Esc. 335 """ 336 self.save_theta= self.theta 337 self.base.freeze_axes() 338 339 def moveend(self, ev): 340 341 self.has_move=False 342 self.base.moveend(ev) 343 344 def restore(self): 345 """ 346 Restore the roughness for this layer. 347 """ 348 self.theta = self.save_theta 349 350 def move(self, x, y, ev): 351 """ 352 Process move to a new position, making sure that the move is allowed. 353 """ 354 355 self.theta= math.atan2(y,x) 356 self.phi= self.theta2 - self.theta 357 358 print "move left or right phi ---theta--thetaM", self.phi, self.theta, self.theta2 359 self.has_move=True 360 self.base.base.update() 361 362 def set_cursor(self, x, y): 363 self.move(x, y, None) 364 self.update() 365 366 367 def get_params(self): 368 params = {} 369 params["radius"] = self.radius 370 params["theta"] = self.theta 371 return params 372 373 def set_params(self, params): 374 375 x = params["radius"] 376 self.set_cursor(x, self._inner_mouse_y) 377 378 379 380 381 382 class LineInteractor(_BaseInteractor): 383 """ 384 Select an annulus through a 2D plot 385 """ 386 def __init__(self,base,axes,color='black', zorder=5, r=1.0,theta=math.pi/4): 387 388 _BaseInteractor.__init__(self, base, axes, color=color) 389 self.markers = [] 390 self.axes = axes 391 392 self.save_theta = theta 393 self.theta= theta 394 395 self.radius = r 396 397 self.scale = 10.0 398 399 #raise "Version error", message 400 401 # Inner circle 402 403 404 x1= self.radius*math.cos(self.theta) 405 y1= self.radius*math.sin(self.theta) 406 x2= -1*self.radius*math.cos(self.theta) 407 y2= -1*self.radius*math.sin(self.theta) 408 409 self.line = self.axes.plot([x1,x2],[y1,y2], 410 linestyle='-', marker='', 411 color=self.color, 412 visible=True)[0] 413 414 self.npts = 20 415 self.has_move=False 416 self.connect_markers([self.line]) 417 self.update() 418 419 def set_layer(self, n): 420 self.layernum = n 421 self.update() 422 423 def clear(self): 424 self.clear_markers() 425 try: 426 427 self.line.remove() 428 except: 429 # Old version of matplotlib 430 for item in range(len(self.axes.lines)): 431 del self.axes.lines[0] 432 433 434 435 def get_radius(self): 436 437 return self.theta - self.save_theta 438 439 def update(self, theta=None): 440 """ 441 Draw the new roughness on the graph. 442 """ 443 print "update main line", self.theta 444 if theta !=None: 445 self.theta= theta 446 x1= self.radius*math.cos(self.theta) 447 y1= self.radius*math.sin(self.theta) 448 x2= -1*self.radius*math.cos(self.theta) 449 y2= -1*self.radius*math.sin(self.theta) 450 451 self.line.set(xdata=[x1,x2], ydata=[y1,y2]) 452 453 454 455 def save(self, ev): 456 """ 457 Remember the roughness for this layer and the next so that we 458 can restore on Esc. 459 """ 460 self.save_theta= self.theta 461 self.base.freeze_axes() 462 463 def moveend(self, ev): 464 465 self.has_move=False 466 self.base.moveend(ev) 467 468 def restore(self): 469 """ 470 Restore the roughness for this layer. 471 """ 472 self.theta = self.save_theta 473 474 def move(self, x, y, ev): 475 """ 476 Process move to a new position, making sure that the move is allowed. 477 """ 478 479 self.theta= math.atan2(y,x) 480 print "main_line previous theta --- next theta ",math.degrees(self.save_theta),math.degrees(self.theta) 481 482 self.has_move=True 483 self.base.base.update() 484 485 def set_cursor(self, x, y): 486 self.move(x, y, None) 487 self.update() 488 489 490 def get_params(self): 491 params = {} 492 params["radius"] = self.radius 493 params["theta"] = self.theta 494 return params 495 496 def set_params(self, params): 497 498 x = params["radius"] 499 self.set_cursor(x, self._inner_mouse_y) 500 501 502 503 -
guiframe/local_perspectives/plotting/SlicerParameters.py
rcd84dca ref0c170 10 10 (SlicerParameterEvent, EVT_SLICER_PARS) = wx.lib.newevent.NewEvent() 11 11 12 class SlicerParameterPanel(wx.Panel): 12 13 def format_number(value, high=False): 14 """ 15 Return a float in a standardized, human-readable formatted string 16 """ 17 try: 18 value = float(value) 19 except: 20 return "NaN" 21 22 if high: 23 return "%-6.4g" % value 24 else: 25 return "%-5.3g" % value 26 27 class SlicerParameterPanel(wx.Dialog): 13 28 #TODO: show units 14 29 #TODO: order parameters properly 15 30 16 31 def __init__(self, parent, *args, **kwargs): 17 wx. Panel.__init__(self, parent, *args, **kwargs)32 wx.Dialog.__init__(self, parent, *args, **kwargs) 18 33 self.params = {} 19 34 self.parent = parent … … 58 73 title = wx.StaticText(self, -1, "Slicer Parameters", style=wx.ALIGN_LEFT) 59 74 self.bck.Add(title, (0,0), (1,2), flag=wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border=15) 60 61 n = 175 ix = 0 76 iy = 0 62 77 self.parameters = [] 63 78 #params = slicer.get_params() … … 66 81 67 82 for item in keys: 68 n += 1 83 iy += 1 84 ix = 0 69 85 text = wx.StaticText(self, -1, item, style=wx.ALIGN_LEFT) 70 self.bck.Add(text, (n-1,0), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 86 #self.bck.Add(text, (iy,ix), flag = wx.LEFT|wx.ALIGN_CENTER_VERTICAL, border = 15) 87 self.bck.Add(text, (iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 71 88 ctl = wx.TextCtrl(self, -1, size=(80,20), style=wx.TE_PROCESS_ENTER) 72 89 73 90 ctl.SetToolTipString("Modify the value of %s to change the 2D slicer" % item) 74 91 75 76 ctl.SetValue( str(params[item]))92 ix = 1 93 ctl.SetValue(format_number(str(params[item]))) 77 94 self.Bind(wx.EVT_TEXT_ENTER, self.onTextEnter) 78 95 ctl.Bind(wx.EVT_KILL_FOCUS, self.onTextEnter) 79 96 self.parameters.append([item, ctl]) 80 self.bck.Add(ctl, (n-1,1), flag=wx.TOP|wx.BOTTOM, border = 0) 81 97 #self.bck.Add(ctl, (iy,ix), flag=wx.TOP|wx.BOTTOM, border = 0) 98 self.bck.Add(ctl, (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 99 100 ix =3 101 self.bck.Add((20,20), (iy,ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) 102 iy +=1 103 ix = 1 104 self.bck.Add((20,20),(iy,ix),(1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 82 105 self.bck.Layout() 83 106 self.bck.Fit(self)
Note: See TracChangeset
for help on using the changeset viewer.