Package reflectometry :: Package model1d :: Package profileview :: Module changeProfileDialog

Source Code for Module reflectometry.model1d.profileview.changeProfileDialog

  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 ChangeProfileDialog(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 layer_num = 0 20 ):
21 self.parent = parent 22 self.model = model 23 self.layer_num = layer_num 24 25 pre = wx.PreDialog() 26 pre.SetExtraStyle(wx.DIALOG_EX_CONTEXTHELP) 27 pre.Create(parent, ID, title, pos, size, style) 28 29 self.PostCreate(pre) 30 31 # This extra style can be set after the UI object has been created. 32 if 'wxMac' in wx.PlatformInfo and useMetal: 33 self.SetExtraStyle(wx.DIALOG_EX_METAL) 34 35 self._mgr = wx.aui.AuiManager(self) 36 37 self.txts = [ r'Profile:', r'Old profile:', r'New peofile:' ] 38 39 self.DefaultTxts = [r'rho', r'0.0', r'1.0'] 40 41 if model.magnetic: 42 self.ProfileTypes = [r"rho", r"mu", r"phi", r"theta"] 43 else: 44 self.ProfileTypes = [r"rho", r"mu"] 45 46 47 for x in xrange( len(self.DefaultTxts) ): 48 wx.StaticText(self, -1, self.txts[x], (20, 20+x*30)) 49 50 51 self.typeComboBox = wx.ComboBox(choices=self.ProfileTypes, 52 id=-1, 53 name=u'typeComboBox', 54 parent=self, 55 pos=wx.Point(85, 20), 56 size=wx.Size(380, 20), 57 style= 0, 58 value=u'rho' 59 ) 60 self.typeComboBox.SetSelection(0) 61 self.Bind(wx.EVT_COMBOBOX, self.OnTypeCombobox, self.typeComboBox) 62 self.selection = 0 63 64 self.textCtrls = [] 65 for x in xrange( 2): 66 textctl = wx.TextCtrl(self, 67 -1, 68 pos=(85, 50+x*30), 69 size=wx.Size(380, 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( 2 ): 78 self.textCtrls[x].SetValue( self.DefaultTxts[x+1] ) 79 80 81 self.button = wx.Button(self, wx.ID_OK, '', (200, 126) ) 82 self.cancelbutton = wx.Button(self, wx.ID_CANCEL, '', (300, 126) ) 83 84 self.Bind(wx.aui.EVT_AUINOTEBOOK_PAGE_CLOSE, self.OnClosePage) 85 self.Bind(wx.EVT_CLOSE, self.OnClose) 86 87 88 _txt = self.model.Lrho[self.layer_num]._toStr() 89 self.textCtrls[0].SetValue( _txt ) 90 self.textCtrls[0].Enable(False) 91 self.textCtrls[1].SetValue( _txt ) 92 93 # error_flag 94 self._error = 0
95 96
97 - def getLayerInfo(self):
98 ret = [] 99 ret.append( self.getProfileTypeValue() ) 100 ret.append( "None" ) 101 ret.append( self.getLayerNewValue() ) 102 103 ret.append( self._error ) 104 105 return ret
106 107
108 - def getProfileTypeValue(self):
109 return self.typeComboBox.GetValue().strip()
110 111
112 - def getLayerOldValue(self):
113 try: 114 ret = CheckValid( self.textCtrls[0].GetValue() ) 115 except: 116 self._error = 1 117 ret = None 118 119 return ret
120 121
122 - def getLayerNewValue(self):
123 try: 124 ret = eval( self.textCtrls[1].GetValue().strip() ) 125 except: 126 self._error = 1 127 ret = None 128 return ret
129 130 131
132 - def GetOwnerManager(self):
133 return self._mgr
134 135
136 - def OnClose(self, event):
137 self._mgr.UnInit() 138 event.Skip()
139 140
141 - def OnClosePage(self, event):
142 event.Veto()
143 144
145 - def OnTypeCombobox(self, event):
146 self.selection = self.typeComboBox.GetSelection() 147 self.typeComboBox.SetLabel( self.ProfileTypes[self.selection] ) 148 self.typeComboBox.SetValue( self.ProfileTypes[self.selection] ) 149 150 _type = self.typeComboBox.GetValue().strip() 151 152 idx = self.layer_num 153 if _type == "rho": 154 _txt = self.model.Lrho[idx]._toStr() 155 elif _type == "mu": 156 _txt = self.model.Lmu[idx]._toStr() 157 elif _type == "phi": 158 _txt = self.model.Lphi[idx]._toStr() 159 elif _type == "theta": 160 _txt = self.model.Ltheta[idx]._toStr() 161 else: 162 pass 163 164 self.textCtrls[0].SetValue( _txt ) 165 self.textCtrls[1].SetValue( _txt )
166 167
168 - def OnTypeComboboxText(self, event):
169 if self.selection < 0: 170 return 171 else: 172 txt = self.typeComboBox.GetValue() 173 self.typeComboBox.SetString(self.selection,txt)
174