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