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.guiframe.dataFitting import Data1D |
---|
28 | from sas.guiframe.dataFitting import Data2D |
---|
29 | from sas.guiframe.panel_base import PanelBase |
---|
30 | from sas.guiframe.events import StatusEvent |
---|
31 | from sas.guiframe.events import EVT_DELETE_PLOTPANEL |
---|
32 | from sas.guiframe.events import NewLoadDataEvent |
---|
33 | from sas.guiframe.events import NewPlotEvent |
---|
34 | from sas.guiframe.gui_style import GUIFRAME |
---|
35 | from sas.guiframe.events import NewBatchEvent |
---|
36 | from sas.dataloader.loader import Loader |
---|
37 | #from sas.guiframe.local_perspectives.plotting.masking \ |
---|
38 | # import FloatPanel as QucikPlotDialog |
---|
39 | from sas.guiframe.local_perspectives.plotting.SimplePlot import PlotFrame \ |
---|
40 | as QucikPlotDialog |
---|
41 | import sas.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.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.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 | _ = self.tree_ctrl.AppendItem(d_p_c, |
---|
689 | process.__str__()) |
---|
690 | wx.CallAfter(self.append_theory, state_id, theory_list) |
---|
691 | # Sort by data name |
---|
692 | if self.tree_ctrl.root: |
---|
693 | self.tree_ctrl.SortChildren(self.tree_ctrl.root) |
---|
694 | self.enable_remove() |
---|
695 | self.enable_import() |
---|
696 | self.enable_plot() |
---|
697 | self.enable_freeze() |
---|
698 | self.enable_selection() |
---|
699 | |
---|
700 | def _uncheck_all(self): |
---|
701 | """ |
---|
702 | Uncheck all check boxes |
---|
703 | """ |
---|
704 | for item in self.list_cb_data.values(): |
---|
705 | data_ctrl, _, _, _, _, _, _, _ = item |
---|
706 | self.tree_ctrl.CheckItem(data_ctrl, False) |
---|
707 | self.enable_append() |
---|
708 | self.enable_freeze() |
---|
709 | self.enable_plot() |
---|
710 | self.enable_import() |
---|
711 | self.enable_remove() |
---|
712 | |
---|
713 | def append_theory(self, state_id, theory_list): |
---|
714 | """ |
---|
715 | append theory object under data from a state of id = state_id |
---|
716 | replace that theory if already displayed |
---|
717 | """ |
---|
718 | if not theory_list: |
---|
719 | return |
---|
720 | if state_id not in self.list_cb_data.keys(): |
---|
721 | root = self.tree_ctrl_theory.root |
---|
722 | tree = self.tree_ctrl_theory |
---|
723 | else: |
---|
724 | item = self.list_cb_data[state_id] |
---|
725 | data_c, _, _, _, _, _, _, _ = item |
---|
726 | root = data_c |
---|
727 | tree = self.tree_ctrl |
---|
728 | if root is not None: |
---|
729 | wx.CallAfter(self.append_theory_helper, tree=tree, root=root, |
---|
730 | state_id=state_id, |
---|
731 | theory_list=theory_list) |
---|
732 | |
---|
733 | |
---|
734 | def append_theory_helper(self, tree, root, state_id, theory_list): |
---|
735 | """ |
---|
736 | Append theory helper |
---|
737 | """ |
---|
738 | if state_id in self.list_cb_theory.keys(): |
---|
739 | #update current list of theory for this data |
---|
740 | theory_list_ctrl = self.list_cb_theory[state_id] |
---|
741 | |
---|
742 | for theory_id, item in theory_list.iteritems(): |
---|
743 | theory_data, _ = item |
---|
744 | if theory_data is None: |
---|
745 | name = "Unknown" |
---|
746 | theory_class = "Unknown" |
---|
747 | theory_id = "Unknown" |
---|
748 | temp = (None, None, None) |
---|
749 | else: |
---|
750 | name = theory_data.name |
---|
751 | theory_class = theory_data.__class__.__name__ |
---|
752 | theory_id = theory_data.id |
---|
753 | #if theory_state is not None: |
---|
754 | # name = theory_state.model.name |
---|
755 | temp = (theory_id, theory_class, state_id) |
---|
756 | if theory_id not in theory_list_ctrl: |
---|
757 | #add new theory |
---|
758 | t_child = tree.AppendItem(root, |
---|
759 | name, ct_type=1, data=temp) |
---|
760 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
761 | i_c_c = tree.AppendItem(t_i_c, |
---|
762 | 'Type: %s' % theory_class) |
---|
763 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
764 | |
---|
765 | for process in theory_data.process: |
---|
766 | tree.AppendItem(t_p_c, process.__str__()) |
---|
767 | theory_list_ctrl[theory_id] = [t_child, |
---|
768 | i_c_c, |
---|
769 | t_p_c] |
---|
770 | else: |
---|
771 | #replace theory |
---|
772 | t_child, i_c_c, t_p_c = theory_list_ctrl[theory_id] |
---|
773 | tree.SetItemText(t_child, name) |
---|
774 | tree.SetItemPyData(t_child, temp) |
---|
775 | tree.SetItemText(i_c_c, 'Type: %s' % theory_class) |
---|
776 | tree.DeleteChildren(t_p_c) |
---|
777 | for process in theory_data.process: |
---|
778 | tree.AppendItem(t_p_c, process.__str__()) |
---|
779 | |
---|
780 | else: |
---|
781 | #data didn't have a theory associated it before |
---|
782 | theory_list_ctrl = {} |
---|
783 | for theory_id, item in theory_list.iteritems(): |
---|
784 | theory_data, _ = item |
---|
785 | if theory_data is not None: |
---|
786 | name = theory_data.name |
---|
787 | theory_class = theory_data.__class__.__name__ |
---|
788 | theory_id = theory_data.id |
---|
789 | #if theory_state is not None: |
---|
790 | # name = theory_state.model.name |
---|
791 | temp = (theory_id, theory_class, state_id) |
---|
792 | t_child = tree.AppendItem(root, |
---|
793 | name, ct_type=1, |
---|
794 | data=(theory_data.id, theory_class, state_id)) |
---|
795 | t_i_c = tree.AppendItem(t_child, 'Info') |
---|
796 | i_c_c = tree.AppendItem(t_i_c, |
---|
797 | 'Type: %s' % theory_class) |
---|
798 | t_p_c = tree.AppendItem(t_i_c, 'Process') |
---|
799 | |
---|
800 | for process in theory_data.process: |
---|
801 | tree.AppendItem(t_p_c, process.__str__()) |
---|
802 | |
---|
803 | theory_list_ctrl[theory_id] = [t_child, i_c_c, t_p_c] |
---|
804 | #self.list_cb_theory[data_id] = theory_list_ctrl |
---|
805 | self.list_cb_theory[state_id] = theory_list_ctrl |
---|
806 | |
---|
807 | |
---|
808 | |
---|
809 | def set_data_helper(self): |
---|
810 | """ |
---|
811 | Set data helper |
---|
812 | """ |
---|
813 | data_to_plot = [] |
---|
814 | state_to_plot = [] |
---|
815 | theory_to_plot = [] |
---|
816 | for value in self.list_cb_data.values(): |
---|
817 | item, _, _, _, _, _, _, _ = value |
---|
818 | if item.IsChecked(): |
---|
819 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
820 | data_to_plot.append(data_id) |
---|
821 | if state_id not in state_to_plot: |
---|
822 | state_to_plot.append(state_id) |
---|
823 | |
---|
824 | for theory_dict in self.list_cb_theory.values(): |
---|
825 | for _, value in theory_dict.iteritems(): |
---|
826 | item, _, _ = value |
---|
827 | if item.IsChecked(): |
---|
828 | theory_id, _, state_id = self.tree_ctrl.GetItemPyData(item) |
---|
829 | theory_to_plot.append(theory_id) |
---|
830 | if state_id not in state_to_plot: |
---|
831 | state_to_plot.append(state_id) |
---|
832 | return data_to_plot, theory_to_plot, state_to_plot |
---|
833 | |
---|
834 | def remove_by_id(self, id): |
---|
835 | """ |
---|
836 | Remove_dat by id |
---|
837 | """ |
---|
838 | for item in self.list_cb_data.values(): |
---|
839 | data_c, _, _, _, _, _, _, _ = item |
---|
840 | data_id, _, state_id = self.tree_ctrl.GetItemPyData(data_c) |
---|
841 | if id == data_id: |
---|
842 | self.tree_ctrl.Delete(data_c) |
---|
843 | del self.list_cb_data[state_id] |
---|
844 | del self.list_cb_theory[data_id] |
---|
845 | |
---|
846 | def load_error(self, error=None): |
---|
847 | """ |
---|
848 | Pop up an error message. |
---|
849 | |
---|
850 | :param error: details error message to be displayed |
---|
851 | """ |
---|
852 | if error is not None or str(error).strip() != "": |
---|
853 | dial = wx.MessageDialog(self.parent, str(error), |
---|
854 | 'Error Loading File', |
---|
855 | wx.OK | wx.ICON_EXCLAMATION) |
---|
856 | dial.ShowModal() |
---|
857 | |
---|
858 | def _load_data(self, event): |
---|
859 | """ |
---|
860 | send an event to the parent to trigger load from plugin module |
---|
861 | """ |
---|
862 | if self.parent is not None: |
---|
863 | wx.PostEvent(self.parent, NewLoadDataEvent()) |
---|
864 | |
---|
865 | |
---|
866 | def on_remove(self, event): |
---|
867 | """ |
---|
868 | Get a list of item checked and remove them from the treectrl |
---|
869 | Ask the parent to remove reference to this item |
---|
870 | """ |
---|
871 | msg = "This operation will delete the data sets checked " |
---|
872 | msg += "and all the dependents." |
---|
873 | msg_box = wx.MessageDialog(None, msg, 'Warning', wx.OK|wx.CANCEL) |
---|
874 | if msg_box.ShowModal() != wx.ID_OK: |
---|
875 | return |
---|
876 | |
---|
877 | data_to_remove, theory_to_remove, _ = self.set_data_helper() |
---|
878 | data_key = [] |
---|
879 | theory_key = [] |
---|
880 | #remove data from treectrl |
---|
881 | for d_key, item in self.list_cb_data.iteritems(): |
---|
882 | data_c, _, _, _, _, _, _, _ = item |
---|
883 | if data_c.IsChecked(): |
---|
884 | self.tree_ctrl.Delete(data_c) |
---|
885 | data_key.append(d_key) |
---|
886 | if d_key in self.list_cb_theory.keys(): |
---|
887 | theory_list_ctrl = self.list_cb_theory[d_key] |
---|
888 | theory_to_remove += theory_list_ctrl.keys() |
---|
889 | # Remove theory from treectrl |
---|
890 | for _, theory_dict in self.list_cb_theory.iteritems(): |
---|
891 | for key, value in theory_dict.iteritems(): |
---|
892 | item, _, _ = value |
---|
893 | if item.IsChecked(): |
---|
894 | try: |
---|
895 | self.tree_ctrl.Delete(item) |
---|
896 | except: |
---|
897 | pass |
---|
898 | theory_key.append(key) |
---|
899 | |
---|
900 | #Remove data and related theory references |
---|
901 | for key in data_key: |
---|
902 | del self.list_cb_data[key] |
---|
903 | if key in theory_key: |
---|
904 | del self.list_cb_theory[key] |
---|
905 | #remove theory references independently of data |
---|
906 | for key in theory_key: |
---|
907 | for _, theory_dict in self.list_cb_theory.iteritems(): |
---|
908 | if key in theory_dict: |
---|
909 | for key, value in theory_dict.iteritems(): |
---|
910 | item, _, _ = value |
---|
911 | if item.IsChecked(): |
---|
912 | try: |
---|
913 | self.tree_ctrl_theory.Delete(item) |
---|
914 | except: |
---|
915 | pass |
---|
916 | del theory_dict[key] |
---|
917 | |
---|
918 | |
---|
919 | self.parent.remove_data(data_id=data_to_remove, |
---|
920 | theory_id=theory_to_remove) |
---|
921 | self.enable_remove() |
---|
922 | self.enable_freeze() |
---|
923 | self.enable_remove_plot() |
---|
924 | |
---|
925 | def on_import(self, event=None): |
---|
926 | """ |
---|
927 | Get all select data and set them to the current active perspetive |
---|
928 | """ |
---|
929 | if event != None: |
---|
930 | event.Skip() |
---|
931 | data_id, theory_id, state_id = self.set_data_helper() |
---|
932 | temp = data_id + state_id |
---|
933 | self.parent.set_data(data_id=temp, theory_id=theory_id) |
---|
934 | |
---|
935 | def on_append_plot(self, event=None): |
---|
936 | """ |
---|
937 | append plot to plot panel on focus |
---|
938 | """ |
---|
939 | self._on_plot_selection() |
---|
940 | data_id, theory_id, state_id = self.set_data_helper() |
---|
941 | self.parent.plot_data(data_id=data_id, |
---|
942 | state_id=state_id, |
---|
943 | theory_id=theory_id, |
---|
944 | append=True) |
---|
945 | |
---|
946 | def on_plot(self, event=None): |
---|
947 | """ |
---|
948 | Send a list of data names to plot |
---|
949 | """ |
---|
950 | data_id, theory_id, state_id = self.set_data_helper() |
---|
951 | self.parent.plot_data(data_id=data_id, |
---|
952 | state_id=state_id, |
---|
953 | theory_id=theory_id, |
---|
954 | append=False) |
---|
955 | self.enable_remove_plot() |
---|
956 | |
---|
957 | def on_close_page(self, event=None): |
---|
958 | """ |
---|
959 | On close |
---|
960 | """ |
---|
961 | if event != None: |
---|
962 | event.Skip() |
---|
963 | # send parent to update menu with no show nor hide action |
---|
964 | self.parent.show_data_panel(action=False) |
---|
965 | |
---|
966 | def on_freeze(self, event): |
---|
967 | """ |
---|
968 | On freeze to make a theory to a data set |
---|
969 | """ |
---|
970 | _, theory_id, state_id = self.set_data_helper() |
---|
971 | if len(theory_id) > 0: |
---|
972 | self.parent.freeze(data_id=state_id, theory_id=theory_id) |
---|
973 | msg = "Freeze Theory:" |
---|
974 | msg += " The theory(s) copied to the Data box as a data set." |
---|
975 | else: |
---|
976 | msg = "Freeze Theory: Requires at least one theory checked." |
---|
977 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
978 | |
---|
979 | def set_active_perspective(self, name): |
---|
980 | """ |
---|
981 | set the active perspective |
---|
982 | """ |
---|
983 | self.perspective_cbox.SetStringSelection(name) |
---|
984 | self.enable_import() |
---|
985 | |
---|
986 | def _on_delete_plot_panel(self, event): |
---|
987 | """ |
---|
988 | get an event with attribute name and caption to delete existing name |
---|
989 | from the combobox of the current panel |
---|
990 | """ |
---|
991 | #name = event.name |
---|
992 | caption = event.caption |
---|
993 | if self.cb_plotpanel is not None: |
---|
994 | pos = self.cb_plotpanel.FindString(str(caption)) |
---|
995 | if pos != wx.NOT_FOUND: |
---|
996 | self.cb_plotpanel.Delete(pos) |
---|
997 | self.enable_append() |
---|
998 | |
---|
999 | def set_panel_on_focus(self, name=None): |
---|
1000 | """ |
---|
1001 | set the plot panel on focus |
---|
1002 | """ |
---|
1003 | for _, value in self.parent.plot_panels.iteritems(): |
---|
1004 | name_plot_panel = str(value.window_caption) |
---|
1005 | if name_plot_panel not in self.cb_plotpanel.GetItems(): |
---|
1006 | self.cb_plotpanel.Append(name_plot_panel, value) |
---|
1007 | if name != None and name == name_plot_panel: |
---|
1008 | self.cb_plotpanel.SetStringSelection(name_plot_panel) |
---|
1009 | break |
---|
1010 | self.enable_append() |
---|
1011 | self.enable_remove_plot() |
---|
1012 | |
---|
1013 | def set_plot_unfocus(self): |
---|
1014 | """ |
---|
1015 | Unfocus plot |
---|
1016 | """ |
---|
1017 | return |
---|
1018 | |
---|
1019 | def _on_perspective_selection(self, event=None): |
---|
1020 | """ |
---|
1021 | select the current perspective for guiframe |
---|
1022 | """ |
---|
1023 | selection = self.perspective_cbox.GetSelection() |
---|
1024 | if self.perspective_cbox.GetValue() != 'None': |
---|
1025 | perspective = self.perspective_cbox.GetClientData(selection) |
---|
1026 | perspective.on_perspective(event=None) |
---|
1027 | self.parent.check_multimode(perspective=perspective) |
---|
1028 | |
---|
1029 | def _on_plot_selection(self, event=None): |
---|
1030 | """ |
---|
1031 | On source combobox selection |
---|
1032 | """ |
---|
1033 | if event != None: |
---|
1034 | combo = event.GetEventObject() |
---|
1035 | event.Skip() |
---|
1036 | else: |
---|
1037 | combo = self.cb_plotpanel |
---|
1038 | selection = combo.GetSelection() |
---|
1039 | |
---|
1040 | if combo.GetValue() != 'None': |
---|
1041 | panel = combo.GetClientData(selection) |
---|
1042 | self.parent.on_set_plot_focus(panel) |
---|
1043 | |
---|
1044 | def on_close_plot(self, event): |
---|
1045 | """ |
---|
1046 | clseo the panel on focus |
---|
1047 | """ |
---|
1048 | self.enable_append() |
---|
1049 | selection = self.cb_plotpanel.GetSelection() |
---|
1050 | if self.cb_plotpanel.GetValue() != 'None': |
---|
1051 | panel = self.cb_plotpanel.GetClientData(selection) |
---|
1052 | if self.parent is not None and panel is not None: |
---|
1053 | wx.PostEvent(self.parent, |
---|
1054 | NewPlotEvent(group_id=panel.group_id, |
---|
1055 | action="delete")) |
---|
1056 | self.enable_remove_plot() |
---|
1057 | |
---|
1058 | def set_frame(self, frame): |
---|
1059 | """ |
---|
1060 | """ |
---|
1061 | self.frame = frame |
---|
1062 | |
---|
1063 | def get_frame(self): |
---|
1064 | """ |
---|
1065 | """ |
---|
1066 | return self.frame |
---|
1067 | |
---|
1068 | def on_close(self, event): |
---|
1069 | """ |
---|
1070 | On close event |
---|
1071 | """ |
---|
1072 | self.parent.show_data_panel(event) |
---|
1073 | |
---|
1074 | def set_schedule_full_draw(self, panel=None, func='del'): |
---|
1075 | """ |
---|
1076 | Send full draw to guimanager |
---|
1077 | """ |
---|
1078 | self.parent.set_schedule_full_draw(panel, func) |
---|
1079 | |
---|
1080 | def enable_remove_plot(self): |
---|
1081 | """ |
---|
1082 | enable remove plot button if there is a plot panel on focus |
---|
1083 | """ |
---|
1084 | pass |
---|
1085 | #if self.cb_plotpanel.GetCount() == 0: |
---|
1086 | # self.bt_close_plot.Disable() |
---|
1087 | #else: |
---|
1088 | # self.bt_close_plot.Enable() |
---|
1089 | |
---|
1090 | def enable_remove(self): |
---|
1091 | """ |
---|
1092 | enable or disable remove button |
---|
1093 | """ |
---|
1094 | n_t = self.tree_ctrl.GetCount() |
---|
1095 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
1096 | if n_t + n_t_t <= 0: |
---|
1097 | self.bt_remove.Disable() |
---|
1098 | else: |
---|
1099 | self.bt_remove.Enable() |
---|
1100 | |
---|
1101 | def enable_import(self): |
---|
1102 | """ |
---|
1103 | enable or disable send button |
---|
1104 | """ |
---|
1105 | n_t = 0 |
---|
1106 | if self.tree_ctrl != None: |
---|
1107 | n_t = self.tree_ctrl.GetCount() |
---|
1108 | if n_t > 0 and len(self.list_of_perspective) > 0: |
---|
1109 | self.bt_import.Enable() |
---|
1110 | else: |
---|
1111 | self.bt_import.Disable() |
---|
1112 | if len(self.list_of_perspective) <= 0 or \ |
---|
1113 | self.perspective_cbox.GetValue() in ["None", |
---|
1114 | "No Active Application"]: |
---|
1115 | self.perspective_cbox.Disable() |
---|
1116 | else: |
---|
1117 | self.perspective_cbox.Enable() |
---|
1118 | |
---|
1119 | def enable_plot(self): |
---|
1120 | """ |
---|
1121 | enable or disable plot button |
---|
1122 | """ |
---|
1123 | n_t = 0 |
---|
1124 | n_t_t = 0 |
---|
1125 | if self.tree_ctrl != None: |
---|
1126 | n_t = self.tree_ctrl.GetCount() |
---|
1127 | if self.tree_ctrl_theory != None: |
---|
1128 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
1129 | if n_t + n_t_t <= 0: |
---|
1130 | self.bt_plot.Disable() |
---|
1131 | else: |
---|
1132 | self.bt_plot.Enable() |
---|
1133 | self.enable_append() |
---|
1134 | |
---|
1135 | def enable_append(self): |
---|
1136 | """ |
---|
1137 | enable or disable append button |
---|
1138 | """ |
---|
1139 | n_t = 0 |
---|
1140 | n_t_t = 0 |
---|
1141 | if self.tree_ctrl != None: |
---|
1142 | n_t = self.tree_ctrl.GetCount() |
---|
1143 | if self.tree_ctrl_theory != None: |
---|
1144 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
1145 | if n_t + n_t_t <= 0: |
---|
1146 | self.bt_append_plot.Disable() |
---|
1147 | self.cb_plotpanel.Disable() |
---|
1148 | elif self.cb_plotpanel.GetCount() <= 0: |
---|
1149 | self.cb_plotpanel.Disable() |
---|
1150 | self.bt_append_plot.Disable() |
---|
1151 | else: |
---|
1152 | self.bt_append_plot.Enable() |
---|
1153 | self.cb_plotpanel.Enable() |
---|
1154 | |
---|
1155 | def check_theory_to_freeze(self): |
---|
1156 | """ |
---|
1157 | Check_theory_to_freeze |
---|
1158 | """ |
---|
1159 | def enable_freeze(self): |
---|
1160 | """ |
---|
1161 | enable or disable the freeze button |
---|
1162 | """ |
---|
1163 | n_t_t = 0 |
---|
1164 | n_l = 0 |
---|
1165 | if self.tree_ctrl_theory != None: |
---|
1166 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
1167 | n_l = len(self.list_cb_theory) |
---|
1168 | if (n_t_t + n_l > 0): |
---|
1169 | self.bt_freeze.Enable() |
---|
1170 | else: |
---|
1171 | self.bt_freeze.Disable() |
---|
1172 | |
---|
1173 | def enable_selection(self): |
---|
1174 | """ |
---|
1175 | enable or disable combobo box selection |
---|
1176 | """ |
---|
1177 | n_t = 0 |
---|
1178 | n_t_t = 0 |
---|
1179 | if self.tree_ctrl != None: |
---|
1180 | n_t = self.tree_ctrl.GetCount() |
---|
1181 | if self.tree_ctrl_theory != None: |
---|
1182 | n_t_t = self.tree_ctrl_theory.GetCount() |
---|
1183 | if n_t + n_t_t > 0 and self.selection_cbox != None: |
---|
1184 | self.selection_cbox.Enable() |
---|
1185 | else: |
---|
1186 | self.selection_cbox.Disable() |
---|
1187 | |
---|
1188 | def show_data_button(self): |
---|
1189 | """ |
---|
1190 | show load data and remove data button if |
---|
1191 | dataloader on else hide them |
---|
1192 | """ |
---|
1193 | try: |
---|
1194 | gui_style = self.parent.get_style() |
---|
1195 | style = gui_style & GUIFRAME.DATALOADER_ON |
---|
1196 | if style == GUIFRAME.DATALOADER_ON: |
---|
1197 | #self.bt_remove.Show(True) |
---|
1198 | self.bt_add.Show(True) |
---|
1199 | else: |
---|
1200 | #self.bt_remove.Hide() |
---|
1201 | self.bt_add.Hide() |
---|
1202 | except: |
---|
1203 | #self.bt_remove.Hide() |
---|
1204 | self.bt_add.Hide() |
---|
1205 | |
---|
1206 | |
---|
1207 | |
---|
1208 | WIDTH = 400 |
---|
1209 | HEIGHT = 300 |
---|
1210 | |
---|
1211 | |
---|
1212 | class DataDialog(wx.Dialog): |
---|
1213 | """ |
---|
1214 | Allow file selection at loading time |
---|
1215 | """ |
---|
1216 | def __init__(self, data_list, parent=None, text='', *args, **kwds): |
---|
1217 | wx.Dialog.__init__(self, parent, *args, **kwds) |
---|
1218 | self.SetTitle("Data Selection") |
---|
1219 | self.SetSize((WIDTH, HEIGHT)) |
---|
1220 | self.list_of_ctrl = [] |
---|
1221 | if not data_list: |
---|
1222 | return |
---|
1223 | self._sizer_main = wx.BoxSizer(wx.VERTICAL) |
---|
1224 | self._sizer_txt = wx.BoxSizer(wx.VERTICAL) |
---|
1225 | self._sizer_button = wx.BoxSizer(wx.HORIZONTAL) |
---|
1226 | self.sizer = wx.GridBagSizer(5, 5) |
---|
1227 | self._panel = ScrolledPanel(self, style=wx.RAISED_BORDER, |
---|
1228 | size=(WIDTH-20, HEIGHT-50)) |
---|
1229 | self._panel.SetupScrolling() |
---|
1230 | self.__do_layout(data_list, text=text) |
---|
1231 | |
---|
1232 | def __do_layout(self, data_list, text=''): |
---|
1233 | """ |
---|
1234 | layout the dialog |
---|
1235 | """ |
---|
1236 | if not data_list or len(data_list) <= 1: |
---|
1237 | return |
---|
1238 | #add text |
---|
1239 | |
---|
1240 | text = "Deleting these file reset some panels.\n" |
---|
1241 | text += "Do you want to proceed?\n" |
---|
1242 | text_ctrl = wx.StaticText(self, -1, str(text)) |
---|
1243 | self._sizer_txt.Add(text_ctrl) |
---|
1244 | iy = 0 |
---|
1245 | ix = 0 |
---|
1246 | #data_count = 0 |
---|
1247 | for (data_name, in_use, sub_menu) in range(len(data_list)): |
---|
1248 | if in_use == True: |
---|
1249 | ctrl_name = wx.StaticBox(self, -1, str(data_name)) |
---|
1250 | ctrl_in_use = wx.StaticBox(self, -1, " is used by ") |
---|
1251 | plug_name = str(sub_menu) + "\n" |
---|
1252 | #ctrl_sub_menu = wx.StaticBox(self, -1, plug_name) |
---|
1253 | self.sizer.Add(ctrl_name, (iy, ix), |
---|
1254 | (1, 1), wx.LEFT|wx.EXPAND|wx.ADJUST_MINSIZE, 15) |
---|
1255 | ix += 1 |
---|
1256 | self._sizer_button.Add(ctrl_in_use, 1, |
---|
1257 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1258 | ix += 1 |
---|
1259 | self._sizer_button.Add(plug_name, 1, |
---|
1260 | wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1261 | iy += 1 |
---|
1262 | self._panel.SetSizer(self.sizer) |
---|
1263 | #add sizer |
---|
1264 | self._sizer_button.Add((20, 20), 1, wx.EXPAND|wx.ADJUST_MINSIZE, 0) |
---|
1265 | button_cancel = wx.Button(self, wx.ID_CANCEL, "Cancel") |
---|
1266 | self._sizer_button.Add(button_cancel, 0, |
---|
1267 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
1268 | button_OK = wx.Button(self, wx.ID_OK, "Ok") |
---|
1269 | button_OK.SetFocus() |
---|
1270 | self._sizer_button.Add(button_OK, 0, |
---|
1271 | wx.LEFT|wx.RIGHT|wx.ADJUST_MINSIZE, 10) |
---|
1272 | static_line = wx.StaticLine(self, -1) |
---|
1273 | |
---|
1274 | self._sizer_txt.Add(self._panel, 1, wx.EXPAND|wx.LEFT|wx.RIGHT, 5) |
---|
1275 | self._sizer_main.Add(self._sizer_txt, 1, wx.EXPAND|wx.ALL, 10) |
---|
1276 | #self._sizer_main.Add(self._data_text_ctrl, 0, |
---|
1277 | # wx.EXPAND|wx.LEFT|wx.RIGHT, 10) |
---|
1278 | self._sizer_main.Add(static_line, 0, wx.EXPAND, 0) |
---|
1279 | self._sizer_main.Add(self._sizer_button, 0, wx.EXPAND|wx.ALL, 10) |
---|
1280 | self.SetSizer(self._sizer_main) |
---|
1281 | self.Layout() |
---|
1282 | |
---|
1283 | def get_data(self): |
---|
1284 | """ |
---|
1285 | return the selected data |
---|
1286 | """ |
---|
1287 | temp = [] |
---|
1288 | for item in self.list_of_ctrl: |
---|
1289 | cb, data = item |
---|
1290 | if cb.GetValue(): |
---|
1291 | temp.append(data) |
---|
1292 | return temp |
---|
1293 | |
---|
1294 | class DataFrame(wx.Frame): |
---|
1295 | """ |
---|
1296 | Data Frame |
---|
1297 | """ |
---|
1298 | ## Internal name for the AUI manager |
---|
1299 | window_name = "Data Panel" |
---|
1300 | ## Title to appear on top of the window |
---|
1301 | window_caption = "Data Panel" |
---|
1302 | ## Flag to tell the GUI manager that this panel is not |
---|
1303 | # tied to any perspective |
---|
1304 | ALWAYS_ON = True |
---|
1305 | |
---|
1306 | def __init__(self, parent=None, owner=None, manager=None, size=(300, 800), |
---|
1307 | list_of_perspective=[], list=[], *args, **kwds): |
---|
1308 | kwds['size'] = size |
---|
1309 | kwds['id'] = -1 |
---|
1310 | kwds['title'] = "Loaded Data" |
---|
1311 | wx.Frame.__init__(self, parent=parent, *args, **kwds) |
---|
1312 | self.parent = parent |
---|
1313 | self.owner = owner |
---|
1314 | self._manager = manager |
---|
1315 | self.panel = DataPanel(parent=self, |
---|
1316 | manager=manager, |
---|
1317 | list_of_perspective=list_of_perspective) |
---|
1318 | |
---|
1319 | def load_data_list(self, list=[]): |
---|
1320 | """ |
---|
1321 | Fill the list inside its panel |
---|
1322 | """ |
---|
1323 | self.panel.load_data_list(list=list) |
---|
1324 | |
---|
1325 | |
---|
1326 | |
---|
1327 | from sas.guiframe.dataFitting import Theory1D |
---|
1328 | from sas.guiframe.data_state import DataState |
---|
1329 | |
---|
1330 | class State(): |
---|
1331 | """ |
---|
1332 | DataPanel State |
---|
1333 | """ |
---|
1334 | def __init__(self): |
---|
1335 | self.msg = "" |
---|
1336 | def __str__(self): |
---|
1337 | self.msg = "model mane : model1\n" |
---|
1338 | self.msg += "params : \n" |
---|
1339 | self.msg += "name value\n" |
---|
1340 | return self.msg |
---|
1341 | |
---|
1342 | def set_data_state(data=None, path=None, theory=None, state=None): |
---|
1343 | """ |
---|
1344 | Set data state |
---|
1345 | """ |
---|
1346 | dstate = DataState(data=data) |
---|
1347 | dstate.set_path(path=path) |
---|
1348 | dstate.set_theory(theory, state) |
---|
1349 | |
---|
1350 | return dstate |
---|
1351 | |
---|
1352 | if __name__ == "__main__": |
---|
1353 | |
---|
1354 | app = wx.App() |
---|
1355 | try: |
---|
1356 | #list_of_perspective = [('perspective2', False), ('perspective1', True)] |
---|
1357 | data_list1 = {} |
---|
1358 | # state 1 |
---|
1359 | data1 = Data2D() |
---|
1360 | data1.name = "data2" |
---|
1361 | data1.id = 1 |
---|
1362 | data1.append_empty_process() |
---|
1363 | process1 = data1.process[len(data1.process)-1] |
---|
1364 | process1.data = "07/01/2010" |
---|
1365 | theory1 = Data2D() |
---|
1366 | theory1.id = 34 |
---|
1367 | theory1.name = "theory1" |
---|
1368 | path1 = "path1" |
---|
1369 | state1 = State() |
---|
1370 | data_list1['1'] = set_data_state(data1, path1, theory1, state1) |
---|
1371 | #state 2 |
---|
1372 | data1 = Data2D() |
---|
1373 | data1.name = "data2" |
---|
1374 | data1.id = 76 |
---|
1375 | theory1 = Data2D() |
---|
1376 | theory1.id = 78 |
---|
1377 | theory1.name = "CoreShell 07/24/25" |
---|
1378 | path1 = "path2" |
---|
1379 | #state3 |
---|
1380 | state1 = State() |
---|
1381 | data_list1['2'] = set_data_state(data1, path1, theory1, state1) |
---|
1382 | data1 = Data1D() |
---|
1383 | data1.id = 3 |
---|
1384 | data1.name = "data2" |
---|
1385 | theory1 = Theory1D() |
---|
1386 | theory1.name = "CoreShell" |
---|
1387 | theory1.id = 4 |
---|
1388 | theory1.append_empty_process() |
---|
1389 | process1 = theory1.process[len(theory1.process)-1] |
---|
1390 | process1.description = "this is my description" |
---|
1391 | path1 = "path3" |
---|
1392 | data1.append_empty_process() |
---|
1393 | process1 = data1.process[len(data1.process)-1] |
---|
1394 | process1.data = "07/22/2010" |
---|
1395 | data_list1['4'] = set_data_state(data1, path1, theory1, state1) |
---|
1396 | #state 4 |
---|
1397 | temp_data_list = {} |
---|
1398 | data1.name = "data5 erasing data2" |
---|
1399 | temp_data_list['4'] = set_data_state(data1, path1, theory1, state1) |
---|
1400 | #state 5 |
---|
1401 | data1 = Data2D() |
---|
1402 | data1.name = "data3" |
---|
1403 | data1.id = 5 |
---|
1404 | data1.append_empty_process() |
---|
1405 | process1 = data1.process[len(data1.process)-1] |
---|
1406 | process1.data = "07/01/2010" |
---|
1407 | theory1 = Theory1D() |
---|
1408 | theory1.name = "Cylinder" |
---|
1409 | path1 = "path2" |
---|
1410 | state1 = State() |
---|
1411 | dstate1 = set_data_state(data1, path1, theory1, state1) |
---|
1412 | theory1 = Theory1D() |
---|
1413 | theory1.id = 6 |
---|
1414 | theory1.name = "CoreShell" |
---|
1415 | dstate1.set_theory(theory1) |
---|
1416 | theory1 = Theory1D() |
---|
1417 | theory1.id = 6 |
---|
1418 | theory1.name = "CoreShell replacing coreshell in data3" |
---|
1419 | dstate1.set_theory(theory1) |
---|
1420 | data_list1['3'] = dstate1 |
---|
1421 | #state 6 |
---|
1422 | data_list1['6'] = set_data_state(None, path1, theory1, state1) |
---|
1423 | data_list1['6'] = set_data_state(theory=theory1, state=None) |
---|
1424 | theory1 = Theory1D() |
---|
1425 | theory1.id = 7 |
---|
1426 | data_list1['6'] = set_data_state(theory=theory1, state=None) |
---|
1427 | data_list1['7'] = set_data_state(theory=theory1, state=None) |
---|
1428 | window = DataFrame(list=data_list1) |
---|
1429 | window.load_data_list(list=data_list1) |
---|
1430 | window.Show(True) |
---|
1431 | window.load_data_list(list=temp_data_list) |
---|
1432 | except: |
---|
1433 | #raise |
---|
1434 | print "error", sys.exc_value |
---|
1435 | |
---|
1436 | app.MainLoop() |
---|
1437 | |
---|
1438 | |
---|