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