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