Changeset 7764b41 in sasview for guiframe/local_perspectives
- Timestamp:
- Oct 15, 2008 4:16:39 PM (16 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- fee780b
- Parents:
- 00353b4
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
guiframe/local_perspectives/plotting/plotting.py
r1c9419f4 r7764b41 12 12 import wx 13 13 import sys 14 #from sans.guitools.PlotPanel import PlotPanel15 14 import danse.common.plottools 16 15 from danse.common.plottools.PlotPanel import PlotPanel 17 #from sans.guitools.plottables import Graph 18 from danse.common.plottools.plottables import Graph 16 from danse.common.plottools.plottables import Graph,Data1D 19 17 from sans.guicomm.events import EVT_NEW_PLOT 20 18 … … 28 26 def set_graph(self, graph): 29 27 self.graph = graph 30 31 class View1DPanel (PlotPanel):28 29 class View1DPanel1D(PlotPanel): 32 30 """ 33 31 Plot panel for use with the GUI manager … … 145 143 self.graph.render(self) 146 144 self.subplot.figure.canvas.draw_idle() 147 148 145 149 146 … … 199 196 slicerpop.AppendSeparator() 200 197 201 #id = wx.NewId()202 #slicerpop.Append(id, '&Toggle Linear/Log scale')203 #wx.EVT_MENU(self, id, self._onToggleScale)204 205 198 if self.graph.selected_plottable in self.plots: 206 199 if self.plots[self.graph.selected_plottable].__class__.__name__=="Theory1D": … … 213 206 wx.EVT_MENU(self, id, self.onFitting) 214 207 215 id = wx.NewId() 216 slicerpop.Append(id, '&Toggle Linear/Log scale') 217 wx.EVT_MENU(self, id, self._onToggleScale) 208 218 209 219 210 id = wx.NewId() … … 230 221 self.PopupMenu(slicerpop, pos) 231 222 223 232 224 def _on_add_errors(self, evt): 233 225 """ … … 237 229 import math 238 230 import numpy 239 from sans.guitools.plottables import Data1D240 231 import time 241 232 … … 250 241 dy=dy) 251 242 new_plot.interactive = True 252 new_plot.name = self.plots[self.graph.selected_plottable].name #+" data"243 new_plot.name = self.plots[self.graph.selected_plottable].name 253 244 if hasattr(self.plots[self.graph.selected_plottable], "group_id"): 254 245 new_plot.group_id = self.plots[self.graph.selected_plottable].group_id … … 324 315 self.set_yscale('log') 325 316 self.subplot.figure.canvas.draw_idle() 326 317 318 class View1DPanel2D( View1DPanel1D): 319 """ 320 Plot panel for use with the GUI manager 321 """ 322 323 ## Internal name for the AUI manager 324 window_name = "plotpanel" 325 ## Title to appear on top of the window 326 window_caption = "Plot Panel" 327 ## Flag to tell the GUI manager that this panel is not 328 # tied to any perspective 329 ALWAYS_ON = True 330 ## Group ID 331 group_id = None 332 333 def __init__(self, parent, id = -1, color = None,\ 334 dpi = None, style = wx.NO_FULL_REPAINT_ON_RESIZE, **kwargs): 335 """ 336 Initialize the panel 337 """ 338 View1DPanel1D.__init__(self, parent, id = id, style = style, **kwargs) 339 340 ## Reference to the parent window 341 self.parent = parent 342 ## Plottables 343 self.plots = {} 344 345 ## Unique ID (from gui_manager) 346 self.uid = None 347 348 ## Action IDs for internal call-backs 349 self.action_ids = {} 350 351 ## Graph 352 self.graph = Graph() 353 self.graph.xaxis("\\rm{Q}", 'A^{-1}') 354 self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 355 self.graph.render(self) 356 357 def _onEVT_1DREPLOT(self, event): 358 """ 359 Data is ready to be displayed 360 @param event: data event 361 """ 362 #TODO: Check for existence of plot attribute 363 364 # Check whether this is a replot. If we ask for a replot 365 # and the plottable no longer exists, ignore the event. 366 if hasattr(event, "update") and event.update==True \ 367 and event.plot.name not in self.plots.keys(): 368 return 369 370 if hasattr(event, "reset"): 371 self._reset() 372 373 is_new = True 374 if event.plot.name in self.plots.keys(): 375 # Check whether the class of plottable changed 376 if not event.plot.__class__==self.plots[event.plot.name].__class__: 377 self.graph.delete(self.plots[event.plot.name]) 378 else: 379 is_new = False 380 381 if is_new: 382 self.plots[event.plot.name] = event.plot 383 self.graph.add(self.plots[event.plot.name]) 384 else: 385 self.plots[event.plot.name].x = event.plot.x 386 self.plots[event.plot.name].y = event.plot.y 387 self.plots[event.plot.name].dy = event.plot.dy 388 if hasattr(event.plot, 'dx') and hasattr(self.plots[event.plot.name], 'dx'): 389 self.plots[event.plot.name].dx = event.plot.dx 390 391 392 # Check axis labels 393 #TODO: Should re-factor this 394 #if event.plot._xunit != self.graph.prop["xunit"]: 395 self.graph.xaxis(event.plot._xaxis, event.plot._xunit) 396 397 #if event.plot._yunit != self.graph.prop["yunit"]: 398 self.graph.yaxis(event.plot._yaxis, event.plot._yunit) 399 400 401 self.graph.render(self) 402 self.subplot.figure.canvas.draw_idle() 403 404 405 def onContextMenu(self, event): 406 """ 407 1D plot context menu 408 @param event: wx context event 409 """ 410 #slicerpop = wx.Menu() 411 slicerpop = PanelMenu() 412 slicerpop.set_plots(self.plots) 413 slicerpop.set_graph(self.graph) 414 415 # Option to save the data displayed 416 417 418 # Various plot options 419 id = wx.NewId() 420 slicerpop.Append(id,'&Save image', 'Save image as PNG') 421 wx.EVT_MENU(self, id, self.onSaveImage) 422 423 424 item_list = self.parent.get_context_menu(self.graph) 425 if (not item_list==None) and (not len(item_list)==0): 426 slicerpop.AppendSeparator() 427 for item in item_list: 428 try: 429 id = wx.NewId() 430 slicerpop.Append(id, item[0], item[1]) 431 wx.EVT_MENU(self, id, item[2]) 432 except: 433 print sys.exc_value 434 print RuntimeError, "View1DPanel2D.onContextMenu: bad menu item" 435 436 slicerpop.AppendSeparator() 437 438 439 id = wx.NewId() 440 slicerpop.Append(id, '&Toggle Linear/Log scale') 441 wx.EVT_MENU(self, id, self._onToggleScale) 442 443 pos = event.GetPosition() 444 pos = self.ScreenToClient(pos) 445 self.PopupMenu(slicerpop, pos) 446 447 448 449 327 450 class Plugin: 328 451 """ … … 423 546 # Create a new plot panel if none was available 424 547 if not is_available: 425 new_panel = View1DPanel(self.parent, -1, style=wx.RAISED_BORDER) 548 if not hasattr(event.plot,'image'): 549 new_panel = View1DPanel1D(self.parent, -1, style=wx.RAISED_BORDER) 550 else: 551 new_panel = View1DPanel2D(self.parent, -1, style=wx.RAISED_BORDER) 426 552 # Set group ID if available 427 553 group_id_str = '' … … 440 566 self.menu.Append(event_id, new_panel.window_caption, 441 567 "Show %s plot panel" % new_panel.window_caption) 442 443 568 # Set UID to allow us to reference the panel later 444 569 new_panel.uid = event_id 445 446 570 # Ship the plottable to its panel 447 571 new_panel._onEVT_1DREPLOT(event)
Note: See TracChangeset
for help on using the changeset viewer.