Changeset 1c94a9f1 in sasview for guitools/fitDialog.py
- Timestamp:
- Jul 8, 2008 11:40:33 AM (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:
- 792db7d5
- Parents:
- 9a3adab
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/fitDialog.py
rad8bcd6 r1c94a9f1 27 27 class LinearFit(wx.Dialog): 28 28 def __init__(self, parent, plottable, push_data,transform, id, title): 29 wx.Dialog.__init__(self, parent, id, title, size=(400, 3 80))29 wx.Dialog.__init__(self, parent, id, title, size=(400, 350)) 30 30 31 31 """ … … 35 35 self.parent = parent 36 36 self.transform = transform 37 38 # Registered owner for close event 39 self._registered_close = None 37 40 38 41 #dialog panel self call function to plot the fitting function … … 65 68 self.xmaxFit = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 66 69 self.xmaxFit.SetToolTipString("Enter the maximum value on the x-axis to be included in the fit.") 67 self.xminTransFit = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20))68 self.xminTransFit.SetToolTipString("Minimum value on the x-axis for the plotted data.")69 self.xmaxTransFit = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20))70 self.xmaxTransFit.SetToolTipString("Maximum value on the x-axis for the plotted data.")71 70 self.initXmin = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 72 self.initXmin.SetToolTipString("Minimum value availableon the x-axis for the plotted data.")71 self.initXmin.SetToolTipString("Minimum value on the x-axis for the plotted data.") 73 72 self.initXmax = wx.TextCtrl(self,-1,size=(_BOX_WIDTH,20)) 74 self.initXmax.SetToolTipString("Maximum value availableon the x-axis for the plotted data.")73 self.initXmax.SetToolTipString("Maximum value on the x-axis for the plotted data.") 75 74 76 75 # Make the info box not editable 77 76 #_BACKGROUND_COLOR = '#ffdf85' 78 77 _BACKGROUND_COLOR = self.GetBackgroundColour() 79 self.xminTransFit.SetEditable(False)80 self.xminTransFit.SetBackgroundColour(_BACKGROUND_COLOR)81 self.xmaxTransFit.SetEditable(False)82 self.xmaxTransFit.SetBackgroundColour(_BACKGROUND_COLOR)83 78 self.initXmin.SetEditable(False) 84 79 self.initXmin.SetBackgroundColour(_BACKGROUND_COLOR) … … 93 88 self.btFit.SetToolTipString("Perform fit.") 94 89 self.btClose =wx.Button(self, wx.ID_CANCEL,'Close') 90 self.btClose.Bind(wx.EVT_BUTTON, self._on_close) 95 91 96 92 # Intro … … 136 132 iy += 1 137 133 ix = 0 138 sizer.Add(wx.StaticText(self, -1, 'Maximum range '),(iy, ix),(1,1),\134 sizer.Add(wx.StaticText(self, -1, 'Maximum range (linear scale)'),(iy, ix),(1,1),\ 139 135 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 140 136 ix +=1 … … 147 143 ix = 0 148 144 sizer.Add(wx.StaticText(self, -1, 'Fit range of '+self.xLabel),(iy, ix),(1,1),\ 149 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)150 ix += 1151 sizer.Add(self.xminTransFit, (iy, ix),(1,1),\152 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 0)153 ix += 2154 sizer.Add(self.xmaxTransFit, (iy, ix),(1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)155 156 iy += 1157 ix = 0158 sizer.Add(wx.StaticText(self, -1, 'Fit range of x'),(iy, ix),(1,1),\159 145 wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) 160 146 ix += 1 … … 216 202 self.tcChi.SetLabel(format_number(self.Chivalue)) 217 203 if self.plottable.x !=[]: 218 self.mini =min(self.plottable.x)219 self.maxi =max(self.plottable.x)220 204 #store the values of View in self.x,self.y,self.dx,self.dy 221 205 self.x,self.y,self.dx,self.dy= self.plottable.returnValuesOfView() 222 206 223 224 self. xminTransFit.SetLabel(format_number(min(self.x)))225 self.xmaxTransFit.SetLabel(format_number(max(self.x)))226 227 self.initXmin.SetValue(format_number( self.mini))228 self.initXmax.SetValue(format_number( self.maxi))207 self.mini =min(self.x) 208 self.maxi =max(self.x) 209 210 211 self.initXmin.SetValue(format_number(min(self.plottable.x))) 212 self.initXmax.SetValue(format_number(max(self.plottable.x))) 229 213 230 214 self.xminFit.SetLabel(format_number(self.mini)) … … 232 216 233 217 218 def register_close(self, owner): 219 """ 220 Method to register the close event to a parent 221 window that needs notification when the dialog 222 is closed 223 @param owner: parent window 224 """ 225 self._registered_close = owner 226 227 def _on_close(self, event): 228 """ 229 Close event. 230 Notify registered owner if available. 231 """ 232 event.Skip() 233 if self._registered_close is not None: 234 self._registered_close() 235 234 236 def _onFit(self ,event): 235 237 """ … … 252 254 if(self.checkFitValues(self.xminFit) == True): 253 255 #Check if the field of Fit Dialog contain values and use the x max and min of the user 254 xmin,xmax = self._checkVal(self.xminFit.GetValue(),self.xmaxFit.GetValue()) 255 256 xminView=self.floatTransform(xmin) 257 xmaxView=self.floatTransform(xmax) 258 if (self.xLabel=="log10(x)"): 259 self.xminTransFit.SetValue(format_number(math.log10(xminView))) 260 self.xmaxTransFit.SetValue(format_number(math.log10(xmaxView))) 261 else: 262 self.xminTransFit.SetValue(format_number(xminView)) 263 self.xmaxTransFit.SetValue(format_number(xmaxView)) 256 xminView,xmaxView = self._checkVal(self.xminFit.GetValue(),self.xmaxFit.GetValue()) 257 xmin = self.floatInvTransform(xminView) 258 xmax = self.floatInvTransform(xmaxView) 259 260 264 261 # Store the transformed values of view x, y,dy in variables before the fit 265 262 if self.yLabel.lower() == "log10(y)": … … 402 399 not in x 403 400 """ 401 #TODO: refactor this with proper object-oriented design 402 # This code stinks. 403 404 404 if ( self.xLabel=="x" ): 405 405 return transform.toX(x) … … 413 413 else: 414 414 raise ValueError,"cannot compute log of a negative number" 415 416 def floatInvTransform(self,x): 417 """ 418 transform a float.It is use to determine the x.View min and x.View max for values 419 not in x 420 """ 421 #TODO: refactor this. This is just a hack to make the 422 # functionality work without rewritting the whole code 423 # with good design (which really should be done...). 424 425 if ( self.xLabel=="x^(2)" ): 426 return math.sqrt(x) 427 428 elif (self.xLabel=="log10(x)" ): 429 return math.pow(10, x) 430 431 return x 415 432 416 433 def checkFitValues(self,item): … … 438 455 self.xminFit.SetValue(format_number(xmin)) 439 456 self.xmaxFit.SetValue(format_number(xmax)) 440 self.xminTransFit.SetValue(format_number(xminTrans)) 441 self.xmaxTransFit.SetValue(format_number(xmaxTrans)) 442 457 458 def set_fit_region(self, xmin, xmax): 459 """ 460 Set the fit region 461 @param xmin: minimum x-value to be included in fit 462 @param xmax: maximum x-value to be included in fit 463 """ 464 # Check values 465 try: 466 float(xmin) 467 float(xmax) 468 except: 469 raise ValueError, "LinearFit.set_fit_region: fit range must be floats" 470 self.xminFit.SetValue(format_number(xmin)) 471 self.xmaxFit.SetValue(format_number(xmax)) 443 472 444 473 class MyApp(wx.App):
Note: See TracChangeset
for help on using the changeset viewer.