1 | ################################################################################ |
---|
2 | #This software was developed by the University of Tennessee as part of the |
---|
3 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
4 | #project funded by the US National Science Foundation. |
---|
5 | # |
---|
6 | #See the license text in license.txt |
---|
7 | # |
---|
8 | #copyright 2010, University of Tennessee |
---|
9 | ################################################################################ |
---|
10 | """ |
---|
11 | This module provides Graphic interface for the data_manager module. |
---|
12 | """ |
---|
13 | import wx |
---|
14 | import sys |
---|
15 | import warnings |
---|
16 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
17 | import wx.lib.agw.customtreectrl as CT |
---|
18 | from sans.guiframe.dataFitting import Data1D |
---|
19 | from sans.guiframe.dataFitting import Data2D |
---|
20 | from sans.guiframe.panel_base import PanelBase |
---|
21 | |
---|
22 | PANEL_WIDTH = 200 |
---|
23 | #PANEL_HEIGHT = 560 |
---|
24 | PANEL_HEIGHT = 840 |
---|
25 | STYLE_FLAG = wx.SUNKEN_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\ |
---|
26 | wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT |
---|
27 | |
---|
28 | |
---|
29 | class DataTreeCtrl(CT.CustomTreeCtrl): |
---|
30 | """ |
---|
31 | Check list control to be used for Data Panel |
---|
32 | """ |
---|
33 | def __init__(self, parent,*args, **kwds): |
---|
34 | #agwstyle is introduced in wx.2.8.11 |
---|
35 | try: |
---|
36 | kwds['agwStyle'] = STYLE_FLAG |
---|
37 | except: |
---|
38 | try: |
---|
39 | kwds['style'] = STYLE_FLAG |
---|
40 | except: |
---|
41 | raise |
---|
42 | |
---|
43 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
44 | self.root = self.AddRoot("Available Data") |
---|
45 | |
---|
46 | class DataPanel(ScrolledPanel, PanelBase): |
---|
47 | """ |
---|
48 | This panel displays data available in the application and widgets to |
---|
49 | interact with data. |
---|
50 | """ |
---|
51 | ## Internal name for the AUI manager |
---|
52 | window_name = "Data Panel" |
---|
53 | ## Title to appear on top of the window |
---|
54 | window_caption = "Data Panel" |
---|
55 | #type of window |
---|
56 | window_type = "Data Panel" |
---|
57 | ## Flag to tell the GUI manager that this panel is not |
---|
58 | # tied to any perspective |
---|
59 | #ALWAYS_ON = True |
---|
60 | def __init__(self, parent, list=[],list_of_perspective=[], |
---|
61 | size=(PANEL_WIDTH,PANEL_HEIGHT), manager=None, *args, **kwds): |
---|
62 | kwds['size']= size |
---|
63 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
64 | PanelBase.__init__(self) |
---|
65 | self.SetupScrolling() |
---|
66 | self.all_data1d = True |
---|
67 | self.parent = parent |
---|
68 | self.manager = manager |
---|
69 | self.list_of_data = list |
---|
70 | self.list_of_perspective = list_of_perspective |
---|
71 | self.list_rb_perspectives= [] |
---|
72 | self.list_cb_data = {} |
---|
73 | self.list_cb_theory = {} |
---|
74 | |
---|
75 | self.owner = None |
---|
76 | self.do_layout() |
---|
77 | |
---|
78 | def do_layout(self): |
---|
79 | """ |
---|
80 | """ |
---|
81 | self.define_panel_structure() |
---|
82 | self.layout_selection() |
---|
83 | self.layout_data_list() |
---|
84 | self.layout_button() |
---|
85 | self.layout_batch() |
---|
86 | |
---|
87 | def define_panel_structure(self): |
---|
88 | """ |
---|
89 | Define the skeleton of the panel |
---|
90 | """ |
---|
91 | w, h = self.parent.GetSize() |
---|
92 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
93 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
94 | self.sizer1.SetMinSize((w/12, h*2/5)) |
---|
95 | |
---|
96 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
97 | self.sizer3 = wx.GridBagSizer(5,5) |
---|
98 | self.sizer4 = wx.BoxSizer(wx.HORIZONTAL) |
---|
99 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
100 | |
---|
101 | self.vbox.Add(self.sizer5, 0,wx.EXPAND|wx.ALL,10) |
---|
102 | self.vbox.Add(self.sizer1, 0,wx.EXPAND|wx.ALL,0) |
---|
103 | self.vbox.Add(self.sizer2, 0,wx.EXPAND|wx.ALL,10) |
---|
104 | self.vbox.Add(self.sizer3, 0,wx.EXPAND|wx.ALL,10) |
---|
105 | self.vbox.Add(self.sizer4, 0,wx.EXPAND|wx.ALL,10) |
---|
106 | |
---|
107 | self.SetSizer(self.vbox) |
---|
108 | |
---|
109 | def layout_selection(self): |
---|
110 | """ |
---|
111 | """ |
---|
112 | select_txt = wx.StaticText(self, -1, 'Selection Options') |
---|
113 | select_txt.SetForegroundColour('blue') |
---|
114 | self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
115 | list_of_options = ['Select all Data', |
---|
116 | 'Unselect all Data', |
---|
117 | 'Select all Data 1D', |
---|
118 | 'Unselect all Data 1D', |
---|
119 | 'Select all Data 2D', |
---|
120 | 'Unselect all Data 2D' ] |
---|
121 | for option in list_of_options: |
---|
122 | self.selection_cbox.Append(str(option)) |
---|
123 | self.selection_cbox.SetValue('Select all Data') |
---|
124 | wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type) |
---|
125 | self.sizer5.AddMany([(select_txt,0, wx.ALL,5), |
---|
126 | (self.selection_cbox,0, wx.ALL,5)]) |
---|
127 | def layout_perspective(self, list_of_perspective=[]): |
---|
128 | """ |
---|
129 | Layout widgets related to the list of plug-ins of the gui_manager |
---|
130 | """ |
---|
131 | if len(list_of_perspective)==0: |
---|
132 | return |
---|
133 | w, h = self.parent.GetSize() |
---|
134 | box_description_2= wx.StaticBox(self, -1, "Set Active Perspective") |
---|
135 | self.boxsizer_2 = wx.StaticBoxSizer(box_description_2, wx.HORIZONTAL) |
---|
136 | self.sizer_perspective = wx.GridBagSizer(5,5) |
---|
137 | self.boxsizer_2.Add(self.sizer_perspective) |
---|
138 | self.sizer2.Add(self.boxsizer_2,1, wx.ALL, 10) |
---|
139 | self.list_of_perspective = list_of_perspective |
---|
140 | self.sizer_perspective.Clear(True) |
---|
141 | self.list_rb_perspectives = [] |
---|
142 | |
---|
143 | nb_active_perspective = 0 |
---|
144 | if list_of_perspective: |
---|
145 | ix = 0 |
---|
146 | iy = 0 |
---|
147 | for perspective_name, is_active in list_of_perspective: |
---|
148 | |
---|
149 | if is_active: |
---|
150 | nb_active_perspective += 1 |
---|
151 | if nb_active_perspective == 1: |
---|
152 | rb = wx.RadioButton(self, -1, perspective_name, |
---|
153 | style=wx.RB_GROUP) |
---|
154 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
155 | rb.SetValue(is_active) |
---|
156 | else: |
---|
157 | rb = wx.RadioButton(self, -1, perspective_name) |
---|
158 | rb.SetToolTipString("Data will be applied to this perspective") |
---|
159 | #only one perpesctive can be active |
---|
160 | rb.SetValue(False) |
---|
161 | |
---|
162 | self.Bind(wx.EVT_RADIOBUTTON, self.on_set_active_perspective, |
---|
163 | id=rb.GetId()) |
---|
164 | self.list_rb_perspectives.append(rb) |
---|
165 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
166 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
167 | iy += 1 |
---|
168 | else: |
---|
169 | rb = wx.RadioButton(self, -1, 'No Perspective', |
---|
170 | style=wx.RB_GROUP) |
---|
171 | rb.SetValue(True) |
---|
172 | rb.Disable() |
---|
173 | ix = 0 |
---|
174 | iy = 0 |
---|
175 | self.sizer_perspective.Add(rb,(iy, ix),(1,1), |
---|
176 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 10) |
---|
177 | |
---|
178 | def _on_selection_type(self, event): |
---|
179 | """ |
---|
180 | Select data according to patterns |
---|
181 | """ |
---|
182 | |
---|
183 | list_of_options = ['Select all Data', |
---|
184 | 'Unselect all Data', |
---|
185 | 'Select all Data 1D', |
---|
186 | 'Unselect all Data 1D', |
---|
187 | 'Select all Data 2D', |
---|
188 | 'Unselect all Data 2D' ] |
---|
189 | option = self.selection_cbox.GetValue() |
---|
190 | |
---|
191 | pos = self.selection_cbox.GetSelection() |
---|
192 | if pos == wx.NOT_FOUND: |
---|
193 | return |
---|
194 | option = self.selection_cbox.GetString(pos) |
---|
195 | for item in self.list_cb_data.values(): |
---|
196 | data_ctrl, _, _, _,_, _ = item |
---|
197 | data_id, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) |
---|
198 | if option == 'Select all Data': |
---|
199 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
200 | elif option == 'Unselect all Data': |
---|
201 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
202 | elif option == 'Select all Data 1D': |
---|
203 | if data_class == 'Data1D': |
---|
204 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
205 | elif option == 'Unselect all Data 1D': |
---|
206 | if data_class == 'Data1D': |
---|
207 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
208 | elif option == 'Select all Data 1D': |
---|
209 | if data_class == 'Data1D': |
---|
210 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
211 | elif option == 'Select all Data 2D': |
---|
212 | if data_class == 'Data2D': |
---|
213 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
214 | elif option == 'Unselect all Data 2D': |
---|
215 | if data_class == 'Data2D': |
---|
216 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
217 | |
---|
218 | def on_set_active_perspective(self, event): |
---|
219 | """ |
---|
220 | Select the active perspective |
---|
221 | """ |
---|
222 | ctrl = event.GetEventObject() |
---|
223 | |
---|
224 | def layout_button(self): |
---|
225 | """ |
---|
226 | Layout widgets related to buttons |
---|
227 | """ |
---|
228 | self.bt_import = wx.Button(self, wx.NewId(), "Send To") |
---|
229 | self.bt_import.SetToolTipString("Send set of Data to active perspective") |
---|
230 | wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) |
---|
231 | |
---|
232 | self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To") |
---|
233 | self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel") |
---|
234 | wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) |
---|
235 | |
---|
236 | self.bt_plot = wx.Button(self, wx.NewId(), "New Plot") |
---|
237 | self.bt_plot.SetToolTipString("To trigger plotting") |
---|
238 | wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) |
---|
239 | |
---|
240 | self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze") |
---|
241 | self.bt_freeze.SetToolTipString("To trigger freeze") |
---|
242 | wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) |
---|
243 | |
---|
244 | self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data") |
---|
245 | self.bt_remove.SetToolTipString("Remove data from the application") |
---|
246 | wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) |
---|
247 | |
---|
248 | self.tctrl_perspective = wx.StaticText(self, -1, 'No Active Application') |
---|
249 | self.tctrl_perspective.SetToolTipString("Active Application") |
---|
250 | self.tctrl_plotpanel = wx.StaticText(self, -1, 'No Plot panel on focus') |
---|
251 | self.tctrl_plotpanel.SetToolTipString("Active Plot Panel") |
---|
252 | |
---|
253 | ix = 0 |
---|
254 | iy = 0 |
---|
255 | self.sizer3.Add(self.bt_import,( iy, ix),(1,1), |
---|
256 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
257 | ix += 1 |
---|
258 | self.sizer3.Add(self.tctrl_perspective,(iy, ix),(1,1), |
---|
259 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
260 | ix = 0 |
---|
261 | iy += 1 |
---|
262 | self.sizer3.Add(self.bt_append_plot,( iy, ix),(1,1), |
---|
263 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
264 | ix += 1 |
---|
265 | self.sizer3.Add(self.tctrl_plotpanel,(iy, ix),(1,1), |
---|
266 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
267 | ix = 0 |
---|
268 | iy += 1 |
---|
269 | self.sizer3.Add(self.bt_plot,( iy, ix),(1,1), |
---|
270 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
271 | ix = 0 |
---|
272 | iy += 1 |
---|
273 | self.sizer3.Add(self.bt_freeze,( iy, ix),(1,1), |
---|
274 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
275 | ix = 0 |
---|
276 | iy += 1 |
---|
277 | self.sizer3.Add(self.bt_remove,( iy, ix),(1,1), |
---|
278 | wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
279 | |
---|
280 | |
---|
281 | |
---|
282 | def layout_batch(self): |
---|
283 | """ |
---|
284 | """ |
---|
285 | |
---|
286 | self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode', |
---|
287 | style=wx.RB_GROUP) |
---|
288 | self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode') |
---|
289 | |
---|
290 | self.rb_single_mode.SetValue(True) |
---|
291 | self.rb_batch_mode.SetValue(False) |
---|
292 | self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5), |
---|
293 | (self.rb_batch_mode,0, wx.ALL,5)]) |
---|
294 | |
---|
295 | def old_layout_data_list(self): |
---|
296 | """ |
---|
297 | Add a listcrtl in the panel |
---|
298 | """ |
---|
299 | self.tree_ctrl = DataTreeCtrl(parent=self) |
---|
300 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) |
---|
301 | self.sizer1.Add(self.tree_ctrl,1, wx.EXPAND|wx.ALL, 10) |
---|
302 | self.theory_root = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0, |
---|
303 | "THEORIES", ct_type=0) |
---|
304 | |
---|
305 | def layout_data_list(self): |
---|
306 | """ |
---|
307 | Add a listcrtl in the panel |
---|
308 | """ |
---|
309 | tree_ctrl_label = wx.StaticText(self, -1, "Data") |
---|
310 | tree_ctrl_label.SetForegroundColour('blue') |
---|
311 | self.tree_ctrl = DataTreeCtrl(parent=self) |
---|
312 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) |
---|
313 | tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") |
---|
314 | tree_ctrl_theory_label.SetForegroundColour('blue') |
---|
315 | self.tree_ctrl_theory = DataTreeCtrl(parent=self) |
---|
316 | self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) |
---|
317 | self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) |
---|
318 | self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10) |
---|
319 | self.sizer1.Add(tree_ctrl_theory_label, 0, wx.LEFT, 10) |
---|
320 | self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10) |
---|
321 | |
---|
322 | def onContextMenu(self, event): |
---|
323 | """ |
---|
324 | Retrieve the state selected state |
---|
325 | """ |
---|
326 | # Skipping the save state functionality for release 0.9.0 |
---|
327 | #return |
---|
328 | pos = event.GetPosition() |
---|
329 | pos = self.ScreenToClient(pos) |
---|
330 | self.PopupMenu(self.popUpMenu, pos) |
---|
331 | |
---|
332 | |
---|
333 | def on_check_item(self, event): |
---|
334 | """ |
---|
335 | """ |
---|
336 | item = event.GetItem() |
---|
337 | item.Check(not item.IsChecked()) |
---|
338 | self.enable_button(item) |
---|
339 | event.Skip() |
---|
340 | |
---|
341 | def enable_button(self, item): |
---|
342 | """ |
---|
343 | """ |
---|
344 | _, data_class, _= self.tree_ctrl.GetItemPyData(item) |
---|
345 | if item.IsChecked(): |
---|
346 | self.all_data1d &= (data_class != "Data2D") |
---|
347 | if self.all_data1d: |
---|
348 | self.bt_freeze.Enable() |
---|
349 | else: |
---|
350 | self.bt_freeze.Disable() |
---|
351 | else: |
---|
352 | self.all_data1d |= True |
---|
353 | self.all_data1d &= (data_class != "Data2D") |
---|
354 | if self.all_data1d: |
---|
355 | self.bt_freeze.Enable() |
---|
356 | else: |
---|
357 | self.bt_freeze.Disable() |
---|
358 | |
---|
359 | def load_data_list(self, list): |
---|
360 | """ |
---|
361 | add need data with its theory under the tree |
---|
362 | """ |
---|
363 | if not list: |
---|
364 | return |
---|
365 | |
---|
366 | for state_id, dstate in list.iteritems(): |
---|
367 | data = dstate.get_data() |
---|
368 | theory_list = dstate.get_theory() |
---|
369 | if data is not None: |
---|
370 | data_name = data.name |
---|
371 | data_class = data.__class__.__name__ |
---|
372 | path = dstate.get_path() |
---|
373 | process_list = data.process |
---|
374 | data_id = data.id |
---|
375 | |
---|
376 | if state_id not in self.list_cb_data: |
---|
377 | #new state |
---|
378 | data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0, |
---|
379 | data_name, ct_type=1, |
---|
380 | data=(data_id, data_class, state_id)) |
---|
381 | data_c.Check(True) |
---|
382 | self.enable_button(data_c) |
---|
383 | d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info') |
---|
384 | i_c_c = self.tree_ctrl.AppendItem(d_i_c, |
---|
385 | 'Type: %s' % data_class) |
---|
386 | p_c_c = self.tree_ctrl.AppendItem(d_i_c, |
---|
387 | 'Path: %s' % str(path)) |
---|
388 | d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process') |
---|
389 | |
---|
390 | for process in process_list: |
---|
391 | i_t_c = self.tree_ctrl.AppendItem(d_p_c, |
---|
392 | process.__str__()) |
---|
393 | theory_child = self.tree_ctrl.AppendItem(data_c, "THEORIES") |
---|
394 | |
---|
395 | self.list_cb_data[state_id] = [data_c, |
---|
396 | d_i_c, |
---|
397 | i_c_c, |
---|
398 | p_c_c, |
---|
399 | d_p_c, |
---|
400 | theory_child] |
---|
401 | else: |
---|
402 | data_ctrl_list = self.list_cb_data[state_id] |
---|
403 | #This state is already display replace it contains |
---|
404 | data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = data_ctrl_list |
---|
405 | self.tree_ctrl.SetItemText(data_c, data_name) |
---|
406 | temp = (data_id, data_class, state_id) |
---|
407 | self.tree_ctrl.SetItemPyData(data_c, temp) |
---|
408 | self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % data_class) |
---|
409 | self.tree_ctrl.SetItemText(p_c_c, 'Path: %s' % str(path)) |
---|
410 | self.tree_ctrl.DeleteChildren(d_p_c) |
---|
411 | for process in process_list: |
---|
412 | i_t_c = self.tree_ctrl.AppendItem(d_p_c, |
---|
413 | process.__str__()) |
---|
414 | self.append_theory(state_id, theory_list) |
---|
415 | |
---|
416 | |
---|
417 | def old_append_theory(self, state_id, theory_list): |
---|
418 | """ |
---|
419 | append theory object under data from a state of id = state_id |
---|
420 | replace that theory if already displayed |
---|
421 | """ |
---|
422 | if not theory_list: |
---|
423 | return |
---|
424 | if state_id not in self.list_cb_data.keys(): |
---|
425 | root = self.theory_root |
---|
426 | else: |
---|
427 | item = self.list_cb_data[state_id] |
---|
428 | data_c, _, _, _, _, _ = item |
---|
429 | root = data_c |
---|
430 | if root is not None: |
---|
431 | self.append_theory_helper(root=root, |
---|
432 | state_id=state_id, |
---|
433 | theory_list=theory_list) |
---|
434 | def append_theory(self, state_id, theory_list): |
---|
435 | """ |
---|
436 | append theory object under data from a state of id = state_id |
---|
437 | replace that theory if already displayed |
---|
438 | """ |
---|
439 | if not theory_list: |
---|
440 | return |
---|
441 | if state_id not in self.list_cb_data.keys(): |
---|
442 | root = self.tree_ctrl_theory.root |
---|
443 | tree = self.tree_ctrl_theory |
---|
444 | else: |
---|
445 | item = self.list_cb_data[state_id] |
---|
446 | data_c, _, _, _, _, _ = item |
---|
447 | root = data_c |
---|
448 | tree = self.tree_ctrl |
---|
449 | if root is not None: |
---|
450 | self.append_theory_helper(tree=tree, root=root, |
---|
451 | state_id=state_id, |
---|
452 | theory_list=theory_list) |
---|
453 | |
---|
454 | |
---|
455 | def append_theory_helper(self, tree, root, state_id, theory_list): |
---|
456 | """ |
---|
457 | """ |
---|
458 | if state_id in self.list_cb_theory.keys(): |
---|
459 | #update current list of theory for this data |
---|
460 | theory_list_ctrl = self.list_cb_theory[state_id] |
---|
461 | |
---|
462 | for theory_id, item in theory_list.iteritems(): |
---|
463 | theory_data, theory_state = item |
---|
464 | if theory_data is None: |
---|
465 | name = "Unknown" |
---|
466 | theory_class = "Unknown" |
---|
467 | theory_id = "Unknown" |
---|
468 | temp = (None, None, None) |
---|
469 | else: |
---|
470 | name = theory_data.name |
---|
471 | theory_class = theory_data.__class__.__name__ |
---|
472 | theory_id = theory_data.id |
---|
473 | #if theory_state is not None: |
---|
474 | # name = theory_state.model.name |
---|
475 | temp = (theory_id, theory_class, state_id) |
---|
476 | if theory_id not in theory_list_ctrl: |
---|
477 | #add new theory |
---|
478 | t_child = tree.AppendItem(root, |
---|
479 | name, ct_type=1, data=temp) |
---|
480 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
481 | i_c_c = tree.AppendItem(t_i_c, |
---|
482 | 'Type: %s' % theory_class) |
---|
483 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
484 | |
---|
485 | for process in theory_data.process: |
---|
486 | i_t_c = tree.AppendItem(t_p_c, |
---|
487 | process.__str__()) |
---|
488 | theory_list_ctrl[theory_id] = [t_child, |
---|
489 | i_c_c, |
---|
490 | t_p_c] |
---|
491 | else: |
---|
492 | #replace theory |
---|
493 | t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] |
---|
494 | tree.SetItemText(t_child, name) |
---|
495 | tree.SetItemPyData(t_child, temp) |
---|
496 | tree.SetItemText(i_c_c, 'Type: %s' % theory_class) |
---|
497 | tree.DeleteChildren(t_p_c) |
---|
498 | for process in theory_data.process: |
---|
499 | i_t_c = tree.AppendItem(t_p_c, |
---|
500 | process.__str__()) |
---|
501 | |
---|
502 | else: |
---|
503 | #data didn't have a theory associated it before |
---|
504 | theory_list_ctrl = {} |
---|
505 | for theory_id, item in theory_list.iteritems(): |
---|
506 | theory_data, theory_state = item |
---|
507 | if theory_data is not None: |
---|
508 | name = theory_data.name |
---|
509 | theory_class = theory_data.__class__.__name__ |
---|
510 | theory_id = theory_data.id |
---|
511 | #if theory_state is not None: |
---|
512 | # name = theory_state.model.name |
---|
513 | temp = (theory_id, theory_class, state_id) |
---|
514 | t_child = tree.AppendItem(root, |
---|
515 | name, ct_type=1, |
---|
516 | data=(theory_data.id, theory_class, state_id)) |
---|
517 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
518 | i_c_c = tree.AppendItem(t_i_c, |
---|
519 | 'Type: %s' % theory_class) |
---|
520 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
521 | |
---|
522 | for process in theory_data.process: |
---|
523 | i_t_c = tree.AppendItem(t_p_c, |
---|
524 | process.__str__()) |
---|
525 | |
---|
526 | theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] |
---|
527 | #self.list_cb_theory[data_id] = theory_list_ctrl |
---|
528 | self.list_cb_theory[state_id] = theory_list_ctrl |
---|
529 | |
---|
530 | |
---|
531 | |
---|
532 | def set_data_helper(self): |
---|
533 | """ |
---|
534 | """ |
---|
535 | data_to_plot = [] |
---|
536 | state_to_plot = [] |
---|
537 | theory_to_plot = [] |
---|
538 | for value in self.list_cb_data.values(): |
---|
539 | item, _, _, _, _, _ = value |
---|
540 | if item.IsChecked(): |
---|
541 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
542 | data_to_plot.append(data_id) |
---|
543 | if state_id not in state_to_plot: |
---|
544 | state_to_plot.append(state_id) |
---|
545 | |
---|
546 | for theory_dict in self.list_cb_theory.values(): |
---|
547 | for key, value in theory_dict.iteritems(): |
---|
548 | item, _, _ = value |
---|
549 | if item.IsChecked(): |
---|
550 | theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
551 | theory_to_plot.append(theory_id) |
---|
552 | if state_id not in state_to_plot: |
---|
553 | state_to_plot.append(state_id) |
---|
554 | return data_to_plot, theory_to_plot, state_to_plot |
---|
555 | |
---|
556 | def remove_by_id(self, id): |
---|
557 | """ |
---|
558 | """ |
---|
559 | for item in self.list_cb_data.values(): |
---|
560 | data_c, _, _, _, _, theory_child = item |
---|
561 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) |
---|
562 | if id == data_id: |
---|
563 | self.tree_ctrl.Delete(data_c) |
---|
564 | del self.list_cb_data[state_id] |
---|
565 | del self.list_cb_theory[data_id] |
---|
566 | |
---|
567 | def on_remove(self, event): |
---|
568 | """ |
---|
569 | Get a list of item checked and remove them from the treectrl |
---|
570 | Ask the parent to remove reference to this item |
---|
571 | """ |
---|
572 | data_to_remove, theory_to_remove, _ = self.set_data_helper() |
---|
573 | data_key = [] |
---|
574 | theory_key = [] |
---|
575 | #remove data from treectrl |
---|
576 | for d_key, item in self.list_cb_data.iteritems(): |
---|
577 | data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = item |
---|
578 | if data_c.IsChecked(): |
---|
579 | self.tree_ctrl.Delete(data_c) |
---|
580 | data_key.append(d_key) |
---|
581 | if d_key in self.list_cb_theory.keys(): |
---|
582 | theory_list_ctrl = self.list_cb_theory[d_key] |
---|
583 | theory_to_remove += theory_list_ctrl.keys() |
---|
584 | # Remove theory from treectrl |
---|
585 | for t_key, theory_dict in self.list_cb_theory.iteritems(): |
---|
586 | for key, value in theory_dict.iteritems(): |
---|
587 | item, _, _ = value |
---|
588 | if item.IsChecked(): |
---|
589 | self.tree_ctrl.Delete(item) |
---|
590 | theory_key.append(key) |
---|
591 | #Remove data and related theory references |
---|
592 | for key in data_key: |
---|
593 | del self.list_cb_data[key] |
---|
594 | if key in theory_key: |
---|
595 | del self.list_cb_theory[key] |
---|
596 | #remove theory references independently of data |
---|
597 | for key in theory_key: |
---|
598 | for t_key, theory_dict in self.list_cb_theory.iteritems(): |
---|
599 | if key in theory_dict: |
---|
600 | del theory_dict[key] |
---|
601 | |
---|
602 | self.parent.remove_data(data_id=data_to_remove, |
---|
603 | theory_id=theory_to_remove) |
---|
604 | |
---|
605 | def on_import(self, event=None): |
---|
606 | """ |
---|
607 | Get all select data and set them to the current active perspetive |
---|
608 | """ |
---|
609 | data_id, theory_id, state_id = self.set_data_helper() |
---|
610 | self.parent.set_data(data_id) |
---|
611 | self.parent.set_data(state_id=state_id, theory_id=theory_id) |
---|
612 | |
---|
613 | def on_append_plot(self, event=None): |
---|
614 | """ |
---|
615 | append plot to plot panel on focus |
---|
616 | """ |
---|
617 | data_id, theory_id, state_id = self.set_data_helper() |
---|
618 | self.parent.plot_data(data_id=data_id, |
---|
619 | state_id=state_id, |
---|
620 | theory_id=theory_id, |
---|
621 | append=True) |
---|
622 | |
---|
623 | def on_plot(self, event=None): |
---|
624 | """ |
---|
625 | Send a list of data names to plot |
---|
626 | """ |
---|
627 | data_id, theory_id, state_id = self.set_data_helper() |
---|
628 | self.parent.plot_data(data_id=data_id, |
---|
629 | state_id=state_id, |
---|
630 | theory_id=theory_id, |
---|
631 | append=False) |
---|
632 | |
---|
633 | def on_freeze(self, event): |
---|
634 | """ |
---|
635 | """ |
---|
636 | _, theory_id, state_id = self.set_data_helper() |
---|
637 | self.parent.freeze(data_id=state_id, theory_id=theory_id) |
---|
638 | |
---|
639 | def set_active_perspective(self, name): |
---|
640 | """ |
---|
641 | set the active perspective |
---|
642 | """ |
---|
643 | self.tctrl_perspective.SetLabel(str(name)) |
---|
644 | |
---|
645 | def set_panel_on_focus(self, name): |
---|
646 | """ |
---|
647 | set the plot panel on focus |
---|
648 | """ |
---|
649 | self.tctrl_plotpanel.SetLabel(str(name)) |
---|
650 | |
---|
651 | |
---|
652 | |
---|
653 | |
---|
654 | class DataFrame(wx.Frame): |
---|
655 | ## Internal name for the AUI manager |
---|
656 | window_name = "Data Panel" |
---|
657 | ## Title to appear on top of the window |
---|
658 | window_caption = "Data Panel" |
---|
659 | ## Flag to tell the GUI manager that this panel is not |
---|
660 | # tied to any perspective |
---|
661 | ALWAYS_ON = True |
---|
662 | |
---|
663 | def __init__(self, parent=None, owner=None, manager=None,size=(400, 800), |
---|
664 | list_of_perspective=[],list=[], *args, **kwds): |
---|
665 | kwds['size'] = size |
---|
666 | kwds['id'] = -1 |
---|
667 | kwds['title']= "Loaded Data" |
---|
668 | wx.Frame.__init__(self, parent=parent, *args, **kwds) |
---|
669 | self.parent = parent |
---|
670 | self.owner = owner |
---|
671 | self.manager = manager |
---|
672 | self.panel = DataPanel(parent=self, |
---|
673 | #size=size, |
---|
674 | list_of_perspective=list_of_perspective) |
---|
675 | |
---|
676 | def load_data_list(self, list=[]): |
---|
677 | """ |
---|
678 | Fill the list inside its panel |
---|
679 | """ |
---|
680 | self.panel.load_data_list(list=list) |
---|
681 | |
---|
682 | def layout_perspective(self, list_of_perspective=[]): |
---|
683 | """ |
---|
684 | """ |
---|
685 | self.panel.layout_perspective(list_of_perspective=list_of_perspective) |
---|
686 | |
---|
687 | |
---|
688 | |
---|
689 | |
---|
690 | from dataFitting import Data1D |
---|
691 | from dataFitting import Data2D, Theory1D |
---|
692 | from data_state import DataState |
---|
693 | import sys |
---|
694 | class State(): |
---|
695 | def __init__(self): |
---|
696 | self.msg = "" |
---|
697 | def __str__(self): |
---|
698 | self.msg = "model mane : model1\n" |
---|
699 | self.msg += "params : \n" |
---|
700 | self.msg += "name value\n" |
---|
701 | return msg |
---|
702 | def set_data_state(data=None, path=None, theory=None, state=None): |
---|
703 | dstate = DataState(data=data) |
---|
704 | dstate.set_path(path=path) |
---|
705 | dstate.set_theory(theory, state) |
---|
706 | |
---|
707 | return dstate |
---|
708 | """' |
---|
709 | data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"), |
---|
710 | ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"), |
---|
711 | ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"), |
---|
712 | ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"), |
---|
713 | ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")] |
---|
714 | """ |
---|
715 | if __name__ == "__main__": |
---|
716 | |
---|
717 | app = wx.App() |
---|
718 | try: |
---|
719 | list_of_perspective = [('perspective2', False), ('perspective1', True)] |
---|
720 | data_list = {} |
---|
721 | # state 1 |
---|
722 | data = Data2D() |
---|
723 | data.name = "data2" |
---|
724 | data.id = 1 |
---|
725 | data.append_empty_process() |
---|
726 | process = data.process[len(data.process)-1] |
---|
727 | process.data = "07/01/2010" |
---|
728 | theory = Data2D() |
---|
729 | theory.id = 34 |
---|
730 | theory.name = "theory1" |
---|
731 | path = "path1" |
---|
732 | state = State() |
---|
733 | data_list['1']=set_data_state(data, path,theory, state) |
---|
734 | #state 2 |
---|
735 | data = Data2D() |
---|
736 | data.name = "data2" |
---|
737 | data.id = 76 |
---|
738 | theory = Data2D() |
---|
739 | theory.id = 78 |
---|
740 | theory.name = "CoreShell 07/24/25" |
---|
741 | path = "path2" |
---|
742 | #state3 |
---|
743 | state = State() |
---|
744 | data_list['2']=set_data_state(data, path,theory, state) |
---|
745 | data = Data1D() |
---|
746 | data.id = 3 |
---|
747 | data.name = "data2" |
---|
748 | theory = Theory1D() |
---|
749 | theory.name = "CoreShell" |
---|
750 | theory.id = 4 |
---|
751 | theory.append_empty_process() |
---|
752 | process = theory.process[len(theory.process)-1] |
---|
753 | process.description = "this is my description" |
---|
754 | path = "path3" |
---|
755 | data.append_empty_process() |
---|
756 | process = data.process[len(data.process)-1] |
---|
757 | process.data = "07/22/2010" |
---|
758 | data_list['4']=set_data_state(data, path,theory, state) |
---|
759 | #state 4 |
---|
760 | temp_data_list = {} |
---|
761 | data.name = "data5 erasing data2" |
---|
762 | temp_data_list['4'] = set_data_state(data, path,theory, state) |
---|
763 | #state 5 |
---|
764 | data = Data2D() |
---|
765 | data.name = "data3" |
---|
766 | data.id = 5 |
---|
767 | data.append_empty_process() |
---|
768 | process = data.process[len(data.process)-1] |
---|
769 | process.data = "07/01/2010" |
---|
770 | theory = Theory1D() |
---|
771 | theory.name = "Cylinder" |
---|
772 | path = "path2" |
---|
773 | state = State() |
---|
774 | dstate= set_data_state(data, path,theory, state) |
---|
775 | theory = Theory1D() |
---|
776 | theory.id = 6 |
---|
777 | theory.name = "CoreShell" |
---|
778 | dstate.set_theory(theory) |
---|
779 | theory = Theory1D() |
---|
780 | theory.id = 6 |
---|
781 | theory.name = "CoreShell replacing coreshell in data3" |
---|
782 | dstate.set_theory(theory) |
---|
783 | data_list['3'] = dstate |
---|
784 | #state 6 |
---|
785 | data_list['6']=set_data_state(None, path,theory, state) |
---|
786 | data_list['6']=set_data_state(theory=theory, state=None) |
---|
787 | theory = Theory1D() |
---|
788 | theory.id = 7 |
---|
789 | data_list['6']=set_data_state(theory=theory, state=None) |
---|
790 | data_list['7']=set_data_state(theory=theory, state=None) |
---|
791 | window = DataFrame(list=data_list) |
---|
792 | window.load_data_list(list=data_list) |
---|
793 | #window.layout_perspective(list_of_perspective=list_of_perspective) |
---|
794 | window.Show(True) |
---|
795 | window.load_data_list(list=temp_data_list) |
---|
796 | except: |
---|
797 | #raise |
---|
798 | print "error",sys.exc_value |
---|
799 | |
---|
800 | app.MainLoop() |
---|
801 | |
---|
802 | |
---|