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 | # Check zoom |
---|
321 | xlo, xhi = self.subplot.get_xlim() |
---|
322 | ylo, yhi = self.subplot.get_ylim() |
---|
323 | |
---|
324 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
325 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
326 | selected_plot.hide_error = True |
---|
327 | else: |
---|
328 | selected_plot.hide_error = False |
---|
329 | ## increment graph color |
---|
330 | self.graph.render(self) |
---|
331 | self.subplot.figure.canvas.draw_idle() |
---|
332 | # Check if zoomed |
---|
333 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
334 | if self.is_zoomed or toolbar_zoomed: |
---|
335 | # Recover the x,y limits |
---|
336 | self.subplot.set_xlim((xlo, xhi)) |
---|
337 | self.subplot.set_ylim((ylo, yhi)) |
---|
338 | |
---|
339 | |
---|
340 | def _onRemove(self, event): |
---|
341 | """ |
---|
342 | Remove a plottable from the graph and render the graph |
---|
343 | |
---|
344 | :param event: Menu event |
---|
345 | |
---|
346 | """ |
---|
347 | ## Check if there is a selected graph to remove |
---|
348 | if self.graph.selected_plottable in self.plots.keys(): |
---|
349 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
350 | id = self.graph.selected_plottable |
---|
351 | self.remove_data_by_id(id) |
---|
352 | |
---|
353 | def onContextMenu(self, event): |
---|
354 | """ |
---|
355 | 1D plot context menu |
---|
356 | |
---|
357 | :param event: wx context event |
---|
358 | |
---|
359 | """ |
---|
360 | self._slicerpop = PanelMenu() |
---|
361 | self._slicerpop.set_plots(self.plots) |
---|
362 | self._slicerpop.set_graph(self.graph) |
---|
363 | # Various plot options |
---|
364 | id = wx.NewId() |
---|
365 | self._slicerpop.Append(id, '&Save Image', 'Save image as PNG') |
---|
366 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
367 | id = wx.NewId() |
---|
368 | self._slicerpop.Append(id, '&Print Image', 'Print image ') |
---|
369 | wx.EVT_MENU(self, id, self.onPrint) |
---|
370 | id = wx.NewId() |
---|
371 | self._slicerpop.Append(id, '&Print Preview', 'Print preview') |
---|
372 | wx.EVT_MENU(self, id, self.onPrinterPreview) |
---|
373 | |
---|
374 | id = wx.NewId() |
---|
375 | self._slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') |
---|
376 | wx.EVT_MENU(self, id, self.OnCopyFigureMenu) |
---|
377 | |
---|
378 | self._slicerpop.AppendSeparator() |
---|
379 | |
---|
380 | #add menu of other plugins |
---|
381 | item_list = self.parent.get_context_menu(self) |
---|
382 | |
---|
383 | if (not item_list == None) and (not len(item_list) == 0): |
---|
384 | for item in item_list: |
---|
385 | try: |
---|
386 | id = wx.NewId() |
---|
387 | self._slicerpop.Append(id, item[0], item[1]) |
---|
388 | wx.EVT_MENU(self, id, item[2]) |
---|
389 | except: |
---|
390 | msg = "ModelPanel1D.onContextMenu: " |
---|
391 | msg += "bad menu item %s" % sys.exc_value |
---|
392 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
393 | pass |
---|
394 | self._slicerpop.AppendSeparator() |
---|
395 | #id = wx.NewId() |
---|
396 | #self._slicerpop.Append(id, '&Print image', 'Print image') |
---|
397 | if self.graph.selected_plottable in self.plots: |
---|
398 | plot = self.plots[self.graph.selected_plottable] |
---|
399 | |
---|
400 | id = wx.NewId() |
---|
401 | name = plot.name |
---|
402 | self._slicerpop.Append(id, "&Save Points as a File") |
---|
403 | wx.EVT_MENU(self, id, self._onSave) |
---|
404 | self._slicerpop.AppendSeparator() |
---|
405 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
406 | id = wx.NewId() |
---|
407 | self._slicerpop.Append(id, '&Linear Fit') |
---|
408 | wx.EVT_MENU(self, id, self.onFitting) |
---|
409 | self._slicerpop.AppendSeparator() |
---|
410 | |
---|
411 | id = wx.NewId() |
---|
412 | self._slicerpop.Append(id, "Remove %s Curve" % name) |
---|
413 | wx.EVT_MENU(self, id, self._onRemove) |
---|
414 | if not plot.is_data: |
---|
415 | id = wx.NewId() |
---|
416 | self._slicerpop.Append(id, '&Freeze', 'Freeze') |
---|
417 | wx.EVT_MENU(self, id, self.onFreeze) |
---|
418 | self._slicerpop.AppendSeparator() |
---|
419 | symbol_menu = wx.Menu() |
---|
420 | for label in self._symbol_labels: |
---|
421 | id = wx.NewId() |
---|
422 | symbol_menu.Append(id, str(label), str(label)) |
---|
423 | wx.EVT_MENU(self, id, self.onChangeSymbol) |
---|
424 | id = wx.NewId() |
---|
425 | self._slicerpop.AppendMenu(id,'&Modify Symbol', symbol_menu) |
---|
426 | |
---|
427 | color_menu = wx.Menu() |
---|
428 | for label in self._color_labels: |
---|
429 | id = wx.NewId() |
---|
430 | color_menu.Append(id, str(label), str(label)) |
---|
431 | wx.EVT_MENU(self, id, self.onChangeColor) |
---|
432 | id = wx.NewId() |
---|
433 | self._slicerpop.AppendMenu(id, '&Modify Symbol Color', color_menu) |
---|
434 | |
---|
435 | size_menu = wx.Menu() |
---|
436 | for i in range(10): |
---|
437 | id = wx.NewId() |
---|
438 | size_menu.Append(id, str(i), str(i)) |
---|
439 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
440 | id = wx.NewId() |
---|
441 | size_menu.Append(id, '&Custom', 'Custom') |
---|
442 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
443 | id = wx.NewId() |
---|
444 | self._slicerpop.AppendMenu(id, '&Modify Symbol Size', size_menu) |
---|
445 | |
---|
446 | self.hide_menu = self._slicerpop.Append(id, "Hide Error Bar") |
---|
447 | |
---|
448 | if plot.dy is not None and plot.dy != []: |
---|
449 | if plot.hide_error : |
---|
450 | self.hide_menu.SetText('Show Error Bar') |
---|
451 | else: |
---|
452 | self.hide_menu.SetText('Hide Error Bar') |
---|
453 | else: |
---|
454 | self.hide_menu.Enable(False) |
---|
455 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
456 | |
---|
457 | self._slicerpop.AppendSeparator() |
---|
458 | id = wx.NewId() |
---|
459 | self._slicerpop.Append(id, '&Edit Legend Label', 'Edit Legend Label') |
---|
460 | wx.EVT_MENU(self, id, self.onEditLabels) |
---|
461 | # Option to hide |
---|
462 | #TODO: implement functionality to hide a plottable (legend click) |
---|
463 | |
---|
464 | loc_menu = wx.Menu() |
---|
465 | for label in self._loc_labels: |
---|
466 | id = wx.NewId() |
---|
467 | loc_menu.Append(id, str(label), str(label)) |
---|
468 | wx.EVT_MENU(self, id, self.onChangeLegendLoc) |
---|
469 | id = wx.NewId() |
---|
470 | self._slicerpop.AppendMenu(id, '&Modify Legend Location', loc_menu) |
---|
471 | |
---|
472 | id = wx.NewId() |
---|
473 | self._slicerpop.Append(id, '&Toggle Legend On/Off', 'Toggle Legend On/Off') |
---|
474 | wx.EVT_MENU(self, id, self.onLegend) |
---|
475 | self._slicerpop.AppendSeparator() |
---|
476 | |
---|
477 | id = wx.NewId() |
---|
478 | self._slicerpop.Append(id, '&Edit Y Axis Label') |
---|
479 | wx.EVT_MENU(self, id, self._on_yaxis_label) |
---|
480 | id = wx.NewId() |
---|
481 | self._slicerpop.Append(id, '&Edit X Axis Label') |
---|
482 | wx.EVT_MENU(self, id, self._on_xaxis_label) |
---|
483 | |
---|
484 | id = wx.NewId() |
---|
485 | self._slicerpop.Append(id, '&Toggle Grid On/Off', 'Toggle Grid On/Off') |
---|
486 | wx.EVT_MENU(self, id, self.onGridOnOff) |
---|
487 | self._slicerpop.AppendSeparator() |
---|
488 | |
---|
489 | if self.position != None: |
---|
490 | id = wx.NewId() |
---|
491 | self._slicerpop.Append(id, '&Add Text') |
---|
492 | wx.EVT_MENU(self, id, self._on_addtext) |
---|
493 | id = wx.NewId() |
---|
494 | self._slicerpop.Append(id, '&Remove Text') |
---|
495 | wx.EVT_MENU(self, id, self._on_removetext) |
---|
496 | self._slicerpop.AppendSeparator() |
---|
497 | id = wx.NewId() |
---|
498 | self._slicerpop.Append(id, '&Change Scale') |
---|
499 | wx.EVT_MENU(self, id, self._onProperties) |
---|
500 | self._slicerpop.AppendSeparator() |
---|
501 | id = wx.NewId() |
---|
502 | self._slicerpop.Append(id, '&Reset Graph Range') |
---|
503 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
504 | try: |
---|
505 | pos_evt = event.GetPosition() |
---|
506 | pos = self.ScreenToClient(pos_evt) |
---|
507 | except: |
---|
508 | pos_x, pos_y = self.toolbar.GetPositionTuple() |
---|
509 | pos = (pos_x, pos_y + 5) |
---|
510 | |
---|
511 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
512 | self._slicerpop.AppendSeparator() |
---|
513 | id = wx.NewId() |
---|
514 | self._slicerpop.Append(id, '&Window Title') |
---|
515 | wx.EVT_MENU(self, id, self.onChangeCaption) |
---|
516 | |
---|
517 | self.PopupMenu(self._slicerpop, pos) |
---|
518 | |
---|
519 | def onFreeze(self, event): |
---|
520 | """ |
---|
521 | """ |
---|
522 | plot = self.plots[self.graph.selected_plottable] |
---|
523 | self.parent.onfreeze([plot.id]) |
---|
524 | |
---|
525 | def onEditLabels(self, event): |
---|
526 | """ |
---|
527 | Edit legend label |
---|
528 | """ |
---|
529 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
530 | label = selected_plot.label |
---|
531 | dial = LabelDialog(None, -1, 'Change Legend Label', label) |
---|
532 | if dial.ShowModal() == wx.ID_OK: |
---|
533 | newLabel = dial.getText() |
---|
534 | selected_plot.label = newLabel |
---|
535 | # Updata Graph menu help string |
---|
536 | pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
537 | helpString = 'Show/Hide Graph: ' |
---|
538 | for plot in self.plots.itervalues(): |
---|
539 | helpString += (' ' + str(plot.label) +';') |
---|
540 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
541 | self._is_changed_legend_label = True |
---|
542 | #break |
---|
543 | dial.Destroy() |
---|
544 | |
---|
545 | ## render the graph |
---|
546 | try: |
---|
547 | self._onEVT_FUNC_PROPERTY() |
---|
548 | except: |
---|
549 | msg=" Encountered singular points..." |
---|
550 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
551 | "Plotting Erorr: %s"% msg, info="error")) |
---|
552 | |
---|
553 | def onChangeColor(self, event): |
---|
554 | """ |
---|
555 | Changes the color of the graph when selected |
---|
556 | """ |
---|
557 | menu = event.GetEventObject() |
---|
558 | id = event.GetId() |
---|
559 | label = menu.GetLabel(id) |
---|
560 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
561 | selected_plot.custom_color = self._color_labels[label] |
---|
562 | ## Set the view scale for all plots |
---|
563 | self._check_zoom_plot() |
---|
564 | #self._onEVT_FUNC_PROPERTY() |
---|
565 | #wx.PostEvent(self.parent, |
---|
566 | # NewColorEvent(color=selected_plot.custom_color, |
---|
567 | # id=selected_plot.id)) |
---|
568 | |
---|
569 | def onChangeSize(self, event): |
---|
570 | |
---|
571 | menu = event.GetEventObject() |
---|
572 | id = event.GetId() |
---|
573 | label = menu.GetLabel(id) |
---|
574 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
575 | |
---|
576 | if label == "&Custom": |
---|
577 | sizedial = SizeDialog(None, -1, 'Change Marker Size') |
---|
578 | if sizedial.ShowModal() == wx.ID_OK: |
---|
579 | try: |
---|
580 | label = sizedial.getText() |
---|
581 | |
---|
582 | except: |
---|
583 | msg = 'Symbol Size: Got an invalid Value.' |
---|
584 | wx.PostEvent( self.parent, |
---|
585 | StatusEvent(status= msg, info='error')) |
---|
586 | sizedial.Destroy() |
---|
587 | try: |
---|
588 | selected_plot.markersize = int(label) |
---|
589 | self._check_zoom_plot() |
---|
590 | except: |
---|
591 | msg = 'Symbol Size: Got an invalid Value.' |
---|
592 | wx.PostEvent( self.parent, |
---|
593 | StatusEvent(status= msg, info='error')) |
---|
594 | |
---|
595 | |
---|
596 | def onChangeSymbol(self, event): |
---|
597 | """ |
---|
598 | """ |
---|
599 | menu = event.GetEventObject() |
---|
600 | id = event.GetId() |
---|
601 | label = menu.GetLabel(id) |
---|
602 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
603 | selected_plot.symbol = self._symbol_labels[label] |
---|
604 | ## Set the view scale for all plots |
---|
605 | self._check_zoom_plot() |
---|
606 | #self._onEVT_FUNC_PROPERTY() |
---|
607 | ## render the graph |
---|
608 | #self.graph.render(self) |
---|
609 | #self.subplot.figure.canvas.draw_idle() |
---|
610 | |
---|
611 | def _onSave(self, evt): |
---|
612 | """ |
---|
613 | Save a data set to a text file |
---|
614 | |
---|
615 | :param evt: Menu event |
---|
616 | |
---|
617 | """ |
---|
618 | data = self.plots[self.graph.selected_plottable] |
---|
619 | default_name = data.label |
---|
620 | if default_name.count('.') > 0: |
---|
621 | default_name = default_name.split('.')[0] |
---|
622 | default_name += "_out" |
---|
623 | if self.parent != None: |
---|
624 | self.parent.save_data1d(data, default_name) |
---|
625 | |
---|
626 | def _add_more_tool(self): |
---|
627 | """ |
---|
628 | Add refresh, add/delete button in the tool bar |
---|
629 | """ |
---|
630 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
631 | return |
---|
632 | self.toolbar.AddSeparator() |
---|
633 | id_delete = wx.NewId() |
---|
634 | delete = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR) |
---|
635 | self.toolbar.AddSimpleTool(id_delete, delete, |
---|
636 | 'Delete', 'permanently Delete') |
---|
637 | |
---|
638 | self.toolbar.Realize() |
---|
639 | wx.EVT_TOOL(self, id_delete, self._on_delete) |
---|
640 | |
---|
641 | """ |
---|
642 | self.toolbar.AddSeparator() |
---|
643 | id_text = wx.NewId() |
---|
644 | text = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR) |
---|
645 | self.toolbar.AddSimpleTool(id_text, text, |
---|
646 | 'Remove Text from Plot', 'Removes text from plot') |
---|
647 | |
---|
648 | self.toolbar.Realize() |
---|
649 | wx.EVT_TOOL(self, id_text, self._on_removetext) |
---|
650 | """ |
---|
651 | def _on_delete(self, event): |
---|
652 | """ |
---|
653 | Refreshes the plotpanel on refresh tollbar button |
---|
654 | """ |
---|
655 | |
---|
656 | if self.parent is not None: |
---|
657 | wx.PostEvent(self.parent, |
---|
658 | NewPlotEvent(group_id=self.group_id, |
---|
659 | action="delete")) |
---|
660 | |
---|
661 | |
---|