[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) |
---|
[7fb69f26] | 192 | wx.CallAfter(self.parent.disable_app_menu,self) |
---|
[5112838] | 193 | |
---|
[6d727ae] | 194 | def set_resizing(self, resizing=False): |
---|
| 195 | """ |
---|
| 196 | Set the resizing (True/False) |
---|
| 197 | """ |
---|
| 198 | self.resizing = resizing |
---|
| 199 | #self.canvas.set_resizing(resizing) |
---|
[1bf33c1] | 200 | |
---|
[6d727ae] | 201 | def schedule_full_draw(self, func='append'): |
---|
| 202 | """ |
---|
| 203 | Put self in schedule to full redraw list |
---|
| 204 | """ |
---|
| 205 | # append/del this panel in the schedule list |
---|
| 206 | self.parent.set_schedule_full_draw(self, func) |
---|
| 207 | |
---|
| 208 | |
---|
[a07e72f] | 209 | def remove_data_by_id(self, id): |
---|
| 210 | """' |
---|
| 211 | remove data from plot |
---|
| 212 | """ |
---|
| 213 | if id in self.plots.keys(): |
---|
| 214 | data = self.plots[id] |
---|
| 215 | self.graph.delete(data) |
---|
| 216 | data_manager = self._manager.parent.get_data_manager() |
---|
[df22224] | 217 | data_list, theory_list = data_manager.get_by_id(id_list=[id]) |
---|
| 218 | |
---|
| 219 | if id in data_list.keys(): |
---|
| 220 | data = data_list[id] |
---|
[248b918] | 221 | if id in theory_list.keys(): |
---|
[df22224] | 222 | data = theory_list[id] |
---|
[fec4939] | 223 | |
---|
[a07e72f] | 224 | del self.plots[id] |
---|
| 225 | self.graph.render(self) |
---|
| 226 | self.subplot.figure.canvas.draw_idle() |
---|
| 227 | if len(self.graph.plottables) == 0: |
---|
[df22224] | 228 | #onRemove: graph is empty must be the panel must be destroyed |
---|
| 229 | self.parent.delete_panel(self.uid) |
---|
[fec4939] | 230 | |
---|
[a07e72f] | 231 | |
---|
| 232 | def plot_data(self, data): |
---|
[1bf33c1] | 233 | """ |
---|
[d955bf19] | 234 | Data is ready to be displayed |
---|
| 235 | |
---|
| 236 | :param event: data event |
---|
[1bf33c1] | 237 | """ |
---|
[b837e1f] | 238 | if data.__class__.__name__ == 'Data2D': |
---|
| 239 | return |
---|
[a07e72f] | 240 | if data.id in self.plots.keys(): |
---|
[e4a703a] | 241 | #Recover panel prop.s |
---|
| 242 | xlo, xhi = self.subplot.get_xlim() |
---|
| 243 | ylo, yhi = self.subplot.get_ylim() |
---|
[5eede4e] | 244 | old_data = self.plots[data.id] |
---|
[36288ca] | 245 | if self._is_changed_legend_label: |
---|
| 246 | data.label = old_data.label |
---|
[c9579e0] | 247 | if old_data.__class__.__name__ == 'Data1D': |
---|
| 248 | data.custom_color = old_data.custom_color |
---|
| 249 | data.symbol = old_data.symbol |
---|
| 250 | data.markersize = old_data.markersize |
---|
[e4a703a] | 251 | # Replace data |
---|
[a07e72f] | 252 | self.graph.replace(data) |
---|
| 253 | self.plots[data.id] = data |
---|
[e4a703a] | 254 | ## Set the view scale for all plots |
---|
[a4964b8e] | 255 | try: |
---|
| 256 | self._onEVT_FUNC_PROPERTY() |
---|
| 257 | except: |
---|
[4904062] | 258 | msg=" Encountered singular points..." |
---|
| 259 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 260 | "Plotting Error: %s"% msg, info="error")) |
---|
[7022fdc] | 261 | # Check if zoomed |
---|
| 262 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
| 263 | if self.is_zoomed or toolbar_zoomed: |
---|
| 264 | # Recover the x,y limits |
---|
| 265 | self.subplot.set_xlim((xlo, xhi)) |
---|
| 266 | self.subplot.set_ylim((ylo, yhi)) |
---|
[53cf669] | 267 | # Update Graph menu and help string |
---|
| 268 | pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
| 269 | helpString = 'Show/Hide Graph: ' |
---|
| 270 | for plot in self.plots.itervalues(): |
---|
[d74fbff] | 271 | helpString += (' ' + str(plot.label) +';') |
---|
[53cf669] | 272 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
[a07e72f] | 273 | else: |
---|
| 274 | self.plots[data.id] = data |
---|
| 275 | self.graph.add(self.plots[data.id]) |
---|
[e4a703a] | 276 | ## Set the view scale for all plots |
---|
[a4964b8e] | 277 | try: |
---|
| 278 | self._onEVT_FUNC_PROPERTY() |
---|
| 279 | except: |
---|
[4904062] | 280 | msg=" Encountered singular points..." |
---|
| 281 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 282 | "Plotting Error: %s"% msg, info="error")) |
---|
[fe48fcc] | 283 | self.toolbar.update() |
---|
[7022fdc] | 284 | if self.is_zoomed: |
---|
| 285 | self.is_zoomed = False |
---|
[fd51a7c] | 286 | |
---|
[e4a703a] | 287 | |
---|
[6d727ae] | 288 | def draw_plot(self): |
---|
| 289 | """ |
---|
| 290 | Draw plot |
---|
| 291 | """ |
---|
| 292 | self.draw() |
---|
| 293 | |
---|
[1bf33c1] | 294 | def onLeftDown(self,event): |
---|
[6c0568b] | 295 | """ |
---|
[d955bf19] | 296 | left button down and ready to drag |
---|
| 297 | Display the position of the mouse on the statusbar |
---|
[6c0568b] | 298 | """ |
---|
[e85e2bc] | 299 | PlotPanel.onLeftDown(self, event) |
---|
| 300 | ax = event.inaxes |
---|
| 301 | if ax != None: |
---|
[902f373] | 302 | try: |
---|
| 303 | pos_x = float(event.xdata)# / size_x |
---|
| 304 | pos_y = float(event.ydata)# / size_y |
---|
| 305 | pos_x = "%8.3g"% pos_x |
---|
| 306 | pos_y = "%8.3g"% pos_y |
---|
| 307 | self.position = str(pos_x), str(pos_y) |
---|
| 308 | wx.PostEvent(self.parent, StatusEvent(status=self.position)) |
---|
| 309 | except: |
---|
| 310 | self.position = None |
---|
[0275276] | 311 | # unfocus all |
---|
| 312 | self.parent.set_plot_unfocus() |
---|
[4ed210f4] | 313 | #post nd event to notify guiframe that this panel is on focus |
---|
[a45037aa] | 314 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[df68da1] | 315 | |
---|
[4ed210f4] | 316 | |
---|
[a07e72f] | 317 | def _ontoggle_hide_error(self, event): |
---|
| 318 | """ |
---|
| 319 | Toggle error display to hide or show |
---|
| 320 | """ |
---|
[70ec588d] | 321 | menu = event.GetEventObject() |
---|
| 322 | id = event.GetId() |
---|
| 323 | self.set_selected_from_menu(menu, id) |
---|
[ebf422a] | 324 | # Check zoom |
---|
| 325 | xlo, xhi = self.subplot.get_xlim() |
---|
| 326 | ylo, yhi = self.subplot.get_ylim() |
---|
| 327 | |
---|
[a07e72f] | 328 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[5637362] | 329 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
[a07e72f] | 330 | selected_plot.hide_error = True |
---|
| 331 | else: |
---|
| 332 | selected_plot.hide_error = False |
---|
| 333 | ## increment graph color |
---|
| 334 | self.graph.render(self) |
---|
| 335 | self.subplot.figure.canvas.draw_idle() |
---|
[ebf422a] | 336 | # Check if zoomed |
---|
| 337 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
| 338 | if self.is_zoomed or toolbar_zoomed: |
---|
| 339 | # Recover the x,y limits |
---|
| 340 | self.subplot.set_xlim((xlo, xhi)) |
---|
| 341 | self.subplot.set_ylim((ylo, yhi)) |
---|
| 342 | |
---|
[a07e72f] | 343 | |
---|
[1bf33c1] | 344 | def _onRemove(self, event): |
---|
| 345 | """ |
---|
[d955bf19] | 346 | Remove a plottable from the graph and render the graph |
---|
| 347 | |
---|
| 348 | :param event: Menu event |
---|
| 349 | |
---|
[1bf33c1] | 350 | """ |
---|
[70ec588d] | 351 | menu = event.GetEventObject() |
---|
| 352 | id = event.GetId() |
---|
| 353 | self.set_selected_from_menu(menu, id) |
---|
[6c0568b] | 354 | ## Check if there is a selected graph to remove |
---|
[a07e72f] | 355 | if self.graph.selected_plottable in self.plots.keys(): |
---|
| 356 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
| 357 | id = self.graph.selected_plottable |
---|
[df22224] | 358 | self.remove_data_by_id(id) |
---|
| 359 | |
---|
[1bf33c1] | 360 | def onContextMenu(self, event): |
---|
| 361 | """ |
---|
[d955bf19] | 362 | 1D plot context menu |
---|
| 363 | |
---|
| 364 | :param event: wx context event |
---|
| 365 | |
---|
[1bf33c1] | 366 | """ |
---|
[52b8b74] | 367 | self._slicerpop = PanelMenu() |
---|
| 368 | self._slicerpop.set_plots(self.plots) |
---|
[70ec588d] | 369 | self._slicerpop.set_graph(self.graph) |
---|
| 370 | if not self.graph.selected_plottable in self.plots: |
---|
| 371 | # Various plot options |
---|
| 372 | id = wx.NewId() |
---|
| 373 | self._slicerpop.Append(id, '&Save Image', 'Save image as PNG') |
---|
| 374 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
| 375 | id = wx.NewId() |
---|
| 376 | self._slicerpop.Append(id, '&Print Image', 'Print image ') |
---|
| 377 | wx.EVT_MENU(self, id, self.onPrint) |
---|
| 378 | id = wx.NewId() |
---|
| 379 | self._slicerpop.Append(id, '&Print Preview', 'Print preview') |
---|
| 380 | wx.EVT_MENU(self, id, self.onPrinterPreview) |
---|
[a436b2e] | 381 | |
---|
[6d727ae] | 382 | id = wx.NewId() |
---|
[70ec588d] | 383 | self._slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') |
---|
| 384 | wx.EVT_MENU(self, id, self.OnCopyFigureMenu) |
---|
| 385 | |
---|
| 386 | self._slicerpop.AppendSeparator() |
---|
| 387 | |
---|
| 388 | for plot in self.plots.values(): |
---|
| 389 | #title = plot.title |
---|
[6d727ae] | 390 | name = plot.name |
---|
[70ec588d] | 391 | plot_menu = wx.Menu() |
---|
[242aff5] | 392 | if self.graph.selected_plottable: |
---|
[4a9bce1] | 393 | if not self.graph.selected_plottable in self.plots.keys(): |
---|
| 394 | continue |
---|
[242aff5] | 395 | if plot != self.plots[self.graph.selected_plottable]: |
---|
| 396 | continue |
---|
[70ec588d] | 397 | #add menu of other plugins |
---|
| 398 | item_list = self.parent.get_context_menu(self) |
---|
[242aff5] | 399 | |
---|
[70ec588d] | 400 | if (not item_list == None) and (not len(item_list) == 0): |
---|
| 401 | for item in item_list: |
---|
[242aff5] | 402 | |
---|
[70ec588d] | 403 | try: |
---|
| 404 | id = wx.NewId() |
---|
| 405 | plot_menu.Append(id, item[0], name) |
---|
| 406 | wx.EVT_MENU(self, id, item[2]) |
---|
| 407 | except: |
---|
| 408 | msg = "ModelPanel1D.onContextMenu: " |
---|
| 409 | msg += "bad menu item %s" % sys.exc_value |
---|
| 410 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
| 411 | pass |
---|
| 412 | plot_menu.AppendSeparator() |
---|
[0aca693] | 413 | |
---|
| 414 | id = wx.NewId() |
---|
| 415 | plot_menu.Append(id, "&DataInfo", name) |
---|
| 416 | wx.EVT_MENU(self, id, self. _onDataShow) |
---|
[70ec588d] | 417 | id = wx.NewId() |
---|
| 418 | plot_menu.Append(id, "&Save Points as a File", name) |
---|
[2d443fd] | 419 | wx.EVT_MENU(self, id, self._onSave) |
---|
[70ec588d] | 420 | plot_menu.AppendSeparator() |
---|
[73eb92fc] | 421 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
[e6a93df] | 422 | id = wx.NewId() |
---|
[70ec588d] | 423 | plot_menu.Append(id, '&Linear Fit', name) |
---|
[a436b2e] | 424 | wx.EVT_MENU(self, id, self.onFitting) |
---|
[70ec588d] | 425 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 426 | |
---|
[a3c96f7a] | 427 | id = wx.NewId() |
---|
[70ec588d] | 428 | plot_menu.Append(id, "Remove", name) |
---|
[a436b2e] | 429 | wx.EVT_MENU(self, id, self._onRemove) |
---|
| 430 | if not plot.is_data: |
---|
| 431 | id = wx.NewId() |
---|
[70ec588d] | 432 | plot_menu.Append(id, '&Freeze', name) |
---|
[a436b2e] | 433 | wx.EVT_MENU(self, id, self.onFreeze) |
---|
[70ec588d] | 434 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 435 | symbol_menu = wx.Menu() |
---|
| 436 | for label in self._symbol_labels: |
---|
| 437 | id = wx.NewId() |
---|
[70ec588d] | 438 | symbol_menu.Append(id, str(label), name) |
---|
[a436b2e] | 439 | wx.EVT_MENU(self, id, self.onChangeSymbol) |
---|
| 440 | id = wx.NewId() |
---|
[70ec588d] | 441 | plot_menu.AppendMenu(id,'&Modify Symbol', symbol_menu, name) |
---|
[2636188] | 442 | |
---|
| 443 | color_menu = wx.Menu() |
---|
| 444 | for label in self._color_labels: |
---|
| 445 | id = wx.NewId() |
---|
[70ec588d] | 446 | color_menu.Append(id, str(label), name) |
---|
[2636188] | 447 | wx.EVT_MENU(self, id, self.onChangeColor) |
---|
| 448 | id = wx.NewId() |
---|
[70ec588d] | 449 | plot_menu.AppendMenu(id, '&Modify Symbol Color', |
---|
| 450 | color_menu, name) |
---|
[2636188] | 451 | |
---|
| 452 | size_menu = wx.Menu() |
---|
| 453 | for i in range(10): |
---|
| 454 | id = wx.NewId() |
---|
[70ec588d] | 455 | size_menu.Append(id, str(i), name) |
---|
[2636188] | 456 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
| 457 | id = wx.NewId() |
---|
[70ec588d] | 458 | size_menu.Append(id, '&Custom', name) |
---|
[2636188] | 459 | wx.EVT_MENU(self, id, self.onChangeSize) |
---|
| 460 | id = wx.NewId() |
---|
[70ec588d] | 461 | plot_menu.AppendMenu(id, '&Modify Symbol Size', |
---|
| 462 | size_menu, name) |
---|
[2636188] | 463 | |
---|
[70ec588d] | 464 | if plot.is_data: |
---|
| 465 | self.hide_menu = plot_menu.Append(id, |
---|
| 466 | "Hide Error Bar", name) |
---|
| 467 | |
---|
| 468 | if plot.dy is not None and plot.dy != []: |
---|
| 469 | if plot.hide_error : |
---|
| 470 | self.hide_menu.SetText('Show Error Bar') |
---|
| 471 | else: |
---|
| 472 | self.hide_menu.SetText('Hide Error Bar') |
---|
[a436b2e] | 473 | else: |
---|
[70ec588d] | 474 | self.hide_menu.Enable(False) |
---|
| 475 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
[a436b2e] | 476 | |
---|
[70ec588d] | 477 | plot_menu.AppendSeparator() |
---|
[e1714a9] | 478 | id = wx.NewId() |
---|
[70ec588d] | 479 | plot_menu.Append(id, '&Edit Legend Label', name) |
---|
[e1714a9] | 480 | wx.EVT_MENU(self, id, self.onEditLabels) |
---|
[70ec588d] | 481 | id = wx.NewId() |
---|
| 482 | #plot_menu.SetTitle(name) |
---|
| 483 | self._slicerpop.AppendMenu(id, '&%s'% name, plot_menu) |
---|
[a436b2e] | 484 | # Option to hide |
---|
| 485 | #TODO: implement functionality to hide a plottable (legend click) |
---|
[70ec588d] | 486 | if not self.graph.selected_plottable in self.plots: |
---|
| 487 | self._slicerpop.AppendSeparator() |
---|
| 488 | loc_menu = wx.Menu() |
---|
| 489 | for label in self._loc_labels: |
---|
| 490 | id = wx.NewId() |
---|
| 491 | loc_menu.Append(id, str(label), str(label)) |
---|
| 492 | wx.EVT_MENU(self, id, self.onChangeLegendLoc) |
---|
[e1714a9] | 493 | id = wx.NewId() |
---|
[70ec588d] | 494 | self._slicerpop.AppendMenu(id, '&Modify Legend Location', loc_menu) |
---|
| 495 | |
---|
| 496 | id = wx.NewId() |
---|
| 497 | self._slicerpop.Append(id, '&Toggle Legend On/Off', 'Toggle Legend On/Off') |
---|
| 498 | wx.EVT_MENU(self, id, self.onLegend) |
---|
| 499 | self._slicerpop.AppendSeparator() |
---|
| 500 | |
---|
| 501 | id = wx.NewId() |
---|
| 502 | self._slicerpop.Append(id, '&Edit Y Axis Label') |
---|
| 503 | wx.EVT_MENU(self, id, self._on_yaxis_label) |
---|
| 504 | id = wx.NewId() |
---|
| 505 | self._slicerpop.Append(id, '&Edit X Axis Label') |
---|
| 506 | wx.EVT_MENU(self, id, self._on_xaxis_label) |
---|
| 507 | |
---|
[ef4a4ea] | 508 | id = wx.NewId() |
---|
[70ec588d] | 509 | self._slicerpop.Append(id, '&Toggle Grid On/Off', 'Toggle Grid On/Off') |
---|
| 510 | wx.EVT_MENU(self, id, self.onGridOnOff) |
---|
| 511 | self._slicerpop.AppendSeparator() |
---|
| 512 | |
---|
| 513 | if self.position != None: |
---|
| 514 | id = wx.NewId() |
---|
| 515 | self._slicerpop.Append(id, '&Add Text') |
---|
| 516 | wx.EVT_MENU(self, id, self._on_addtext) |
---|
| 517 | id = wx.NewId() |
---|
| 518 | self._slicerpop.Append(id, '&Remove Text') |
---|
| 519 | wx.EVT_MENU(self, id, self._on_removetext) |
---|
| 520 | self._slicerpop.AppendSeparator() |
---|
[ef4a4ea] | 521 | id = wx.NewId() |
---|
[70ec588d] | 522 | self._slicerpop.Append(id, '&Change Scale') |
---|
| 523 | wx.EVT_MENU(self, id, self._onProperties) |
---|
[857d00f] | 524 | self._slicerpop.AppendSeparator() |
---|
[70ec588d] | 525 | id = wx.NewId() |
---|
| 526 | self._slicerpop.Append(id, '&Reset Graph Range') |
---|
| 527 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
| 528 | |
---|
| 529 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
| 530 | self._slicerpop.AppendSeparator() |
---|
| 531 | id = wx.NewId() |
---|
| 532 | self._slicerpop.Append(id, '&Window Title') |
---|
| 533 | wx.EVT_MENU(self, id, self.onChangeCaption) |
---|
[dc51a7f] | 534 | try: |
---|
| 535 | pos_evt = event.GetPosition() |
---|
| 536 | pos = self.ScreenToClient(pos_evt) |
---|
| 537 | except: |
---|
| 538 | pos_x, pos_y = self.toolbar.GetPositionTuple() |
---|
| 539 | pos = (pos_x, pos_y + 5) |
---|
[52b8b74] | 540 | self.PopupMenu(self._slicerpop, pos) |
---|
[70ec588d] | 541 | |
---|
[e6a93df] | 542 | def onFreeze(self, event): |
---|
| 543 | """ |
---|
| 544 | """ |
---|
[70ec588d] | 545 | menu = event.GetEventObject() |
---|
| 546 | id = event.GetId() |
---|
| 547 | self.set_selected_from_menu(menu, id) |
---|
[e6a93df] | 548 | plot = self.plots[self.graph.selected_plottable] |
---|
| 549 | self.parent.onfreeze([plot.id]) |
---|
[d7d1255e] | 550 | |
---|
[6d52f21d] | 551 | def onEditLabels(self, event): |
---|
| 552 | """ |
---|
[d7d1255e] | 553 | Edit legend label |
---|
[6d52f21d] | 554 | """ |
---|
[70ec588d] | 555 | menu = event.GetEventObject() |
---|
| 556 | id = event.GetId() |
---|
| 557 | self.set_selected_from_menu(menu, id) |
---|
[6d52f21d] | 558 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[d7d1255e] | 559 | label = selected_plot.label |
---|
| 560 | dial = LabelDialog(None, -1, 'Change Legend Label', label) |
---|
[6d52f21d] | 561 | if dial.ShowModal() == wx.ID_OK: |
---|
[d7d1255e] | 562 | newLabel = dial.getText() |
---|
| 563 | selected_plot.label = newLabel |
---|
[53cf669] | 564 | # Updata Graph menu help string |
---|
| 565 | pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
| 566 | helpString = 'Show/Hide Graph: ' |
---|
| 567 | for plot in self.plots.itervalues(): |
---|
[e2160ab] | 568 | helpString += (' ' + str(plot.label) +';') |
---|
[53cf669] | 569 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
[36288ca] | 570 | self._is_changed_legend_label = True |
---|
[53cf669] | 571 | #break |
---|
[6d52f21d] | 572 | dial.Destroy() |
---|
[53cf669] | 573 | |
---|
[d7d1255e] | 574 | ## render the graph |
---|
[a4964b8e] | 575 | try: |
---|
| 576 | self._onEVT_FUNC_PROPERTY() |
---|
| 577 | except: |
---|
[4904062] | 578 | msg=" Encountered singular points..." |
---|
| 579 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 580 | "Plotting Erorr: %s"% msg, info="error")) |
---|
[a4964b8e] | 581 | |
---|
[2636188] | 582 | def onChangeColor(self, event): |
---|
| 583 | """ |
---|
| 584 | Changes the color of the graph when selected |
---|
| 585 | """ |
---|
| 586 | menu = event.GetEventObject() |
---|
| 587 | id = event.GetId() |
---|
[70ec588d] | 588 | self.set_selected_from_menu(menu, id) |
---|
[2636188] | 589 | label = menu.GetLabel(id) |
---|
| 590 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
| 591 | selected_plot.custom_color = self._color_labels[label] |
---|
| 592 | ## Set the view scale for all plots |
---|
[e6c6b67] | 593 | self._check_zoom_plot() |
---|
| 594 | #self._onEVT_FUNC_PROPERTY() |
---|
| 595 | #wx.PostEvent(self.parent, |
---|
| 596 | # NewColorEvent(color=selected_plot.custom_color, |
---|
| 597 | # id=selected_plot.id)) |
---|
[2636188] | 598 | |
---|
| 599 | def onChangeSize(self, event): |
---|
[70ec588d] | 600 | """ |
---|
| 601 | On Change size menu |
---|
| 602 | """ |
---|
[2636188] | 603 | menu = event.GetEventObject() |
---|
| 604 | id = event.GetId() |
---|
[70ec588d] | 605 | self.set_selected_from_menu(menu, id) |
---|
[2636188] | 606 | label = menu.GetLabel(id) |
---|
| 607 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
| 608 | |
---|
| 609 | if label == "&Custom": |
---|
| 610 | sizedial = SizeDialog(None, -1, 'Change Marker Size') |
---|
| 611 | if sizedial.ShowModal() == wx.ID_OK: |
---|
[30ccad1] | 612 | try: |
---|
| 613 | label = sizedial.getText() |
---|
[1e35434] | 614 | |
---|
[30ccad1] | 615 | except: |
---|
| 616 | msg = 'Symbol Size: Got an invalid Value.' |
---|
| 617 | wx.PostEvent( self.parent, |
---|
| 618 | StatusEvent(status= msg, info='error')) |
---|
[2636188] | 619 | sizedial.Destroy() |
---|
[c0e747c] | 620 | try: |
---|
| 621 | selected_plot.markersize = int(label) |
---|
| 622 | self._check_zoom_plot() |
---|
| 623 | except: |
---|
| 624 | msg = 'Symbol Size: Got an invalid Value.' |
---|
| 625 | wx.PostEvent( self.parent, |
---|
| 626 | StatusEvent(status= msg, info='error')) |
---|
[2636188] | 627 | |
---|
| 628 | |
---|
[a07e72f] | 629 | def onChangeSymbol(self, event): |
---|
[6c0568b] | 630 | """ |
---|
| 631 | """ |
---|
[a07e72f] | 632 | menu = event.GetEventObject() |
---|
| 633 | id = event.GetId() |
---|
[70ec588d] | 634 | self.set_selected_from_menu(menu, id) |
---|
[a07e72f] | 635 | label = menu.GetLabel(id) |
---|
| 636 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
| 637 | selected_plot.symbol = self._symbol_labels[label] |
---|
| 638 | ## Set the view scale for all plots |
---|
[e6c6b67] | 639 | self._check_zoom_plot() |
---|
| 640 | #self._onEVT_FUNC_PROPERTY() |
---|
[a07e72f] | 641 | ## render the graph |
---|
[6d727ae] | 642 | #self.graph.render(self) |
---|
| 643 | #self.subplot.figure.canvas.draw_idle() |
---|
[176fbf1] | 644 | |
---|
[1bf33c1] | 645 | def _onSave(self, evt): |
---|
| 646 | """ |
---|
[d955bf19] | 647 | Save a data set to a text file |
---|
| 648 | |
---|
| 649 | :param evt: Menu event |
---|
| 650 | |
---|
[1bf33c1] | 651 | """ |
---|
[70ec588d] | 652 | menu = evt.GetEventObject() |
---|
| 653 | id = evt.GetId() |
---|
| 654 | self.set_selected_from_menu(menu, id) |
---|
[176fbf1] | 655 | data = self.plots[self.graph.selected_plottable] |
---|
| 656 | default_name = data.label |
---|
[c553b18] | 657 | if default_name.count('.') > 0: |
---|
| 658 | default_name = default_name.split('.')[0] |
---|
| 659 | default_name += "_out" |
---|
| 660 | if self.parent != None: |
---|
[176fbf1] | 661 | self.parent.save_data1d(data, default_name) |
---|
[c5a769e] | 662 | |
---|
[0aca693] | 663 | |
---|
| 664 | def _onDataShow(self, evt): |
---|
| 665 | """ |
---|
| 666 | Show the data set in text |
---|
| 667 | |
---|
| 668 | :param evt: Menu event |
---|
| 669 | |
---|
| 670 | """ |
---|
| 671 | menu = evt.GetEventObject() |
---|
| 672 | id = evt.GetId() |
---|
| 673 | self.set_selected_from_menu(menu, id) |
---|
| 674 | data = self.plots[self.graph.selected_plottable] |
---|
| 675 | default_name = data.label |
---|
| 676 | if default_name.count('.') > 0: |
---|
| 677 | default_name = default_name.split('.')[0] |
---|
| 678 | #default_name += "_out" |
---|
| 679 | if self.parent != None: |
---|
| 680 | self.parent.show_data1d(data, default_name) |
---|
| 681 | |
---|
[c5a769e] | 682 | def _add_more_tool(self): |
---|
| 683 | """ |
---|
[6d52f21d] | 684 | Add refresh, add/delete button in the tool bar |
---|
[c5a769e] | 685 | """ |
---|
| 686 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
| 687 | return |
---|
| 688 | self.toolbar.AddSeparator() |
---|
| 689 | id_delete = wx.NewId() |
---|
[9149431] | 690 | delete = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR) |
---|
[c5a769e] | 691 | self.toolbar.AddSimpleTool(id_delete, delete, |
---|
[fb40dbb] | 692 | 'Delete', 'permanently Delete') |
---|
[c5a769e] | 693 | |
---|
| 694 | self.toolbar.Realize() |
---|
| 695 | wx.EVT_TOOL(self, id_delete, self._on_delete) |
---|
[6d52f21d] | 696 | |
---|
[dc51a7f] | 697 | """ |
---|
[6d52f21d] | 698 | self.toolbar.AddSeparator() |
---|
| 699 | id_text = wx.NewId() |
---|
| 700 | text = wx.ArtProvider.GetBitmap(wx.ART_CUT, wx.ART_TOOLBAR) |
---|
| 701 | self.toolbar.AddSimpleTool(id_text, text, |
---|
| 702 | 'Remove Text from Plot', 'Removes text from plot') |
---|
| 703 | |
---|
| 704 | self.toolbar.Realize() |
---|
| 705 | wx.EVT_TOOL(self, id_text, self._on_removetext) |
---|
[886657f] | 706 | """ |
---|
[c5a769e] | 707 | def _on_delete(self, event): |
---|
| 708 | """ |
---|
| 709 | Refreshes the plotpanel on refresh tollbar button |
---|
| 710 | """ |
---|
| 711 | |
---|
| 712 | if self.parent is not None: |
---|
| 713 | wx.PostEvent(self.parent, |
---|
| 714 | NewPlotEvent(group_id=self.group_id, |
---|
| 715 | action="delete")) |
---|
[6d52f21d] | 716 | |
---|
[c5a769e] | 717 | |
---|