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 | print "went here" |
---|
502 | |
---|
503 | def on_remove(self, event): |
---|
504 | """ |
---|
505 | remove data from application |
---|
506 | """ |
---|
507 | data_to_remove, theory_to_remove = self.set_data_helper() |
---|
508 | for item in self.list_cb_data: |
---|
509 | if item.IsChecked()and \ |
---|
510 | self.tree_ctrl.GetItemText(item) in data_to_remove: |
---|
511 | self.tree_ctrl.Delete(item) |
---|
512 | for item in self.list_cb_theory: |
---|
513 | if item.IsChecked()and \ |
---|
514 | self.tree_ctrl.GetItemText(item) in theory_to_remove: |
---|
515 | self.tree_ctrl.Delete(item) |
---|
516 | delete_all = False |
---|
517 | if data_to_remove: |
---|
518 | delete_all = True |
---|
519 | self.parent.remove_data(data_id=data_to_remove, |
---|
520 | theory_id=theory_to_remove, |
---|
521 | delete_all=delete_all) |
---|
522 | |
---|
523 | def on_import(self, event=None): |
---|
524 | """ |
---|
525 | Get all select data and set them to the current active perspetive |
---|
526 | """ |
---|
527 | self.post_helper(plot=False) |
---|
528 | |
---|
529 | def on_append_plot(self, event=None): |
---|
530 | """ |
---|
531 | append plot to plot panel on focus |
---|
532 | """ |
---|
533 | self.post_helper(plot=True, append=True) |
---|
534 | |
---|
535 | def on_plot(self, event=None): |
---|
536 | """ |
---|
537 | Send a list of data names to plot |
---|
538 | """ |
---|
539 | self.post_helper(plot=True) |
---|
540 | |
---|
541 | def on_freeze(self, event): |
---|
542 | """ |
---|
543 | """ |
---|
544 | data_to_plot, theory_to_plot = self.set_data_helper() |
---|
545 | self.parent.freeze(data_id=data_to_plot, theory_id=theory_to_plot) |
---|
546 | |
---|
547 | def set_active_perspective(self, name): |
---|
548 | """ |
---|
549 | set the active perspective |
---|
550 | """ |
---|
551 | self.tctrl_perspective.SetLabel(str(name)) |
---|
552 | |
---|
553 | def set_panel_on_focus(self, name): |
---|
554 | """ |
---|
555 | set the plot panel on focus |
---|
556 | """ |
---|
557 | self.tctrl_plotpanel.SetLabel(str(name)) |
---|
558 | |
---|
559 | def post_helper(self, plot=False, append=False): |
---|
560 | """ |
---|
561 | """ |
---|
562 | data_to_plot, theory_to_plot = self.set_data_helper() |
---|
563 | if self.parent is not None: |
---|
564 | self.parent.get_data_from_panel(data_id=data_to_plot, plot=plot, |
---|
565 | append=append) |
---|
566 | |
---|
567 | |
---|
568 | |
---|
569 | |
---|
570 | class DataFrame(wx.Frame): |
---|
571 | ## Internal name for the AUI manager |
---|
572 | window_name = "Data Panel" |
---|
573 | ## Title to appear on top of the window |
---|
574 | window_caption = "Data Panel" |
---|
575 | ## Flag to tell the GUI manager that this panel is not |
---|
576 | # tied to any perspective |
---|
577 | ALWAYS_ON = True |
---|
578 | |
---|
579 | def __init__(self, parent=None, owner=None, manager=None,size=(400, 800), |
---|
580 | list_of_perspective=[],list=[], *args, **kwds): |
---|
581 | kwds['size'] = size |
---|
582 | kwds['id'] = -1 |
---|
583 | kwds['title']= "Loaded Data" |
---|
584 | wx.Frame.__init__(self, parent=parent, *args, **kwds) |
---|
585 | self.parent = parent |
---|
586 | self.owner = owner |
---|
587 | self.manager = manager |
---|
588 | self.panel = DataPanel(parent=self, |
---|
589 | #size=size, |
---|
590 | list_of_perspective=list_of_perspective) |
---|
591 | |
---|
592 | def load_data_list(self, list=[]): |
---|
593 | """ |
---|
594 | Fill the list inside its panel |
---|
595 | """ |
---|
596 | self.panel.load_data_list(list=list) |
---|
597 | |
---|
598 | def layout_perspective(self, list_of_perspective=[]): |
---|
599 | """ |
---|
600 | """ |
---|
601 | self.panel.layout_perspective(list_of_perspective=list_of_perspective) |
---|
602 | |
---|
603 | |
---|
604 | |
---|
605 | |
---|
606 | from dataFitting import Data1D |
---|
607 | from dataFitting import Data2D, Theory1D |
---|
608 | from data_state import DataState |
---|
609 | import sys |
---|
610 | class State(): |
---|
611 | def __init__(self): |
---|
612 | self.msg = "" |
---|
613 | def __str__(self): |
---|
614 | self.msg = "model mane : model1\n" |
---|
615 | self.msg += "params : \n" |
---|
616 | self.msg += "name value\n" |
---|
617 | return msg |
---|
618 | def set_data_state(data, path, theory, state): |
---|
619 | dstate = DataState(data=data) |
---|
620 | dstate.set_path(path=path) |
---|
621 | dstate.set_theory(theory, state) |
---|
622 | |
---|
623 | return dstate |
---|
624 | """' |
---|
625 | data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"), |
---|
626 | ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"), |
---|
627 | ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"), |
---|
628 | ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"), |
---|
629 | ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")] |
---|
630 | """ |
---|
631 | if __name__ == "__main__": |
---|
632 | |
---|
633 | app = wx.App() |
---|
634 | try: |
---|
635 | list_of_perspective = [('perspective2', False), ('perspective1', True)] |
---|
636 | data_list = {} |
---|
637 | # state 1 |
---|
638 | data = Data1D() |
---|
639 | data.name = "data1" |
---|
640 | data.id = 1 |
---|
641 | data.append_empty_process() |
---|
642 | process = data.process[len(data.process)-1] |
---|
643 | process.data = "07/01/2010" |
---|
644 | theory = Theory1D() |
---|
645 | theory.id = 34 |
---|
646 | theory.name = "theory1" |
---|
647 | path = "path1" |
---|
648 | state = State() |
---|
649 | data_list['1']=set_data_state(data, path,theory, state) |
---|
650 | #state 2 |
---|
651 | data = Data1D() |
---|
652 | data.name = "data2" |
---|
653 | data.id = 76 |
---|
654 | theory = Theory1D() |
---|
655 | theory.id = 78 |
---|
656 | theory.name = "CoreShell 07/24/25" |
---|
657 | path = "path2" |
---|
658 | #state3 |
---|
659 | state = State() |
---|
660 | data_list['2']=set_data_state(data, path,theory, state) |
---|
661 | data = Data1D() |
---|
662 | data.id = 3 |
---|
663 | data.name = "data2" |
---|
664 | theory = Theory1D() |
---|
665 | theory.name = "CoreShell" |
---|
666 | theory.id = 4 |
---|
667 | theory.append_empty_process() |
---|
668 | process = theory.process[len(theory.process)-1] |
---|
669 | process.description = "this is my description" |
---|
670 | path = "path3" |
---|
671 | data.append_empty_process() |
---|
672 | process = data.process[len(data.process)-1] |
---|
673 | process.data = "07/22/2010" |
---|
674 | data_list['4']=set_data_state(data, path,theory, state) |
---|
675 | #state 4 |
---|
676 | temp_data_list = {} |
---|
677 | data.name = "data5 erasing data2" |
---|
678 | temp_data_list['4'] = set_data_state(data, path,theory, state) |
---|
679 | #state 5 |
---|
680 | data = Data2D() |
---|
681 | data.name = "data3" |
---|
682 | data.id = 5 |
---|
683 | data.append_empty_process() |
---|
684 | process = data.process[len(data.process)-1] |
---|
685 | process.data = "07/01/2010" |
---|
686 | theory = Theory1D() |
---|
687 | theory.name = "Cylinder" |
---|
688 | path = "path2" |
---|
689 | state = State() |
---|
690 | dstate= set_data_state(data, path,theory, state) |
---|
691 | theory = Theory1D() |
---|
692 | theory.id = 6 |
---|
693 | theory.name = "CoreShell" |
---|
694 | dstate.set_theory(theory) |
---|
695 | theory = Theory1D() |
---|
696 | theory.id = 6 |
---|
697 | theory.name = "CoreShell replacing coreshell in data3" |
---|
698 | dstate.set_theory(theory) |
---|
699 | data_list['3'] = dstate |
---|
700 | #state 6 |
---|
701 | data_list['6']=set_data_state(None, path,theory, state) |
---|
702 | |
---|
703 | window = DataFrame(list=data_list) |
---|
704 | window.load_data_list(list=data_list) |
---|
705 | #window.layout_perspective(list_of_perspective=list_of_perspective) |
---|
706 | window.Show(True) |
---|
707 | window.load_data_list(list=temp_data_list) |
---|
708 | except: |
---|
709 | #raise |
---|
710 | print "error",sys.exc_value |
---|
711 | |
---|
712 | app.MainLoop() |
---|
713 | |
---|
714 | |
---|