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