Package reflectometry :: Package model1d :: Package profileview :: Module addLayerDialog

Source Code for Module reflectometry.model1d.profileview.addLayerDialog

  1  import wx 
  2  from reflutils import CheckValid 
  3  from reflectometry.model1d.model.bspline import BSpline, spline, slope, Slope 
  4  from reflectometry.model1d.model.tetheredPolymer import tetheredPolymer, TetheredPolymer, brush, Brush, BRUSH 
  5   
  6   
  7  # ---------------------------------------------------------------------- 
8 -class AddLayerDialog(wx.Dialog):
9 - def __init__( 10 self, 11 parent, 12 ID, 13 title, 14 size = (300, 300),#wx.DefaultSize, 15 pos = wx.DefaultPosition, 16 style = wx.DEFAULT_DIALOG_STYLE, 17 useMetal = False, 18 model = None 19 ):
20 self.parent = parent 21 self.model = model 22 23 pre = wx.PreDialog() 24 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) 25 pre.Create(parent, ID, title, pos, size, style) 26 27 self.PostCreate(pre) 28 29 # This extra style can be set after the UI object has been created. 30 if 'wxMac' in wx.PlatformInfo and useMetal: 31 self.SetExtraStyle(wx.DIALOG_EX_METAL) 32 33 self._mgr = wx.aui.AuiManager(self) 34 35 self.txts=[r'Layer name', 36 r'depth', 37 r'roughness', 38 r'Rho', 39 r'mu', 40 r'Phi', 41 r'Theta' 42 ] 43 44 self.DefaultTxts = [ 45 r'None', # layer name 46 r'200', # depth 47 r'5.0', # roghhness 48 r'1.0', # rho 49 r'0.0', # mu 50 r'0', # phi 51 r'0' # theta 52 ] 53 54 55 if model.magnetic: 56 self.num = 7 57 else: 58 self.num = 5 59 60 for x in xrange( self.num ): 61 wx.StaticText(self, -1, self.txts[x], (10, 20+x*30)) 62 63 self.textCtrls = [] 64 65 for x in xrange( self.num ): 66 textctl = wx.TextCtrl(self, 67 -1, 68 pos=(80, 20+x*30), 69 size=wx.Size(400, 20) 70 #style=wx.TE_MULTILINE|wx.TE_RICH|wx.TE_RICH2 71 ) 72 self.textCtrls.append( textctl ) 73 74 75 self._mgr.Update() 76 77 for x in xrange( self.num ): 78 self.textCtrls[x].SetValue( self.DefaultTxts[x] ) 79 80 self.button = wx.Button(self, 81 wx.ID_OK, 82 '', 83 (200, 20+(self.num)*30) 84 ) 85 self.cancelbutton = wx.Button(self, 86 wx.ID_CANCEL, 87 '', 88 (300, 20+(self.num)*30) 89 ) 90 91 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnClosePage) 92 self.Bind(wx.EVT_CLOSE, self.OnClose) 93 94 # Layer Information 95 self.layer_info=[] 96 97 # error flag 98 self._error = 0
99 100 101 #=================================================== 102 # Get layer info 103 #===================================================
104 - def getLayerInfo(self):
105 ret = [] 106 ret.append( self.getLayerNameValue() ) 107 ret.append( self.getLayerDepthValue() ) 108 ret.append( self.getLayerRoughnessValue() ) 109 ret.append( self.getLayerRhoValue() ) 110 ret.append( self.getLayerMuValue() ) 111 112 if self.model.magnetic: 113 ret.append( self.getLayerPhiValue() ) 114 ret.append( self.getLayerThetaValue() ) 115 116 ret.append( self._error ) 117 118 return ret
119 120
121 - def getLayerNameValue(self):
122 return self.textCtrls[0].GetValue().strip()
123 124
125 - def getLayerDepthValue(self):
126 try: 127 ret = CheckValid( self.textCtrls[1].GetValue() ) 128 except: 129 self._error = 1 130 ret = None 131 132 return ret
133 134
135 - def getLayerRoughnessValue(self):
136 try: 137 ret = CheckValid( self.textCtrls[2].GetValue() ) 138 except: 139 self._error = 1 140 ret = None 141 return ret
142 143
144 - def getLayerRhoValue(self):
145 try: 146 ret = eval( self.textCtrls[3].GetValue().strip() ) 147 except: 148 self._error = 1 149 ret = None 150 151 return ret
152 153 154
155 - def getLayerMuValue(self):
156 try: 157 ret = eval( self.textCtrls[4].GetValue().strip() ) 158 except: 159 self._error = 1 160 ret = None 161 162 return ret
163 164
165 - def getLayerPhiValue(self):
166 try: 167 ret = eval( self.textCtrls[5].GetValue().strip() ) 168 except: 169 self._error = 1 170 ret = None 171 172 return ret
173 174
175 - def getLayerThetaValue(self):
176 try: 177 ret = eval( self.textCtrls[6].GetValue().strip() ) 178 except: 179 self._error = 1 180 ret = None 181 182 return ret
183 184
185 - def GetOwnerManager(self):
186 return self._mgr
187 188
189 - def OnClose(self, event):
190 self._mgr.UnInit() 191 event.Skip()
192 193
194 - def OnClosePage(self, event):
195 event.Veto()
196 197 198 199 200 201 #=====================================================================
202 -class AddLayerDialogNM(wx.Dialog):
203 - def __init__( 204 self, 205 parent, 206 ID, 207 title, 208 size = (300, 240),#wx.DefaultSize, 209 pos = wx.DefaultPosition, 210 style = wx.DEFAULT_DIALOG_STYLE, 211 useMetal = False, 212 model = None 213 ):
214 self.parent = parent 215 self.model = model 216 # Instead of calling wx.Dialog.__init__ we precreate the dialog 217 # so we can set an extra style that must be set before 218 # creation, and then we create the GUI object using the Create method. 219 pre = wx.PreDialog() 220 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) 221 pre.Create(parent, ID, title, pos, size, style) 222 223 # This next step is the most important, it turns this Python 224 # object into the real wrapper of the dialog (instead of pre) 225 # as far as the wxPython extension is concerned. 226 self.PostCreate(pre) 227 228 # This extra style can be set after the UI object has been created. 229 if 'wxMac' in wx.PlatformInfo and useMetal: 230 self.SetExtraStyle(wx.DIALOG_EX_METAL) 231 232 self._mgr = wx.aui.AuiManager(self) 233 234 self.txts=[r'Type', r'Layer number', r'Layer name', 235 r'depth', r'roughness', 236 r'Rho', r'mu' ] 237 238 self.DefaultTxts = [r'Flat', # type 239 r'1', # layer number, layer 0 is "Air" 240 r'None', # layer name 241 r'100', # depth 242 r'5.0', # roghhness 243 r'1.0', # rho 244 r'1.0' # mu 245 ] 246 247 self.LayerTypes = [r"Flat", r"Slope", r"Spline", r"Cosine"] 248 249 if model.magnetic: 250 self.num = 9 251 else: 252 self.num = 7 253 254 for x in xrange( self.num ): 255 wx.StaticText(self, -1, self.txts[x], (20, 20+x*30)) 256 257 self.textCtrls = [] 258 259 self.typeComboBox = wx.ComboBox(choices=self.LayerTypes, 260 id=-1, 261 name=u'typeComboBox', 262 parent=self, 263 pos=wx.Point(100, 20), 264 size=wx.Size(150, 20), 265 style= 0, 266 value=u'Flat' 267 ) 268 self.typeComboBox.SetSelection(0) 269 self.Bind(wx.EVT_COMBOBOX, self.OnTypeCombobox, self.typeComboBox) 270 #self.selection = 0 271 272 273 for x in xrange( self.num -1): 274 textctl = wx.TextCtrl(self, 275 -1, 276 pos=(100, 50+x*30), 277 size=wx.Size(150, 20) 278 #style=wx.TE_MULTILINE|wx.TE_RICH|wx.TE_RICH2 279 ) 280 self.textCtrls.append( textctl ) 281 282 283 self._mgr.Update() 284 285 for x in xrange( self.num -1 ): 286 self.textCtrls[x].SetValue( self.DefaultTxts[x+1] ) 287 288 289 self.button = wx.Button(self, 290 wx.ID_OK, 291 '', 292 (200, 20+(self.num)*30) 293 ) 294 self.cancelbutton = wx.Button(self, 295 wx.ID_CANCEL, 296 '', 297 (300, 50+(self.num)*30) 298 ) 299 300 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnClosePage) 301 self.Bind(wx.EVT_CLOSE, self.OnClose) 302 303 # Layer Information 304 self.layer_info=[] 305 306 # Debug Msg 307 if _DEBUG < 5: 308 print self.typeComboBox.GetValue()
309 310
311 - def getLayerInfo(self):
312 ret = [] 313 ret.append( self.getLayerTypeValue() ) 314 ret.append( self.getLayerNumValue() ) 315 ret.append( self.getLayerNameValue() ) 316 ret.append( self.getLayerDepthValue() ) 317 ret.append( self.getLayerRoughnessValue() ) 318 ret.append( self.getLayerRhoValue() ) 319 ret.append( self.getLayerMuValue() ) 320 if self.model.magnetic: 321 ret.append( self.getLayerPhiValue() ) 322 ret.append( self.getLayerThetaValue() ) 323 324 return ret
325 326
327 - def getLayerTypeValue(self):
328 return self.typeComboBox.GetValue().strip()
329 330
331 - def getLayerNumValue(self):
332 ret = CheckValid( self.textCtrls[0].GetValue() ) 333 #print ret 334 return int(ret)
335
336 - def getLayerNameValue(self):
337 return self.textCtrls[1].GetValue().strip()
338 339
340 - def getLayerDepthValue(self):
341 ret = CheckValid( self.textCtrls[2].GetValue() ) 342 return ret
343 344
345 - def getLayerRoughnessValue(self):
346 ret = CheckValid( self.textCtrls[3].GetValue() ) 347 return ret
348
349 - def getLayerRhoValue(self):
350 ret = CheckValid( self.textCtrls[4].GetValue() ) 351 return ret
352
353 - def getLayerMuValue(self):
354 ret = CheckValid( self.textCtrls[5].GetValue() ) 355 return ret
356
357 - def getLayerPhiValue(self):
358 ret = CheckValid( self.textCtrls[6].GetValue() ) 359 return ret
360
361 - def getLayerThetaValue(self):
362 ret = CheckValid( self.textCtrls[7].GetValue() ) 363 return ret
364 365
366 - def GetOwnerManager(self):
367 return self._mgr
368 369
370 - def OnClose(self, event):
371 self._mgr.UnInit() 372 event.Skip()
373 374
375 - def OnClosePage(self, event):
376 event.Veto()
377 378
379 - def OnTypeCombobox(self, event):
380 self.selection = self.typeComboBox.GetSelection() 381 self.typeComboBox.SetLabel( self.LayerTypes[self.selection] ) 382 self.typeComboBox.SetValue( self.LayerTypes[self.selection] )
383 384
385 - def OnTypeComboboxText(self, event):
386 if self.selection < 0: 387 return 388 else: 389 txt = self.typeComboBox.GetValue() 390 self.typeComboBox.SetString(self.selection,txt)
391