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