source: sasview/guiframe/local_perspectives/plotting/detector_dialog.py @ ea290ee

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since ea290ee was ea290ee, checked in by Gervaise Alina <gervyh@…>, 16 years ago

edit color for detector

  • Property mode set to 100644
File size: 7.4 KB
Line 
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
7import wx
8from sans.guiframe.utils import format_number
9
10class DetectorDialog(wx.Dialog):
11    """
12        Dialog box to let the user edit detector settings
13    """
14   
15    def __init__(self, *args, **kwds):
16
17        kwds["style"] = wx.DEFAULT_DIALOG_STYLE
18        wx.Dialog.__init__(self, *args, **kwds)
19       
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
68                self.zmin_ctl.SetBackgroundColour("pink")
69                self.zmin_ctl.Refresh()
70            else:
71                self.zmin_ctl.SetBackgroundColour(wx.WHITE)
72                self.zmin_ctl.Refresh()
73        except:
74            flag = False
75            self.zmin_ctl.SetBackgroundColour("pink")
76            self.zmin_ctl.Refresh()
77        try:
78            value=self.zmax_ctl.GetValue()
79            if value and int(value)==0.0:
80                flag = False
81                self.zmax_ctl.SetBackgroundColour("pink")
82                self.zmax_ctl.Refresh()
83            else:
84                self.zmax_ctl.SetBackgroundColour(wx.WHITE)
85                self.zmax_ctl.Refresh()
86        except:
87            flag = False
88            self.zmax_ctl.SetBackgroundColour("pink")
89            self.zmax_ctl.Refresh()
90       
91        if flag:
92            event.Skip(True)
93   
94    def setContent(self, xnpts,ynpts, qmax, beam,zmin=None,zmax=None, sym=False):
95        self.xnpts_ctl.SetLabel(str(format_number(xnpts)))
96        self.ynpts_ctl.SetLabel(str(format_number(ynpts)))
97        self.qmax_ctl.SetLabel(str(format_number(qmax)))
98        self.beam_ctl.SetLabel(str(format_number(beam)))
99        #self.chk_sym.SetValue(sym)
100        if zmin !=None:
101            self.zmin_ctl.SetValue(str(format_number(zmin)))
102        if zmax !=None:
103            self.zmax_ctl.SetValue(str(format_number(zmax)))
104
105    def getContent(self):
106        event = self.Event()
107        #event.npts = int(self.npts_ctl.GetValue())
108        #event.qmax = float(self.qmax_ctl.GetValue())
109        #event.beam = float(self.beam_ctl.GetValue())
110        #event.sym4 = self.chk_sym.GetValue()
111       
112        t_min = self.zmin_ctl.GetValue()
113        t_max = self.zmax_ctl.GetValue()
114        v_min = None
115        v_max = None
116       
117        if len(t_min.lstrip())>0:
118            try:
119                v_min = float(t_min)
120            except:
121                v_min = None
122       
123        if len(t_max.lstrip())>0:
124            try:
125                v_max = float(t_max)
126            except:
127                v_max = None
128       
129        event.zmin = v_min
130        event.zmax = v_max
131       
132        return event
133
134    def __set_properties(self):
135        self.SetTitle("Detector parameters")
136        self.SetSize((600, 595))
137
138    def __do_layout(self):
139        sizer_main = wx.BoxSizer(wx.VERTICAL)
140        sizer_button = wx.BoxSizer(wx.HORIZONTAL)
141        sizer_params = wx.GridBagSizer(5,5)
142
143        iy = 0
144        sizer_params.Add(self.label_xnpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
145        sizer_params.Add(self.xnpts_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
146        iy += 1
147        sizer_params.Add(self.label_ynpts, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
148        sizer_params.Add(self.ynpts_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
149        iy += 1
150        sizer_params.Add(self.label_qmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
151        sizer_params.Add(self.qmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
152        iy += 1
153        sizer_params.Add(self.label_beam, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
154        sizer_params.Add(self.beam_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
155        iy += 1
156        sizer_params.Add(self.label_zmin, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
157        sizer_params.Add(self.zmin_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
158        iy += 1
159        sizer_params.Add(self.label_zmax, (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
160        sizer_params.Add(self.zmax_ctl,   (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
161        iy += 1
162        #sizer_params.Add(self.label_sym,  (iy,0), (1,1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15)
163        #sizer_params.Add(self.chk_sym,    (iy,1), (1,1), wx.EXPAND|wx.ADJUST_MINSIZE, 0)
164
165        sizer_main.Add(sizer_params, 0, wx.EXPAND|wx.ALL, 10)
166        sizer_main.Add(self.static_line_3, 0, wx.EXPAND, 0)
167       
168       
169        sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0)
170        sizer_button.Add(self.button_OK, 0, wx.LEFT|wx.ADJUST_MINSIZE, 10)
171        sizer_button.Add(self.button_Cancel, 0, wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10)
172       
173       
174        sizer_main.Add(sizer_button, 0, wx.EXPAND|wx.BOTTOM|wx.TOP, 10)
175        self.SetAutoLayout(True)
176        self.SetSizer(sizer_main)
177        self.Layout()
178        self.Centre()
179        # end wxGlade
180
181
182# end of class DialogAbout
183
184##### testing code ############################################################
185class MyApp(wx.App):
186    def OnInit(self):
187        wx.InitAllImageHandlers()
188        dialog = DetectorDialog(None, -1, "")
189        self.SetTopWindow(dialog)
190        dialog.setContent(128, 0.05)
191        print dialog.ShowModal()
192        evt = dialog.getContent()
193        print evt.npts, evt.qmax
194        dialog.Destroy()
195        return 1
196
197# end of class MyApp
198
199if __name__ == "__main__":
200    app = MyApp(0)
201    app.MainLoop()
202   
203##### end of testing code #####################################################   
Note: See TracBrowser for help on using the repository browser.