1 | |
---|
2 | ################################################################################ |
---|
3 | #This software was developed by the University of Tennessee as part of the |
---|
4 | #Distributed Data Analysis of Neutron Scattering Experiments (DANSE) |
---|
5 | #project funded by the US National Science Foundation. |
---|
6 | # |
---|
7 | #See the license text in license.txt |
---|
8 | # |
---|
9 | #copyright 2008, University of Tennessee |
---|
10 | ################################################################################ |
---|
11 | |
---|
12 | |
---|
13 | import wx |
---|
14 | import sys |
---|
15 | import os |
---|
16 | import pylab |
---|
17 | import math |
---|
18 | import numpy |
---|
19 | import time |
---|
20 | |
---|
21 | from danse.common.plottools.PlotPanel import PlotPanel |
---|
22 | from danse.common.plottools.SizeDialog import SizeDialog |
---|
23 | from danse.common.plottools.LabelDialog import LabelDialog |
---|
24 | #from danse.common.plottools.plottables import Graph |
---|
25 | from sans.guiframe import dataFitting |
---|
26 | from sans.guiframe.events import EVT_NEW_PLOT |
---|
27 | from sans.guiframe.events import StatusEvent |
---|
28 | from sans.guiframe.events import NewPlotEvent |
---|
29 | from sans.guiframe.events import NewColorEvent |
---|
30 | from sans.guiframe.events import SlicerEvent |
---|
31 | from sans.guiframe.events import PanelOnFocusEvent |
---|
32 | from sans.guiframe.events import EVT_NEW_LOADED_DATA |
---|
33 | from sans.guiframe.utils import PanelMenu |
---|
34 | from sans.guiframe.dataFitting import Data1D |
---|
35 | from sans.guiframe.panel_base import PanelBase |
---|
36 | from sans.guiframe.gui_style import GUIFRAME_ICON |
---|
37 | from danse.common.plottools.binder import BindArtist |
---|
38 | from appearanceDialog import appearanceDialog |
---|
39 | from graphAppearance import graphAppearance |
---|
40 | |
---|
41 | DEFAULT_QMAX = 0.05 |
---|
42 | DEFAULT_QSTEP = 0.001 |
---|
43 | DEFAULT_BEAM = 0.005 |
---|
44 | BIN_WIDTH = 1 |
---|
45 | IS_MAC = (sys.platform == 'darwin') |
---|
46 | |
---|
47 | |
---|
48 | def find_key(dic, val): |
---|
49 | """return the key of dictionary dic given the value""" |
---|
50 | return [k for k, v in dic.iteritems() if v == val][0] |
---|
51 | |
---|
52 | |
---|
53 | |
---|
54 | class ModelPanel1D(PlotPanel, PanelBase): |
---|
55 | """ |
---|
56 | Plot panel for use with the GUI manager |
---|
57 | """ |
---|
58 | |
---|
59 | ## Internal name for the AUI manager |
---|
60 | window_name = "plotpanel" |
---|
61 | ## Title to appear on top of the window |
---|
62 | window_caption = "Graph" |
---|
63 | ## Flag to tell the GUI manager that this panel is not |
---|
64 | # tied to any perspective |
---|
65 | ALWAYS_ON = True |
---|
66 | ## Group ID |
---|
67 | group_id = None |
---|
68 | |
---|
69 | def __init__(self, parent, id=-1, color = None, |
---|
70 | dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): |
---|
71 | PlotPanel.__init__(self, parent, id=id, style=style, **kwargs) |
---|
72 | PanelBase.__init__(self, parent) |
---|
73 | ## Reference to the parent window |
---|
74 | self.parent = parent |
---|
75 | ## Plottables |
---|
76 | self.plots = {} |
---|
77 | #context menu |
---|
78 | self._slicerpop = None |
---|
79 | |
---|
80 | self._available_data = [] |
---|
81 | self._menu_add_ids = [] |
---|
82 | self._symbol_labels = self.get_symbol_label() |
---|
83 | self._color_labels = self.get_color_label() |
---|
84 | self.currColorIndex = "" |
---|
85 | self._is_changed_legend_label = False |
---|
86 | |
---|
87 | self.hide_menu = None |
---|
88 | ## Unique ID (from gui_manager) |
---|
89 | self.uid = None |
---|
90 | self.x_size = None |
---|
91 | ## Default locations |
---|
92 | #self._default_save_location = os.getcwd() |
---|
93 | self.size = None |
---|
94 | ## Graph |
---|
95 | #self.graph = Graph() |
---|
96 | self.graph.xaxis("\\rm{Q}", 'A^{-1}') |
---|
97 | self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") |
---|
98 | self.graph.render(self) |
---|
99 | |
---|
100 | # In resizing event |
---|
101 | self.resizing = False |
---|
102 | self.canvas.set_resizing(self.resizing) |
---|
103 | self.Bind(wx.EVT_SIZE, self._OnReSize) |
---|
104 | self._add_more_tool() |
---|
105 | self.parent.SetFocus() |
---|
106 | |
---|
107 | |
---|
108 | def get_symbol_label(self): |
---|
109 | """ |
---|
110 | Associates label to symbol |
---|
111 | """ |
---|
112 | _labels = {} |
---|
113 | i = 0 |
---|
114 | _labels['Circle'] = i |
---|
115 | i += 1 |
---|
116 | _labels['Cross X '] = i |
---|
117 | i += 1 |
---|
118 | _labels['Triangle Down'] = i |
---|
119 | i += 1 |
---|
120 | _labels['Triangle Up'] = i |
---|
121 | i += 1 |
---|
122 | _labels['Triangle Left'] = i |
---|
123 | i += 1 |
---|
124 | _labels['Triangle Right'] = i |
---|
125 | i += 1 |
---|
126 | _labels['Cross +'] = i |
---|
127 | i += 1 |
---|
128 | _labels['Square'] = i |
---|
129 | i += 1 |
---|
130 | _labels['Diamond'] = i |
---|
131 | i += 1 |
---|
132 | _labels['Diamond'] = i |
---|
133 | i += 1 |
---|
134 | _labels['Hexagon1'] = i |
---|
135 | i += 1 |
---|
136 | _labels['Hexagon2'] = i |
---|
137 | i += 1 |
---|
138 | _labels['Pentagon'] = i |
---|
139 | i += 1 |
---|
140 | _labels['Line'] = i |
---|
141 | i += 1 |
---|
142 | _labels['Dash'] = i |
---|
143 | i += 1 |
---|
144 | _labels['Vline'] = i |
---|
145 | i += 1 |
---|
146 | _labels['Step'] = i |
---|
147 | return _labels |
---|
148 | |
---|
149 | def get_color_label(self): |
---|
150 | """ |
---|
151 | Associates label to a specific color |
---|
152 | """ |
---|
153 | _labels = {} |
---|
154 | i = 0 |
---|
155 | _labels['Blue'] = i |
---|
156 | i += 1 |
---|
157 | _labels['Green'] = i |
---|
158 | i += 1 |
---|
159 | _labels['Red'] = i |
---|
160 | i += 1 |
---|
161 | _labels['Cyan'] = i |
---|
162 | i += 1 |
---|
163 | _labels['Magenta'] = i |
---|
164 | i += 1 |
---|
165 | _labels['Yellow'] = i |
---|
166 | i += 1 |
---|
167 | _labels['Black'] = i |
---|
168 | return _labels |
---|
169 | |
---|
170 | |
---|
171 | def set_data(self, list=None): |
---|
172 | """ |
---|
173 | """ |
---|
174 | pass |
---|
175 | |
---|
176 | def _reset(self): |
---|
177 | """ |
---|
178 | Resets internal data and graph |
---|
179 | """ |
---|
180 | self.graph.reset() |
---|
181 | self.plots = {} |
---|
182 | if self.is_zoomed: |
---|
183 | self.is_zoomed = False |
---|
184 | |
---|
185 | def _OnReSize(self, event): |
---|
186 | """ |
---|
187 | On response of the resize of a panel, set axes_visiable False |
---|
188 | """ |
---|
189 | # It was found that wx >= 2.9.3 sends an event even if no size changed. |
---|
190 | # So manually recode the size (=x_size) and compare here. |
---|
191 | # Massy code to work around:< |
---|
192 | if self.parent._mgr != None: |
---|
193 | max_panel = self.parent._mgr.GetPane(self) |
---|
194 | if max_panel.IsMaximized(): |
---|
195 | self.parent._mgr.RestorePane(max_panel) |
---|
196 | max_panel.Maximize() |
---|
197 | if self.x_size != None: |
---|
198 | if self.x_size == self.GetSize(): |
---|
199 | self.resizing = False |
---|
200 | self.canvas.set_resizing(self.resizing) |
---|
201 | return |
---|
202 | self.x_size = self.GetSize() |
---|
203 | |
---|
204 | # Ready for another event |
---|
205 | # Do not remove this Skip. Otherwise it will get runtime error on wx>=2.9. |
---|
206 | event.Skip() |
---|
207 | # set the resizing flag |
---|
208 | self.resizing = True |
---|
209 | self.canvas.set_resizing(self.resizing) |
---|
210 | self.parent.set_schedule(True) |
---|
211 | pos_x, pos_y = self.GetPositionTuple() |
---|
212 | if pos_x != 0 and pos_y != 0: |
---|
213 | self.size, _ = self.GetClientSizeTuple() |
---|
214 | self.SetSizer(self.sizer) |
---|
215 | wx.CallAfter(self.parent.disable_app_menu,self) |
---|
216 | |
---|
217 | def set_resizing(self, resizing=False): |
---|
218 | """ |
---|
219 | Set the resizing (True/False) |
---|
220 | """ |
---|
221 | self.resizing = resizing |
---|
222 | #self.canvas.set_resizing(resizing) |
---|
223 | |
---|
224 | def schedule_full_draw(self, func='append'): |
---|
225 | """ |
---|
226 | Put self in schedule to full redraw list |
---|
227 | """ |
---|
228 | # append/del this panel in the schedule list |
---|
229 | self.parent.set_schedule_full_draw(self, func) |
---|
230 | |
---|
231 | |
---|
232 | def remove_data_by_id(self, id): |
---|
233 | """' |
---|
234 | remove data from plot |
---|
235 | """ |
---|
236 | if id in self.plots.keys(): |
---|
237 | data = self.plots[id] |
---|
238 | self.graph.delete(data) |
---|
239 | data_manager = self._manager.parent.get_data_manager() |
---|
240 | data_list, theory_list = data_manager.get_by_id(id_list=[id]) |
---|
241 | |
---|
242 | if id in data_list.keys(): |
---|
243 | data = data_list[id] |
---|
244 | if id in theory_list.keys(): |
---|
245 | data = theory_list[id] |
---|
246 | # Update Graph menu and help string |
---|
247 | h_id = self.parent._window_menu.FindItem(self.window_caption) |
---|
248 | if data != None: |
---|
249 | if data.__class__.__name__ == 'list': |
---|
250 | label = data[0].label |
---|
251 | else: |
---|
252 | label = data.label |
---|
253 | else: |
---|
254 | label = '???' |
---|
255 | helpString = self.parent._window_menu.GetHelpString(h_id) |
---|
256 | d_string = (' ' + str(label) +';') |
---|
257 | new_tip = helpString.replace(d_string, '') |
---|
258 | self.parent._window_menu.SetHelpString(h_id, new_tip) |
---|
259 | |
---|
260 | del self.plots[id] |
---|
261 | self.graph.render(self) |
---|
262 | self.subplot.figure.canvas.draw_idle() |
---|
263 | if len(self.graph.plottables) == 0: |
---|
264 | #onRemove: graph is empty must be the panel must be destroyed |
---|
265 | self.parent.delete_panel(self.uid) |
---|
266 | |
---|
267 | |
---|
268 | def plot_data(self, data): |
---|
269 | """ |
---|
270 | Data is ready to be displayed |
---|
271 | |
---|
272 | :param event: data event |
---|
273 | """ |
---|
274 | if data.__class__.__name__ == 'Data2D': |
---|
275 | return |
---|
276 | plot_keys = self.plots.keys() |
---|
277 | if data.id in plot_keys: |
---|
278 | #Recover panel prop.s |
---|
279 | xlo, xhi = self.subplot.get_xlim() |
---|
280 | ylo, yhi = self.subplot.get_ylim() |
---|
281 | old_data = self.plots[data.id] |
---|
282 | if self._is_changed_legend_label: |
---|
283 | data.label = old_data.label |
---|
284 | if old_data.__class__.__name__ == 'Data1D': |
---|
285 | data.custom_color = old_data.custom_color |
---|
286 | data.symbol = old_data.symbol |
---|
287 | data.markersize = old_data.markersize |
---|
288 | data.zorder = len(plot_keys) |
---|
289 | # Replace data |
---|
290 | self.graph.replace(data) |
---|
291 | self.plots[data.id] = data |
---|
292 | ## Set the view scale for all plots |
---|
293 | try: |
---|
294 | self._onEVT_FUNC_PROPERTY() |
---|
295 | except: |
---|
296 | msg=" Encountered singular points..." |
---|
297 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
298 | "Plotting Error: %s"% msg, info="error")) |
---|
299 | # Check if zoomed |
---|
300 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
301 | if self.is_zoomed or toolbar_zoomed: |
---|
302 | # Recover the x,y limits |
---|
303 | self.subplot.set_xlim((xlo, xhi)) |
---|
304 | self.subplot.set_ylim((ylo, yhi)) |
---|
305 | else: |
---|
306 | self.plots[data.id] = data |
---|
307 | self.graph.add(self.plots[data.id]) |
---|
308 | data.zorder = len(plot_keys) |
---|
309 | ## Set the view scale for all plots |
---|
310 | try: |
---|
311 | self._onEVT_FUNC_PROPERTY() |
---|
312 | if IS_MAC: |
---|
313 | # MAC: forcing to plot 2D avg |
---|
314 | self.canvas._onDrawIdle() |
---|
315 | except: |
---|
316 | msg=" Encountered singular points..." |
---|
317 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
318 | "Plotting Error: %s"% msg, info="error")) |
---|
319 | self.toolbar.update() |
---|
320 | if self.is_zoomed: |
---|
321 | self.is_zoomed = False |
---|
322 | # Update Graph menu and help string |
---|
323 | pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
324 | helpString = 'Show/Hide Graph: ' |
---|
325 | for plot in self.plots.itervalues(): |
---|
326 | helpString += (' ' + str(plot.label) +';') |
---|
327 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
328 | |
---|
329 | def draw_plot(self): |
---|
330 | """ |
---|
331 | Draw plot |
---|
332 | """ |
---|
333 | self.draw() |
---|
334 | |
---|
335 | def onLeftDown(self,event): |
---|
336 | """ |
---|
337 | left button down and ready to drag |
---|
338 | Display the position of the mouse on the statusbar |
---|
339 | """ |
---|
340 | PlotPanel.onLeftDown(self, event) |
---|
341 | ax = event.inaxes |
---|
342 | if ax != None: |
---|
343 | try: |
---|
344 | pos_x = float(event.xdata)# / size_x |
---|
345 | pos_y = float(event.ydata)# / size_y |
---|
346 | pos_x = "%8.3g"% pos_x |
---|
347 | pos_y = "%8.3g"% pos_y |
---|
348 | self.position = str(pos_x), str(pos_y) |
---|
349 | wx.PostEvent(self.parent, StatusEvent(status=self.position)) |
---|
350 | except: |
---|
351 | self.position = None |
---|
352 | # unfocus all |
---|
353 | self.parent.set_plot_unfocus() |
---|
354 | #post nd event to notify guiframe that this panel is on focus |
---|
355 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
356 | |
---|
357 | |
---|
358 | def _ontoggle_hide_error(self, event): |
---|
359 | """ |
---|
360 | Toggle error display to hide or show |
---|
361 | """ |
---|
362 | menu = event.GetEventObject() |
---|
363 | id = event.GetId() |
---|
364 | self.set_selected_from_menu(menu, id) |
---|
365 | # Check zoom |
---|
366 | xlo, xhi = self.subplot.get_xlim() |
---|
367 | ylo, yhi = self.subplot.get_ylim() |
---|
368 | |
---|
369 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
370 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
371 | selected_plot.hide_error = True |
---|
372 | else: |
---|
373 | selected_plot.hide_error = False |
---|
374 | ## increment graph color |
---|
375 | self.graph.render(self) |
---|
376 | self.subplot.figure.canvas.draw_idle() |
---|
377 | # Check if zoomed |
---|
378 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
379 | if self.is_zoomed or toolbar_zoomed: |
---|
380 | # Recover the x,y limits |
---|
381 | self.subplot.set_xlim((xlo, xhi)) |
---|
382 | self.subplot.set_ylim((ylo, yhi)) |
---|
383 | |
---|
384 | |
---|
385 | def _onRemove(self, event): |
---|
386 | """ |
---|
387 | Remove a plottable from the graph and render the graph |
---|
388 | |
---|
389 | :param event: Menu event |
---|
390 | |
---|
391 | """ |
---|
392 | menu = event.GetEventObject() |
---|
393 | id = event.GetId() |
---|
394 | self.set_selected_from_menu(menu, id) |
---|
395 | ## Check if there is a selected graph to remove |
---|
396 | if self.graph.selected_plottable in self.plots.keys(): |
---|
397 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
398 | id = self.graph.selected_plottable |
---|
399 | self.remove_data_by_id(id) |
---|
400 | |
---|
401 | def onContextMenu(self, event): |
---|
402 | """ |
---|
403 | 1D plot context menu |
---|
404 | |
---|
405 | :param event: wx context event |
---|
406 | |
---|
407 | """ |
---|
408 | self._slicerpop = PanelMenu() |
---|
409 | self._slicerpop.set_plots(self.plots) |
---|
410 | self._slicerpop.set_graph(self.graph) |
---|
411 | if not self.graph.selected_plottable in self.plots: |
---|
412 | # Various plot options |
---|
413 | id = wx.NewId() |
---|
414 | self._slicerpop.Append(id, '&Save Image', 'Save image as PNG') |
---|
415 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
416 | id = wx.NewId() |
---|
417 | self._slicerpop.Append(id, '&Print Image', 'Print image ') |
---|
418 | wx.EVT_MENU(self, id, self.onPrint) |
---|
419 | id = wx.NewId() |
---|
420 | self._slicerpop.Append(id, '&Print Preview', 'Print preview') |
---|
421 | wx.EVT_MENU(self, id, self.onPrinterPreview) |
---|
422 | |
---|
423 | id = wx.NewId() |
---|
424 | self._slicerpop.Append(id, '&Copy to Clipboard', |
---|
425 | 'Copy to the clipboard') |
---|
426 | wx.EVT_MENU(self, id, self.OnCopyFigureMenu) |
---|
427 | |
---|
428 | self._slicerpop.AppendSeparator() |
---|
429 | |
---|
430 | for plot in self.plots.values(): |
---|
431 | #title = plot.title |
---|
432 | name = plot.name |
---|
433 | plot_menu = wx.Menu() |
---|
434 | if self.graph.selected_plottable: |
---|
435 | if not self.graph.selected_plottable in self.plots.keys(): |
---|
436 | continue |
---|
437 | if plot != self.plots[self.graph.selected_plottable]: |
---|
438 | continue |
---|
439 | |
---|
440 | id = wx.NewId() |
---|
441 | plot_menu.Append(id, "&DataInfo", name) |
---|
442 | wx.EVT_MENU(self, id, self. _onDataShow) |
---|
443 | id = wx.NewId() |
---|
444 | plot_menu.Append(id, "&Save Points as a File", name) |
---|
445 | wx.EVT_MENU(self, id, self._onSave) |
---|
446 | plot_menu.AppendSeparator() |
---|
447 | |
---|
448 | #add menu of other plugins |
---|
449 | item_list = self.parent.get_current_context_menu(self) |
---|
450 | |
---|
451 | if (not item_list == None) and (not len(item_list) == 0): |
---|
452 | for item in item_list: |
---|
453 | |
---|
454 | try: |
---|
455 | id = wx.NewId() |
---|
456 | plot_menu.Append(id, item[0], name) |
---|
457 | wx.EVT_MENU(self, id, item[2]) |
---|
458 | except: |
---|
459 | msg = "ModelPanel1D.onContextMenu: " |
---|
460 | msg += "bad menu item %s" % sys.exc_value |
---|
461 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
462 | pass |
---|
463 | plot_menu.AppendSeparator() |
---|
464 | |
---|
465 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
466 | id = wx.NewId() |
---|
467 | plot_menu.Append(id, '&Linear Fit', name) |
---|
468 | wx.EVT_MENU(self, id, self.onFitting) |
---|
469 | plot_menu.AppendSeparator() |
---|
470 | |
---|
471 | id = wx.NewId() |
---|
472 | plot_menu.Append(id, "Remove", name) |
---|
473 | wx.EVT_MENU(self, id, self._onRemove) |
---|
474 | if not plot.is_data: |
---|
475 | id = wx.NewId() |
---|
476 | plot_menu.Append(id, '&Freeze', name) |
---|
477 | wx.EVT_MENU(self, id, self.onFreeze) |
---|
478 | plot_menu.AppendSeparator() |
---|
479 | symbol_menu = wx.Menu() |
---|
480 | |
---|
481 | if plot.is_data: |
---|
482 | id = wx.NewId() |
---|
483 | self.hide_menu = plot_menu.Append(id, |
---|
484 | "Hide Error Bar", name) |
---|
485 | |
---|
486 | if plot.dy is not None and plot.dy != []: |
---|
487 | if plot.hide_error : |
---|
488 | self.hide_menu.SetText('Show Error Bar') |
---|
489 | else: |
---|
490 | self.hide_menu.SetText('Hide Error Bar') |
---|
491 | else: |
---|
492 | self.hide_menu.Enable(False) |
---|
493 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
494 | |
---|
495 | plot_menu.AppendSeparator() |
---|
496 | |
---|
497 | id = wx.NewId() |
---|
498 | plot_menu.Append(id, '&Modify Plot Property', name) |
---|
499 | wx.EVT_MENU(self, id, self.createAppDialog) |
---|
500 | |
---|
501 | |
---|
502 | |
---|
503 | id = wx.NewId() |
---|
504 | #plot_menu.SetTitle(name) |
---|
505 | self._slicerpop.AppendMenu(id, '&%s'% name, plot_menu) |
---|
506 | # Option to hide |
---|
507 | #TODO: implement functionality to hide a plottable (legend click) |
---|
508 | if not self.graph.selected_plottable in self.plots: |
---|
509 | self._slicerpop.AppendSeparator() |
---|
510 | loc_menu = wx.Menu() |
---|
511 | for label in self._loc_labels: |
---|
512 | id = wx.NewId() |
---|
513 | loc_menu.Append(id, str(label), str(label)) |
---|
514 | wx.EVT_MENU(self, id, self.onChangeLegendLoc) |
---|
515 | |
---|
516 | id = wx.NewId() |
---|
517 | self._slicerpop.Append(id, '&Modify Graph Appearance', |
---|
518 | 'Modify graph appearance') |
---|
519 | wx.EVT_MENU(self, id, self.modifyGraphAppearance) |
---|
520 | self._slicerpop.AppendSeparator() |
---|
521 | |
---|
522 | |
---|
523 | if self.position != None: |
---|
524 | id = wx.NewId() |
---|
525 | self._slicerpop.Append(id, '&Add Text') |
---|
526 | wx.EVT_MENU(self, id, self._on_addtext) |
---|
527 | id = wx.NewId() |
---|
528 | self._slicerpop.Append(id, '&Remove Text') |
---|
529 | wx.EVT_MENU(self, id, self._on_removetext) |
---|
530 | self._slicerpop.AppendSeparator() |
---|
531 | id = wx.NewId() |
---|
532 | self._slicerpop.Append(id, '&Change Scale') |
---|
533 | wx.EVT_MENU(self, id, self._onProperties) |
---|
534 | self._slicerpop.AppendSeparator() |
---|
535 | id = wx.NewId() |
---|
536 | self._slicerpop.Append(id, '&Reset Graph Range') |
---|
537 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
538 | |
---|
539 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
540 | self._slicerpop.AppendSeparator() |
---|
541 | id = wx.NewId() |
---|
542 | self._slicerpop.Append(id, '&Window Title') |
---|
543 | wx.EVT_MENU(self, id, self.onChangeCaption) |
---|
544 | try: |
---|
545 | pos_evt = event.GetPosition() |
---|
546 | pos = self.ScreenToClient(pos_evt) |
---|
547 | except: |
---|
548 | pos_x, pos_y = self.toolbar.GetPositionTuple() |
---|
549 | pos = (pos_x, pos_y + 5) |
---|
550 | self.PopupMenu(self._slicerpop, pos) |
---|
551 | |
---|
552 | def onFreeze(self, event): |
---|
553 | """ |
---|
554 | on Freeze data |
---|
555 | """ |
---|
556 | menu = event.GetEventObject() |
---|
557 | id = event.GetId() |
---|
558 | self.set_selected_from_menu(menu, id) |
---|
559 | plot = self.plots[self.graph.selected_plottable] |
---|
560 | self.parent.onfreeze([plot.id]) |
---|
561 | |
---|
562 | |
---|
563 | def _onSave(self, evt): |
---|
564 | """ |
---|
565 | Save a data set to a text file |
---|
566 | |
---|
567 | :param evt: Menu event |
---|
568 | |
---|
569 | """ |
---|
570 | menu = evt.GetEventObject() |
---|
571 | id = evt.GetId() |
---|
572 | self.set_selected_from_menu(menu, id) |
---|
573 | data = self.plots[self.graph.selected_plottable] |
---|
574 | default_name = data.label |
---|
575 | if default_name.count('.') > 0: |
---|
576 | default_name = default_name.split('.')[0] |
---|
577 | default_name += "_out" |
---|
578 | if self.parent != None: |
---|
579 | self.parent.save_data1d(data, default_name) |
---|
580 | |
---|
581 | |
---|
582 | def _onDataShow(self, evt): |
---|
583 | """ |
---|
584 | Show the data set in text |
---|
585 | |
---|
586 | :param evt: Menu event |
---|
587 | |
---|
588 | """ |
---|
589 | menu = evt.GetEventObject() |
---|
590 | id = evt.GetId() |
---|
591 | self.set_selected_from_menu(menu, id) |
---|
592 | data = self.plots[self.graph.selected_plottable] |
---|
593 | default_name = data.label |
---|
594 | if default_name.count('.') > 0: |
---|
595 | default_name = default_name.split('.')[0] |
---|
596 | #default_name += "_out" |
---|
597 | if self.parent != None: |
---|
598 | self.parent.show_data1d(data, default_name) |
---|
599 | |
---|
600 | def _add_more_tool(self): |
---|
601 | """ |
---|
602 | Add refresh, add/hide button in the tool bar |
---|
603 | """ |
---|
604 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
605 | return |
---|
606 | self.toolbar.AddSeparator() |
---|
607 | id_hide = wx.NewId() |
---|
608 | hide = wx.Bitmap(GUIFRAME_ICON.HIDE_ID_PATH, wx.BITMAP_TYPE_PNG) |
---|
609 | self.toolbar.AddSimpleTool(id_hide, hide, 'Hide', 'Hide') |
---|
610 | self.toolbar.Realize() |
---|
611 | wx.EVT_TOOL(self, id_hide, self._on_hide) |
---|
612 | |
---|
613 | def _on_hide(self, event): |
---|
614 | """ |
---|
615 | Hides the plot when button is pressed |
---|
616 | """ |
---|
617 | if self.parent is not None: |
---|
618 | self.parent.hide_panel(self.uid) |
---|
619 | |
---|
620 | def createAppDialog(self, event): |
---|
621 | """ |
---|
622 | Create the custom dialog for fit appearance modification |
---|
623 | """ |
---|
624 | menu = event.GetEventObject() |
---|
625 | id = event.GetId() |
---|
626 | self.set_selected_from_menu(menu, id) |
---|
627 | self.appearance_selected_plot = \ |
---|
628 | self.plots[self.graph.selected_plottable] |
---|
629 | # find current properties |
---|
630 | curr_color = self.appearance_selected_plot.custom_color |
---|
631 | curr_symbol = self.appearance_selected_plot.symbol |
---|
632 | curr_size = self.appearance_selected_plot.markersize |
---|
633 | curr_label = self.appearance_selected_plot.label |
---|
634 | |
---|
635 | if curr_color == None: |
---|
636 | curr_color = self._color_labels['Blue'] |
---|
637 | curr_symbol = 13 |
---|
638 | |
---|
639 | self.appD = appearanceDialog(self, 'Modify Plot Property') |
---|
640 | icon = self.parent.GetIcon() |
---|
641 | self.appD.SetIcon(icon) |
---|
642 | self.appD.set_defaults(float(curr_size), int(curr_color), |
---|
643 | str(appearanceDialog.find_key(self.get_symbol_label(), |
---|
644 | int(curr_symbol))), curr_label) |
---|
645 | self.appD.Bind(wx.EVT_CLOSE, self.on_AppDialog_close) |
---|
646 | |
---|
647 | def on_AppDialog_close(self, event): |
---|
648 | """ |
---|
649 | on_Modify Plot Property_close |
---|
650 | """ |
---|
651 | if(self.appD.okay_clicked == True): |
---|
652 | # returns (size,color,symbol,datalabel) |
---|
653 | info = self.appD.get_current_values() |
---|
654 | self.appearance_selected_plot.custom_color = \ |
---|
655 | self._color_labels[info[1].encode('ascii', 'ignore')] |
---|
656 | |
---|
657 | self.appearance_selected_plot.markersize = float(info[0]) |
---|
658 | self.appearance_selected_plot.symbol = \ |
---|
659 | self.get_symbol_label()[info[2]] |
---|
660 | self.appearance_selected_plot.label = str(info[3]) |
---|
661 | |
---|
662 | pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
663 | helpString = 'Show/Hide Graph: ' |
---|
664 | for plot in self.plots.itervalues(): |
---|
665 | helpString += (' ' + str(plot.label) + ';') |
---|
666 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
667 | self._is_changed_legend_label = True |
---|
668 | |
---|
669 | self.appD.Destroy() |
---|
670 | self._check_zoom_plot() |
---|
671 | |
---|
672 | |
---|
673 | def modifyGraphAppearance(self, event): |
---|
674 | """ |
---|
675 | On Modify Graph Appearance |
---|
676 | """ |
---|
677 | self.graphApp = graphAppearance(self, 'Modify Graph Appearance') |
---|
678 | icon = self.parent.GetIcon() |
---|
679 | self.graphApp.SetIcon(icon) |
---|
680 | self.graphApp.setDefaults(self.grid_on, self.legend_on, |
---|
681 | self.xaxis_label, self.yaxis_label, |
---|
682 | self.xaxis_unit, self.yaxis_unit, |
---|
683 | self.xaxis_font, self.yaxis_font, |
---|
684 | find_key(self.get_loc_label(), |
---|
685 | self.legendLoc), |
---|
686 | self.xcolor,self.ycolor) |
---|
687 | self.graphApp.Bind(wx.EVT_CLOSE, self.on_graphApp_close) |
---|
688 | |
---|
689 | |
---|
690 | def on_graphApp_close(self, event): |
---|
691 | """ |
---|
692 | Gets values from graph appearance dialog and sends them off |
---|
693 | to modify the plot |
---|
694 | """ |
---|
695 | graph_app = self.graphApp |
---|
696 | toggle_grid = graph_app.get_togglegrid() |
---|
697 | legend_loc = graph_app.get_legend_loc() |
---|
698 | toggle_legend = graph_app.get_togglelegend() |
---|
699 | |
---|
700 | self.onGridOnOff(toggle_grid ) |
---|
701 | self.ChangeLegendLoc(legend_loc) |
---|
702 | self.onLegend(toggle_legend) |
---|
703 | |
---|
704 | self.xaxis_label = graph_app.get_xlab() |
---|
705 | self.yaxis_label = graph_app.get_ylab() |
---|
706 | self.xaxis_unit = graph_app.get_xunit() |
---|
707 | self.yaxis_unit = graph_app.get_yunit() |
---|
708 | |
---|
709 | self.xaxis(self.xaxis_label, self.xaxis_unit, |
---|
710 | graph_app.get_xfont(), graph_app.get_xcolor()) |
---|
711 | self.yaxis(self.yaxis_label, self.yaxis_unit, |
---|
712 | graph_app.get_yfont(), graph_app.get_ycolor()) |
---|
713 | |
---|
714 | graph_app.Destroy() |
---|