1 | |
---|
2 | ################################################################################ |
---|
3 | #This software was developed by the University of Tennessee as part of the |
---|
4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
5 | #project funded by the US National Science Foundation. |
---|
6 | # |
---|
7 | #See the license text in license.txt |
---|
8 | # |
---|
9 | #copyright 2009, University of Tennessee |
---|
10 | ################################################################################ |
---|
11 | |
---|
12 | |
---|
13 | import wx |
---|
14 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
15 | |
---|
16 | |
---|
17 | MAX_NBR_DATA = 4 |
---|
18 | WIDTH = 430 |
---|
19 | HEIGHT = 350 |
---|
20 | |
---|
21 | class DialogPanel(ScrolledPanel): |
---|
22 | def __init__(self, *args, **kwds): |
---|
23 | ScrolledPanel.__init__(self, *args, **kwds) |
---|
24 | self.SetupScrolling() |
---|
25 | |
---|
26 | class BatchDataDialog(wx.Dialog): |
---|
27 | """ |
---|
28 | The current design of Batch fit allows only of type of data in the data |
---|
29 | set. This allows the user to make a quick selection of the type of data |
---|
30 | to use in fit tab. |
---|
31 | """ |
---|
32 | def __init__(self, parent=None, *args, **kwds): |
---|
33 | wx.Dialog.__init__(self, parent, *args, **kwds) |
---|
34 | self.SetSize((WIDTH, HEIGHT)) |
---|
35 | self.data_1d_selected = None |
---|
36 | self.data_2d_selected = None |
---|
37 | self._do_layout() |
---|
38 | |
---|
39 | def _do_layout(self): |
---|
40 | """ |
---|
41 | Draw the content of the current dialog window |
---|
42 | """ |
---|
43 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
44 | box_description= wx.StaticBox(self, -1,str("Hint")) |
---|
45 | hint_sizer = wx.StaticBoxSizer(box_description, wx.VERTICAL) |
---|
46 | selection_sizer = wx.GridBagSizer(5,5) |
---|
47 | button_sizer = wx.BoxSizer(wx.HORIZONTAL) |
---|
48 | self.data_1d_selected = wx.RadioButton(self, -1, 'Data1D', |
---|
49 | style=wx.RB_GROUP) |
---|
50 | self.data_2d_selected = wx.RadioButton(self, -1, 'Data2D') |
---|
51 | self.data_1d_selected.SetValue(True) |
---|
52 | self.data_2d_selected.SetValue(False) |
---|
53 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
54 | button_OK = wx.Button(self, wx.ID_OK, "Ok") |
---|
55 | button_OK.SetFocus() |
---|
56 | hint = "Selected Data set contains both 1D and 2D Data.\n" |
---|
57 | hint += "Please select on type of analysis before proceeding.\n" |
---|
58 | hint_sizer.Add(wx.StaticText(self, -1, hint)) |
---|
59 | #draw area containing radio buttons |
---|
60 | ix = 0 |
---|
61 | iy = 0 |
---|
62 | selection_sizer.Add(self.data_1d_selected, (iy, ix), |
---|
63 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
64 | iy += 1 |
---|
65 | selection_sizer.Add(self.data_2d_selected, (iy, ix), |
---|
66 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
67 | #contruction the sizer contaning button |
---|
68 | button_sizer.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
69 | button_sizer.Add(button_cancel, 0, |
---|
70 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
71 | button_sizer.Add(button_OK, 0, |
---|
72 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
73 | vbox.Add(hint_sizer, 0, wx.EXPAND|wx.ALL, 10) |
---|
74 | vbox.Add(selection_sizer, 0, wx.TOP|wx.BOTTOM, 10) |
---|
75 | vbox.Add(wx.StaticLine(self, -1), 0, wx.EXPAND, 0) |
---|
76 | vbox.Add(button_sizer, 0 , wx.TOP|wx.BOTTOM, 10) |
---|
77 | self.SetSizer(vbox) |
---|
78 | self.Layout() |
---|
79 | |
---|
80 | def get_data(self): |
---|
81 | """ |
---|
82 | return 1 if user requested Data1D , 2 if user requested Data2D |
---|
83 | """ |
---|
84 | if self.data_1d_selected.GetValue(): |
---|
85 | return 1 |
---|
86 | else: |
---|
87 | return 2 |
---|
88 | |
---|
89 | |
---|
90 | |
---|
91 | class DataDialog(wx.Dialog): |
---|
92 | """ |
---|
93 | Allow file selection at loading time |
---|
94 | """ |
---|
95 | def __init__(self, data_list, parent=None, text='', |
---|
96 | nb_data=MAX_NBR_DATA, *args, **kwds): |
---|
97 | wx.Dialog.__init__(self, parent, *args, **kwds) |
---|
98 | self.SetTitle("Data Selection") |
---|
99 | self._max_data = nb_data |
---|
100 | self._nb_selected_data = nb_data |
---|
101 | |
---|
102 | self.SetSize((WIDTH, HEIGHT)) |
---|
103 | self.list_of_ctrl = [] |
---|
104 | if not data_list: |
---|
105 | return |
---|
106 | select_data_text = " %s Data selected.\n" % str(self._nb_selected_data) |
---|
107 | self._data_text_ctrl = wx.StaticText(self, -1, str(select_data_text)) |
---|
108 | |
---|
109 | self._data_text_ctrl.SetForegroundColour('blue') |
---|
110 | self._sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
111 | self._sizer_txt = wx.BoxSizer(wx.VERTICAL) |
---|
112 | self._sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
113 | self._choice_sizer = wx.GridBagSizer(5, 5) |
---|
114 | self._panel = DialogPanel(self, style=wx.RAISED_BORDER, |
---|
115 | size=(WIDTH-20, HEIGHT/3)) |
---|
116 | self.__do_layout(data_list, text=text) |
---|
117 | |
---|
118 | def __do_layout(self, data_list, text=''): |
---|
119 | """ |
---|
120 | layout the dialog |
---|
121 | """ |
---|
122 | if not data_list or len(data_list) <= 1: |
---|
123 | return |
---|
124 | #add text |
---|
125 | if text.strip() == "": |
---|
126 | text = "Fitting: We recommend that you selected" |
---|
127 | text += " no more than '%s' data\n" % str(self._max_data) |
---|
128 | text += "for adequate plot display size. \n" |
---|
129 | text += "unchecked data won't be send to fitting . \n" |
---|
130 | text_ctrl = wx.StaticText(self, -1, str(text)) |
---|
131 | self._sizer_txt.Add(text_ctrl) |
---|
132 | iy = 0 |
---|
133 | ix = 0 |
---|
134 | data_count = 0 |
---|
135 | for i in range(len(data_list)): |
---|
136 | data_count += 1 |
---|
137 | cb = wx.CheckBox(self._panel, -1, str(data_list[i].name), (10, 10)) |
---|
138 | wx.EVT_CHECKBOX(self, cb.GetId(), self._count_selected_data) |
---|
139 | if data_count <= MAX_NBR_DATA: |
---|
140 | cb.SetValue(True) |
---|
141 | else: |
---|
142 | cb.SetValue(False) |
---|
143 | self.list_of_ctrl.append((cb, data_list[i])) |
---|
144 | self._choice_sizer.Add(cb, (iy, ix), |
---|
145 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
146 | iy += 1 |
---|
147 | self._panel.SetSizer(self._choice_sizer) |
---|
148 | #add sizer |
---|
149 | self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
150 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
151 | self._sizer_button.Add(button_cancel, 0, |
---|
152 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
153 | button_OK = wx.Button(self, wx.ID_OK, "Ok") |
---|
154 | button_OK.SetFocus() |
---|
155 | self._sizer_button.Add(button_OK, 0, |
---|
156 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
157 | static_line = wx.StaticLine(self, -1) |
---|
158 | |
---|
159 | self._sizer_txt.Add(self._panel, 0, wx.EXPAND|wx.ALL, 10) |
---|
160 | self._sizer_main.Add(self._sizer_txt, 0, wx.EXPAND|wx.ALL, 10) |
---|
161 | self._sizer_main.Add(self._data_text_ctrl, 0, wx.EXPAND|wx.ALL, 10) |
---|
162 | self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) |
---|
163 | self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10) |
---|
164 | self.SetSizer(self._sizer_main) |
---|
165 | self.Layout() |
---|
166 | |
---|
167 | def get_data(self): |
---|
168 | """ |
---|
169 | return the selected data |
---|
170 | """ |
---|
171 | temp = [] |
---|
172 | for item in self.list_of_ctrl: |
---|
173 | cb, data = item |
---|
174 | if cb.GetValue(): |
---|
175 | temp.append(data) |
---|
176 | return temp |
---|
177 | |
---|
178 | def _count_selected_data(self, event): |
---|
179 | """ |
---|
180 | count selected data |
---|
181 | """ |
---|
182 | if event.GetEventObject().GetValue(): |
---|
183 | self._nb_selected_data += 1 |
---|
184 | else: |
---|
185 | self._nb_selected_data -= 1 |
---|
186 | select_data_text = " %s Data selected.\n" % str(self._nb_selected_data) |
---|
187 | self._data_text_ctrl.SetLabel(select_data_text) |
---|
188 | if self._nb_selected_data <= self._max_data: |
---|
189 | self._data_text_ctrl.SetForegroundColour('blue') |
---|
190 | else: |
---|
191 | self._data_text_ctrl.SetForegroundColour('red') |
---|
192 | |
---|
193 | |
---|