Changeset c87d55a in sasview
- Timestamp:
- Sep 4, 2008 11:37:08 AM (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:
- d89f09b
- Parents:
- 84545dd
- Location:
- guitools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
guitools/PlotPanel.py
r08b9e586 rc87d55a 382 382 when clicking on linear Fit on context menu , display Fitting Dialog 383 383 """ 384 list =[] 385 list = self.graph.returnPlottable() 384 list = {} 385 plotlist = self.graph.returnPlottable() 386 if self.graph.selected_plottable is not None: 387 for item in plotlist: 388 if item.name==self.graph.selected_plottable: 389 list[item] = plotlist[item] 390 else: 391 list = plotlist 386 392 from fitDialog import LinearFit 387 393 -
guitools/test_panel.py
r057210c rc87d55a 1 1 import wx 2 2 from PlotPanel import PlotPanel 3 from plottables import Plottable, Graph, Data1D 3 from plottables import Plottable, Graph, Data1D, Theory1D 4 4 import sys 5 5 import numpy 6 import pylab6 import random, math 7 7 8 class SANSplotpanel(PlotPanel): 9 10 def __init__(self, parent, id = -1, color = None,\ 11 dpi = None, **kwargs): 12 PlotPanel.__init__(self, parent, id=id, color=color, dpi=dpi, **kwargs) 13 14 # Keep track of the parent Frame 15 self.parent = parent 16 17 # Internal list of plottable names (because graph 18 # doesn't have a dictionary of handles for the plottables) 19 self.plots = {} 20 21 def add_plottable(self, plot): 22 self.plots[plot.name] = plot 23 24 self.graph.add(plot) 25 self.graph.xaxis('\\rm{q} ', 'A^{-1}') 26 self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 27 self.onResetGraph(None) 28 29 def plottable_selected(self, id): 30 PlotPanel.plottable_selected(self, id) 31 if id is not None: 32 self.parent.SetStatusText("Hovering over %s" % self.graph.selected_plottable) 33 else: 34 self.parent.SetStatusText("") 35 36 37 def onContextMenu(self, event): 38 """ 39 Default context menu for a plot panel 40 """ 41 # Slicer plot popup menu 42 id = wx.NewId() 43 slicerpop = wx.Menu() 44 slicerpop.Append(id,'&Save image', 'Save image as PNG') 45 wx.EVT_MENU(self, id, self.onSaveImage) 46 47 slicerpop.AppendSeparator() 48 id = wx.NewId() 49 slicerpop.Append(id, '&Change scale') 50 wx.EVT_MENU(self, id, self._onProperties) 51 52 id = wx.NewId() 53 slicerpop.Append(id, '&Reset Graph') 54 wx.EVT_MENU(self, id, self.onResetGraph) 55 56 if self.graph.selected_plottable in self.plots: 57 # Careful here: Message to status bar 58 self.parent.SetStatusText("Fit a line to %s" % self.graph.selected_plottable) 59 id = wx.NewId() 60 slicerpop.AppendSeparator() 61 slicerpop.Append(id, '&Linear Fit to %s' % self.graph.selected_plottable ) 62 wx.EVT_MENU(self, id, self.onFitting) 63 64 pos = event.GetPosition() 65 pos = self.ScreenToClient(pos) 66 self.PopupMenu(slicerpop, pos) 67 68 def onFitting(self, event): 69 if self.graph.selected_plottable is not None: 70 if self.plots[self.graph.selected_plottable].__class__.__name__ == 'Data1D': 71 PlotPanel.onFitting(self, event) 72 else: 73 self.parent.SetStatusText("Can't fit a theory curve") 8 74 9 75 class ViewerFrame(wx.Frame): … … 20 86 21 87 # Panel for 1D plot 22 self.plotpanel = PlotPanel(self, -1, style=wx.RAISED_BORDER) 23 24 x = pylab.arange(0, 25, 1) 25 dx = numpy.zeros(len(x)) 26 y = x/2.0 27 dy = y*0.1 28 29 self.data = Data1D(x=x, y=y, dx=None, dy=dy) 30 31 # Graph 32 self.graph = Graph() 33 self.graph.xaxis('\\rm{q} ', 'A^{-1}') 34 self.graph.yaxis("\\rm{Intensity} ","cm^{-1}") 35 self.graph.add(self.data) 36 self.graph.render(self.plotpanel) 88 self.plotpanel = SANSplotpanel(self, -1, style=wx.RAISED_BORDER) 37 89 38 90 # Set up the menu … … 63 115 self.SetSizer(sizer) 64 116 self.Centre() 65 66 67 117 68 118 def _setup_menus(self): … … 75 125 # File menu 76 126 filemenu = wx.Menu() 77 filemenu.Append(101,'&Quit', 'Exit') 127 128 # Quit 129 id = wx.NewId() 130 filemenu.Append(id,'&Quit', 'Exit') 131 wx.EVT_MENU(self, id, self.Close) 132 133 # New plot 134 id = wx.NewId() 135 filemenu.Append(id,'&Add data', 'Add a new curve to the plot') 136 wx.EVT_MENU(self, id, self._add_data) 78 137 79 138 # Add sub menus … … 81 140 82 141 self.SetMenuBar(menubar) 83 84 # Bind handlers 85 wx.EVT_MENU(self, 101, self.Close) 86 142 87 143 def _onClose(self, event): 88 144 """ … … 90 146 wx.Exit() 91 147 sys.exit() 92 93 def Close(self, event=None): 94 """ 95 Quit the application 96 """ 97 wx.Frame.Close(self) 98 wx.Exit() 99 sys.exit() 100 148 149 def _add_data(self, event): 150 data_len = 25 151 x = numpy.zeros(data_len) 152 y = numpy.zeros(data_len) 153 x2 = numpy.zeros(data_len) 154 y2 = numpy.zeros(data_len) 155 dy2 = numpy.zeros(data_len) 156 x3 = numpy.zeros(data_len) 157 y3 = numpy.zeros(data_len) 158 dy3 = numpy.zeros(data_len) 159 for i in range(len(x)): 160 x[i] = i 161 x2[i] = i-0.1+0.2*random.random() 162 x3[i] = i-0.1+0.2*random.random() 163 y[i] = 0.5*(i+random.random()) 164 y2[i] = i+random.random() 165 dy2[i] = math.sqrt(y2[i]) 166 y3[i] = 0.3*(i+random.random()) 167 dy3[i] = math.sqrt(y3[i]) 168 169 newplot = Theory1D(x=x, y=y) 170 newplot.name = "Theory curve" 171 self.plotpanel.add_plottable(newplot) 172 173 newplot = Data1D(x=x2, y=y2, dy=dy2) 174 newplot.name = "Data set 1" 175 self.plotpanel.add_plottable(newplot) 176 177 newplot = Data1D(x=x3, y=y3, dy=dy3) 178 newplot.name = "Data set 2" 179 self.plotpanel.add_plottable(newplot) 180 101 181 102 182 class ViewApp(wx.App):
Note: See TracChangeset
for help on using the changeset viewer.