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