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