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 os |
---|
14 | import wx |
---|
15 | import sys |
---|
16 | import warnings |
---|
17 | import logging |
---|
18 | from wx.lib.scrolledpanel import ScrolledPanel |
---|
19 | import wx.lib.agw.customtreectrl as CT |
---|
20 | from sans.guiframe.dataFitting import Data1D |
---|
21 | from sans.guiframe.dataFitting import Data2D |
---|
22 | from sans.guiframe.panel_base import PanelBase |
---|
23 | from sans.guiframe.events import StatusEvent |
---|
24 | from sans.guiframe.events import EVT_DELETE_PLOTPANEL |
---|
25 | from sans.guiframe.events import NewLoadDataEvent |
---|
26 | from sans.guiframe.events import NewPlotEvent |
---|
27 | from sans.guiframe.gui_style import GUIFRAME |
---|
28 | from DataLoader.loader import Loader |
---|
29 | |
---|
30 | try: |
---|
31 | # Try to find a local config |
---|
32 | import imp |
---|
33 | path = os.getcwd() |
---|
34 | if(os.path.isfile("%s/%s.py" % (path, 'local_config'))) or \ |
---|
35 | (os.path.isfile("%s/%s.pyc" % (path, 'local_config'))): |
---|
36 | fObj, path, descr = imp.find_module('local_config', [path]) |
---|
37 | config = imp.load_module('local_config', fObj, path, descr) |
---|
38 | else: |
---|
39 | # Try simply importing local_config |
---|
40 | import local_config as config |
---|
41 | except: |
---|
42 | # Didn't find local config, load the default |
---|
43 | import config |
---|
44 | |
---|
45 | extension_list = [] |
---|
46 | if config.APPLICATION_STATE_EXTENSION is not None: |
---|
47 | extension_list.append(config.APPLICATION_STATE_EXTENSION) |
---|
48 | EXTENSIONS = config.PLUGIN_STATE_EXTENSIONS + extension_list |
---|
49 | PLUGINS_WLIST = config.PLUGINS_WLIST |
---|
50 | APPLICATION_WLIST = config.APPLICATION_WLIST |
---|
51 | try: |
---|
52 | PANEL_WIDTH = config.DATA_PANEL_WIDTH |
---|
53 | PANEL_HEIGHT = config.DATA_PANEL_HEIGHT |
---|
54 | except: |
---|
55 | PANEL_WIDTH = 235 |
---|
56 | PANEL_HEIGHT = 700 |
---|
57 | CBOX_WIDTH = 140 |
---|
58 | BUTTON_WIDTH = 80 |
---|
59 | STYLE_FLAG =wx.RAISED_BORDER|CT.TR_HAS_BUTTONS| CT.TR_HIDE_ROOT|\ |
---|
60 | wx.WANTS_CHARS|CT.TR_HAS_VARIABLE_ROW_HEIGHT |
---|
61 | |
---|
62 | |
---|
63 | class DataTreeCtrl(CT.CustomTreeCtrl): |
---|
64 | """ |
---|
65 | Check list control to be used for Data Panel |
---|
66 | """ |
---|
67 | def __init__(self, parent,*args, **kwds): |
---|
68 | #agwstyle is introduced in wx.2.8.11 but is not working for mac |
---|
69 | if sys.platform.count("darwin") != 0: |
---|
70 | try: |
---|
71 | kwds['style'] = STYLE_FLAG |
---|
72 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
73 | except: |
---|
74 | del kwds['style'] |
---|
75 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
76 | else: |
---|
77 | #agwstyle is introduced in wx.2.8.11 .argument working only for windows |
---|
78 | try: |
---|
79 | kwds['agwStyle'] = STYLE_FLAG |
---|
80 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
81 | except: |
---|
82 | try: |
---|
83 | del kwds['agwStyle'] |
---|
84 | kwds['style'] = STYLE_FLAG |
---|
85 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
86 | except: |
---|
87 | del kwds['style'] |
---|
88 | CT.CustomTreeCtrl.__init__(self, parent, *args, **kwds) |
---|
89 | self.root = self.AddRoot("Available Data") |
---|
90 | |
---|
91 | class DataPanel(ScrolledPanel, PanelBase): |
---|
92 | """ |
---|
93 | This panel displays data available in the application and widgets to |
---|
94 | interact with data. |
---|
95 | """ |
---|
96 | ## Internal name for the AUI manager |
---|
97 | window_name = "Data Panel" |
---|
98 | ## Title to appear on top of the window |
---|
99 | window_caption = "Data Explorer" |
---|
100 | #type of window |
---|
101 | window_type = "Data Panel" |
---|
102 | ## Flag to tell the GUI manager that this panel is not |
---|
103 | # tied to any perspective |
---|
104 | #ALWAYS_ON = True |
---|
105 | def __init__(self, parent, |
---|
106 | list=None, |
---|
107 | size=(PANEL_WIDTH, PANEL_HEIGHT), |
---|
108 | list_of_perspective=None, manager=None, *args, **kwds): |
---|
109 | |
---|
110 | kwds['size']= size |
---|
111 | kwds['style'] = STYLE_FLAG |
---|
112 | ScrolledPanel.__init__(self, parent=parent, *args, **kwds) |
---|
113 | PanelBase.__init__(self) |
---|
114 | self.SetupScrolling() |
---|
115 | self.loader = Loader() |
---|
116 | #Default location |
---|
117 | self._default_save_location = None |
---|
118 | self.all_data1d = True |
---|
119 | self.parent = parent |
---|
120 | self.manager = manager |
---|
121 | if list is None: |
---|
122 | list = [] |
---|
123 | self.list_of_data = list |
---|
124 | if list_of_perspective is None: |
---|
125 | list_of_perspective = [] |
---|
126 | self.list_of_perspective = list_of_perspective |
---|
127 | self.list_rb_perspectives= [] |
---|
128 | self.list_cb_data = {} |
---|
129 | self.list_cb_theory = {} |
---|
130 | self.tree_ctrl = None |
---|
131 | self.tree_ctrl_theory = None |
---|
132 | self.perspective_cbox = None |
---|
133 | |
---|
134 | self.owner = None |
---|
135 | self.do_layout() |
---|
136 | self.fill_cbox_analysis(self.list_of_perspective) |
---|
137 | self.Bind(wx.EVT_SHOW, self.on_close_page) |
---|
138 | if self.parent is not None: |
---|
139 | self.parent.Bind(EVT_DELETE_PLOTPANEL, self._on_delete_plot_panel) |
---|
140 | |
---|
141 | |
---|
142 | def do_layout(self): |
---|
143 | """ |
---|
144 | """ |
---|
145 | self.define_panel_structure() |
---|
146 | self.layout_selection() |
---|
147 | self.layout_data_list() |
---|
148 | self.layout_button() |
---|
149 | #self.layout_batch() |
---|
150 | |
---|
151 | def define_panel_structure(self): |
---|
152 | """ |
---|
153 | Define the skeleton of the panel |
---|
154 | """ |
---|
155 | w, h = self.parent.GetSize() |
---|
156 | self.vbox = wx.BoxSizer(wx.VERTICAL) |
---|
157 | self.sizer1 = wx.BoxSizer(wx.VERTICAL) |
---|
158 | self.sizer1.SetMinSize((w/13, h*2/5)) |
---|
159 | |
---|
160 | self.sizer2 = wx.BoxSizer(wx.VERTICAL) |
---|
161 | self.sizer3 = wx.FlexGridSizer(7, 2, 0, 0) |
---|
162 | self.sizer4 = wx.BoxSizer(wx.HORIZONTAL) |
---|
163 | self.sizer5 = wx.BoxSizer(wx.VERTICAL) |
---|
164 | |
---|
165 | self.vbox.Add(self.sizer5, 0, wx.EXPAND|wx.ALL,1) |
---|
166 | self.vbox.Add(self.sizer1, 0, wx.EXPAND|wx.ALL,0) |
---|
167 | self.vbox.Add(self.sizer2, 0, wx.EXPAND|wx.ALL,1) |
---|
168 | self.vbox.Add(self.sizer3, 0, wx.EXPAND|wx.ALL,1) |
---|
169 | self.vbox.Add(self.sizer4, 0, wx.EXPAND|wx.ALL,5) |
---|
170 | |
---|
171 | self.SetSizer(self.vbox) |
---|
172 | |
---|
173 | def layout_selection(self): |
---|
174 | """ |
---|
175 | """ |
---|
176 | select_txt = wx.StaticText(self, -1, 'Selection Options') |
---|
177 | select_txt.SetForegroundColour('blue') |
---|
178 | self.selection_cbox = wx.ComboBox(self, -1, style=wx.CB_READONLY) |
---|
179 | list_of_options = ['Select all Data', |
---|
180 | 'Unselect all Data', |
---|
181 | 'Select all Data 1D', |
---|
182 | 'Unselect all Data 1D', |
---|
183 | 'Select all Data 2D', |
---|
184 | 'Unselect all Data 2D' ] |
---|
185 | for option in list_of_options: |
---|
186 | self.selection_cbox.Append(str(option)) |
---|
187 | self.selection_cbox.SetValue('Select all Data') |
---|
188 | wx.EVT_COMBOBOX(self.selection_cbox,-1, self._on_selection_type) |
---|
189 | self.sizer5.AddMany([(select_txt,0, wx.ALL,5), |
---|
190 | (self.selection_cbox,0, wx.ALL,5)]) |
---|
191 | self.enable_selection() |
---|
192 | |
---|
193 | |
---|
194 | def _on_selection_type(self, event): |
---|
195 | """ |
---|
196 | Select data according to patterns |
---|
197 | """ |
---|
198 | |
---|
199 | list_of_options = ['Select all Data', |
---|
200 | 'Unselect all Data', |
---|
201 | 'Select all Data 1D', |
---|
202 | 'Unselect all Data 1D', |
---|
203 | 'Select all Data 2D', |
---|
204 | 'Unselect all Data 2D' ] |
---|
205 | option = self.selection_cbox.GetValue() |
---|
206 | |
---|
207 | pos = self.selection_cbox.GetSelection() |
---|
208 | if pos == wx.NOT_FOUND: |
---|
209 | return |
---|
210 | option = self.selection_cbox.GetString(pos) |
---|
211 | for item in self.list_cb_data.values(): |
---|
212 | data_ctrl, _, _, _,_, _ = item |
---|
213 | data_id, data_class, _ = self.tree_ctrl.GetItemPyData(data_ctrl) |
---|
214 | if option == 'Select all Data': |
---|
215 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
216 | elif option == 'Unselect all Data': |
---|
217 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
218 | elif option == 'Select all Data 1D': |
---|
219 | if data_class == 'Data1D': |
---|
220 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
221 | elif option == 'Unselect all Data 1D': |
---|
222 | if data_class == 'Data1D': |
---|
223 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
224 | elif option == 'Select all Data 1D': |
---|
225 | if data_class == 'Data1D': |
---|
226 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
227 | elif option == 'Select all Data 2D': |
---|
228 | if data_class == 'Data2D': |
---|
229 | self.tree_ctrl.CheckItem(data_ctrl, True) |
---|
230 | elif option == 'Unselect all Data 2D': |
---|
231 | if data_class == 'Data2D': |
---|
232 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
233 | self.enable_append() |
---|
234 | self.enable_freeze() |
---|
235 | self.enable_plot() |
---|
236 | self.enable_import() |
---|
237 | self.enable_remove() |
---|
238 | |
---|
239 | def layout_button(self): |
---|
240 | """ |
---|
241 | Layout widgets related to buttons |
---|
242 | """ |
---|
243 | w, _ = self.GetSize() |
---|
244 | |
---|
245 | self.bt_add = wx.Button(self, wx.NewId(), "Load Data", |
---|
246 | size=(BUTTON_WIDTH, -1)) |
---|
247 | self.bt_add.SetToolTipString("Load data files") |
---|
248 | wx.EVT_BUTTON(self, self.bt_add.GetId(), self._load_data) |
---|
249 | self.bt_remove = wx.Button(self, wx.NewId(), "Remove Data", |
---|
250 | size=(BUTTON_WIDTH, -1)) |
---|
251 | self.bt_remove.SetToolTipString("Remove data from the application") |
---|
252 | wx.EVT_BUTTON(self, self.bt_remove.GetId(), self.on_remove) |
---|
253 | self.bt_import = wx.Button(self, wx.NewId(), "Send To", |
---|
254 | size=(BUTTON_WIDTH, -1)) |
---|
255 | self.bt_import.SetToolTipString("Send set of Data to active perspective") |
---|
256 | wx.EVT_BUTTON(self, self.bt_import.GetId(), self.on_import) |
---|
257 | self.perspective_cbox = wx.ComboBox(self, -1, size=(CBOX_WIDTH, -1), |
---|
258 | style=wx.CB_READONLY) |
---|
259 | wx.EVT_COMBOBOX(self.perspective_cbox,-1, |
---|
260 | self._on_perspective_selection) |
---|
261 | |
---|
262 | self.bt_append_plot = wx.Button(self, wx.NewId(), "Append Plot To", |
---|
263 | size=(BUTTON_WIDTH, -1)) |
---|
264 | self.bt_append_plot.SetToolTipString("Plot the selected data in the active panel") |
---|
265 | wx.EVT_BUTTON(self, self.bt_append_plot.GetId(), self.on_append_plot) |
---|
266 | |
---|
267 | self.bt_plot = wx.Button(self, wx.NewId(), "New Plot", |
---|
268 | size=(BUTTON_WIDTH, -1)) |
---|
269 | self.bt_plot.SetToolTipString("To trigger plotting") |
---|
270 | wx.EVT_BUTTON(self, self.bt_plot.GetId(), self.on_plot) |
---|
271 | |
---|
272 | self.bt_freeze = wx.Button(self, wx.NewId(), "Freeze Theory", |
---|
273 | size=(BUTTON_WIDTH, -1)) |
---|
274 | self.bt_freeze.SetToolTipString("To trigger freeze a theory") |
---|
275 | wx.EVT_BUTTON(self, self.bt_freeze.GetId(), self.on_freeze) |
---|
276 | #hide plot |
---|
277 | self.bt_close_plot = wx.Button(self, wx.NewId(), "Close Plot", |
---|
278 | size=(BUTTON_WIDTH, -1)) |
---|
279 | self.bt_freeze.SetToolTipString("Close the plot panel on focus") |
---|
280 | wx.EVT_BUTTON(self, self.bt_close_plot.GetId(), self.on_close_plot) |
---|
281 | |
---|
282 | self.cb_plotpanel = wx.ComboBox(self, -1, size=(CBOX_WIDTH, -1), |
---|
283 | style=wx.CB_READONLY|wx.CB_SORT) |
---|
284 | wx.EVT_COMBOBOX(self.cb_plotpanel,-1, self._on_plot_selection) |
---|
285 | self.cb_plotpanel.Disable() |
---|
286 | |
---|
287 | self.sizer3.AddMany([(self.bt_add), |
---|
288 | ((10, 10)), |
---|
289 | (self.bt_remove), |
---|
290 | ((10, 10)), |
---|
291 | (self.bt_import, 0, wx.EXPAND|wx.RIGHT, 5), |
---|
292 | (self.perspective_cbox, wx.EXPAND), |
---|
293 | (self.bt_append_plot), |
---|
294 | (self.cb_plotpanel, wx.EXPAND), |
---|
295 | (self.bt_plot), |
---|
296 | ((10, 10)), |
---|
297 | (self.bt_freeze), |
---|
298 | ((10, 10)), |
---|
299 | (self.bt_close_plot), |
---|
300 | ((10, 10))]) |
---|
301 | |
---|
302 | self.sizer3.AddGrowableCol(1, 1) |
---|
303 | self.show_data_button() |
---|
304 | self.enable_remove() |
---|
305 | self.enable_import() |
---|
306 | self.enable_plot() |
---|
307 | self.enable_append() |
---|
308 | self.enable_freeze() |
---|
309 | self.enable_remove_plot() |
---|
310 | |
---|
311 | def layout_batch(self): |
---|
312 | """ |
---|
313 | """ |
---|
314 | self.rb_single_mode = wx.RadioButton(self, -1, 'Single Mode', |
---|
315 | style=wx.RB_GROUP) |
---|
316 | self.rb_batch_mode = wx.RadioButton(self, -1, 'Batch Mode') |
---|
317 | |
---|
318 | self.rb_single_mode.SetValue(True) |
---|
319 | self.rb_batch_mode.SetValue(False) |
---|
320 | self.sizer4.AddMany([(self.rb_single_mode,0, wx.ALL,5), |
---|
321 | (self.rb_batch_mode,0, wx.ALL,5)]) |
---|
322 | |
---|
323 | def layout_data_list(self): |
---|
324 | """ |
---|
325 | Add a listcrtl in the panel |
---|
326 | """ |
---|
327 | tree_ctrl_label = wx.StaticText(self, -1, "Data") |
---|
328 | tree_ctrl_label.SetForegroundColour('blue') |
---|
329 | self.tree_ctrl = DataTreeCtrl(parent=self) |
---|
330 | self.tree_ctrl.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) |
---|
331 | tree_ctrl_theory_label = wx.StaticText(self, -1, "Theory") |
---|
332 | tree_ctrl_theory_label.SetForegroundColour('blue') |
---|
333 | self.tree_ctrl_theory = DataTreeCtrl(parent=self) |
---|
334 | self.tree_ctrl_theory.Bind(CT.EVT_TREE_ITEM_CHECKING, self.on_check_item) |
---|
335 | self.sizer1.Add(tree_ctrl_label, 0, wx.LEFT, 10) |
---|
336 | self.sizer1.Add(self.tree_ctrl, 1, wx.EXPAND|wx.ALL, 10) |
---|
337 | self.sizer1.Add(tree_ctrl_theory_label, 0, wx.LEFT, 10) |
---|
338 | self.sizer1.Add(self.tree_ctrl_theory, 1, wx.EXPAND|wx.ALL, 10) |
---|
339 | |
---|
340 | def onContextMenu(self, event): |
---|
341 | """ |
---|
342 | Retrieve the state selected state |
---|
343 | """ |
---|
344 | # Skipping the save state functionality for release 0.9.0 |
---|
345 | #return |
---|
346 | pos = event.GetPosition() |
---|
347 | pos = self.ScreenToClient(pos) |
---|
348 | self.PopupMenu(self.popUpMenu, pos) |
---|
349 | |
---|
350 | |
---|
351 | def on_check_item(self, event): |
---|
352 | """ |
---|
353 | """ |
---|
354 | item = event.GetItem() |
---|
355 | item.Check(not item.IsChecked()) |
---|
356 | self.enable_append() |
---|
357 | self.enable_freeze() |
---|
358 | self.enable_plot() |
---|
359 | self.enable_import() |
---|
360 | self.enable_remove() |
---|
361 | event.Skip() |
---|
362 | |
---|
363 | def fill_cbox_analysis(self, plugin): |
---|
364 | """ |
---|
365 | fill the combobox with analysis name |
---|
366 | """ |
---|
367 | self.list_of_perspective = plugin |
---|
368 | if self.parent is None or \ |
---|
369 | not hasattr(self.parent, "get_current_perspective") or \ |
---|
370 | len(self.list_of_perspective) == 0: |
---|
371 | return |
---|
372 | if self.parent is not None and self.perspective_cbox is not None: |
---|
373 | for plug in self.list_of_perspective: |
---|
374 | if plug.get_perspective(): |
---|
375 | self.perspective_cbox.Append(plug.sub_menu, plug) |
---|
376 | |
---|
377 | curr_pers = self.parent.get_current_perspective() |
---|
378 | self.perspective_cbox.SetStringSelection(curr_pers.sub_menu) |
---|
379 | self.enable_import() |
---|
380 | |
---|
381 | def load_data_list(self, list): |
---|
382 | """ |
---|
383 | add need data with its theory under the tree |
---|
384 | """ |
---|
385 | if list: |
---|
386 | for state_id, dstate in list.iteritems(): |
---|
387 | data = dstate.get_data() |
---|
388 | theory_list = dstate.get_theory() |
---|
389 | if data is not None: |
---|
390 | data_name = data.name |
---|
391 | data_class = data.__class__.__name__ |
---|
392 | path = dstate.get_path() |
---|
393 | process_list = data.process |
---|
394 | data_id = data.id |
---|
395 | |
---|
396 | if state_id not in self.list_cb_data: |
---|
397 | #new state |
---|
398 | data_c = self.tree_ctrl.InsertItem(self.tree_ctrl.root,0, |
---|
399 | data_name, ct_type=1, |
---|
400 | data=(data_id, data_class, state_id)) |
---|
401 | data_c.Check(True) |
---|
402 | d_i_c = self.tree_ctrl.AppendItem(data_c, 'Info') |
---|
403 | i_c_c = self.tree_ctrl.AppendItem(d_i_c, |
---|
404 | 'Type: %s' % data_class) |
---|
405 | p_c_c = self.tree_ctrl.AppendItem(d_i_c, |
---|
406 | 'Path: %s' % str(path)) |
---|
407 | d_p_c = self.tree_ctrl.AppendItem(d_i_c, 'Process') |
---|
408 | |
---|
409 | for process in process_list: |
---|
410 | i_t_c = self.tree_ctrl.AppendItem(d_p_c, |
---|
411 | process.__str__()) |
---|
412 | theory_child = self.tree_ctrl.AppendItem(data_c, "THEORIES") |
---|
413 | |
---|
414 | self.list_cb_data[state_id] = [data_c, |
---|
415 | d_i_c, |
---|
416 | i_c_c, |
---|
417 | p_c_c, |
---|
418 | d_p_c, |
---|
419 | theory_child] |
---|
420 | else: |
---|
421 | data_ctrl_list = self.list_cb_data[state_id] |
---|
422 | #This state is already display replace it contains |
---|
423 | data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = data_ctrl_list |
---|
424 | self.tree_ctrl.SetItemText(data_c, data_name) |
---|
425 | temp = (data_id, data_class, state_id) |
---|
426 | self.tree_ctrl.SetItemPyData(data_c, temp) |
---|
427 | self.tree_ctrl.SetItemText(i_c_c, 'Type: %s' % data_class) |
---|
428 | self.tree_ctrl.SetItemText(p_c_c, 'Path: %s' % str(path)) |
---|
429 | self.tree_ctrl.DeleteChildren(d_p_c) |
---|
430 | for process in process_list: |
---|
431 | i_t_c = self.tree_ctrl.AppendItem(d_p_c, |
---|
432 | process.__str__()) |
---|
433 | self.append_theory(state_id, theory_list) |
---|
434 | self.enable_remove() |
---|
435 | self.enable_import() |
---|
436 | self.enable_plot() |
---|
437 | self.enable_freeze() |
---|
438 | self.enable_selection() |
---|
439 | |
---|
440 | def _uncheck_all(self): |
---|
441 | """ |
---|
442 | Uncheck all check boxes |
---|
443 | """ |
---|
444 | for item in self.list_cb_data.values(): |
---|
445 | data_ctrl, _, _, _,_, _ = item |
---|
446 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
447 | self.enable_append() |
---|
448 | self.enable_freeze() |
---|
449 | self.enable_plot() |
---|
450 | self.enable_import() |
---|
451 | self.enable_remove() |
---|
452 | |
---|
453 | def append_theory(self, state_id, theory_list): |
---|
454 | """ |
---|
455 | append theory object under data from a state of id = state_id |
---|
456 | replace that theory if already displayed |
---|
457 | """ |
---|
458 | if not theory_list: |
---|
459 | return |
---|
460 | if state_id not in self.list_cb_data.keys(): |
---|
461 | root = self.tree_ctrl_theory.root |
---|
462 | tree = self.tree_ctrl_theory |
---|
463 | else: |
---|
464 | item = self.list_cb_data[state_id] |
---|
465 | data_c, _, _, _, _, _ = item |
---|
466 | root = data_c |
---|
467 | tree = self.tree_ctrl |
---|
468 | if root is not None: |
---|
469 | self.append_theory_helper(tree=tree, root=root, |
---|
470 | state_id=state_id, |
---|
471 | theory_list=theory_list) |
---|
472 | |
---|
473 | |
---|
474 | def append_theory_helper(self, tree, root, state_id, theory_list): |
---|
475 | """ |
---|
476 | """ |
---|
477 | if state_id in self.list_cb_theory.keys(): |
---|
478 | #update current list of theory for this data |
---|
479 | theory_list_ctrl = self.list_cb_theory[state_id] |
---|
480 | |
---|
481 | for theory_id, item in theory_list.iteritems(): |
---|
482 | theory_data, theory_state = item |
---|
483 | if theory_data is None: |
---|
484 | name = "Unknown" |
---|
485 | theory_class = "Unknown" |
---|
486 | theory_id = "Unknown" |
---|
487 | temp = (None, None, None) |
---|
488 | else: |
---|
489 | name = theory_data.name |
---|
490 | theory_class = theory_data.__class__.__name__ |
---|
491 | theory_id = theory_data.id |
---|
492 | #if theory_state is not None: |
---|
493 | # name = theory_state.model.name |
---|
494 | temp = (theory_id, theory_class, state_id) |
---|
495 | if theory_id not in theory_list_ctrl: |
---|
496 | #add new theory |
---|
497 | t_child = tree.AppendItem(root, |
---|
498 | name, ct_type=1, data=temp) |
---|
499 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
500 | i_c_c = tree.AppendItem(t_i_c, |
---|
501 | 'Type: %s' % theory_class) |
---|
502 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
503 | |
---|
504 | for process in theory_data.process: |
---|
505 | i_t_c = tree.AppendItem(t_p_c, |
---|
506 | process.__str__()) |
---|
507 | theory_list_ctrl[theory_id] = [t_child, |
---|
508 | i_c_c, |
---|
509 | t_p_c] |
---|
510 | else: |
---|
511 | #replace theory |
---|
512 | t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] |
---|
513 | tree.SetItemText(t_child, name) |
---|
514 | tree.SetItemPyData(t_child, temp) |
---|
515 | tree.SetItemText(i_c_c, 'Type: %s' % theory_class) |
---|
516 | tree.DeleteChildren(t_p_c) |
---|
517 | for process in theory_data.process: |
---|
518 | i_t_c = tree.AppendItem(t_p_c, |
---|
519 | process.__str__()) |
---|
520 | |
---|
521 | else: |
---|
522 | #data didn't have a theory associated it before |
---|
523 | theory_list_ctrl = {} |
---|
524 | for theory_id, item in theory_list.iteritems(): |
---|
525 | theory_data, theory_state = item |
---|
526 | if theory_data is not None: |
---|
527 | name = theory_data.name |
---|
528 | theory_class = theory_data.__class__.__name__ |
---|
529 | theory_id = theory_data.id |
---|
530 | #if theory_state is not None: |
---|
531 | # name = theory_state.model.name |
---|
532 | temp = (theory_id, theory_class, state_id) |
---|
533 | t_child = tree.AppendItem(root, |
---|
534 | name, ct_type=1, |
---|
535 | data=(theory_data.id, theory_class, state_id)) |
---|
536 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
537 | i_c_c = tree.AppendItem(t_i_c, |
---|
538 | 'Type: %s' % theory_class) |
---|
539 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
540 | |
---|
541 | for process in theory_data.process: |
---|
542 | i_t_c = tree.AppendItem(t_p_c, |
---|
543 | process.__str__()) |
---|
544 | |
---|
545 | theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] |
---|
546 | #self.list_cb_theory[data_id] = theory_list_ctrl |
---|
547 | self.list_cb_theory[state_id] = theory_list_ctrl |
---|
548 | |
---|
549 | |
---|
550 | |
---|
551 | def set_data_helper(self): |
---|
552 | """ |
---|
553 | """ |
---|
554 | data_to_plot = [] |
---|
555 | state_to_plot = [] |
---|
556 | theory_to_plot = [] |
---|
557 | for value in self.list_cb_data.values(): |
---|
558 | item, _, _, _, _, _ = value |
---|
559 | if item.IsChecked(): |
---|
560 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
561 | data_to_plot.append(data_id) |
---|
562 | if state_id not in state_to_plot: |
---|
563 | state_to_plot.append(state_id) |
---|
564 | |
---|
565 | for theory_dict in self.list_cb_theory.values(): |
---|
566 | for key, value in theory_dict.iteritems(): |
---|
567 | item, _, _ = value |
---|
568 | if item.IsChecked(): |
---|
569 | theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
570 | theory_to_plot.append(theory_id) |
---|
571 | if state_id not in state_to_plot: |
---|
572 | state_to_plot.append(state_id) |
---|
573 | return data_to_plot, theory_to_plot, state_to_plot |
---|
574 | |
---|
575 | def remove_by_id(self, id): |
---|
576 | """ |
---|
577 | """ |
---|
578 | for item in self.list_cb_data.values(): |
---|
579 | data_c, _, _, _, _, theory_child = item |
---|
580 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) |
---|
581 | if id == data_id: |
---|
582 | self.tree_ctrl.Delete(data_c) |
---|
583 | del self.list_cb_data[state_id] |
---|
584 | del self.list_cb_theory[data_id] |
---|
585 | |
---|
586 | def load_error(self, error=None): |
---|
587 | """ |
---|
588 | Pop up an error message. |
---|
589 | |
---|
590 | :param error: details error message to be displayed |
---|
591 | """ |
---|
592 | if error is not None or str(error).strip() != "": |
---|
593 | dial = wx.MessageDialog(self.parent, str(error), 'Error Loading File', |
---|
594 | wx.OK | wx.ICON_EXCLAMATION) |
---|
595 | dial.ShowModal() |
---|
596 | |
---|
597 | def _load_data(self, event): |
---|
598 | """ |
---|
599 | send an event to the parent to trigger load from plugin module |
---|
600 | """ |
---|
601 | if self.parent is not None: |
---|
602 | wx.PostEvent(self.parent, NewLoadDataEvent()) |
---|
603 | |
---|
604 | |
---|
605 | def on_remove(self, event): |
---|
606 | """ |
---|
607 | Get a list of item checked and remove them from the treectrl |
---|
608 | Ask the parent to remove reference to this item |
---|
609 | """ |
---|
610 | data_to_remove, theory_to_remove, _ = self.set_data_helper() |
---|
611 | data_key = [] |
---|
612 | theory_key = [] |
---|
613 | #remove data from treectrl |
---|
614 | for d_key, item in self.list_cb_data.iteritems(): |
---|
615 | data_c, d_i_c, i_c_c, p_c_c, d_p_c, t_c = item |
---|
616 | if data_c.IsChecked(): |
---|
617 | self.tree_ctrl.Delete(data_c) |
---|
618 | data_key.append(d_key) |
---|
619 | if d_key in self.list_cb_theory.keys(): |
---|
620 | theory_list_ctrl = self.list_cb_theory[d_key] |
---|
621 | theory_to_remove += theory_list_ctrl.keys() |
---|
622 | # Remove theory from treectrl |
---|
623 | for t_key, theory_dict in self.list_cb_theory.iteritems(): |
---|
624 | for key, value in theory_dict.iteritems(): |
---|
625 | item, _, _ = value |
---|
626 | if item.IsChecked(): |
---|
627 | try: |
---|
628 | self.tree_ctrl.Delete(item) |
---|
629 | except: |
---|
630 | pass |
---|
631 | theory_key.append(key) |
---|
632 | |
---|
633 | #Remove data and related theory references |
---|
634 | for key in data_key: |
---|
635 | del self.list_cb_data[key] |
---|
636 | if key in theory_key: |
---|
637 | del self.list_cb_theory[key] |
---|
638 | #remove theory references independently of data |
---|
639 | for key in theory_key: |
---|
640 | for t_key, theory_dict in self.list_cb_theory.iteritems(): |
---|
641 | if key in theory_dict: |
---|
642 | for key, value in theory_dict.iteritems(): |
---|
643 | item, _, _ = value |
---|
644 | if item.IsChecked(): |
---|
645 | try: |
---|
646 | self.tree_ctrl_theory.Delete(item) |
---|
647 | except: |
---|
648 | pass |
---|
649 | del theory_dict[key] |
---|
650 | |
---|
651 | |
---|
652 | self.parent.remove_data(data_id=data_to_remove, |
---|
653 | theory_id=theory_to_remove) |
---|
654 | self.enable_remove() |
---|
655 | self.enable_freeze() |
---|
656 | self.enable_remove_plot() |
---|
657 | |
---|
658 | def on_import(self, event=None): |
---|
659 | """ |
---|
660 | Get all select data and set them to the current active perspetive |
---|
661 | """ |
---|
662 | data_id, theory_id, state_id = self.set_data_helper() |
---|
663 | temp = data_id + state_id |
---|
664 | self.parent.set_data(data_id=temp, theory_id=theory_id) |
---|
665 | |
---|
666 | def on_append_plot(self, event=None): |
---|
667 | """ |
---|
668 | append plot to plot panel on focus |
---|
669 | """ |
---|
670 | self._on_plot_selection() |
---|
671 | data_id, theory_id, state_id = self.set_data_helper() |
---|
672 | self.parent.plot_data(data_id=data_id, |
---|
673 | state_id=state_id, |
---|
674 | theory_id=theory_id, |
---|
675 | append=True) |
---|
676 | |
---|
677 | def on_plot(self, event=None): |
---|
678 | """ |
---|
679 | Send a list of data names to plot |
---|
680 | """ |
---|
681 | data_id, theory_id, state_id = self.set_data_helper() |
---|
682 | self.parent.plot_data(data_id=data_id, |
---|
683 | state_id=state_id, |
---|
684 | theory_id=theory_id, |
---|
685 | append=False) |
---|
686 | self.enable_remove_plot() |
---|
687 | |
---|
688 | def on_close_page(self, event=None): |
---|
689 | """ |
---|
690 | On close |
---|
691 | """ |
---|
692 | if event != None: |
---|
693 | event.Skip() |
---|
694 | # send parent to update menu with no show nor hide action |
---|
695 | self.parent.show_data_panel(action=False) |
---|
696 | |
---|
697 | def on_freeze(self, event): |
---|
698 | """ |
---|
699 | """ |
---|
700 | _, theory_id, state_id = self.set_data_helper() |
---|
701 | self.parent.freeze(data_id=state_id, theory_id=theory_id) |
---|
702 | |
---|
703 | def set_active_perspective(self, name): |
---|
704 | """ |
---|
705 | set the active perspective |
---|
706 | """ |
---|
707 | self.perspective_cbox.SetStringSelection(name) |
---|
708 | self.enable_import() |
---|
709 | |
---|
710 | def _on_delete_plot_panel(self, event): |
---|
711 | """ |
---|
712 | get an event with attribute name and caption to delete existing name |
---|
713 | from the combobox of the current panel |
---|
714 | """ |
---|
715 | name = event.name |
---|
716 | caption = event.caption |
---|
717 | if self.cb_plotpanel is not None: |
---|
718 | pos = self.cb_plotpanel.FindString(str(caption)) |
---|
719 | if pos != wx.NOT_FOUND: |
---|
720 | self.cb_plotpanel.Delete(pos) |
---|
721 | self.enable_append() |
---|
722 | |
---|
723 | def set_panel_on_focus(self, name=None): |
---|
724 | """ |
---|
725 | set the plot panel on focus |
---|
726 | """ |
---|
727 | for key, value in self.parent.plot_panels.iteritems(): |
---|
728 | name_plot_panel = str(value.window_caption) |
---|
729 | if name_plot_panel not in self.cb_plotpanel.GetItems(): |
---|
730 | self.cb_plotpanel.Append(name_plot_panel, value) |
---|
731 | if name != None and name == name_plot_panel: |
---|
732 | self.cb_plotpanel.SetStringSelection(name_plot_panel) |
---|
733 | break |
---|
734 | self.enable_append() |
---|
735 | self.enable_remove_plot() |
---|
736 | |
---|
737 | def _on_perspective_selection(self, event=None): |
---|
738 | """ |
---|
739 | select the current perspective for guiframe |
---|
740 | """ |
---|
741 | selection = self.perspective_cbox.GetSelection() |
---|
742 | |
---|
743 | if self.perspective_cbox.GetValue() != 'None': |
---|
744 | perspective = self.perspective_cbox.GetClientData(selection) |
---|
745 | perspective.on_perspective(event=None) |
---|
746 | |
---|
747 | def _on_plot_selection(self, event=None): |
---|
748 | """ |
---|
749 | On source combobox selection |
---|
750 | """ |
---|
751 | if event != None: |
---|
752 | combo = event.GetEventObject() |
---|
753 | event.Skip() |
---|
754 | else: |
---|
755 | combo = self.cb_plotpanel |
---|
756 | selection = combo.GetSelection() |
---|
757 | |
---|
758 | if combo.GetValue() != 'None': |
---|
759 | panel = combo.GetClientData(selection) |
---|
760 | self.parent.on_set_plot_focus(panel) |
---|
761 | |
---|
762 | def on_close_plot(self, event): |
---|
763 | """ |
---|
764 | clseo the panel on focus |
---|
765 | """ |
---|
766 | self.enable_append() |
---|
767 | selection = self.cb_plotpanel.GetSelection() |
---|
768 | if self.cb_plotpanel.GetValue() != 'None': |
---|
769 | panel = self.cb_plotpanel.GetClientData(selection) |
---|
770 | if self.parent is not None and panel is not None: |
---|
771 | wx.PostEvent(self.parent, |
---|
772 | NewPlotEvent(group_id=panel.group_id, |
---|
773 | action="delete")) |
---|
774 | self.enable_remove_plot() |
---|
775 | |
---|
776 | def enable_remove_plot(self): |
---|
777 | """ |
---|
778 | enable remove plot button if there is a plot panel on focus |
---|
779 | """ |
---|
780 | if self.cb_plotpanel.GetCount() == 0: |
---|
781 | self.bt_close_plot.Disable() |
---|
782 | else: |
---|
783 | self.bt_close_plot.Enable() |
---|
784 | |
---|
785 | def enable_remove(self): |
---|
786 | """ |
---|
787 | enable or disable remove button |
---|
788 | """ |
---|
789 | n_t = self.tree_ctrl.GetCount() |
---|
790 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
791 | if n_t + n_t_t <= 0: |
---|
792 | self.bt_remove.Disable() |
---|
793 | else: |
---|
794 | self.bt_remove.Enable() |
---|
795 | |
---|
796 | def enable_import(self): |
---|
797 | """ |
---|
798 | enable or disable send button |
---|
799 | """ |
---|
800 | n_t = 0 |
---|
801 | if self.tree_ctrl != None: |
---|
802 | n_t = self.tree_ctrl.GetCount() |
---|
803 | if n_t > 0 and len(self.list_of_perspective) > 0: |
---|
804 | self.bt_import.Enable() |
---|
805 | else: |
---|
806 | self.bt_import.Disable() |
---|
807 | if len(self.list_of_perspective) <= 0 or \ |
---|
808 | self.perspective_cbox.GetValue() in ["None", |
---|
809 | "No Active Application"]: |
---|
810 | self.perspective_cbox.Disable() |
---|
811 | else: |
---|
812 | self.perspective_cbox.Enable() |
---|
813 | |
---|
814 | def enable_plot(self): |
---|
815 | """ |
---|
816 | enable or disable plot button |
---|
817 | """ |
---|
818 | n_t = 0 |
---|
819 | n_t_t = 0 |
---|
820 | if self.tree_ctrl != None: |
---|
821 | n_t = self.tree_ctrl.GetCount() |
---|
822 | if self.tree_ctrl_theory != None: |
---|
823 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
824 | if n_t + n_t_t <= 0: |
---|
825 | self.bt_plot.Disable() |
---|
826 | else: |
---|
827 | self.bt_plot.Enable() |
---|
828 | self.enable_append() |
---|
829 | |
---|
830 | def enable_append(self): |
---|
831 | """ |
---|
832 | enable or disable append button |
---|
833 | """ |
---|
834 | n_t = 0 |
---|
835 | n_t_t = 0 |
---|
836 | if self.tree_ctrl != None: |
---|
837 | n_t = self.tree_ctrl.GetCount() |
---|
838 | if self.tree_ctrl_theory != None: |
---|
839 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
840 | if n_t + n_t_t <= 0: |
---|
841 | self.bt_append_plot.Disable() |
---|
842 | self.cb_plotpanel.Disable() |
---|
843 | elif self.cb_plotpanel.GetCount() <= 0: |
---|
844 | self.cb_plotpanel.Disable() |
---|
845 | self.bt_append_plot.Disable() |
---|
846 | else: |
---|
847 | self.bt_append_plot.Enable() |
---|
848 | self.cb_plotpanel.Enable() |
---|
849 | |
---|
850 | def check_theory_to_freeze(self): |
---|
851 | """ |
---|
852 | """ |
---|
853 | def enable_freeze(self): |
---|
854 | """ |
---|
855 | enable or disable the freeze button |
---|
856 | """ |
---|
857 | n_t_t = 0 |
---|
858 | n_l = 0 |
---|
859 | if self.tree_ctrl_theory != None: |
---|
860 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
861 | n_l = len(self.list_cb_theory) |
---|
862 | if (n_t_t + n_l > 0): |
---|
863 | self.bt_freeze.Enable() |
---|
864 | else: |
---|
865 | self.bt_freeze.Disable() |
---|
866 | |
---|
867 | def enable_selection(self): |
---|
868 | """ |
---|
869 | enable or disable combobo box selection |
---|
870 | """ |
---|
871 | n_t = 0 |
---|
872 | n_t_t = 0 |
---|
873 | if self.tree_ctrl != None: |
---|
874 | n_t = self.tree_ctrl.GetCount() |
---|
875 | if self.tree_ctrl_theory != None: |
---|
876 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
877 | if n_t + n_t_t > 0 and self.selection_cbox != None: |
---|
878 | self.selection_cbox.Enable() |
---|
879 | else: |
---|
880 | self.selection_cbox.Disable() |
---|
881 | |
---|
882 | def show_data_button(self): |
---|
883 | """ |
---|
884 | show load data and remove data button if |
---|
885 | dataloader on else hide them |
---|
886 | """ |
---|
887 | try: |
---|
888 | gui_style = self.parent.get_style() |
---|
889 | style = gui_style & GUIFRAME.DATALOADER_ON |
---|
890 | if style == GUIFRAME.DATALOADER_ON: |
---|
891 | #self.bt_remove.Show(True) |
---|
892 | self.bt_add.Show(True) |
---|
893 | else: |
---|
894 | #self.bt_remove.Hide() |
---|
895 | self.bt_add.Hide() |
---|
896 | except: |
---|
897 | #self.bt_remove.Hide() |
---|
898 | self.bt_add.Hide() |
---|
899 | |
---|
900 | |
---|
901 | |
---|
902 | WIDTH = 400 |
---|
903 | HEIGHT = 300 |
---|
904 | |
---|
905 | |
---|
906 | class DataDialog(wx.Dialog): |
---|
907 | """ |
---|
908 | Allow file selection at loading time |
---|
909 | """ |
---|
910 | def __init__(self, data_list, parent=None, text='', *args, **kwds): |
---|
911 | wx.Dialog.__init__(self, parent, *args, **kwds) |
---|
912 | self.SetTitle("Data Selection") |
---|
913 | self.SetSize((WIDTH, HEIGHT)) |
---|
914 | self.list_of_ctrl = [] |
---|
915 | if not data_list: |
---|
916 | return |
---|
917 | self._sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
918 | self._sizer_txt = wx.BoxSizer(wx.VERTICAL) |
---|
919 | self._sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
920 | self.sizer = wx.GridBagSizer(5, 5) |
---|
921 | self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER, |
---|
922 | size=(WIDTH-20, HEIGHT-50)) |
---|
923 | self._panel.SetupScrolling() |
---|
924 | self.__do_layout(data_list, text=text) |
---|
925 | |
---|
926 | def __do_layout(self, data_list, text=''): |
---|
927 | """ |
---|
928 | layout the dialog |
---|
929 | """ |
---|
930 | if not data_list or len(data_list) <= 1: |
---|
931 | return |
---|
932 | #add text |
---|
933 | |
---|
934 | text = "Deleting these file reset some panels.\n" |
---|
935 | text += "Do you want to proceed?\n" |
---|
936 | text_ctrl = wx.StaticText(self, -1, str(text)) |
---|
937 | self._sizer_txt.Add(text_ctrl) |
---|
938 | iy = 0 |
---|
939 | ix = 0 |
---|
940 | data_count = 0 |
---|
941 | for (data_name, in_use, sub_menu) in range(len(data_list)): |
---|
942 | if in_use == True: |
---|
943 | ctrl_name = wx.StaticBox(self, -1, str(data_name)) |
---|
944 | ctrl_in_use = wx.StaticBox(self, -1, " is used by ") |
---|
945 | plug_name = str(sub_menu) + "\n" |
---|
946 | ctrl_sub_menu = wx.StaticBox(self, -1, plug_name) |
---|
947 | self.sizer.Add(ctrl_name, (iy, ix), |
---|
948 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
949 | ix += 1 |
---|
950 | self._sizer_button.Add(ctrl_in_use, 1, |
---|
951 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
952 | ix += 1 |
---|
953 | self._sizer_button.Add(plug_name, 1, |
---|
954 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
955 | iy += 1 |
---|
956 | self._panel.SetSizer(self.sizer) |
---|
957 | #add sizer |
---|
958 | self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
959 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
960 | self._sizer_button.Add(button_cancel, 0, |
---|
961 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
962 | button_OK = wx.Button(self, wx.ID_OK, "Ok") |
---|
963 | button_OK.SetFocus() |
---|
964 | self._sizer_button.Add(button_OK, 0, |
---|
965 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
966 | static_line = wx.StaticLine(self, -1) |
---|
967 | |
---|
968 | self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) |
---|
969 | self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10) |
---|
970 | self._sizer_main.Add(self._data_text_ctrl, 0, |
---|
971 | wx.EXPAND|wx.LEFT|wx.RIGHT, 10) |
---|
972 | self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) |
---|
973 | self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10) |
---|
974 | self.SetSizer(self._sizer_main) |
---|
975 | self.Layout() |
---|
976 | |
---|
977 | def get_data(self): |
---|
978 | """ |
---|
979 | return the selected data |
---|
980 | """ |
---|
981 | temp = [] |
---|
982 | for item in self.list_of_ctrl: |
---|
983 | cb, data = item |
---|
984 | if cb.GetValue(): |
---|
985 | temp.append(data) |
---|
986 | return temp |
---|
987 | |
---|
988 | def _count_selected_data(self, event): |
---|
989 | """ |
---|
990 | count selected data |
---|
991 | """ |
---|
992 | if event.GetEventObject().GetValue(): |
---|
993 | self._nb_selected_data += 1 |
---|
994 | else: |
---|
995 | self._nb_selected_data -= 1 |
---|
996 | select_data_text = " %s Data selected.\n" % str(self._nb_selected_data) |
---|
997 | self._data_text_ctrl.SetLabel(select_data_text) |
---|
998 | if self._nb_selected_data <= self._max_data: |
---|
999 | self._data_text_ctrl.SetForegroundColour('blue') |
---|
1000 | else: |
---|
1001 | self._data_text_ctrl.SetForegroundColour('red') |
---|
1002 | |
---|
1003 | |
---|
1004 | |
---|
1005 | class DataFrame(wx.Frame): |
---|
1006 | ## Internal name for the AUI manager |
---|
1007 | window_name = "Data Panel" |
---|
1008 | ## Title to appear on top of the window |
---|
1009 | window_caption = "Data Panel" |
---|
1010 | ## Flag to tell the GUI manager that this panel is not |
---|
1011 | # tied to any perspective |
---|
1012 | ALWAYS_ON = True |
---|
1013 | |
---|
1014 | def __init__(self, parent=None, owner=None, manager=None,size=(300, 800), |
---|
1015 | list_of_perspective=[],list=[], *args, **kwds): |
---|
1016 | kwds['size'] = size |
---|
1017 | kwds['id'] = -1 |
---|
1018 | kwds['title']= "Loaded Data" |
---|
1019 | wx.Frame.__init__(self, parent=parent, *args, **kwds) |
---|
1020 | self.parent = parent |
---|
1021 | self.owner = owner |
---|
1022 | self.manager = manager |
---|
1023 | self.panel = DataPanel(parent=self, |
---|
1024 | #size=size, |
---|
1025 | list_of_perspective=list_of_perspective) |
---|
1026 | |
---|
1027 | def load_data_list(self, list=[]): |
---|
1028 | """ |
---|
1029 | Fill the list inside its panel |
---|
1030 | """ |
---|
1031 | self.panel.load_data_list(list=list) |
---|
1032 | |
---|
1033 | |
---|
1034 | |
---|
1035 | from dataFitting import Data1D |
---|
1036 | from dataFitting import Data2D, Theory1D |
---|
1037 | from data_state import DataState |
---|
1038 | import sys |
---|
1039 | class State(): |
---|
1040 | def __init__(self): |
---|
1041 | self.msg = "" |
---|
1042 | def __str__(self): |
---|
1043 | self.msg = "model mane : model1\n" |
---|
1044 | self.msg += "params : \n" |
---|
1045 | self.msg += "name value\n" |
---|
1046 | return msg |
---|
1047 | def set_data_state(data=None, path=None, theory=None, state=None): |
---|
1048 | dstate = DataState(data=data) |
---|
1049 | dstate.set_path(path=path) |
---|
1050 | dstate.set_theory(theory, state) |
---|
1051 | |
---|
1052 | return dstate |
---|
1053 | """' |
---|
1054 | data_list = [1:('Data1', 'Data1D', '07/01/2010', "theory1d", "state1"), |
---|
1055 | ('Data2', 'Data2D', '07/03/2011', "theory2d", "state1"), |
---|
1056 | ('Data3', 'Theory1D', '06/01/2010', "theory1d", "state1"), |
---|
1057 | ('Data4', 'Theory2D', '07/01/2010', "theory2d", "state1"), |
---|
1058 | ('Data5', 'Theory2D', '07/02/2010', "theory2d", "state1")] |
---|
1059 | """ |
---|
1060 | if __name__ == "__main__": |
---|
1061 | |
---|
1062 | app = wx.App() |
---|
1063 | try: |
---|
1064 | list_of_perspective = [('perspective2', False), ('perspective1', True)] |
---|
1065 | data_list = {} |
---|
1066 | # state 1 |
---|
1067 | data = Data2D() |
---|
1068 | data.name = "data2" |
---|
1069 | data.id = 1 |
---|
1070 | data.append_empty_process() |
---|
1071 | process = data.process[len(data.process)-1] |
---|
1072 | process.data = "07/01/2010" |
---|
1073 | theory = Data2D() |
---|
1074 | theory.id = 34 |
---|
1075 | theory.name = "theory1" |
---|
1076 | path = "path1" |
---|
1077 | state = State() |
---|
1078 | data_list['1']=set_data_state(data, path,theory, state) |
---|
1079 | #state 2 |
---|
1080 | data = Data2D() |
---|
1081 | data.name = "data2" |
---|
1082 | data.id = 76 |
---|
1083 | theory = Data2D() |
---|
1084 | theory.id = 78 |
---|
1085 | theory.name = "CoreShell 07/24/25" |
---|
1086 | path = "path2" |
---|
1087 | #state3 |
---|
1088 | state = State() |
---|
1089 | data_list['2']=set_data_state(data, path,theory, state) |
---|
1090 | data = Data1D() |
---|
1091 | data.id = 3 |
---|
1092 | data.name = "data2" |
---|
1093 | theory = Theory1D() |
---|
1094 | theory.name = "CoreShell" |
---|
1095 | theory.id = 4 |
---|
1096 | theory.append_empty_process() |
---|
1097 | process = theory.process[len(theory.process)-1] |
---|
1098 | process.description = "this is my description" |
---|
1099 | path = "path3" |
---|
1100 | data.append_empty_process() |
---|
1101 | process = data.process[len(data.process)-1] |
---|
1102 | process.data = "07/22/2010" |
---|
1103 | data_list['4']=set_data_state(data, path,theory, state) |
---|
1104 | #state 4 |
---|
1105 | temp_data_list = {} |
---|
1106 | data.name = "data5 erasing data2" |
---|
1107 | temp_data_list['4'] = set_data_state(data, path,theory, state) |
---|
1108 | #state 5 |
---|
1109 | data = Data2D() |
---|
1110 | data.name = "data3" |
---|
1111 | data.id = 5 |
---|
1112 | data.append_empty_process() |
---|
1113 | process = data.process[len(data.process)-1] |
---|
1114 | process.data = "07/01/2010" |
---|
1115 | theory = Theory1D() |
---|
1116 | theory.name = "Cylinder" |
---|
1117 | path = "path2" |
---|
1118 | state = State() |
---|
1119 | dstate= set_data_state(data, path,theory, state) |
---|
1120 | theory = Theory1D() |
---|
1121 | theory.id = 6 |
---|
1122 | theory.name = "CoreShell" |
---|
1123 | dstate.set_theory(theory) |
---|
1124 | theory = Theory1D() |
---|
1125 | theory.id = 6 |
---|
1126 | theory.name = "CoreShell replacing coreshell in data3" |
---|
1127 | dstate.set_theory(theory) |
---|
1128 | data_list['3'] = dstate |
---|
1129 | #state 6 |
---|
1130 | data_list['6']=set_data_state(None, path,theory, state) |
---|
1131 | data_list['6']=set_data_state(theory=theory, state=None) |
---|
1132 | theory = Theory1D() |
---|
1133 | theory.id = 7 |
---|
1134 | data_list['6']=set_data_state(theory=theory, state=None) |
---|
1135 | data_list['7']=set_data_state(theory=theory, state=None) |
---|
1136 | window = DataFrame(list=data_list) |
---|
1137 | window.load_data_list(list=data_list) |
---|
1138 | window.Show(True) |
---|
1139 | window.load_data_list(list=temp_data_list) |
---|
1140 | except: |
---|
1141 | #raise |
---|
1142 | print "error",sys.exc_value |
---|
1143 | |
---|
1144 | app.MainLoop() |
---|
1145 | |
---|
1146 | |
---|