1 | #!/usr/bin/env python |
---|
2 | |
---|
3 | # version |
---|
4 | __id__ = "$Id: aboutdialog.py 1193 2007-05-03 17:29:59Z dmitriy $" |
---|
5 | __revision__ = "$Revision: 1193 $" |
---|
6 | |
---|
7 | import wx |
---|
8 | from sans.guiframe.utils import format_number |
---|
9 | from sans.guicomm.events import StatusEvent ,NewPlotEvent,SlicerEvent |
---|
10 | |
---|
11 | |
---|
12 | class DetectorDialog(wx.Dialog): |
---|
13 | """ |
---|
14 | Dialog box to let the user edit detector settings |
---|
15 | """ |
---|
16 | |
---|
17 | def __init__(self,parent,id=1,base=None, *args, **kwds): |
---|
18 | |
---|
19 | kwds["style"] = wx.DEFAULT_DIALOG_STYLE |
---|
20 | wx.Dialog.__init__(self,parent,id=1, *args, **kwds) |
---|
21 | |
---|
22 | self.parent=base |
---|
23 | self.label_xnpts = wx.StaticText(self, -1, "Detector width in pixels") |
---|
24 | self.label_ynpts = wx.StaticText(self, -1, "Detector Height in pixels") |
---|
25 | self.label_qmax = wx.StaticText(self, -1, "Q max") |
---|
26 | self.label_zmin = wx.StaticText(self, -1, "Min amplitude for color map (optional)") |
---|
27 | self.label_zmax = wx.StaticText(self, -1, "Max amplitude for color map (optional)") |
---|
28 | self.label_beam = wx.StaticText(self, -1, "Beam stop radius in units of q") |
---|
29 | |
---|
30 | self.xnpts_ctl = wx.StaticText(self, -1, "") |
---|
31 | self.ynpts_ctl = wx.StaticText(self, -1, "") |
---|
32 | self.qmax_ctl = wx.StaticText(self, -1, "") |
---|
33 | self.beam_ctl = wx.StaticText(self, -1, "") |
---|
34 | |
---|
35 | self.zmin_ctl = wx.TextCtrl(self, -1, size=(60,20)) |
---|
36 | self.zmax_ctl = wx.TextCtrl(self, -1, size=(60,20)) |
---|
37 | |
---|
38 | self.static_line_3 = wx.StaticLine(self, -1) |
---|
39 | |
---|
40 | |
---|
41 | self.button_OK = wx.Button(self, wx.ID_OK, "OK") |
---|
42 | self.button_Cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
43 | self.Bind(wx.EVT_BUTTON, self.checkValues, self.button_OK) |
---|
44 | |
---|
45 | self.__set_properties() |
---|
46 | self.__do_layout() |
---|
47 | |
---|
48 | self.Fit() |
---|
49 | |
---|
50 | class Event: |
---|
51 | xnpts = 0 |
---|
52 | ynpts = 0 |
---|
53 | qpax = 0 |
---|
54 | beam = 0 |
---|
55 | zmin = 0 |
---|
56 | zmax = 0 |
---|
57 | sym4 = False |
---|
58 | |
---|
59 | def checkValues(self, event): |
---|
60 | """ |
---|
61 | Check the valitidity of zmin and zmax value |
---|
62 | zmax should be a float and zmin less than zmax |
---|
63 | """ |
---|
64 | flag = True |
---|
65 | try: |
---|
66 | value=self.zmin_ctl.GetValue() |
---|
67 | if value and float( value)==0.0: |
---|
68 | flag = False |
---|
69 | wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) |
---|
70 | self.zmin_ctl.SetBackgroundColour("pink") |
---|
71 | self.zmin_ctl.Refresh() |
---|
72 | else: |
---|
73 | self.zmin_ctl.SetBackgroundColour(wx.WHITE) |
---|
74 | self.zmin_ctl.Refresh() |
---|
75 | except: |
---|
76 | flag = False |
---|
77 | wx.PostEvent(self.parent, StatusEvent(status="Enter float value")) |
---|
78 | self.zmin_ctl.SetBackgroundColour("pink") |
---|
79 | self.zmin_ctl.Refresh() |
---|
80 | try: |
---|
81 | value=self.zmax_ctl.GetValue() |
---|
82 | if value and int(value)==0.0: |
---|
83 | flag = False |
---|
84 | wx.PostEvent(self.parent, StatusEvent(status="Enter number greater than zero")) |
---|
85 | self.zmax_ctl.SetBackgroundColour("pink") |
---|
86 | self.zmax_ctl.Refresh() |
---|
87 | else: |
---|
88 | self.zmax_ctl.SetBackgroundColour(wx.WHITE) |
---|
89 | self.zmax_ctl.Refresh() |
---|
90 | except: |
---|
91 | flag = False |
---|
92 | wx.PostEvent(self.parent, StatusEvent(status="Enter Integer value")) |
---|
93 | self.zmax_ctl.SetBackgroundColour("pink") |
---|
94 | self.zmax_ctl.Refresh() |
---|
95 | |
---|
96 | if flag: |
---|
97 | event.Skip(True) |
---|
98 | |
---|
99 | def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False): |
---|
100 | """ |
---|
101 | received value and displayed them |
---|
102 | @param xnpts: the number of point of the x_bins of data |
---|
103 | @param ynpts: the number of point of the y_bins of data |
---|
104 | @param qmax: the maxmimum value of data pixel |
---|
105 | @param beam : the radius of the beam |
---|
106 | @param zmin: the value to get the minimum color |
---|
107 | @param zmax: the value to get the maximum color |
---|
108 | @param sym: |
---|
109 | """ |
---|
110 | self.xnpts_ctl.SetLabel(str(format_number(xnpts))) |
---|
111 | self.ynpts_ctl.SetLabel(str(format_number(ynpts))) |
---|
112 | self.qmax_ctl.SetLabel(str(format_number(qmax))) |
---|
113 | self.beam_ctl.SetLabel(str(format_number(beam))) |
---|
114 | |
---|
115 | if zmin !=None: |
---|
116 | self.zmin_ctl.SetValue(str(format_number(zmin))) |
---|
117 | if zmax !=None: |
---|
118 | self.zmax_ctl.SetValue(str(format_number(zmax))) |
---|
119 | |
---|
120 | def getContent(self): |
---|
121 | """ |
---|
122 | @return event containing value to reset the detector of a given data |
---|
123 | """ |
---|
124 | event = self.Event() |
---|
125 | |
---|
126 | t_min = self.zmin_ctl.GetValue() |
---|
127 | t_max = self.zmax_ctl.GetValue() |
---|
128 | v_min = None |
---|
129 | v_max = None |
---|
130 | |
---|
131 | if len(t_min.lstrip())>0: |
---|
132 | try: |
---|
133 | v_min = float(t_min) |
---|
134 | except: |
---|
135 | v_min = None |
---|
136 | |
---|
137 | if len(t_max.lstrip())>0: |
---|
138 | try: |
---|
139 | v_max = float(t_max) |
---|
140 | except: |
---|
141 | v_max = None |
---|
142 | |
---|
143 | event.zmin = v_min |
---|
144 | event.zmax = v_max |
---|
145 | |
---|
146 | return event |
---|
147 | |
---|
148 | def __set_properties(self): |
---|
149 | """ |
---|
150 | set proprieties of the dialog window |
---|
151 | """ |
---|
152 | self.SetTitle("Detector parameters") |
---|
153 | self.SetSize((600, 595)) |
---|
154 | |
---|
155 | |
---|
156 | def __do_layout(self): |
---|
157 | """ |
---|
158 | fill the dialog window . |
---|
159 | """ |
---|
160 | sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
161 | sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
162 | sizer_params = wx.GridBagSizer(5,5) |
---|
163 | |
---|
164 | iy = 0 |
---|
165 | sizer_params.Add(self.label_xnpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
166 | sizer_params.Add(self.xnpts_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
167 | iy += 1 |
---|
168 | sizer_params.Add(self.label_ynpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
169 | sizer_params.Add(self.ynpts_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
170 | iy += 1 |
---|
171 | sizer_params.Add(self.label_qmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
172 | sizer_params.Add(self.qmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
173 | iy += 1 |
---|
174 | sizer_params.Add(self.label_beam, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
175 | sizer_params.Add(self.beam_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
176 | iy += 1 |
---|
177 | sizer_params.Add(self.label_zmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
178 | sizer_params.Add(self.zmin_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
179 | iy += 1 |
---|
180 | sizer_params.Add(self.label_zmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
181 | sizer_params.Add(self.zmax_ctl, (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
182 | iy += 1 |
---|
183 | |
---|
184 | sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10) |
---|
185 | sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0) |
---|
186 | |
---|
187 | |
---|
188 | sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
189 | sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10) |
---|
190 | sizer_button.Add(self.button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
191 | |
---|
192 | |
---|
193 | sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10) |
---|
194 | self.SetAutoLayout(True) |
---|
195 | self.SetSizer(sizer_main) |
---|
196 | self.Layout() |
---|
197 | self.Centre() |
---|
198 | # end wxGlade |
---|
199 | |
---|
200 | |
---|
201 | # end of class DialogAbout |
---|
202 | |
---|
203 | ##### testing code ############################################################ |
---|
204 | class MyApp(wx.App): |
---|
205 | def OnInit(self): |
---|
206 | wx.InitAllImageHandlers() |
---|
207 | dialog = DetectorDialog(None, -1, "") |
---|
208 | self.SetTopWindow(dialog) |
---|
209 | dialog.setContent(128, 0.05) |
---|
210 | print dialog.ShowModal() |
---|
211 | evt = dialog.getContent() |
---|
212 | print evt.npts, evt.qmax |
---|
213 | dialog.Destroy() |
---|
214 | return 1 |
---|
215 | |
---|
216 | # end of class MyApp |
---|
217 | |
---|
218 | if __name__ == "__main__": |
---|
219 | app = MyApp(0) |
---|
220 | app.MainLoop() |
---|
221 | |
---|
222 | ##### end of testing code ##################################################### |
---|