[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 | """ |
---|
[ebf422a] | 320 | # Check zoom |
---|
| 321 | xlo, xhi = self.subplot.get_xlim() |
---|
| 322 | ylo, yhi = self.subplot.get_ylim() |
---|
| 323 | |
---|
[a07e72f] | 324 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[5637362] | 325 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
[a07e72f] | 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() |
---|
[ebf422a] | 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 | |
---|
[a07e72f] | 339 | |
---|
[1bf33c1] | 340 | def _onRemove(self, event): |
---|
| 341 | """ |
---|
[d955bf19] | 342 | Remove a plottable from the graph and render the graph |
---|
| 343 | |
---|
| 344 | :param event: Menu event |
---|
| 345 | |
---|
[1bf33c1] | 346 | """ |
---|
[6c0568b] | 347 | ## Check if there is a selected graph to remove |
---|
[a07e72f] | 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 |
---|
[df22224] | 351 | self.remove_data_by_id(id) |
---|
| 352 | |
---|
[1bf33c1] | 353 | def onContextMenu(self, event): |
---|
| 354 | """ |
---|
[d955bf19] | 355 | 1D plot context menu |
---|
| 356 | |
---|
| 357 | :param event: wx context event |
---|
| 358 | |
---|
[1bf33c1] | 359 | """ |
---|
[52b8b74] | 360 | self._slicerpop = PanelMenu() |
---|
| 361 | self._slicerpop.set_plots(self.plots) |
---|
| 362 | self._slicerpop.set_graph(self.graph) |
---|
[9a585d0] | 363 | # Various plot options |
---|
| 364 | id = wx.NewId() |
---|
[6d727ae] | 365 | self._slicerpop.Append(id, '&Save Image', 'Save image as PNG') |
---|
[9a585d0] | 366 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
| 367 | id = wx.NewId() |
---|
[6d727ae] | 368 | self._slicerpop.Append(id, '&Print Image', 'Print image ') |
---|
[18eba35] | 369 | wx.EVT_MENU(self, id, self.onPrint) |
---|
| 370 | id = wx.NewId() |
---|
[6d727ae] | 371 | self._slicerpop.Append(id, '&Print Preview', 'Print preview') |
---|
[18eba35] | 372 | wx.EVT_MENU(self, id, self.onPrinterPreview) |
---|
[52b8b74] | 373 | |
---|
[6d727ae] | 374 | id = wx.NewId() |
---|
| 375 | self._slicerpop.Append(id, '&Copy to Clipboard', 'Copy to the clipboard') |
---|
| 376 | wx.EVT_MENU(self, id, self.OnCopyFigureMenu) |
---|
[e1714a9] | 377 | |
---|
[6d727ae] | 378 | self._slicerpop.AppendSeparator() |
---|
| 379 | |
---|
[52b8b74] | 380 | #add menu of other plugins |
---|
[a07e72f] | 381 | item_list = self.parent.get_context_menu(self) |
---|
[6d727ae] | 382 | |
---|
[32c0841] | 383 | if (not item_list == None) and (not len(item_list) == 0): |
---|
[9a585d0] | 384 | for item in item_list: |
---|
| 385 | try: |
---|
| 386 | id = wx.NewId() |
---|
[52b8b74] | 387 | self._slicerpop.Append(id, item[0], item[1]) |
---|
[9a585d0] | 388 | wx.EVT_MENU(self, id, item[2]) |
---|
| 389 | except: |
---|
[32c0841] | 390 | msg = "ModelPanel1D.onContextMenu: " |
---|
[a07e72f] | 391 | msg += "bad menu item %s" % sys.exc_value |
---|
[32c0841] | 392 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
[9a585d0] | 393 | pass |
---|
[52b8b74] | 394 | self._slicerpop.AppendSeparator() |
---|
[6d727ae] | 395 | #id = wx.NewId() |
---|
| 396 | #self._slicerpop.Append(id, '&Print image', 'Print image') |
---|
[1bf33c1] | 397 | if self.graph.selected_plottable in self.plots: |
---|
| 398 | plot = self.plots[self.graph.selected_plottable] |
---|
[a436b2e] | 399 | |
---|
[6d727ae] | 400 | id = wx.NewId() |
---|
| 401 | name = plot.name |
---|
| 402 | self._slicerpop.Append(id, "&Save Points as a File") |
---|
[2d443fd] | 403 | wx.EVT_MENU(self, id, self._onSave) |
---|
[a436b2e] | 404 | self._slicerpop.AppendSeparator() |
---|
[73eb92fc] | 405 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
[e6a93df] | 406 | id = wx.NewId() |
---|
[a436b2e] | 407 | self._slicerpop.Append(id, '&Linear Fit') |
---|
| 408 | wx.EVT_MENU(self, id, self.onFitting) |
---|
| 409 | self._slicerpop.AppendSeparator() |
---|
| 410 | |
---|
[a3c96f7a] | 411 | id = wx.NewId() |
---|
[a436b2e] | 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) |
---|
[e1714a9] | 418 | self._slicerpop.AppendSeparator() |
---|
[a436b2e] | 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) |
---|
[2636188] | 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 | |
---|
[5637362] | 446 | self.hide_menu = self._slicerpop.Append(id, "Hide Error Bar") |
---|
[a436b2e] | 447 | |
---|
| 448 | if plot.dy is not None and plot.dy != []: |
---|
| 449 | if plot.hide_error : |
---|
[5637362] | 450 | self.hide_menu.SetText('Show Error Bar') |
---|
[a436b2e] | 451 | else: |
---|
[5637362] | 452 | self.hide_menu.SetText('Hide Error Bar') |
---|
[a07e72f] | 453 | else: |
---|
[a436b2e] | 454 | self.hide_menu.Enable(False) |
---|
| 455 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
| 456 | |
---|
| 457 | self._slicerpop.AppendSeparator() |
---|
[e1714a9] | 458 | id = wx.NewId() |
---|
| 459 | self._slicerpop.Append(id, '&Edit Legend Label', 'Edit Legend Label') |
---|
| 460 | wx.EVT_MENU(self, id, self.onEditLabels) |
---|
[a436b2e] | 461 | # Option to hide |
---|
| 462 | #TODO: implement functionality to hide a plottable (legend click) |
---|
[e1714a9] | 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) |
---|
[df22224] | 471 | |
---|
[e1714a9] | 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() |
---|
[a07e72f] | 476 | |
---|
[857d00f] | 477 | id = wx.NewId() |
---|
[5637362] | 478 | self._slicerpop.Append(id, '&Edit Y Axis Label') |
---|
[857d00f] | 479 | wx.EVT_MENU(self, id, self._on_yaxis_label) |
---|
| 480 | id = wx.NewId() |
---|
[5637362] | 481 | self._slicerpop.Append(id, '&Edit X Axis Label') |
---|
[857d00f] | 482 | wx.EVT_MENU(self, id, self._on_xaxis_label) |
---|
[5637362] | 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) |
---|
[857d00f] | 487 | self._slicerpop.AppendSeparator() |
---|
| 488 | |
---|
[ef4a4ea] | 489 | if self.position != None: |
---|
| 490 | id = wx.NewId() |
---|
[c17760d] | 491 | self._slicerpop.Append(id, '&Add Text') |
---|
[ef4a4ea] | 492 | wx.EVT_MENU(self, id, self._on_addtext) |
---|
| 493 | id = wx.NewId() |
---|
[c17760d] | 494 | self._slicerpop.Append(id, '&Remove Text') |
---|
[ef4a4ea] | 495 | wx.EVT_MENU(self, id, self._on_removetext) |
---|
[857d00f] | 496 | self._slicerpop.AppendSeparator() |
---|
[886657f] | 497 | id = wx.NewId() |
---|
[c17760d] | 498 | self._slicerpop.Append(id, '&Change Scale') |
---|
[1bf33c1] | 499 | wx.EVT_MENU(self, id, self._onProperties) |
---|
[857d00f] | 500 | self._slicerpop.AppendSeparator() |
---|
[1bf33c1] | 501 | id = wx.NewId() |
---|
[2259920] | 502 | self._slicerpop.Append(id, '&Reset Graph Range') |
---|
[d468daa] | 503 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
[dc51a7f] | 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) |
---|
[fba201a0] | 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) |
---|
[37c36d9] | 516 | |
---|
[52b8b74] | 517 | self.PopupMenu(self._slicerpop, pos) |
---|
[dc51a7f] | 518 | |
---|
[e6a93df] | 519 | def onFreeze(self, event): |
---|
| 520 | """ |
---|
| 521 | """ |
---|
| 522 | plot = self.plots[self.graph.selected_plottable] |
---|
| 523 | self.parent.onfreeze([plot.id]) |
---|
[d7d1255e] | 524 | |
---|
[6d52f21d] | 525 | def onEditLabels(self, event): |
---|
| 526 | """ |
---|
[d7d1255e] | 527 | Edit legend label |
---|
[6d52f21d] | 528 | """ |
---|
| 529 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[d7d1255e] | 530 | label = selected_plot.label |
---|
| 531 | dial = LabelDialog(None, -1, 'Change Legend Label', label) |
---|
[6d52f21d] | 532 | if dial.ShowModal() == wx.ID_OK: |
---|
[d7d1255e] | 533 | newLabel = dial.getText() |
---|
| 534 | selected_plot.label = newLabel |
---|
[53cf669] | 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(): |
---|
[e2160ab] | 539 | helpString += (' ' + str(plot.label) +';') |
---|
[53cf669] | 540 | self.parent._window_menu.SetHelpString(pos, helpString) |
---|
[36288ca] | 541 | self._is_changed_legend_label = True |
---|
[53cf669] | 542 | #break |
---|
[6d52f21d] | 543 | dial.Destroy() |
---|
[53cf669] | 544 | |
---|
[d7d1255e] | 545 | ## render the graph |
---|
[a4964b8e] | 546 | try: |
---|
| 547 | self._onEVT_FUNC_PROPERTY() |
---|
| 548 | except: |
---|
[4904062] | 549 | msg=" Encountered singular points..." |
---|
| 550 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
| 551 | "Plotting Erorr: %s"% msg, info="error")) |
---|
[a4964b8e] | 552 | |
---|
[2636188] | 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 |
---|
[e6c6b67] | 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)) |
---|
[2636188] | 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: |
---|
[30ccad1] | 579 | try: |
---|
| 580 | label = sizedial.getText() |
---|
[1e35434] | 581 | |
---|
[30ccad1] | 582 | except: |
---|
| 583 | msg = 'Symbol Size: Got an invalid Value.' |
---|
| 584 | wx.PostEvent( self.parent, |
---|
| 585 | StatusEvent(status= msg, info='error')) |
---|
[2636188] | 586 | sizedial.Destroy() |
---|
[c0e747c] | 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')) |
---|
[2636188] | 594 | |
---|
| 595 | |
---|
[a07e72f] | 596 | def onChangeSymbol(self, event): |
---|
[6c0568b] | 597 | """ |
---|
| 598 | """ |
---|
[a07e72f] | 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 |
---|
[e6c6b67] | 605 | self._check_zoom_plot() |
---|
| 606 | #self._onEVT_FUNC_PROPERTY() |
---|
[a07e72f] | 607 | ## render the graph |
---|
[6d727ae] | 608 | #self.graph.render(self) |
---|
| 609 | #self.subplot.figure.canvas.draw_idle() |
---|
[176fbf1] | 610 | |
---|
[1bf33c1] | 611 | def _onSave(self, evt): |
---|
| 612 | """ |
---|
[d955bf19] | 613 | Save a data set to a text file |
---|
| 614 | |
---|
| 615 | :param evt: Menu event |
---|
| 616 | |
---|
[1bf33c1] | 617 | """ |
---|
[176fbf1] | 618 | data = self.plots[self.graph.selected_plottable] |
---|
| 619 | default_name = data.label |
---|
[c553b18] | 620 | if default_name.count('.') > 0: |
---|
| 621 | default_name = default_name.split('.')[0] |
---|
| 622 | default_name += "_out" |
---|
| 623 | if self.parent != None: |
---|
[176fbf1] | 624 | self.parent.save_data1d(data, default_name) |
---|
[c5a769e] | 625 | |
---|
| 626 | def _add_more_tool(self): |
---|
| 627 | """ |
---|
[6d52f21d] | 628 | Add refresh, add/delete button in the tool bar |
---|
[c5a769e] | 629 | """ |
---|
| 630 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
| 631 | return |
---|
| 632 | self.toolbar.AddSeparator() |
---|
| 633 | id_delete = wx.NewId() |
---|
[9149431] | 634 | delete = wx.ArtProvider.GetBitmap(wx.ART_DELETE, wx.ART_TOOLBAR) |
---|
[c5a769e] | 635 | self.toolbar.AddSimpleTool(id_delete, delete, |
---|
[fb40dbb] | 636 | 'Delete', 'permanently Delete') |
---|
[c5a769e] | 637 | |
---|
| 638 | self.toolbar.Realize() |
---|
| 639 | wx.EVT_TOOL(self, id_delete, self._on_delete) |
---|
[6d52f21d] | 640 | |
---|
[dc51a7f] | 641 | """ |
---|
[6d52f21d] | 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) |
---|
[886657f] | 650 | """ |
---|
[c5a769e] | 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")) |
---|
[6d52f21d] | 660 | |
---|
[c5a769e] | 661 | |
---|