source: sasview/guitools/test_panel.py @ 057210c

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 057210c was 057210c, checked in by Mathieu Doucet <doucetm@…>, 16 years ago

Added a View class and an example

  • Property mode set to 100644
File size: 2.7 KB
Line 
1import wx
2from PlotPanel import PlotPanel
3from plottables import Plottable, Graph, Data1D
4import  sys
5import numpy
6import pylab
7
8
9class ViewerFrame(wx.Frame):
10    """
11        Add comment
12    """
13    def __init__(self, parent, id, title):
14        """
15            comment
16            @param parent: parent panel/container
17        """
18        # Initialize the Frame object
19        wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850))
20       
21        # 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)
37
38        # Set up the menu
39        self._setup_menus()
40     
41        # Set up the layout
42        self._setup_layout()
43               
44        # Register the close event so it calls our own method
45        wx.EVT_CLOSE(self, self._onClose)
46       
47       
48    def _setup_layout(self):
49        """
50            Set up the layout
51        """
52        # Status bar
53        self.sb = self.CreateStatusBar()
54        self.SetStatusText("This is a data viewer")
55       
56        # Two columns of panels
57        sizer = wx.GridBagSizer(0,0)
58       
59        sizer.Add(self.plotpanel, (0,0), (1,1),   flag=wx.EXPAND | wx.ALL, border=0)
60        sizer.AddGrowableRow(0)
61        sizer.AddGrowableCol(0)
62   
63        self.SetSizer(sizer)
64        self.Centre()
65       
66       
67               
68    def _setup_menus(self):
69        """
70            Set up the application menus
71        """
72       
73        # Menu
74        menubar = wx.MenuBar()
75        # File menu
76        filemenu = wx.Menu()
77        filemenu.Append(101,'&Quit', 'Exit')
78 
79        # Add sub menus
80        menubar.Append(filemenu, '&File')
81         
82        self.SetMenuBar(menubar)
83       
84        # Bind handlers
85        wx.EVT_MENU(self, 101, self.Close)
86               
87    def _onClose(self, event):
88        """
89        """
90        wx.Exit()
91        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   
101 
102class ViewApp(wx.App):
103    def OnInit(self):
104        frame = ViewerFrame(None, -1, 'testView')   
105        frame.Show(True)
106        self.SetTopWindow(frame)
107       
108        return True
109       
110
111if __name__ == "__main__": 
112    app = ViewApp(0)
113    app.MainLoop()       
114           
Note: See TracBrowser for help on using the repository browser.