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