[82a54b8] | 1 | """ |
---|
| 2 | Test application that uses plottools |
---|
| 3 | |
---|
| 4 | An application required by the REFL group and mainly test copy and print. |
---|
| 5 | |
---|
| 6 | The following is a checklist of functionality to look for while testing: |
---|
| 7 | 1- Start the application: |
---|
| 8 | the graph should have theory curve, experimental data, chisq |
---|
| 9 | with a white background. |
---|
| 10 | |
---|
| 11 | 2- Hovering over any plotted data will highlight the whole data set |
---|
| 12 | or line in yellow. |
---|
| 13 | |
---|
| 14 | 3- Left-clicking on the graph and dragging will drag the graph. |
---|
| 15 | |
---|
| 16 | 4- Using the mouse wheel will zoom in and out of the graph. |
---|
| 17 | |
---|
| 18 | 5- Right-clicking on the graph when no curve is highlighted will |
---|
| 19 | pop up the context menu: |
---|
| 20 | - 'copy image': copy the bitmap of figure to system clipboard |
---|
| 21 | - 'print Setup': setup the size of figure for printing |
---|
| 22 | - 'print preview': preview printer page |
---|
| 23 | - 'print': send figure to system printer. |
---|
| 24 | |
---|
| 25 | """ |
---|
| 26 | |
---|
| 27 | import wx |
---|
[f468791] | 28 | from sans.plottools.PlotPanel import PlotPanel |
---|
| 29 | from sans.plottools.plottables import Graph, Data1D, Theory1D |
---|
[82a54b8] | 30 | import sys |
---|
| 31 | sys.platform = 'win95' |
---|
| 32 | import numpy |
---|
| 33 | |
---|
| 34 | |
---|
| 35 | class TestPlotPanel(PlotPanel): |
---|
| 36 | |
---|
| 37 | def __init__(self, parent, id = -1, |
---|
| 38 | color = None, |
---|
| 39 | dpi = None, |
---|
| 40 | **kwargs): |
---|
| 41 | PlotPanel.__init__(self, parent, id=id, color=color, |
---|
| 42 | dpi=dpi, **kwargs) |
---|
| 43 | |
---|
| 44 | # Keep track of the parent Frame |
---|
| 45 | self.parent = parent |
---|
| 46 | |
---|
| 47 | # Internal list of plottable names (because graph |
---|
| 48 | # doesn't have a dictionary of handles for the plottables) |
---|
| 49 | self.plots = {} |
---|
| 50 | |
---|
| 51 | |
---|
| 52 | def onContextMenu(self, event): |
---|
| 53 | """ |
---|
| 54 | Default context menu for a plot panel |
---|
| 55 | """ |
---|
| 56 | wxID_Copy = wx.NewId() |
---|
| 57 | wxID_Print = wx.NewId() |
---|
| 58 | wxID_PrintPreview = wx.NewId() |
---|
| 59 | wxID_PrintSetup = wx.NewId() |
---|
| 60 | |
---|
| 61 | _menu = wx.Menu() |
---|
| 62 | _menu.Append(wxID_Copy,'&Copy Image', 'Copy image to Clipboard') |
---|
| 63 | wx.EVT_MENU(self, wxID_Copy, self.OnCopyFigureMenu) |
---|
| 64 | |
---|
| 65 | _menu.AppendSeparator() |
---|
| 66 | _menu.Append(wxID_PrintSetup, '&Print setup') |
---|
| 67 | wx.EVT_MENU(self, wxID_PrintSetup, self.onPrinterSetup) |
---|
| 68 | |
---|
| 69 | _menu.Append(wxID_PrintPreview, '&Print preview ') |
---|
| 70 | wx.EVT_MENU(self, wxID_PrintPreview, self.onPrinterPreview) |
---|
| 71 | |
---|
| 72 | _menu.Append(wxID_Print, '&Print ') |
---|
| 73 | wx.EVT_MENU(self, wxID_Print, self.onPrint) |
---|
| 74 | |
---|
| 75 | pos = event.GetPosition() |
---|
| 76 | pos = self.ScreenToClient(pos) |
---|
| 77 | self.PopupMenu(_menu, pos) |
---|
| 78 | |
---|
| 79 | |
---|
| 80 | # --------------------------------------------------------------- |
---|
| 81 | def sample_graph(): |
---|
| 82 | # Construct a simple graph |
---|
| 83 | x = numpy.linspace(0,2.0, 50) |
---|
| 84 | y = numpy.sin(2*numpy.pi*x*2.8) |
---|
| 85 | dy = numpy.sqrt(100*numpy.abs(y))/100 |
---|
| 86 | |
---|
| 87 | data = Data1D(x,y,dy=dy) |
---|
| 88 | data.xaxis('distance', 'm') |
---|
| 89 | data.yaxis('time', 's') |
---|
| 90 | |
---|
| 91 | graph = Graph() |
---|
| 92 | |
---|
| 93 | graph.add(data) |
---|
| 94 | graph.add( Theory1D(x,y,dy=dy)) |
---|
| 95 | |
---|
| 96 | graph.title( 'Test Copy and Print Image' ) |
---|
| 97 | return graph |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | def demo_plotter(graph): |
---|
| 101 | # Make a frame to show it |
---|
| 102 | app = wx.PySimpleApp() |
---|
| 103 | frame = wx.Frame(None,-1,'Plottables') |
---|
| 104 | plotter = TestPlotPanel(frame) |
---|
| 105 | frame.Show() |
---|
| 106 | |
---|
| 107 | # render the graph to the pylab plotter |
---|
| 108 | graph.render(plotter) |
---|
| 109 | |
---|
| 110 | app.MainLoop() |
---|
| 111 | |
---|
| 112 | |
---|
| 113 | if __name__ == "__main__": |
---|
| 114 | pass |
---|
| 115 | demo_plotter(sample_graph()) |
---|
| 116 | |
---|
| 117 | |
---|