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