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