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