1 | import wx |
---|
2 | from plottables import Plottable, Graph |
---|
3 | from Plotter1D import ModelPanel1D |
---|
4 | import Plotter1D |
---|
5 | |
---|
6 | class ViewerFrame(wx.Frame): |
---|
7 | |
---|
8 | def __init__(self, parent, id, title): |
---|
9 | # Initialize the Frame object |
---|
10 | wx.Frame.__init__(self, parent, id, title, wx.DefaultPosition, wx.Size(950,850)) |
---|
11 | |
---|
12 | # Panel for 1D plot |
---|
13 | self.slice_plot = ModelPanel1D(self, -1, style=wx.RAISED_BORDER) |
---|
14 | |
---|
15 | # Set up the menu |
---|
16 | self._setup_menus() |
---|
17 | |
---|
18 | # Set up the layout |
---|
19 | self._setup_layout() |
---|
20 | |
---|
21 | # Register the close event so it calls our own method |
---|
22 | wx.EVT_CLOSE(self, self._onClose) |
---|
23 | |
---|
24 | |
---|
25 | def _setup_layout(self): |
---|
26 | """ |
---|
27 | Set up the layout |
---|
28 | """ |
---|
29 | # Status bar |
---|
30 | self.sb = self.CreateStatusBar() |
---|
31 | self.SetStatusText("This is a data viewer") |
---|
32 | |
---|
33 | # Add panel |
---|
34 | vbox = wx.BoxSizer(wx.VERTICAL) |
---|
35 | #sizer = wx.GridBagSizer(6,6) |
---|
36 | sizer = wx.GridBagSizer(5,5) |
---|
37 | pnl1 = wx.Panel(self, -1, style=wx.SIMPLE_BORDER) |
---|
38 | vbox.Add(pnl1, 1, wx.EXPAND | wx.ALL) |
---|
39 | |
---|
40 | self.tc1 = wx.TextCtrl(pnl1, -1,style=wx.SIMPLE_BORDER) |
---|
41 | self.tc2 = wx.TextCtrl(pnl1, -1,style=wx.SIMPLE_BORDER) |
---|
42 | |
---|
43 | ix = 0 |
---|
44 | iy = 0 |
---|
45 | |
---|
46 | #sizer.Add(self.slice_plot,(ix,iy),(1,6), wx.EXPAND | wx.ALL,5) |
---|
47 | sizer.Add(self.slice_plot,(ix,iy),(1,5), wx.EXPAND | wx.ALL,5) |
---|
48 | sizer.SetItemMinSize(self.slice_plot, 150,200) |
---|
49 | |
---|
50 | iy+=1 |
---|
51 | sizer.Add((20,20),(iy,ix)) |
---|
52 | |
---|
53 | ix +=1 |
---|
54 | sizer.Add(wx.StaticText(pnl1, -1, 'Constant A'),(iy,ix)) |
---|
55 | |
---|
56 | ix+=1 |
---|
57 | |
---|
58 | |
---|
59 | sizer.Add(self.tc1, (iy, ix), (1, 1), wx.RIGHT, 550) |
---|
60 | self.tc1.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) |
---|
61 | |
---|
62 | ix = 0 |
---|
63 | iy +=1 |
---|
64 | sizer.Add((20,20),(iy,ix)) |
---|
65 | |
---|
66 | ix +=1 |
---|
67 | sizer.Add(wx.StaticText(pnl1, -1, 'Constant B'),(iy,ix)) |
---|
68 | |
---|
69 | ix +=1 |
---|
70 | sizer.Add(self.tc2, (iy, ix),(1,1), wx.RIGHT, 550) |
---|
71 | self.tc2.Bind(wx.EVT_KILL_FOCUS, self._onTextEnter) |
---|
72 | btn1 = wx.Button(pnl1, 2, 'fit', (50,90)) |
---|
73 | self.Bind(wx.EVT_BUTTON, self.slice_plot._onFit) |
---|
74 | ix +=1 |
---|
75 | sizer.Add(btn1, (iy, ix), (1, 1), wx.RIGHT, 5) |
---|
76 | #sizer.Add(btn1, (1, 3), (1, 1), wx.RIGHT, 5) |
---|
77 | pnl1.SetSizer(sizer) |
---|
78 | sizer.AddGrowableRow(0) |
---|
79 | sizer.AddGrowableCol(0) |
---|
80 | self.SetSizer(vbox) |
---|
81 | self.Centre() |
---|
82 | self.Bind(wx.EVT_TEXT_ENTER, self._onTextEnter) |
---|
83 | |
---|
84 | |
---|
85 | def _onTextEnter(self,event): |
---|
86 | """ |
---|
87 | Send parameters to plot x* cstA + cstB |
---|
88 | |
---|
89 | """ |
---|
90 | param_evt = Plotter1D.FunctionParamEvent(cstA=float(self.tc1.GetValue()),\ |
---|
91 | cstB=float(self.tc2.GetValue())) |
---|
92 | wx.PostEvent(self, param_evt) |
---|
93 | |
---|
94 | |
---|
95 | def _onClicked(self,event): |
---|
96 | |
---|
97 | self.Bind(event,self.slice_plot._onFit ) |
---|
98 | |
---|
99 | def _setup_menus(self): |
---|
100 | """ |
---|
101 | Set up the application menus |
---|
102 | """ |
---|
103 | |
---|
104 | # Menu |
---|
105 | menubar = wx.MenuBar() |
---|
106 | # File menu |
---|
107 | filemenu = wx.Menu() |
---|
108 | filemenu.Append(104,'&Load 1D data', 'Load a 1D data file') |
---|
109 | filemenu.Append(101,'&Quit', 'Exit') |
---|
110 | |
---|
111 | # Add sub menus |
---|
112 | menubar.Append(filemenu, '&File') |
---|
113 | |
---|
114 | self.SetMenuBar(menubar) |
---|
115 | |
---|
116 | # Bind handlers |
---|
117 | wx.EVT_MENU(self, 101, self.Close) |
---|
118 | wx.EVT_MENU(self, 104, self.slice_plot._onLoad1DData) |
---|
119 | |
---|
120 | def _onClose(self, event): |
---|
121 | import sys |
---|
122 | wx.Exit() |
---|
123 | sys.exit() |
---|
124 | |
---|
125 | def Close(self, event=None): |
---|
126 | """ |
---|
127 | Quit the application |
---|
128 | """ |
---|
129 | import sys |
---|
130 | wx.Frame.Close(self) |
---|
131 | wx.Exit() |
---|
132 | sys.exit() |
---|
133 | |
---|
134 | |
---|
135 | class ViewApp(wx.App): |
---|
136 | def OnInit(self): |
---|
137 | frame = ViewerFrame(None, -1, 'miniView') |
---|
138 | frame.Show(True) |
---|
139 | self.SetTopWindow(frame) |
---|
140 | |
---|
141 | return True |
---|
142 | |
---|
143 | |
---|
144 | if __name__ == "__main__": |
---|
145 | app = ViewApp(0) |
---|
146 | app.MainLoop() |
---|
147 | |
---|