[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 math |
---|
| 16 | import numpy |
---|
[f468791] | 17 | |
---|
| 18 | from sans.plottools.PlotPanel import PlotPanel |
---|
[df7046f] | 19 | from sans.guiframe.events import StatusEvent |
---|
[a45037aa] | 20 | from sans.guiframe.events import PanelOnFocusEvent |
---|
[0d9dae8] | 21 | from sans.guiframe.utils import PanelMenu |
---|
[691643c] | 22 | from sans.guiframe.panel_base import PanelBase |
---|
[6e75ed0] | 23 | from sans.guiframe.gui_style import GUIFRAME_ICON |
---|
[f8be87d] | 24 | from appearanceDialog import appearanceDialog |
---|
[8f59e95] | 25 | from graphAppearance import graphAppearance |
---|
[1bf33c1] | 26 | |
---|
[0d9dae8] | 27 | DEFAULT_QMAX = 0.05 |
---|
[1bf33c1] | 28 | DEFAULT_QSTEP = 0.001 |
---|
| 29 | DEFAULT_BEAM = 0.005 |
---|
[32c0841] | 30 | BIN_WIDTH = 1 |
---|
[940aca7] | 31 | IS_MAC = (sys.platform == 'darwin') |
---|
[0d9dae8] | 32 | |
---|
[8f59e95] | 33 | |
---|
| 34 | def find_key(dic, val): |
---|
| 35 | """return the key of dictionary dic given the value""" |
---|
| 36 | return [k for k, v in dic.iteritems() if v == val][0] |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | |
---|
[691643c] | 40 | class ModelPanel1D(PlotPanel, PanelBase): |
---|
[1bf33c1] | 41 | """ |
---|
[d955bf19] | 42 | Plot panel for use with the GUI manager |
---|
[1bf33c1] | 43 | """ |
---|
| 44 | |
---|
| 45 | ## Internal name for the AUI manager |
---|
| 46 | window_name = "plotpanel" |
---|
| 47 | ## Title to appear on top of the window |
---|
[37c36d9] | 48 | window_caption = "Graph" |
---|
[1bf33c1] | 49 | ## Flag to tell the GUI manager that this panel is not |
---|
| 50 | # tied to any perspective |
---|
| 51 | ALWAYS_ON = True |
---|
| 52 | ## Group ID |
---|
| 53 | group_id = None |
---|
| 54 | |
---|
[32c0841] | 55 | def __init__(self, parent, id=-1, color = None, |
---|
| 56 | dpi=None, style=wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): |
---|
| 57 | PlotPanel.__init__(self, parent, id=id, style=style, **kwargs) |
---|
[a45037aa] | 58 | PanelBase.__init__(self, parent) |
---|
[1bf33c1] | 59 | ## Reference to the parent window |
---|
| 60 | self.parent = parent |
---|
[ae84427] | 61 | if hasattr(parent, "parent"): |
---|
| 62 | self.parent = self.parent.parent |
---|
[1bf33c1] | 63 | ## Plottables |
---|
| 64 | self.plots = {} |
---|
[ae84427] | 65 | self.frame = None |
---|
[52b8b74] | 66 | #context menu |
---|
| 67 | self._slicerpop = None |
---|
[a07e72f] | 68 | |
---|
[52b8b74] | 69 | self._available_data = [] |
---|
| 70 | self._menu_add_ids = [] |
---|
[a07e72f] | 71 | self._symbol_labels = self.get_symbol_label() |
---|
[2636188] | 72 | self._color_labels = self.get_color_label() |
---|
| 73 | self.currColorIndex = "" |
---|
[36288ca] | 74 | self._is_changed_legend_label = False |
---|
[657e52c] | 75 | self.is_xtick = False |
---|
| 76 | self.is_ytick = False |
---|
[a07e72f] | 77 | |
---|
| 78 | self.hide_menu = None |
---|
[1bf33c1] | 79 | ## Unique ID (from gui_manager) |
---|
| 80 | self.uid = None |
---|
[66718a1] | 81 | self.x_size = None |
---|
[6063b16] | 82 | ## Default locations |
---|
[c553b18] | 83 | #self._default_save_location = os.getcwd() |
---|
[3e001f9] | 84 | self.size = None |
---|
| 85 | self.vl_ind = 0 |
---|
[1bf33c1] | 86 | ## Graph |
---|
[9f5c8bb] | 87 | #self.graph = Graph() |
---|
[1bf33c1] | 88 | self.graph.xaxis("\\rm{Q}", 'A^{-1}') |
---|
[32c0841] | 89 | self.graph.yaxis("\\rm{Intensity} ", "cm^{-1}") |
---|
[1bf33c1] | 90 | self.graph.render(self) |
---|
[3e001f9] | 91 | self.cursor_id = None |
---|
[ef4a4ea] | 92 | |
---|
[6d727ae] | 93 | # In resizing event |
---|
| 94 | self.resizing = False |
---|
| 95 | self.canvas.set_resizing(self.resizing) |
---|
| 96 | self.Bind(wx.EVT_SIZE, self._OnReSize) |
---|
[c5a769e] | 97 | self._add_more_tool() |
---|
[6e75ed0] | 98 | self.parent.SetFocus() |
---|
| 99 | |
---|
[140fad00] | 100 | |
---|
[a07e72f] | 101 | def get_symbol_label(self): |
---|
[52b8b74] | 102 | """ |
---|
[a07e72f] | 103 | Associates label to symbol |
---|
[52b8b74] | 104 | """ |
---|
[a07e72f] | 105 | _labels = {} |
---|
| 106 | i = 0 |
---|
[6d727ae] | 107 | _labels['Circle'] = i |
---|
[a07e72f] | 108 | i += 1 |
---|
[6d727ae] | 109 | _labels['Cross X '] = i |
---|
[a07e72f] | 110 | i += 1 |
---|
| 111 | _labels['Triangle Down'] = i |
---|
| 112 | i += 1 |
---|
| 113 | _labels['Triangle Up'] = i |
---|
| 114 | i += 1 |
---|
| 115 | _labels['Triangle Left'] = i |
---|
| 116 | i += 1 |
---|
| 117 | _labels['Triangle Right'] = i |
---|
| 118 | i += 1 |
---|
[6d727ae] | 119 | _labels['Cross +'] = i |
---|
[a07e72f] | 120 | i += 1 |
---|
| 121 | _labels['Square'] = i |
---|
| 122 | i += 1 |
---|
[318b5bbb] | 123 | _labels['diamond'] = i |
---|
[a07e72f] | 124 | i += 1 |
---|
| 125 | _labels['Diamond'] = i |
---|
| 126 | i += 1 |
---|
| 127 | _labels['Hexagon1'] = i |
---|
| 128 | i += 1 |
---|
| 129 | _labels['Hexagon2'] = i |
---|
| 130 | i += 1 |
---|
| 131 | _labels['Pentagon'] = i |
---|
| 132 | i += 1 |
---|
[6d727ae] | 133 | _labels['Line'] = i |
---|
[6c4130a] | 134 | i += 1 |
---|
| 135 | _labels['Dash'] = i |
---|
| 136 | i += 1 |
---|
| 137 | _labels['Vline'] = i |
---|
| 138 | i += 1 |
---|
| 139 | _labels['Step'] = i |
---|
[a07e72f] | 140 | return _labels |
---|
[2636188] | 141 | |
---|
| 142 | def get_color_label(self): |
---|
| 143 | """ |
---|
| 144 | Associates label to a specific color |
---|
| 145 | """ |
---|
| 146 | _labels = {} |
---|
| 147 | i = 0 |
---|
| 148 | _labels['Blue'] = i |
---|
| 149 | i += 1 |
---|
| 150 | _labels['Green'] = i |
---|
| 151 | i += 1 |
---|
| 152 | _labels['Red'] = i |
---|
| 153 | i += 1 |
---|
| 154 | _labels['Cyan'] = i |
---|
| 155 | i += 1 |
---|
| 156 | _labels['Magenta'] = i |
---|
| 157 | i += 1 |
---|
| 158 | _labels['Yellow'] = i |
---|
[ad019b83] | 159 | i += 1 |
---|
| 160 | _labels['Black'] = i |
---|
[2636188] | 161 | return _labels |
---|
[a07e72f] | 162 | |
---|
[52b8b74] | 163 | |
---|
[32c0841] | 164 | def set_data(self, list=None): |
---|
[3c44c66] | 165 | """ |
---|
| 166 | """ |
---|
| 167 | pass |
---|
| 168 | |
---|
[1bf33c1] | 169 | def _reset(self): |
---|
| 170 | """ |
---|
[d955bf19] | 171 | Resets internal data and graph |
---|
[1bf33c1] | 172 | """ |
---|
| 173 | self.graph.reset() |
---|
| 174 | self.plots = {} |
---|
[7022fdc] | 175 | if self.is_zoomed: |
---|
[fd51a7c] | 176 | self.is_zoomed = False |
---|
[6d727ae] | 177 | |
---|
| 178 | def _OnReSize(self, event): |
---|
| 179 | """ |
---|
| 180 | On response of the resize of a panel, set axes_visiable False |
---|
| 181 | """ |
---|
[66718a1] | 182 | # It was found that wx >= 2.9.3 sends an event even if no size changed. |
---|
[294efd5] | 183 | # So manually recode the size (=x_size) and compare here. |
---|
[940aca7] | 184 | # Massy code to work around:< |
---|
| 185 | if self.parent._mgr != None: |
---|
| 186 | max_panel = self.parent._mgr.GetPane(self) |
---|
| 187 | if max_panel.IsMaximized(): |
---|
| 188 | self.parent._mgr.RestorePane(max_panel) |
---|
| 189 | max_panel.Maximize() |
---|
[66718a1] | 190 | if self.x_size != None: |
---|
| 191 | if self.x_size == self.GetSize(): |
---|
[71fa9bb9] | 192 | self.resizing = False |
---|
| 193 | self.canvas.set_resizing(self.resizing) |
---|
[66718a1] | 194 | return |
---|
[294efd5] | 195 | self.x_size = self.GetSize() |
---|
| 196 | |
---|
[ad9e5e1] | 197 | # Ready for another event |
---|
[4520830] | 198 | # Do not remove this Skip. Otherwise it will get runtime error on wx>=2.9. |
---|
[ad9e5e1] | 199 | event.Skip() |
---|
[6d727ae] | 200 | # set the resizing flag |
---|
| 201 | self.resizing = True |
---|
| 202 | self.canvas.set_resizing(self.resizing) |
---|
| 203 | self.parent.set_schedule(True) |
---|
[adf44c2] | 204 | pos_x, pos_y = self.GetPositionTuple() |
---|
| 205 | if pos_x != 0 and pos_y != 0: |
---|
[294efd5] | 206 | self.size, _ = self.GetClientSizeTuple() |
---|
[2b29bb4] | 207 | self.SetSizer(self.sizer) |
---|
[7fb69f26] | 208 | wx.CallAfter(self.parent.disable_app_menu,self) |
---|
[5112838] | 209 | |
---|
[3e001f9] | 210 | def on_plot_qrange(self, event=None): |
---|
| 211 | """ |
---|
| 212 | On Qmin Qmax vertical line event |
---|
| 213 | """ |
---|
| 214 | if event == None: |
---|
| 215 | return |
---|
| 216 | event.Skip() |
---|
| 217 | active_ctrl = event.active |
---|
| 218 | if active_ctrl == None: |
---|
| 219 | return |
---|
| 220 | if event.id in self.plots.keys(): |
---|
| 221 | # Set line position and color |
---|
| 222 | colors = ['red', 'purple'] |
---|
| 223 | self.cursor_id = event.id |
---|
| 224 | ctrl = event.ctrl |
---|
| 225 | if self.ly == None: |
---|
| 226 | self.ly = [] |
---|
| 227 | for ind_ly in range(len(colors)): |
---|
| 228 | self.ly.append(self.subplot.axvline(color=colors[ind_ly], |
---|
| 229 | lw=2.5, alpha=0.7)) |
---|
| 230 | self.ly[ind_ly].set_rasterized(True) |
---|
| 231 | try: |
---|
| 232 | # Display x,y in the status bar if possible |
---|
| 233 | xval = float(active_ctrl.GetValue()) |
---|
| 234 | position = self.get_data_xy_vals(xval) |
---|
| 235 | if position != None: |
---|
| 236 | wx.PostEvent(self.parent, StatusEvent(status=position)) |
---|
| 237 | except: |
---|
| 238 | pass |
---|
| 239 | if not event.leftdown: |
---|
| 240 | # text event |
---|
| 241 | try: |
---|
| 242 | is_moved = False |
---|
| 243 | for idx in range(len(self.ly)): |
---|
| 244 | val = float(ctrl[idx].GetValue()) |
---|
| 245 | # check if vline moved |
---|
| 246 | if self.ly[idx].get_xdata() != val: |
---|
| 247 | self.ly[idx].set_xdata(val) |
---|
| 248 | is_moved = True |
---|
| 249 | if is_moved: |
---|
| 250 | self.canvas.draw() |
---|
| 251 | except: |
---|
| 252 | pass |
---|
| 253 | event.Skip() |
---|
| 254 | return |
---|
| 255 | self.q_ctrl = ctrl |
---|
| 256 | try: |
---|
| 257 | pos_x_min = float(self.q_ctrl[0].GetValue()) |
---|
| 258 | except: |
---|
| 259 | pos_x_min = xmin |
---|
| 260 | try: |
---|
| 261 | pos_x_max = float(self.q_ctrl[1].GetValue()) |
---|
| 262 | except: |
---|
| 263 | pos_x_max = xmax |
---|
| 264 | pos_x = [pos_x_min, pos_x_max] |
---|
| 265 | for ind_ly in range(len(colors)): |
---|
| 266 | self.ly[ind_ly].set_color(colors[ind_ly]) |
---|
| 267 | self.ly[ind_ly].set_xdata(pos_x[ind_ly]) |
---|
| 268 | self.canvas.draw() |
---|
| 269 | else: |
---|
| 270 | self.q_ctrl = None |
---|
| 271 | |
---|
| 272 | def get_data_xy_vals(self, xval): |
---|
| 273 | """ |
---|
| 274 | Get x, y data values near x = x_val |
---|
| 275 | """ |
---|
| 276 | try: |
---|
| 277 | x_data = self.plots[self.cursor_id].x |
---|
| 278 | y_data = self.plots[self.cursor_id].y |
---|
| 279 | indx = self._find_nearest(x_data, xval) |
---|
| 280 | pos_x = x_data[indx] |
---|
| 281 | pos_y = y_data[indx] |
---|
| 282 | position = str(pos_x), str(pos_y) |
---|
| 283 | return position |
---|
| 284 | except: |
---|
| 285 | return None |
---|
| 286 | |
---|
| 287 | def _find_nearest(self, array, value): |
---|
| 288 | """ |
---|
| 289 | Find and return the nearest value in array to the value. |
---|
| 290 | Used in cusor_line() |
---|
| 291 | :Param array: numpy array |
---|
| 292 | :Param value: float |
---|
| 293 | """ |
---|
| 294 | idx = (numpy.abs(array - value)).argmin() |
---|
| 295 | return int(idx)#array.flat[idx] |
---|
| 296 | |
---|
| 297 | def _check_line_positions(self, pos_x=None, nop=None): |
---|
| 298 | """ |
---|
| 299 | Check vertical line positions |
---|
| 300 | :Param pos_x: position of the current line [float] |
---|
| 301 | :Param nop: number of plots [int] |
---|
| 302 | """ |
---|
| 303 | ly = self.ly |
---|
| 304 | ly0x = ly[0].get_xdata() |
---|
| 305 | ly1x = ly[1].get_xdata() |
---|
| 306 | self.q_ctrl[0].SetBackgroundColour('white') |
---|
| 307 | self.q_ctrl[1].SetBackgroundColour('white') |
---|
| 308 | if ly0x >= ly1x: |
---|
| 309 | if self.vl_ind == 0: |
---|
| 310 | ly[1].set_xdata(pos_x) |
---|
| 311 | ly[1].set_zorder(nop) |
---|
| 312 | self.q_ctrl[1].SetValue(str(pos_x)) |
---|
| 313 | self.q_ctrl[0].SetBackgroundColour('pink') |
---|
| 314 | elif self.vl_ind == 1: |
---|
| 315 | ly[0].set_xdata(pos_x) |
---|
| 316 | ly[0].set_zorder(nop) |
---|
| 317 | self.q_ctrl[0].SetValue(str(pos_x)) |
---|
| 318 | self.q_ctrl[1].SetBackgroundColour('pink') |
---|
| 319 | |
---|
| 320 | def _get_cusor_lines(self, event): |
---|
| 321 | """ |
---|
| 322 | Revmove or switch cursor line if drawn |
---|
| 323 | :Param event: LeftClick mouse event |
---|
| 324 | """ |
---|
| 325 | ax = event.inaxes |
---|
[ae84427] | 326 | if hasattr(event, "action"): |
---|
| 327 | dclick = event.action == 'dclick' |
---|
| 328 | if ax == None or dclick: |
---|
| 329 | # remove the vline |
---|
| 330 | self._check_zoom_plot() |
---|
| 331 | self.canvas.draw() |
---|
| 332 | self.q_ctrl = None |
---|
| 333 | return |
---|
[3e001f9] | 334 | if self.ly != None and event.xdata != None: |
---|
| 335 | # Selecting a new line if cursor lines are displayed already |
---|
| 336 | dqmin = math.fabs(event.xdata - self.ly[0].get_xdata()) |
---|
| 337 | dqmax = math.fabs(event.xdata - self.ly[1].get_xdata()) |
---|
| 338 | is_qmax = dqmin > dqmax |
---|
| 339 | if is_qmax: |
---|
| 340 | self.vl_ind = 1 |
---|
| 341 | else: |
---|
| 342 | self.vl_ind = 0 |
---|
| 343 | |
---|
| 344 | def cusor_line(self, event): |
---|
| 345 | """ |
---|
| 346 | Move the cursor line to write Q range |
---|
| 347 | """ |
---|
| 348 | if self.q_ctrl == None: |
---|
| 349 | return |
---|
| 350 | #release a q range vline |
---|
| 351 | if self.ly != None and not self.leftdown: |
---|
| 352 | for ly in self.ly: |
---|
| 353 | ly.set_alpha(0.7) |
---|
| 354 | self.canvas.draw() |
---|
| 355 | return |
---|
| 356 | ax = event.inaxes |
---|
| 357 | if ax == None or not hasattr(event, 'action'): |
---|
| 358 | return |
---|
| 359 | end_drag = event.action != 'drag' and event.xdata != None |
---|
| 360 | nop = len(self.plots) |
---|
| 361 | pos_x, pos_y = float(event.xdata), float(event.ydata) |
---|
| 362 | try: |
---|
| 363 | ly = self.ly |
---|
| 364 | ly0x = ly[0].get_xdata() |
---|
| 365 | ly1x = ly[1].get_xdata() |
---|
| 366 | if ly0x == ly1x: |
---|
| 367 | if ly[0].get_zorder() > ly[1].get_zorder(): |
---|
| 368 | self.vl_ind = 0 |
---|
| 369 | else: |
---|
| 370 | self.vl_ind = 1 |
---|
| 371 | vl_ind = self.vl_ind |
---|
| 372 | x_data = self.plots[self.cursor_id].x |
---|
| 373 | y_data = self.plots[self.cursor_id].y |
---|
| 374 | xmin = x_data.min() |
---|
| 375 | xmax = x_data.max() |
---|
| 376 | indx = self._find_nearest(x_data, pos_x) |
---|
| 377 | #pos_x = self._find_nearest(x_data, pos_x) |
---|
| 378 | #indx = int(numpy.searchsorted(x_data, [pos_x])[0]) |
---|
| 379 | # Need to hold LeftButton to drag |
---|
| 380 | if end_drag: |
---|
| 381 | if event.button: |
---|
| 382 | self._check_line_positions(pos_x, nop) |
---|
| 383 | return |
---|
| 384 | if indx >= len(x_data): |
---|
| 385 | indx = len(x_data) - 1 |
---|
| 386 | pos_x = x_data[indx] |
---|
| 387 | pos_y = y_data[indx] |
---|
| 388 | if xmin == ly1x: |
---|
| 389 | vl_ind = 1 |
---|
| 390 | elif xmax == ly0x: |
---|
| 391 | vl_ind = 0 |
---|
| 392 | else: |
---|
| 393 | ly[vl_ind].set_xdata(pos_x) |
---|
| 394 | ly[vl_ind].set_zorder(nop + 1) |
---|
| 395 | self._check_line_positions(pos_x, nop) |
---|
| 396 | ly[vl_ind].set_xdata(pos_x) |
---|
| 397 | ly[vl_ind].set_alpha(1.0) |
---|
| 398 | ly[vl_ind].set_zorder(nop + 1) |
---|
| 399 | self.canvas.draw() |
---|
| 400 | self.q_ctrl[vl_ind].SetValue(str(pos_x)) |
---|
| 401 | except: |
---|
| 402 | pass |
---|
| 403 | |
---|
[6d727ae] | 404 | def set_resizing(self, resizing=False): |
---|
| 405 | """ |
---|
| 406 | Set the resizing (True/False) |
---|
| 407 | """ |
---|
| 408 | self.resizing = resizing |
---|
| 409 | #self.canvas.set_resizing(resizing) |
---|
[1bf33c1] | 410 | |
---|
[6d727ae] | 411 | def schedule_full_draw(self, func='append'): |
---|
| 412 | """ |
---|
| 413 | Put self in schedule to full redraw list |
---|
| 414 | """ |
---|
| 415 | # append/del this panel in the schedule list |
---|
| 416 | self.parent.set_schedule_full_draw(self, func) |
---|
| 417 | |
---|
| 418 | |
---|
[a07e72f] | 419 | def remove_data_by_id(self, id): |
---|
| 420 | """' |
---|
| 421 | remove data from plot |
---|
| 422 | """ |
---|
| 423 | if id in self.plots.keys(): |
---|
| 424 | data = self.plots[id] |
---|
| 425 | self.graph.delete(data) |
---|
| 426 | data_manager = self._manager.parent.get_data_manager() |
---|
[df22224] | 427 | data_list, theory_list = data_manager.get_by_id(id_list=[id]) |
---|
| 428 | |
---|
| 429 | if id in data_list.keys(): |
---|
| 430 | data = data_list[id] |
---|
[248b918] | 431 | if id in theory_list.keys(): |
---|
[df22224] | 432 | data = theory_list[id] |
---|
[53a6d09] | 433 | # Update Graph menu and help string |
---|
[ae84427] | 434 | #h_id = self.parent._window_menu.FindItem(self.window_caption) |
---|
[e032dfc] | 435 | if data != None: |
---|
[78919f45] | 436 | if data.__class__.__name__ == 'list': |
---|
| 437 | label = data[0].label |
---|
| 438 | else: |
---|
| 439 | label = data.label |
---|
[e032dfc] | 440 | else: |
---|
| 441 | label = '???' |
---|
[ae84427] | 442 | #helpString = self.parent._window_menu.GetHelpString(h_id) |
---|
[e032dfc] | 443 | d_string = (' ' + str(label) +';') |
---|
[ae84427] | 444 | #new_tip = helpString.replace(d_string, '') |
---|
| 445 | #self.parent._window_menu.SetHelpString(h_id, new_tip) |
---|
[53a6d09] | 446 | |
---|
[a07e72f] | 447 | del self.plots[id] |
---|
| 448 | self.graph.render(self) |
---|
| 449 | self.subplot.figure.canvas.draw_idle() |
---|
| 450 | if len(self.graph.plottables) == 0: |
---|
[df22224] | 451 | #onRemove: graph is empty must be the panel must be destroyed |
---|
| 452 | self.parent.delete_panel(self.uid) |
---|
[53a6d09] | 453 | |
---|
[a07e72f] | 454 | |
---|
| 455 | def plot_data(self, data): |
---|
[1bf33c1] | 456 | """ |
---|
[d955bf19] | 457 | Data is ready to be displayed |
---|
| 458 | |
---|
| 459 | :param event: data event |
---|
[1bf33c1] | 460 | """ |
---|
[b837e1f] | 461 | if data.__class__.__name__ == 'Data2D': |
---|
| 462 | return |
---|
[6c4130a] | 463 | plot_keys = self.plots.keys() |
---|
| 464 | if data.id in plot_keys: |
---|
[e4a703a] | 465 | #Recover panel prop.s |
---|
| 466 | xlo, xhi = self.subplot.get_xlim() |
---|
| 467 | ylo, yhi = self.subplot.get_ylim() |
---|
[5eede4e] | 468 | old_data = self.plots[data.id] |
---|
[36288ca] | 469 | if self._is_changed_legend_label: |
---|
| 470 | data.label = old_data.label |
---|
[c9579e0] | 471 | if old_data.__class__.__name__ == 'Data1D': |
---|
| 472 | data.custom_color = old_data.custom_color |
---|
| 473 | data.symbol = old_data.symbol |
---|
| 474 | data.markersize = old_data.markersize |
---|
[6c4130a] | 475 | data.zorder = len(plot_keys) |
---|
[e4a703a] | 476 | # Replace data |
---|
[a07e72f] | 477 | self.graph.replace(data) |
---|
| 478 | self.plots[data.id] = data |
---|
[e4a703a] | 479 | ## Set the view scale for all plots |
---|
[a4964b8e] | 480 | try: |
---|
| 481 | self._onEVT_FUNC_PROPERTY() |
---|
| 482 | except: |
---|
[4904062] | 483 | msg=" Encountered singular points..." |
---|
| 484 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 485 | "Plotting Error: %s"% msg, info="error")) |
---|
[7022fdc] | 486 | # Check if zoomed |
---|
| 487 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
| 488 | if self.is_zoomed or toolbar_zoomed: |
---|
| 489 | # Recover the x,y limits |
---|
| 490 | self.subplot.set_xlim((xlo, xhi)) |
---|
| 491 | self.subplot.set_ylim((ylo, yhi)) |
---|
[a07e72f] | 492 | else: |
---|
| 493 | self.plots[data.id] = data |
---|
| 494 | self.graph.add(self.plots[data.id]) |
---|
[6c4130a] | 495 | data.zorder = len(plot_keys) |
---|
[e4a703a] | 496 | ## Set the view scale for all plots |
---|
[a4964b8e] | 497 | try: |
---|
| 498 | self._onEVT_FUNC_PROPERTY() |
---|
[940aca7] | 499 | if IS_MAC: |
---|
| 500 | # MAC: forcing to plot 2D avg |
---|
| 501 | self.canvas._onDrawIdle() |
---|
[a4964b8e] | 502 | except: |
---|
[4904062] | 503 | msg=" Encountered singular points..." |
---|
| 504 | wx.PostEvent(self.parent, StatusEvent(status=\ |
---|
[91a3860] | 505 | "Plotting Error: %s"% msg, info="error")) |
---|
[fe48fcc] | 506 | self.toolbar.update() |
---|
[7022fdc] | 507 | if self.is_zoomed: |
---|
| 508 | self.is_zoomed = False |
---|
[d6e39a8e] | 509 | # Update Graph menu and help string |
---|
[ae84427] | 510 | #pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
[d6e39a8e] | 511 | helpString = 'Show/Hide Graph: ' |
---|
| 512 | for plot in self.plots.itervalues(): |
---|
| 513 | helpString += (' ' + str(plot.label) +';') |
---|
[ae84427] | 514 | #self.parent._window_menu.SetHelpString(pos, helpString) |
---|
| 515 | |
---|
[6d727ae] | 516 | def draw_plot(self): |
---|
| 517 | """ |
---|
| 518 | Draw plot |
---|
| 519 | """ |
---|
| 520 | self.draw() |
---|
| 521 | |
---|
[1bf33c1] | 522 | def onLeftDown(self,event): |
---|
[6c0568b] | 523 | """ |
---|
[d955bf19] | 524 | left button down and ready to drag |
---|
| 525 | Display the position of the mouse on the statusbar |
---|
[6c0568b] | 526 | """ |
---|
[b07ffca] | 527 | #self.parent.set_plot_unfocus() |
---|
[3e001f9] | 528 | self._get_cusor_lines(event) |
---|
[e85e2bc] | 529 | ax = event.inaxes |
---|
[3e001f9] | 530 | PlotPanel.onLeftDown(self, event) |
---|
[e85e2bc] | 531 | if ax != None: |
---|
[902f373] | 532 | try: |
---|
| 533 | pos_x = float(event.xdata)# / size_x |
---|
| 534 | pos_y = float(event.ydata)# / size_y |
---|
| 535 | pos_x = "%8.3g"% pos_x |
---|
| 536 | pos_y = "%8.3g"% pos_y |
---|
| 537 | self.position = str(pos_x), str(pos_y) |
---|
| 538 | wx.PostEvent(self.parent, StatusEvent(status=self.position)) |
---|
| 539 | except: |
---|
| 540 | self.position = None |
---|
[0275276] | 541 | # unfocus all |
---|
| 542 | self.parent.set_plot_unfocus() |
---|
[4ed210f4] | 543 | #post nd event to notify guiframe that this panel is on focus |
---|
[a45037aa] | 544 | wx.PostEvent(self.parent, PanelOnFocusEvent(panel=self)) |
---|
[df68da1] | 545 | |
---|
[4ed210f4] | 546 | |
---|
[a07e72f] | 547 | def _ontoggle_hide_error(self, event): |
---|
| 548 | """ |
---|
| 549 | Toggle error display to hide or show |
---|
| 550 | """ |
---|
[70ec588d] | 551 | menu = event.GetEventObject() |
---|
| 552 | id = event.GetId() |
---|
| 553 | self.set_selected_from_menu(menu, id) |
---|
[ebf422a] | 554 | # Check zoom |
---|
| 555 | xlo, xhi = self.subplot.get_xlim() |
---|
| 556 | ylo, yhi = self.subplot.get_ylim() |
---|
| 557 | |
---|
[a07e72f] | 558 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
[5637362] | 559 | if self.hide_menu.GetText() == "Hide Error Bar": |
---|
[a07e72f] | 560 | selected_plot.hide_error = True |
---|
| 561 | else: |
---|
| 562 | selected_plot.hide_error = False |
---|
| 563 | ## increment graph color |
---|
| 564 | self.graph.render(self) |
---|
| 565 | self.subplot.figure.canvas.draw_idle() |
---|
[ebf422a] | 566 | # Check if zoomed |
---|
| 567 | toolbar_zoomed = self.toolbar.GetToolEnabled(self.toolbar._NTB2_BACK) |
---|
| 568 | if self.is_zoomed or toolbar_zoomed: |
---|
| 569 | # Recover the x,y limits |
---|
| 570 | self.subplot.set_xlim((xlo, xhi)) |
---|
| 571 | self.subplot.set_ylim((ylo, yhi)) |
---|
| 572 | |
---|
[a07e72f] | 573 | |
---|
[1bf33c1] | 574 | def _onRemove(self, event): |
---|
| 575 | """ |
---|
[d955bf19] | 576 | Remove a plottable from the graph and render the graph |
---|
| 577 | |
---|
| 578 | :param event: Menu event |
---|
| 579 | |
---|
[1bf33c1] | 580 | """ |
---|
[70ec588d] | 581 | menu = event.GetEventObject() |
---|
| 582 | id = event.GetId() |
---|
| 583 | self.set_selected_from_menu(menu, id) |
---|
[6c0568b] | 584 | ## Check if there is a selected graph to remove |
---|
[a07e72f] | 585 | if self.graph.selected_plottable in self.plots.keys(): |
---|
| 586 | selected_plot = self.plots[self.graph.selected_plottable] |
---|
| 587 | id = self.graph.selected_plottable |
---|
[df22224] | 588 | self.remove_data_by_id(id) |
---|
| 589 | |
---|
[1bf33c1] | 590 | def onContextMenu(self, event): |
---|
| 591 | """ |
---|
[d955bf19] | 592 | 1D plot context menu |
---|
| 593 | |
---|
| 594 | :param event: wx context event |
---|
| 595 | |
---|
[1bf33c1] | 596 | """ |
---|
[52b8b74] | 597 | self._slicerpop = PanelMenu() |
---|
| 598 | self._slicerpop.set_plots(self.plots) |
---|
[70ec588d] | 599 | self._slicerpop.set_graph(self.graph) |
---|
| 600 | if not self.graph.selected_plottable in self.plots: |
---|
| 601 | # Various plot options |
---|
| 602 | id = wx.NewId() |
---|
| 603 | self._slicerpop.Append(id, '&Save Image', 'Save image as PNG') |
---|
| 604 | wx.EVT_MENU(self, id, self.onSaveImage) |
---|
| 605 | id = wx.NewId() |
---|
| 606 | self._slicerpop.Append(id, '&Print Image', 'Print image ') |
---|
| 607 | wx.EVT_MENU(self, id, self.onPrint) |
---|
| 608 | id = wx.NewId() |
---|
| 609 | self._slicerpop.Append(id, '&Print Preview', 'Print preview') |
---|
| 610 | wx.EVT_MENU(self, id, self.onPrinterPreview) |
---|
[a436b2e] | 611 | |
---|
[6d727ae] | 612 | id = wx.NewId() |
---|
[f866fb5] | 613 | self._slicerpop.Append(id, '&Copy to Clipboard', |
---|
| 614 | 'Copy to the clipboard') |
---|
[70ec588d] | 615 | wx.EVT_MENU(self, id, self.OnCopyFigureMenu) |
---|
| 616 | |
---|
| 617 | self._slicerpop.AppendSeparator() |
---|
| 618 | |
---|
| 619 | for plot in self.plots.values(): |
---|
| 620 | #title = plot.title |
---|
[6d727ae] | 621 | name = plot.name |
---|
[70ec588d] | 622 | plot_menu = wx.Menu() |
---|
[242aff5] | 623 | if self.graph.selected_plottable: |
---|
[4a9bce1] | 624 | if not self.graph.selected_plottable in self.plots.keys(): |
---|
| 625 | continue |
---|
[242aff5] | 626 | if plot != self.plots[self.graph.selected_plottable]: |
---|
| 627 | continue |
---|
[940aca7] | 628 | |
---|
| 629 | id = wx.NewId() |
---|
| 630 | plot_menu.Append(id, "&DataInfo", name) |
---|
| 631 | wx.EVT_MENU(self, id, self. _onDataShow) |
---|
| 632 | id = wx.NewId() |
---|
| 633 | plot_menu.Append(id, "&Save Points as a File", name) |
---|
| 634 | wx.EVT_MENU(self, id, self._onSave) |
---|
| 635 | plot_menu.AppendSeparator() |
---|
| 636 | |
---|
[70ec588d] | 637 | #add menu of other plugins |
---|
[940aca7] | 638 | item_list = self.parent.get_current_context_menu(self) |
---|
[242aff5] | 639 | |
---|
[70ec588d] | 640 | if (not item_list == None) and (not len(item_list) == 0): |
---|
| 641 | for item in item_list: |
---|
[242aff5] | 642 | |
---|
[70ec588d] | 643 | try: |
---|
| 644 | id = wx.NewId() |
---|
| 645 | plot_menu.Append(id, item[0], name) |
---|
| 646 | wx.EVT_MENU(self, id, item[2]) |
---|
| 647 | except: |
---|
| 648 | msg = "ModelPanel1D.onContextMenu: " |
---|
| 649 | msg += "bad menu item %s" % sys.exc_value |
---|
| 650 | wx.PostEvent(self.parent, StatusEvent(status=msg)) |
---|
| 651 | pass |
---|
| 652 | plot_menu.AppendSeparator() |
---|
[940aca7] | 653 | |
---|
[73eb92fc] | 654 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
[e6a93df] | 655 | id = wx.NewId() |
---|
[70ec588d] | 656 | plot_menu.Append(id, '&Linear Fit', name) |
---|
[a436b2e] | 657 | wx.EVT_MENU(self, id, self.onFitting) |
---|
[70ec588d] | 658 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 659 | |
---|
[a3c96f7a] | 660 | id = wx.NewId() |
---|
[70ec588d] | 661 | plot_menu.Append(id, "Remove", name) |
---|
[a436b2e] | 662 | wx.EVT_MENU(self, id, self._onRemove) |
---|
| 663 | if not plot.is_data: |
---|
| 664 | id = wx.NewId() |
---|
[70ec588d] | 665 | plot_menu.Append(id, '&Freeze', name) |
---|
[a436b2e] | 666 | wx.EVT_MENU(self, id, self.onFreeze) |
---|
[70ec588d] | 667 | plot_menu.AppendSeparator() |
---|
[a436b2e] | 668 | symbol_menu = wx.Menu() |
---|
[2636188] | 669 | |
---|
[70ec588d] | 670 | if plot.is_data: |
---|
[f8be87d] | 671 | id = wx.NewId() |
---|
[70ec588d] | 672 | self.hide_menu = plot_menu.Append(id, |
---|
| 673 | "Hide Error Bar", name) |
---|
| 674 | |
---|
| 675 | if plot.dy is not None and plot.dy != []: |
---|
| 676 | if plot.hide_error : |
---|
| 677 | self.hide_menu.SetText('Show Error Bar') |
---|
| 678 | else: |
---|
| 679 | self.hide_menu.SetText('Hide Error Bar') |
---|
[a436b2e] | 680 | else: |
---|
[70ec588d] | 681 | self.hide_menu.Enable(False) |
---|
| 682 | wx.EVT_MENU(self, id, self._ontoggle_hide_error) |
---|
[a436b2e] | 683 | |
---|
[f8be87d] | 684 | plot_menu.AppendSeparator() |
---|
| 685 | |
---|
[e1714a9] | 686 | id = wx.NewId() |
---|
[f866fb5] | 687 | plot_menu.Append(id, '&Modify Plot Property', name) |
---|
[f8be87d] | 688 | wx.EVT_MENU(self, id, self.createAppDialog) |
---|
| 689 | |
---|
| 690 | |
---|
| 691 | |
---|
[70ec588d] | 692 | id = wx.NewId() |
---|
| 693 | #plot_menu.SetTitle(name) |
---|
| 694 | self._slicerpop.AppendMenu(id, '&%s'% name, plot_menu) |
---|
[f866fb5] | 695 | # Option to hide |
---|
| 696 | #TODO: implement functionality to hide a plottable (legend click) |
---|
[70ec588d] | 697 | if not self.graph.selected_plottable in self.plots: |
---|
| 698 | self._slicerpop.AppendSeparator() |
---|
| 699 | loc_menu = wx.Menu() |
---|
| 700 | for label in self._loc_labels: |
---|
| 701 | id = wx.NewId() |
---|
| 702 | loc_menu.Append(id, str(label), str(label)) |
---|
| 703 | wx.EVT_MENU(self, id, self.onChangeLegendLoc) |
---|
| 704 | |
---|
[ef4a4ea] | 705 | id = wx.NewId() |
---|
[f866fb5] | 706 | self._slicerpop.Append(id, '&Modify Graph Appearance', |
---|
| 707 | 'Modify graph appearance') |
---|
[8f59e95] | 708 | wx.EVT_MENU(self, id, self.modifyGraphAppearance) |
---|
[70ec588d] | 709 | self._slicerpop.AppendSeparator() |
---|
[8f59e95] | 710 | |
---|
[70ec588d] | 711 | |
---|
| 712 | if self.position != None: |
---|
| 713 | id = wx.NewId() |
---|
| 714 | self._slicerpop.Append(id, '&Add Text') |
---|
| 715 | wx.EVT_MENU(self, id, self._on_addtext) |
---|
| 716 | id = wx.NewId() |
---|
| 717 | self._slicerpop.Append(id, '&Remove Text') |
---|
| 718 | wx.EVT_MENU(self, id, self._on_removetext) |
---|
| 719 | self._slicerpop.AppendSeparator() |
---|
[ef4a4ea] | 720 | id = wx.NewId() |
---|
[70ec588d] | 721 | self._slicerpop.Append(id, '&Change Scale') |
---|
| 722 | wx.EVT_MENU(self, id, self._onProperties) |
---|
[857d00f] | 723 | self._slicerpop.AppendSeparator() |
---|
[70ec588d] | 724 | id = wx.NewId() |
---|
| 725 | self._slicerpop.Append(id, '&Reset Graph Range') |
---|
| 726 | wx.EVT_MENU(self, id, self.onResetGraph) |
---|
| 727 | |
---|
| 728 | if self.parent.ClassName.count('wxDialog') == 0: |
---|
| 729 | self._slicerpop.AppendSeparator() |
---|
| 730 | id = wx.NewId() |
---|
| 731 | self._slicerpop.Append(id, '&Window Title') |
---|
| 732 | wx.EVT_MENU(self, id, self.onChangeCaption) |
---|
[dc51a7f] | 733 | try: |
---|
| 734 | pos_evt = event.GetPosition() |
---|
| 735 | pos = self.ScreenToClient(pos_evt) |
---|
| 736 | except: |
---|
| 737 | pos_x, pos_y = self.toolbar.GetPositionTuple() |
---|
| 738 | pos = (pos_x, pos_y + 5) |
---|
[52b8b74] | 739 | self.PopupMenu(self._slicerpop, pos) |
---|
[70ec588d] | 740 | |
---|
[e6a93df] | 741 | def onFreeze(self, event): |
---|
| 742 | """ |
---|
[f866fb5] | 743 | on Freeze data |
---|
[e6a93df] | 744 | """ |
---|
[70ec588d] | 745 | menu = event.GetEventObject() |
---|
| 746 | id = event.GetId() |
---|
| 747 | self.set_selected_from_menu(menu, id) |
---|
[e6a93df] | 748 | plot = self.plots[self.graph.selected_plottable] |
---|
| 749 | self.parent.onfreeze([plot.id]) |
---|
[d7d1255e] | 750 | |
---|
[176fbf1] | 751 | |
---|
[1bf33c1] | 752 | def _onSave(self, evt): |
---|
| 753 | """ |
---|
[d955bf19] | 754 | Save a data set to a text file |
---|
| 755 | |
---|
| 756 | :param evt: Menu event |
---|
| 757 | |
---|
[1bf33c1] | 758 | """ |
---|
[70ec588d] | 759 | menu = evt.GetEventObject() |
---|
| 760 | id = evt.GetId() |
---|
| 761 | self.set_selected_from_menu(menu, id) |
---|
[176fbf1] | 762 | data = self.plots[self.graph.selected_plottable] |
---|
| 763 | default_name = data.label |
---|
[c553b18] | 764 | if default_name.count('.') > 0: |
---|
| 765 | default_name = default_name.split('.')[0] |
---|
| 766 | default_name += "_out" |
---|
| 767 | if self.parent != None: |
---|
[176fbf1] | 768 | self.parent.save_data1d(data, default_name) |
---|
[c5a769e] | 769 | |
---|
[0aca693] | 770 | |
---|
| 771 | def _onDataShow(self, evt): |
---|
| 772 | """ |
---|
| 773 | Show the data set in text |
---|
| 774 | |
---|
| 775 | :param evt: Menu event |
---|
| 776 | |
---|
| 777 | """ |
---|
| 778 | menu = evt.GetEventObject() |
---|
| 779 | id = evt.GetId() |
---|
| 780 | self.set_selected_from_menu(menu, id) |
---|
| 781 | data = self.plots[self.graph.selected_plottable] |
---|
| 782 | default_name = data.label |
---|
| 783 | if default_name.count('.') > 0: |
---|
| 784 | default_name = default_name.split('.')[0] |
---|
| 785 | #default_name += "_out" |
---|
| 786 | if self.parent != None: |
---|
| 787 | self.parent.show_data1d(data, default_name) |
---|
| 788 | |
---|
[c5a769e] | 789 | def _add_more_tool(self): |
---|
| 790 | """ |
---|
[6e75ed0] | 791 | Add refresh, add/hide button in the tool bar |
---|
[c5a769e] | 792 | """ |
---|
[ae84427] | 793 | return |
---|
[c5a769e] | 794 | if self.parent.__class__.__name__ != 'ViewerFrame': |
---|
| 795 | return |
---|
| 796 | self.toolbar.AddSeparator() |
---|
[d6e39a8e] | 797 | id_hide = wx.NewId() |
---|
| 798 | hide = wx.Bitmap(GUIFRAME_ICON.HIDE_ID_PATH, wx.BITMAP_TYPE_PNG) |
---|
| 799 | self.toolbar.AddSimpleTool(id_hide, hide, 'Hide', 'Hide') |
---|
[c5a769e] | 800 | self.toolbar.Realize() |
---|
[d6e39a8e] | 801 | wx.EVT_TOOL(self, id_hide, self._on_hide) |
---|
[c5a769e] | 802 | |
---|
[6e75ed0] | 803 | def _on_hide(self, event): |
---|
| 804 | """ |
---|
| 805 | Hides the plot when button is pressed |
---|
| 806 | """ |
---|
[c5a769e] | 807 | if self.parent is not None: |
---|
[6e75ed0] | 808 | self.parent.hide_panel(self.uid) |
---|
[f8be87d] | 809 | |
---|
[ae84427] | 810 | def on_close(self, event): |
---|
| 811 | """ |
---|
| 812 | On Close Event |
---|
| 813 | """ |
---|
| 814 | ID = self.uid |
---|
| 815 | self.parent.delete_panel(ID) |
---|
| 816 | |
---|
[f8be87d] | 817 | def createAppDialog(self, event): |
---|
| 818 | """ |
---|
| 819 | Create the custom dialog for fit appearance modification |
---|
| 820 | """ |
---|
| 821 | menu = event.GetEventObject() |
---|
| 822 | id = event.GetId() |
---|
[f866fb5] | 823 | self.set_selected_from_menu(menu, id) |
---|
| 824 | self.appearance_selected_plot = \ |
---|
| 825 | self.plots[self.graph.selected_plottable] |
---|
[f8be87d] | 826 | # find current properties |
---|
| 827 | curr_color = self.appearance_selected_plot.custom_color |
---|
| 828 | curr_symbol = self.appearance_selected_plot.symbol |
---|
| 829 | curr_size = self.appearance_selected_plot.markersize |
---|
| 830 | curr_label = self.appearance_selected_plot.label |
---|
| 831 | |
---|
| 832 | if curr_color == None: |
---|
| 833 | curr_color = self._color_labels['Blue'] |
---|
| 834 | curr_symbol = 13 |
---|
| 835 | |
---|
[9f51c2c] | 836 | self.appD = appearanceDialog(self, 'Modify Plot Property') |
---|
| 837 | icon = self.parent.GetIcon() |
---|
| 838 | self.appD.SetIcon(icon) |
---|
[f866fb5] | 839 | self.appD.set_defaults(float(curr_size), int(curr_color), |
---|
| 840 | str(appearanceDialog.find_key(self.get_symbol_label(), |
---|
| 841 | int(curr_symbol))), curr_label) |
---|
[9f51c2c] | 842 | self.appD.Bind(wx.EVT_CLOSE, self.on_AppDialog_close) |
---|
| 843 | |
---|
[f866fb5] | 844 | def on_AppDialog_close(self, event): |
---|
| 845 | """ |
---|
| 846 | on_Modify Plot Property_close |
---|
| 847 | """ |
---|
[9f51c2c] | 848 | if(self.appD.okay_clicked == True): |
---|
[f866fb5] | 849 | # returns (size,color,symbol,datalabel) |
---|
| 850 | info = self.appD.get_current_values() |
---|
| 851 | self.appearance_selected_plot.custom_color = \ |
---|
| 852 | self._color_labels[info[1].encode('ascii', 'ignore')] |
---|
[9f51c2c] | 853 | |
---|
| 854 | self.appearance_selected_plot.markersize = float(info[0]) |
---|
[f866fb5] | 855 | self.appearance_selected_plot.symbol = \ |
---|
| 856 | self.get_symbol_label()[info[2]] |
---|
[9f51c2c] | 857 | self.appearance_selected_plot.label = str(info[3]) |
---|
| 858 | |
---|
[ae84427] | 859 | #pos = self.parent._window_menu.FindItem(self.window_caption) |
---|
| 860 | #helpString = 'Show/Hide Graph: ' |
---|
| 861 | #for plot in self.plots.itervalues(): |
---|
| 862 | # helpString += (' ' + str(plot.label) + ';') |
---|
| 863 | # self.parent._window_menu.SetHelpString(pos, helpString) |
---|
| 864 | # self._is_changed_legend_label = True |
---|
[f8be87d] | 865 | |
---|
| 866 | self.appD.Destroy() |
---|
| 867 | self._check_zoom_plot() |
---|
[8f59e95] | 868 | |
---|
| 869 | |
---|
[f866fb5] | 870 | def modifyGraphAppearance(self, event): |
---|
| 871 | """ |
---|
| 872 | On Modify Graph Appearance |
---|
| 873 | """ |
---|
| 874 | self.graphApp = graphAppearance(self, 'Modify Graph Appearance') |
---|
[9f51c2c] | 875 | icon = self.parent.GetIcon() |
---|
| 876 | self.graphApp.SetIcon(icon) |
---|
[f866fb5] | 877 | self.graphApp.setDefaults(self.grid_on, self.legend_on, |
---|
| 878 | self.xaxis_label, self.yaxis_label, |
---|
| 879 | self.xaxis_unit, self.yaxis_unit, |
---|
| 880 | self.xaxis_font, self.yaxis_font, |
---|
| 881 | find_key(self.get_loc_label(), |
---|
| 882 | self.legendLoc), |
---|
[657e52c] | 883 | self.xcolor, self.ycolor, |
---|
| 884 | self.is_xtick, self.is_ytick) |
---|
[9f51c2c] | 885 | self.graphApp.Bind(wx.EVT_CLOSE, self.on_graphApp_close) |
---|
[8f59e95] | 886 | |
---|
| 887 | |
---|
[9f51c2c] | 888 | def on_graphApp_close(self, event): |
---|
[83d9120] | 889 | """ |
---|
| 890 | Gets values from graph appearance dialog and sends them off |
---|
| 891 | to modify the plot |
---|
| 892 | """ |
---|
| 893 | graph_app = self.graphApp |
---|
| 894 | toggle_grid = graph_app.get_togglegrid() |
---|
| 895 | legend_loc = graph_app.get_legend_loc() |
---|
| 896 | toggle_legend = graph_app.get_togglelegend() |
---|
| 897 | |
---|
| 898 | self.onGridOnOff(toggle_grid ) |
---|
| 899 | self.ChangeLegendLoc(legend_loc) |
---|
| 900 | self.onLegend(toggle_legend) |
---|
[8a687cfd] | 901 | |
---|
[83d9120] | 902 | self.xaxis_label = graph_app.get_xlab() |
---|
| 903 | self.yaxis_label = graph_app.get_ylab() |
---|
| 904 | self.xaxis_unit = graph_app.get_xunit() |
---|
| 905 | self.yaxis_unit = graph_app.get_yunit() |
---|
[657e52c] | 906 | self.xaxis_font = graph_app.get_xfont() |
---|
| 907 | self.yaxis_font = graph_app.get_yfont() |
---|
| 908 | self.is_xtick = graph_app.get_xtick_check() |
---|
| 909 | self.is_ytick = graph_app.get_ytick_check() |
---|
| 910 | if self.is_xtick: |
---|
| 911 | self.xaxis_tick = self.xaxis_font |
---|
| 912 | if self.is_ytick: |
---|
| 913 | self.yaxis_tick = self.yaxis_font |
---|
[8a687cfd] | 914 | |
---|
[83d9120] | 915 | self.xaxis(self.xaxis_label, self.xaxis_unit, |
---|
[657e52c] | 916 | graph_app.get_xfont(), graph_app.get_xcolor(), |
---|
| 917 | self.xaxis_tick) |
---|
[83d9120] | 918 | self.yaxis(self.yaxis_label, self.yaxis_unit, |
---|
[657e52c] | 919 | graph_app.get_yfont(), graph_app.get_ycolor(), |
---|
| 920 | self.yaxis_tick) |
---|
[8f59e95] | 921 | |
---|
[83d9120] | 922 | graph_app.Destroy() |
---|