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