1 | import wx |
---|
2 | from PlotPanel import PlotPanel |
---|
3 | from plottables import Plottable, Graph, Data1D |
---|
4 | import sys |
---|
5 | import numpy |
---|
6 | import pylab |
---|
7 | |
---|
8 | |
---|
9 | class 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 | |
---|
102 | class 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 | |
---|
111 | if __name__ == "__main__": |
---|
112 | app = ViewApp(0) |
---|
113 | app.MainLoop() |
---|
114 | |
---|