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