1 | import wx |
---|
2 | _BOX_WIDTH = 76 |
---|
3 | _STATICBOX_WIDTH = 350 |
---|
4 | |
---|
5 | class SldPanel(wx.Panel): |
---|
6 | def __init__(self, parent, id = -1): |
---|
7 | wx.Panel.__init__(self, parent, id = id) |
---|
8 | |
---|
9 | self._do_layout() |
---|
10 | self.SetAutoLayout(True) |
---|
11 | self.Layout() |
---|
12 | |
---|
13 | |
---|
14 | def _do_layout(self): |
---|
15 | """ |
---|
16 | Draw window content |
---|
17 | """ |
---|
18 | sizer_input = wx.GridBagSizer(5,5) |
---|
19 | sizer_output = wx.GridBagSizer(5,5) |
---|
20 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
21 | sizer1 = wx.BoxSizer(wx.HORIZONTAL) |
---|
22 | sizer2 = wx.BoxSizer(wx.HORIZONTAL) |
---|
23 | sizer3 = wx.BoxSizer(wx.HORIZONTAL) |
---|
24 | #---------inputs---------------- |
---|
25 | inputbox = wx.StaticBox(self, -1, "Input") |
---|
26 | boxsizer1 = wx.StaticBoxSizer(inputbox, wx.VERTICAL) |
---|
27 | boxsizer1.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
28 | |
---|
29 | compound_txt = wx.StaticText(self, -1, 'Compound') |
---|
30 | self.compound_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
31 | density_txt = wx.StaticText(self, -1, 'Density(g/cm^3)') |
---|
32 | self.density_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
33 | wavelength_txt = wx.StaticText(self, -1, 'Wavelength (A)') |
---|
34 | self.wavelength_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
35 | iy = 0 |
---|
36 | ix = 0 |
---|
37 | sizer_input.Add(compound_txt,(iy, ix),(1,1),\ |
---|
38 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
39 | ix +=1 |
---|
40 | sizer_input.Add(self.compound_ctl,(iy, ix),(1,1),\ |
---|
41 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
42 | iy += 1 |
---|
43 | ix = 0 |
---|
44 | sizer_input.Add(density_txt,(iy, ix),(1,1),\ |
---|
45 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
46 | ix +=1 |
---|
47 | sizer_input.Add(self.density_ctl,(iy, ix),(1,1),\ |
---|
48 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
49 | iy += 1 |
---|
50 | ix = 0 |
---|
51 | sizer_input.Add(wavelength_txt,(iy, ix),(1,1),\ |
---|
52 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
53 | ix +=1 |
---|
54 | sizer_input.Add(self.wavelength_ctl,(iy, ix),(1,1),\ |
---|
55 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
56 | boxsizer1.Add( sizer_input ) |
---|
57 | sizer1.Add(boxsizer1,0, wx.EXPAND | wx.ALL, 10) |
---|
58 | #---------Outputs sizer-------- |
---|
59 | outputbox = wx.StaticBox(self, -1, "Output") |
---|
60 | boxsizer2 = wx.StaticBoxSizer(outputbox, wx.VERTICAL) |
---|
61 | boxsizer2.SetMinSize((_STATICBOX_WIDTH,-1)) |
---|
62 | |
---|
63 | unit_a= '[A^(-2)]' |
---|
64 | unit_cm1='[cm^(-1)]' |
---|
65 | unit_cm='[cm]' |
---|
66 | i_complex= '+ i' |
---|
67 | neutron_sld_txt = wx.StaticText(self, -1, 'Neutron SLD') |
---|
68 | self.neutron_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
69 | self.neutron_sld_reel_ctl.SetEditable(False) |
---|
70 | self.neutron_sld_reel_ctl.SetToolTipString("Neutron SLD reel.") |
---|
71 | self.neutron_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
72 | self.neutron_sld_im_ctl.SetEditable(False) |
---|
73 | self.neutron_sld_im_ctl.SetToolTipString("Neutron SLD imaginary.") |
---|
74 | neutron_sld_units_txt = wx.StaticText(self, -1, unit_a) |
---|
75 | |
---|
76 | cu_ka_sld_txt = wx.StaticText(self, -1, 'Cu Ka SLD') |
---|
77 | self.cu_ka_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
78 | self.cu_ka_sld_reel_ctl.SetEditable(False) |
---|
79 | self.cu_ka_sld_reel_ctl.SetToolTipString("Cu Ka SLD reel.") |
---|
80 | self.cu_ka_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
81 | self.cu_ka_sld_im_ctl.SetEditable(False) |
---|
82 | self.cu_ka_sld_im_ctl.SetToolTipString("Cu Ka SLD imaginary.") |
---|
83 | cu_ka_sld_units_txt = wx.StaticText(self, -1, unit_a) |
---|
84 | |
---|
85 | mo_ka_sld_txt = wx.StaticText(self, -1, 'Mo Ka SLD') |
---|
86 | self.mo_ka_sld_reel_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
87 | self.mo_ka_sld_reel_ctl.SetEditable(False) |
---|
88 | self.mo_ka_sld_reel_ctl.SetToolTipString("Mo Ka SLD reel.") |
---|
89 | self.mo_ka_sld_im_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
90 | self.mo_ka_sld_im_ctl.SetEditable(False) |
---|
91 | self.mo_ka_sld_im_ctl.SetToolTipString("Mo Ka SLD reel.") |
---|
92 | mo_ka_sld_units_txt = wx.StaticText(self, -1, unit_a) |
---|
93 | |
---|
94 | neutron_inc_txt = wx.StaticText(self, -1, 'Neutron Inc. Xs') |
---|
95 | self.neutron_inc_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
96 | self.neutron_inc_ctl.SetEditable(False) |
---|
97 | self.neutron_inc_ctl.SetToolTipString("Neutron Inc. Xs") |
---|
98 | |
---|
99 | neutron_abs_txt = wx.StaticText(self, -1, 'Neutron Abs. Xs') |
---|
100 | self.neutron_abs_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
101 | self.neutron_abs_ctl.SetEditable(False) |
---|
102 | self.neutron_abs_ctl.SetToolTipString("Neutron Abs. Xs") |
---|
103 | |
---|
104 | neutron_length_txt = wx.StaticText(self, -1, 'Neutron 1/e length') |
---|
105 | self.neutron_length_ctl = wx.TextCtrl(self, -1, size=(_BOX_WIDTH,-1)) |
---|
106 | self.neutron_length_ctl.SetEditable(False) |
---|
107 | self.neutron_length_ctl.SetToolTipString("Neutron 1/e length") |
---|
108 | iy = 0 |
---|
109 | ix = 0 |
---|
110 | sizer_output.Add(neutron_sld_txt,(iy, ix),(1,1), |
---|
111 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
112 | ix +=1 |
---|
113 | sizer_output.Add(self.neutron_sld_reel_ctl,(iy, ix),(1,1), |
---|
114 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
115 | ix +=1 |
---|
116 | sizer_output.Add(wx.StaticText(self, -1, i_complex) |
---|
117 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
118 | ix +=1 |
---|
119 | sizer_output.Add(self.neutron_sld_im_ctl |
---|
120 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
121 | ix +=1 |
---|
122 | sizer_output.Add(neutron_sld_units_txt |
---|
123 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
124 | iy += 1 |
---|
125 | ix = 0 |
---|
126 | sizer_output.Add(cu_ka_sld_txt,(iy, ix),(1,1), |
---|
127 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
128 | ix +=1 |
---|
129 | sizer_output.Add(self.cu_ka_sld_reel_ctl,(iy, ix),(1,1), |
---|
130 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
131 | ix +=1 |
---|
132 | sizer_output.Add(wx.StaticText(self, -1, i_complex) |
---|
133 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
134 | ix +=1 |
---|
135 | sizer_output.Add(self.cu_ka_sld_im_ctl |
---|
136 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
137 | ix +=1 |
---|
138 | sizer_output.Add(cu_ka_sld_units_txt |
---|
139 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
140 | iy += 1 |
---|
141 | ix = 0 |
---|
142 | sizer_output.Add(mo_ka_sld_txt,(iy, ix),(1,1), |
---|
143 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
144 | ix +=1 |
---|
145 | sizer_output.Add(self.mo_ka_sld_reel_ctl,(iy, ix),(1,1), |
---|
146 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
147 | ix +=1 |
---|
148 | sizer_output.Add(wx.StaticText(self, -1, i_complex) |
---|
149 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
150 | ix +=1 |
---|
151 | sizer_output.Add(self.mo_ka_sld_im_ctl |
---|
152 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
153 | ix +=1 |
---|
154 | sizer_output.Add(mo_ka_sld_units_txt |
---|
155 | ,(iy, ix),(1,1),wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
156 | iy += 1 |
---|
157 | ix = 0 |
---|
158 | sizer_output.Add(neutron_inc_txt,(iy, ix),(1,1), |
---|
159 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
160 | ix +=1 |
---|
161 | sizer_output.Add(self.neutron_inc_ctl,(iy, ix),(1,1), |
---|
162 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
163 | iy += 1 |
---|
164 | ix = 0 |
---|
165 | sizer_output.Add(neutron_abs_txt,(iy, ix),(1,1), |
---|
166 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
167 | ix +=1 |
---|
168 | sizer_output.Add(self.neutron_abs_ctl,(iy, ix),(1,1), |
---|
169 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
170 | iy += 1 |
---|
171 | ix = 0 |
---|
172 | sizer_output.Add(neutron_length_txt,(iy, ix),(1,1), |
---|
173 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
174 | ix +=1 |
---|
175 | sizer_output.Add(self.neutron_length_ctl,(iy, ix),(1,1), |
---|
176 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
177 | boxsizer2.Add( sizer_output ) |
---|
178 | sizer2.Add(boxsizer2,0, wx.EXPAND | wx.ALL, 10) |
---|
179 | #-----Button sizer------------ |
---|
180 | id = wx.NewId() |
---|
181 | button_calculate = wx.Button(self, id, "Calculate") |
---|
182 | button_calculate.SetToolTipString("Calculate SlD of neutrons.") |
---|
183 | #self.Bind(wx.EVT_BUTTON, self._calculateSld, id = id) |
---|
184 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
185 | sizer_button.Add(button_calculate, 0, wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
186 | sizer3.Add(sizer_button) |
---|
187 | #---------layout---------------- |
---|
188 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
189 | |
---|
190 | vbox.Add(sizer1) |
---|
191 | vbox.Add(sizer2) |
---|
192 | vbox.Add(sizer3) |
---|
193 | vbox.Fit(self) |
---|
194 | self.SetSizer(vbox) |
---|
195 | |
---|
196 | |
---|
197 | class SldWindow(wx.Frame): |
---|
198 | def __init__(self, parent, id, title): |
---|
199 | wx.Frame.__init__(self, parent, id, title, size=(400, 400)) |
---|
200 | |
---|
201 | self.panel = SldPanel(self) |
---|
202 | self.Centre() |
---|
203 | self.Show(True) |
---|
204 | |
---|
205 | class ViewApp(wx.App): |
---|
206 | def OnInit(self): |
---|
207 | frame = SldWindow(None, -1, 'SLD Calculator') |
---|
208 | frame.Show(True) |
---|
209 | self.SetTopWindow(frame) |
---|
210 | |
---|
211 | return True |
---|
212 | |
---|
213 | |
---|
214 | if __name__ == "__main__": |
---|
215 | app = ViewApp(0) |
---|
216 | app.MainLoop() |
---|