source: sasview/plottools/examples/test_text_panel.py @ fd67a9e

ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change on this file since fd67a9e was 82a54b8, checked in by Mathieu Doucet <doucetm@…>, 13 years ago

adding plottools Part 2

  • Property mode set to 100755
File size: 3.2 KB
RevLine 
[82a54b8]1"""
2Test application that uses plottools
3
4An application required by the REFL group and mainly test the Chisq class.
5   
6The following is a checklist of functionality to look for while testing:
71- Start the application:
8   the graph should have theory curve, experimental data, chisq
9   with a white background.
10
112- Hovering over any plotted data will highlight the whole data set
12   or line in yellow.
13
143- Left-clicking on the graph and dragging will drag the graph.
15
164- Using the mouse wheel will zoom in and out of the graph.
17
185- Right-clicking on the graph when no curve is highlighted will
19   pop up the context menu:
20   - 'Save image' will pop up a save dialog to save an image.
21   - 'Reset graph' will reset the graph to its original appearance after it
22                   has been dragged around or zoomed in or out.
23   - 'Change scale' will pop up a scale dialog with which the axes can
24                    be transformed. Each transformation choice should work.
25
26"""
27
28import wx
29from danse.common.plottools.PlotPanel import PlotPanel
30from danse.common.plottools.plottables import Plottable, Graph, Data1D, Theory1D
31import  sys
32import numpy
33
34
35class 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        # Slicer plot popup menu
57        id = wx.NewId()
58        _menu = wx.Menu()
59        _menu.Append(id,'&Save image', 'Save image as PNG')
60        wx.EVT_MENU(self, id, self.onSaveImage)
61       
62        _menu.AppendSeparator()
63        id = wx.NewId()
64        _menu.Append(id, '&Change scale')
65        wx.EVT_MENU(self, id, self._onProperties)
66       
67        id = wx.NewId()
68        _menu.Append(id, '&Reset Graph')
69        wx.EVT_MENU(self, id, self.onResetGraph)
70 
71        pos = event.GetPosition()
72        pos = self.ScreenToClient(pos)
73        self.PopupMenu(slicerpop, pos)
74       
75
76# ---------------------------------------------------------------
77def sample_graph():
78    # Construct a simple graph
79
80    from danse.common.plottools.plottables import Text, Graph
81   
82    T1 = Text(text='text example 1', xpos=0.2, ypos=0.2)
83    T2 = Text(text='text example 2', xpos=0.5, ypos=0.5)
84    T3 = Text(text=r'$\chi^2=1.2$', xpos=0.8, ypos=0.8)
85   
86    graph = Graph()
87    graph.title( 'Test Text Class' )
88    graph.add( T1 )
89    graph.add( T2 ) 
90    graph.add( T3 )
91    return graph
92
93
94def demo_plotter(graph):
95    # Make a frame to show it
96    app     = wx.PySimpleApp()
97    frame   = wx.Frame(None,-1,'Plottables')
98    plotter = TestPlotPanel(frame)
99    frame.Show()
100
101    # render the graph to the pylab plotter
102    graph.render(plotter)
103   
104    app.MainLoop()
105
106   
107if __name__ == "__main__":
108    pass
109    demo_plotter(sample_graph())
110
111           
Note: See TracBrowser for help on using the repository browser.