[1bf33c1] | 1 | |
---|
[d955bf19] | 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 | ################################################################################ |
---|
[1bf33c1] | 11 | |
---|
| 12 | |
---|
| 13 | import wx |
---|
[4ac8556] | 14 | import sys |
---|
| 15 | import os |
---|
| 16 | import pylab |
---|
| 17 | import math |
---|
| 18 | import numpy |
---|
| 19 | import time |
---|
[a07e72f] | 20 | |
---|
[1bf33c1] | 21 | from danse.common.plottools.PlotPanel import PlotPanel |
---|
[6d52f21d] | 22 | from danse.common.plottools.SizeDialog import SizeDialog |
---|
| 23 | from danse.common.plottools.LabelDialog import LabelDialog |
---|
[9f5c8bb] | 24 | #from danse.common.plottools.plottables import Graph |
---|
[3b69ca6] | 25 | from sans.guiframe import dataFitting |
---|
[df7046f] | 26 | from sans.guiframe.events import EVT_NEW_PLOT |
---|
| 27 | from sans.guiframe.events import StatusEvent |
---|
| 28 | from sans.guiframe.events import NewPlotEvent |
---|
[2636188] | 29 | from sans.guiframe.events import NewColorEvent |
---|
[df7046f] | 30 | from sans.guiframe.events import SlicerEvent |
---|
[a45037aa] | 31 | from sans.guiframe.events import PanelOnFocusEvent |
---|
[52b8b74] | 32 | from sans.guiframe.events import EVT_NEW_LOADED_DATA |
---|
[0d9dae8] | 33 | from sans.guiframe.utils import PanelMenu |
---|
[4ac8556] | 34 | from sans.guiframe.dataFitting import Data1D |
---|
[691643c] | 35 | from sans.guiframe.panel_base import PanelBase |
---|
[1bf33c1] | 36 | from binder import BindArtist |
---|
| 37 | |
---|
[0d9dae8] | 38 | DEFAULT_QMAX = 0.05 |
---|
[1bf33c1] | 39 | DEFAULT_QSTEP = 0.001 |
---|
| 40 | DEFAULT_BEAM = 0.005 |
---|
[32c0841] | 41 | BIN_WIDTH = 1 |
---|
[1bf33c1] | 42 | |
---|
[0d9dae8] | 43 | |
---|
[691643c] | 44 | class ModelPanel1D(PlotPanel, PanelBase): |
---|
[1bf33c1] | 45 | """ |
---|
[d955bf19] | 46 | Plot panel for use with the GUI manager |
---|
[1bf33c1] | 47 | """ |
---|
| 48 | |
---|
| 49 | ## Internal name for the AUI manager |
---|
| 50 | window_name = "plotpanel" |
---|
| 51 | ## Title to appear on top of the window |
---|
[37c36d9] | 52 | window_caption = "Graph" |
---|
[1bf33c1] | 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 | |
---|
[32c0841] | 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) |
---|
[a45037aa] | 62 | PanelBase.__init__(self, parent) |
---|
[1bf33c1] | 63 | ## Reference to the parent window |
---|
| 64 | self.parent = parent |
---|
| 65 | ## Plottables |
---|
| 66 | self.plots = {} |
---|
[52b8b74] | 67 | #context menu |
---|
| 68 | self._slicerpop = None |
---|
[a07e72f] | 69 | |
---|
[52b8b74] | 70 | self._available_data = [] |
---|
| 71 | self._menu_add_ids = [] |
---|
[a07e72f] | 72 | self._symbol_labels = self.get_symbol_label() |
---|
[2636188] | 73 | self._color_labels = self.get_color_label() |
---|
| 74 | self.currColorIndex = "" |
---|
[36288ca] | 75 | self._is_changed_legend_label = False |
---|
[a07e72f] | 76 | |
---|
| 77 | self.hide_menu = None |
---|
[1bf33c1] | 78 | ## Unique ID (from gui_manager) |
---|
| 79 | self.uid = None |
---|
[66718a1] | 80 | self.x_size = None |
---|
[6063b16] | 81 | ## Default locations |
---|
[c553b18] | 82 | #self._default_save_location = os.getcwd() |
---|
[adf44c2] | 83 | self.size = None |
---|
[1bf33c1] | 84 | ## Graph |
---|
[9f5c8bb] | 85 | #self.graph = Graph() |
---|
[1bf33c1] | 86 | self.graph.xaxis("\\rm{Q}", 'A^{-1}') |
---|
[32c0841] | 87 | self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") |
---|
[1bf33c1] | 88 | self.graph.render(self) |
---|
[ef4a4ea] | 89 | |
---|
[6d727ae] | 90 | # In resizing event |
---|
| 91 | self.resizing = False |
---|
| 92 | self.canvas.set_resizing(self.resizing) |
---|
| 93 | self.Bind(wx.EVT_SIZE, self._OnReSize) |
---|
[c5a769e] | 94 | self._add_more_tool() |
---|
[140fad00] | 95 | self.parent.SetFocus() |
---|
| 96 | |
---|
[a07e72f] | 97 | def get_symbol_label(self): |
---|
[52b8b74] | 98 | """ |
---|
[a07e72f] | 99 | Associates label to symbol |
---|
[52b8b74] | 100 | """ |
---|
[a07e72f] | 101 | _labels = {} |
---|
| 102 | i = 0 |
---|
[6d727ae] | 103 | _labels['Circle'] = i |
---|
[a07e72f] | 104 | i += 1 |
---|
[6d727ae] | 105 | _labels['Cross X '] = i |
---|
[a07e72f] | 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 |
---|
[6d727ae] | 115 | _labels['Cross +'] = i |
---|
[a07e72f] | 116 | i += 1 |
---|
| 117 | _labels['Square'] = i |
---|
| 118 | i += 1 |
---|
[6d727ae] | 119 | _labels['Diamond'] = i |
---|
[a07e72f] | 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 |
---|
[6d727ae] | 129 | _labels['Line'] = i |
---|
[a07e72f] | 130 | return _labels |
---|
[2636188] | 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 |
---|
[ad019b83] | 149 | i += 1 |
---|
| 150 | _labels['Black'] = i |
---|
[2636188] | 151 | return _labels |
---|
[a07e72f] | 152 | |
---|
[52b8b74] | 153 | |
---|
[32c0841] | 154 | def set_data(self, list=None): |
---|
[3c44c66] | 155 | """ |
---|
| 156 | """ |
---|
| 157 | pass |
---|
| 158 | |
---|
[1bf33c1] | 159 | def _reset(self): |
---|
| 160 | """ |
---|
[d955bf19] | 161 | Resets internal data and graph |
---|
[1bf33c1] | 162 | """ |
---|
| 163 | self.graph.reset() |
---|
| 164 | self.plots = {} |
---|
[7022fdc] | 165 | if self.is_zoomed: |
---|
[fd51a7c] | 166 | self.is_zoomed = False |
---|
[6d727ae] | 167 | |
---|
| 168 | def _OnReSize(self, event): |
---|
| 169 | """ |
---|
| 170 | On response of the resize of a panel, set axes_visiable False |
---|
| 171 | """ |
---|
[66718a1] | 172 | # It was found that wx >= 2.9.3 sends an event even if no size changed. |
---|
[294efd5] | 173 | # So manually recode the size (=x_size) and compare here. |
---|
[66718a1] | 174 | if self.x_size != None: |
---|
| 175 | if self.x_size == self.GetSize(): |
---|
[71fa9bb9] | 176 | self.resizing = False |
---|
| 177 | self.canvas.set_resizing(self.resizing) |
---|
[66718a1] | 178 | return |
---|
[294efd5] | 179 | self.x_size = self.GetSize() |
---|
| 180 | |
---|
[ad9e5e1] | 181 | # Ready for another event |
---|
[4520830] | 182 | # Do not remove this Skip. Otherwise it will get runtime error on wx>=2.9. |
---|
[ad9e5e1] | 183 | event.Skip() |
---|
[6d727ae] | 184 | # set the resizing flag |
---|
| 185 | self.resizing = True |
---|
| 186 | self.canvas.set_resizing(self.resizing) |
---|
| 187 | self.parent.set_schedule(True) |
---|
[adf44c2] | 188 | pos_x, pos_y = self.GetPositionTuple() |
---|
| 189 | if pos_x != 0 and pos_y != 0: |
---|
[294efd5] | 190 | self.size, _ = self.GetClientSizeTuple() |
---|
[2b29bb4] | 191 | self.SetSizer(self.sizer) |
---|
[5112838] | 192 | |
---|
[6d727ae] | 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) |
---|
[1bf33c1] | 199 | |
---|
[6d727ae] | 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 | |
---|
[a07e72f] | 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() |
---|
[df22224] | 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] |
---|
[248b918] | 220 | if id in theory_list.keys(): |
---|
[df22224] | 221 | data = theory_list[id] |
---|
[fec4939] | 222 | |
---|
[a07e72f] | 223 | del self.plots[id] |
---|
| 224 | self.graph.render(self) |
---|
| 225 | self.subplot.figure.canvas.draw_idle() |
---|
| 226 | if len(self.graph.plottables) == 0: |
---|
[df22224] | 227 | #onRemove: graph is empty must be the panel must be destroyed |
---|
| 228 | self.parent.delete_panel(self.uid) |
---|
[fec4939] | 229 | |
---|
[a07e72f] | 230 | |
---|
| 231 | def plot_data(self, data): |
---|
[1bf33c1] | 232 | """ |
---|
[d955bf19] | 233 | Data is ready to be displayed |
---|
| 234 | |
---|
| 235 | :param event: data event |
---|
[1bf33c1] | 236 | """ |
---|
[b837e1f] | 237 | if data.__class__.__name__ == 'Data2D': |
---|
| 238 | return |
---|
[a07e72f] | 239 | if data.id in self.plots.keys(): |
---|
[e4a703a] | 240 | #Recover panel prop.s |
---|
| 241 | xlo, xhi = self.subplot.get_xlim() |
---|
| 242 | ylo, yhi = self.subplot.get_ylim() |
---|
[5eede4e] | 243 | old_data = self.plots[data.id] |
---|
[36288ca] | 244 | if self._is_changed_legend_label: |
---|
| 245 | data.label = old_data.label |
---|
[c9579e0] | 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 |
---|
[e4a703a] | 250 | # Replace data |
---|
[a07e72f] | 251 | self.graph.replace(data) |
---|
| 252 | self.plots[data.id] = data |
---|
[e4a703a] | 253 | ## Set the view scale for all plots |
---|
[a4964b8e] | 254 | try: |
---|
| 255 | self._onEVT_FUNC_PROPERTY() |
---|
| 256 | except: |
---|
[4904062] | 257 | msg=" Encountered singular points..." |
---|
| 258 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 259 | "Plotting Error: %s"% msg, info="error")) |
---|
[7022fdc] | 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)) |
---|
[53cf669] | 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(): |
---|
[d74fbff] | 270 | helpString += (' ' + str(plot.label) +';') |
---|
[53cf669] | 271 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
[a07e72f] | 272 | else: |
---|
| 273 | self.plots[data.id] = data |
---|
| 274 | self.graph.add(self.plots[data.id]) |
---|
[e4a703a] | 275 | ## Set the view scale for all plots |
---|
[a4964b8e] | 276 | try: |
---|
| 277 | self._onEVT_FUNC_PROPERTY() |
---|
| 278 | except: |
---|
[4904062] | 279 | msg=" Encountered singular points..." |
---|
| 280 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 281 | "Plotting Error: %s"% msg, info="error")) |
---|
[fe48fcc] | 282 | self.toolbar.update() |
---|
[7022fdc] | 283 | if self.is_zoomed: |
---|
| 284 | self.is_zoomed = False |
---|
[fd51a7c] | 285 | |
---|
[e4a703a] | 286 | |
---|
[6d727ae] | 287 | def draw_plot(self): |
---|
| 288 | """ |
---|
| 289 | Draw plot |
---|
| 290 | """ |
---|
| 291 | self.draw() |
---|
| 292 | |
---|
[1bf33c1] | 293 | def onLeftDown(self,event): |
---|
[6c0568b] | 294 | """ |
---|
[d955bf19] | 295 | left button down and ready to drag |
---|
| 296 | Display the position of the mouse on the statusbar |
---|
[6c0568b] | 297 | """ |
---|
[e85e2bc] | 298 | PlotPanel.onLeftDown(self, event) |
---|
| 299 | ax = event.inaxes |
---|
| 300 | if ax != None: |
---|
[902f373] | 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 |
---|
[0275276] | 310 | # unfocus all |
---|
| 311 | self.parent.set_plot_unfocus() |
---|
[4ed210f4] | 312 | #post nd event to notify guiframe that this panel is on focus |
---|
[a45037aa] | 313 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[df68da1] | 314 | |
---|
[4ed210f4] | 315 | |
---|
[a07e72f] | 316 | def _ontoggle_hide_error(self, event): |
---|
| 317 | """ |
---|
| 318 | Toggle error display to hide or show |
---|
| 319 | """ |
---|
[70ec588d] | 320 | menu = event.GetEventObject() |
---|
| 321 | id = event.GetId() |
---|
| 322 | self.set_selected_from_menu(menu, id) |
---|
[ebf422a] | 323 | # Check zoom |
---|
| 324 | xlo, xhi = self.subplot.get_xlim() |
---|
| 325 | ylo, yhi = self.subplot.get_ylim() |
---|
| 326 | |
---|
[a07e72f] | 327 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[5637362] | 328 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
[a07e72f] | 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() |
---|
[ebf422a] | 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 | |
---|
[a07e72f] | 342 | |
---|
[1bf33c1] | 343 | def _onRemove(self, event): |
---|
| 344 | """ |
---|
[d955bf19] | 345 | Remove a plottable from the graph and render the graph |
---|
| 346 | |
---|
| 347 | :param event: Menu event |
---|
| 348 | |
---|
[1bf33c1] | 349 | """ |
---|
[70ec588d] | 350 | menu = event.GetEventObject() |
---|
| 351 | id = event.GetId() |
---|
| 352 | self.set_selected_from_menu(menu, id) |
---|
[6c0568b] | 353 | ## Check if there is a selected graph to remove |
---|
[a07e72f] | 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 |
---|
[df22224] | 357 | self.remove_data_by_id(id) |
---|
| 358 | |
---|
[1bf33c1] | 359 | def onContextMenu(self, event): |
---|
| 360 | """ |
---|
[d955bf19] | 361 | 1D plot context menu |
---|
| 362 | |
---|
| 363 | :param event: wx context event |
---|
| 364 | |
---|
[1bf33c1] | 365 | """ |
---|
[52b8b74] | 366 | self._slicerpop = PanelMenu() |
---|
| 367 | self._slicerpop.set_plots(self.plots) |
---|
[70ec588d] | 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) |
---|
[a436b2e] | 380 | |
---|
[6d727ae] | 381 | id = wx.NewId() |
---|
[70ec588d] | 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 |
---|
[6d727ae] | 389 | name = plot.name |
---|
[70ec588d] | 390 | plot_menu = wx.Menu() |
---|
[242aff5] | 391 | if self.graph.selected_plottable: |
---|
[4a9bce1] | 392 | if not self.graph.selected_plottable in self.plots.keys(): |
---|
| 393 | continue |
---|
[242aff5] | 394 | if plot != self.plots[self.graph.selected_plottable]: |
---|
| 395 | continue |
---|
[70ec588d] | 396 | #add menu of other plugins |
---|
| 397 | item_list = self.parent.get_context_menu(self) |
---|
[242aff5] | 398 | |
---|
[70ec588d] | 399 | if (not item_list == None) and (not len(item_list) == 0): |
---|
| 400 | for item in item_list: |
---|
[242aff5] | 401 | |
---|
[70ec588d] | 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) |
---|
[2d443fd] | 415 | wx.EVT_MENU(self, id, self._onSave) |
---|
[70ec588d] | 416 | plot_menu.AppendSeparator() |
---|
[73eb92fc] | 417 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
[e6a93df] | 418 | id = wx.NewId() |
---|
[70ec588d] | 419 | plot_menu.Append(id, '&Linear Fit', name) |
---|
[a436b2e] | 420 | wx.EVT_MENU(self, id, self.onFitting) |
---|
[70ec588d] | 421 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 422 | |
---|
[a3c96f7a] | 423 | id = wx.NewId() |
---|
[70ec588d] | 424 | plot_menu.Append(id, "Remove", name) |
---|
[a436b2e] | 425 | wx.EVT_MENU(self, id, self._onRemove) |
---|
| 426 | if not plot.is_data: |
---|
| 427 | id = wx.NewId() |
---|
[70ec588d] | 428 | plot_menu.Append(id, '&Freeze', name) |
---|
[a436b2e] | 429 | wx.EVT_MENU(self, id, self.onFreeze) |
---|
[70ec588d] | 430 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 431 | symbol_menu = wx.Menu() |
---|
| 432 | for label in self._symbol_labels: |
---|
| 433 | id = wx.NewId() |
---|
[70ec588d] | 434 | symbol_menu.Append(id, str(label), name) |
---|
[a436b2e] | 435 | wx.EVT_MENU(self, id, self.onChangeSymbol) |
---|
| 436 | id = wx.NewId() |
---|
[70ec588d] | 437 | plot_menu.AppendMenu(id,'&Modify Symbol', symbol_menu, name) |
---|
[2636188] | 438 | |
---|
| 439 | color_menu = wx.Menu() |
---|
| 440 | for label in self._color_labels: |
---|
| 441 | id = wx.NewId() |
---|
[70ec588d] | 442 | color_menu.Append(id, str(label), name) |
---|
[2636188] | 443 | wx.EVT_MENU(self, id, self.onChangeColor) |
---|
| 444 | id = wx.NewId() |
---|
[70ec588d] | 445 | plot_menu.AppendMenu(id, '&Modify Symbol Color', |
---|
| 446 | color_menu, name) |
---|
[2636188] | 447 | |
---|
| 448 | size_menu = wx.Menu() |
---|
| 449 | for i in range(10): |
---|
| 450 | id = wx.NewId() |
---|
[70ec588d] | 451 | size_menu.Append(id, str(i), name) |
---|
[2636188] | 452 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
| 453 | id = wx.NewId() |
---|
[70ec588d] | 454 | size_menu.Append(id, '&Custom', name) |
---|
[2636188] | 455 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
| 456 | id = wx.NewId() |
---|
[70ec588d] | 457 | plot_menu.AppendMenu(id, '&Modify Symbol Size', |
---|
| 458 | size_menu, name) |
---|
[2636188] | 459 | |
---|
[70ec588d] | 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') |
---|
[a436b2e] | 469 | else: |
---|
[70ec588d] | 470 | self.hide_menu.Enable(False) |
---|
| 471 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
[a436b2e] | 472 | |
---|
[70ec588d] | 473 | plot_menu.AppendSeparator() |
---|
[e1714a9] | 474 | id = wx.NewId() |
---|
[70ec588d] | 475 | plot_menu.Append(id, '&Edit Legend Label', name) |
---|
[e1714a9] | 476 | wx.EVT_MENU(self, id, self.onEditLabels) |
---|
[70ec588d] | 477 | id = wx.NewId() |
---|
| 478 | #plot_menu.SetTitle(name) |
---|
| 479 | self._slicerpop.AppendMenu(id, '&%s'% name, plot_menu) |
---|
[a436b2e] | 480 | # Option to hide |
---|
| 481 | #TODO: implement functionality to hide a plottable (legend click) |
---|
[70ec588d] | 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) |
---|
[e1714a9] | 489 | id = wx.NewId() |
---|
[70ec588d] | 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 | |
---|
[ef4a4ea] | 504 | id = wx.NewId() |
---|
[70ec588d] | 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() |
---|
[ef4a4ea] | 517 | id = wx.NewId() |
---|
[70ec588d] | 518 | self._slicerpop.Append(id, '&Change Scale') |
---|
| 519 | wx.EVT_MENU(self, id, self._onProperties) |
---|
[857d00f] | 520 | self._slicerpop.AppendSeparator() |
---|
[70ec588d] | 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) |
---|
[dc51a7f] | 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) |
---|
[52b8b74] | 536 | self.PopupMenu(self._slicerpop, pos) |
---|
[70ec588d] | 537 | |
---|
[e6a93df] | 538 | def onFreeze(self, event): |
---|
| 539 | """ |
---|
| 540 | """ |
---|
[70ec588d] | 541 | menu = event.GetEventObject() |
---|
| 542 | id = event.GetId() |
---|
| 543 | self.set_selected_from_menu(menu, id) |
---|
[e6a93df] | 544 | plot = self.plots[self.graph.selected_plottable] |
---|
| 545 | self.parent.onfreeze([plot.id]) |
---|
[d7d1255e] | 546 | |
---|
[6d52f21d] | 547 | def onEditLabels(self, event): |
---|
| 548 | """ |
---|
[d7d1255e] | 549 | Edit legend label |
---|
[6d52f21d] | 550 | """ |
---|
[70ec588d] | 551 | menu = event.GetEventObject() |
---|
| 552 | id = event.GetId() |
---|
| 553 | self.set_selected_from_menu(menu, id) |
---|
[6d52f21d] | 554 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[d7d1255e] | 555 | label = selected_plot.label |
---|
| 556 | dial = LabelDialog(None, -1, 'Change Legend Label', label) |
---|
[6d52f21d] | 557 | if dial.ShowModal() == wx.ID_OK: |
---|
[d7d1255e] | 558 | newLabel = dial.getText() |
---|
| 559 | selected_plot.label = newLabel |
---|
[53cf669] | 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(): |
---|
[e2160ab] | 564 | helpString += (' ' + str(plot.label) +';') |
---|
[53cf669] | 565 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
[36288ca] | 566 | self._is_changed_legend_label = True |
---|
[53cf669] | 567 | #break |
---|
[6d52f21d] | 568 | dial.Destroy() |
---|
[53cf669] | 569 | |
---|
[d7d1255e] | 570 | ## render the graph |
---|
[a4964b8e] | 571 | try: |
---|
| 572 | self._onEVT_FUNC_PROPERTY() |
---|
| 573 | except: |
---|
[4904062] | 574 | msg=" Encountered singular points..." |
---|
| 575 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 576 | "Plotting Erorr: %s"% msg, info="error")) |
---|
[a4964b8e] | 577 | |
---|
[2636188] | 578 | def onChangeColor(self, event): |
---|
| 579 | """ |
---|
| 580 | Changes the color of the graph when selected |
---|
| 581 | """ |
---|
| 582 | menu = event.GetEventObject() |
---|
| 583 | id = event.GetId() |
---|
[70ec588d] | 584 | self.set_selected_from_menu(menu, id) |
---|
[2636188] | 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 |
---|
[e6c6b67] | 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)) |
---|
[2636188] | 594 | |
---|
| 595 | def onChangeSize(self, event): |
---|
[70ec588d] | 596 | """ |
---|
| 597 | On Change size menu |
---|
| 598 | """ |
---|
[2636188] | 599 | menu = event.GetEventObject() |
---|
| 600 | id = event.GetId() |
---|
[70ec588d] | 601 | self.set_selected_from_menu(menu, id) |
---|
[2636188] | 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: |
---|
[30ccad1] | 608 | try: |
---|
| 609 | label = sizedial.getText() |
---|
[1e35434] | 610 | |
---|
[30ccad1] | 611 | except: |
---|
| 612 | msg = 'Symbol Size: Got an invalid Value.' |
---|
| 613 | wx.PostEvent( self.parent, |
---|
| 614 | StatusEvent(status= msg, info='error')) |
---|
[2636188] | 615 | sizedial.Destroy() |
---|
[c0e747c] | 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')) |
---|
[2636188] | 623 | |
---|
| 624 | |
---|
[a07e72f] | 625 | def onChangeSymbol(self, event): |
---|
[6c0568b] | 626 | """ |
---|
| 627 | """ |
---|
[a07e72f] | 628 | menu = event.GetEventObject() |
---|
| 629 | id = event.GetId() |
---|
[70ec588d] | 630 | self.set_selected_from_menu(menu, id) |
---|
[a07e72f] | 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 |
---|
[e6c6b67] | 635 | self._check_zoom_plot() |
---|
| 636 | #self._onEVT_FUNC_PROPERTY() |
---|
[a07e72f] | 637 | ## render the graph |
---|
[6d727ae] | 638 | #self.graph.render(self) |
---|
| 639 | #self.subplot.figure.canvas.draw_idle() |
---|
[176fbf1] | 640 | |
---|
[1bf33c1] | 641 | def _onSave(self, evt): |
---|
| 642 | """ |
---|
[d955bf19] | 643 | Save a data set to a text file |
---|
| 644 | |
---|
| 645 | :param evt: Menu event |
---|
| 646 | |
---|
[1bf33c1] | 647 | """ |
---|
[70ec588d] | 648 | menu = evt.GetEventObject() |
---|
| 649 | id = evt.GetId() |
---|
| 650 | self.set_selected_from_menu(menu, id) |
---|
[176fbf1] | 651 | data = self.plots[self.graph.selected_plottable] |
---|
| 652 | default_name = data.label |
---|
[c553b18] | 653 | if default_name.count('.') > 0: |
---|
| 654 | default_name = default_name.split('.')[0] |
---|
| 655 | default_name += "_out" |
---|
| 656 | if self.parent != None: |
---|
[176fbf1] | 657 | self.parent.save_data1d(data, default_name) |
---|
[c5a769e] | 658 | |
---|
| 659 | def _add_more_tool(self): |
---|
| 660 | """ |
---|
[6d52f21d] | 661 | Add refresh, add/delete button in the tool bar |
---|
[c5a769e] | 662 | """ |
---|
| 663 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
| 664 | return |
---|
| 665 | self.toolbar.AddSeparator() |
---|
| 666 | id_delete = wx.NewId() |
---|
[9149431] | 667 | delete = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR) |
---|
[c5a769e] | 668 | self.toolbar.AddSimpleTool(id_delete, delete, |
---|
[fb40dbb] | 669 | 'Delete', 'permanently Delete') |
---|
[c5a769e] | 670 | |
---|
| 671 | self.toolbar.Realize() |
---|
| 672 | wx.EVT_TOOL(self, id_delete, self._on_delete) |
---|
[6d52f21d] | 673 | |
---|
[dc51a7f] | 674 | """ |
---|
[6d52f21d] | 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) |
---|
[886657f] | 683 | """ |
---|
[c5a769e] | 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")) |
---|
[6d52f21d] | 693 | |
---|
[c5a769e] | 694 | |
---|