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