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