Show More
@@ -1,255 +1,256 b'' | |||
|
1 | 1 | #!/usr/bin/python |
|
2 | 2 | # -*- coding: iso-8859-15 -*- |
|
3 | 3 | |
|
4 | 4 | import wx.aui |
|
5 | 5 | import sys |
|
6 | 6 | #used for about dialog |
|
7 | 7 | from wx.lib.wordwrap import wordwrap |
|
8 | 8 | |
|
9 | 9 | #used for ipython GUI objects |
|
10 | 10 | from IPython.gui.wx.ipython_view import IPShellWidget |
|
11 | 11 | from IPython.gui.wx.ipython_history import IPythonHistoryPanel |
|
12 | 12 | |
|
13 | 13 | #used to invoke ipython1 wx implementation |
|
14 | 14 | from IPython.frontend.wx.ipythonx import IPythonXController |
|
15 | 15 | |
|
16 | 16 | #used to create options.conf file in user directory |
|
17 | 17 | from IPython.ipapi import get |
|
18 | 18 | |
|
19 | 19 | __version__ = 0.9 |
|
20 | 20 | __author__ = "Laurent Dufrechou" |
|
21 | 21 | __email__ = "laurent.dufrechou _at_ gmail.com" |
|
22 | 22 | __license__ = "BSD" |
|
23 | 23 | |
|
24 | 24 | #----------------------------------------- |
|
25 | 25 | # Creating one main frame for our |
|
26 | 26 | # application with movables windows |
|
27 | 27 | #----------------------------------------- |
|
28 | 28 | class MyFrame(wx.Frame): |
|
29 | 29 | """Creating one main frame for our |
|
30 | 30 | application with movables windows""" |
|
31 | 31 | def __init__(self, parent=None, id=-1, title="WxIPython", |
|
32 | 32 | pos=wx.DefaultPosition, |
|
33 | 33 | size=(800, 600), style=wx.DEFAULT_FRAME_STYLE): |
|
34 | 34 | wx.Frame.__init__(self, parent, id, title, pos, size, style) |
|
35 | 35 | self._mgr = wx.aui.AuiManager() |
|
36 | 36 | |
|
37 | 37 | # notify PyAUI which frame to use |
|
38 | 38 | self._mgr.SetManagedWindow(self) |
|
39 | 39 | |
|
40 | 40 | #create differents panels and make them persistant |
|
41 | 41 | self.history_panel = IPythonHistoryPanel(self) |
|
42 | 42 | |
|
43 | 43 | self.history_panel.setOptionTrackerHook(self.optionSave) |
|
44 | 44 | |
|
45 | 45 | self.ipython_panel = IPShellWidget(self,background_color = "BLACK") |
|
46 | 46 | self.ipython_panel2 = IPythonXController(self) |
|
47 | 47 | #self.ipython_panel = IPShellWidget(self,background_color = "WHITE") |
|
48 | 48 | |
|
49 | 49 | self.ipython_panel.setHistoryTrackerHook(self.history_panel.write) |
|
50 | 50 | self.ipython_panel.setStatusTrackerHook(self.updateStatus) |
|
51 | 51 | self.ipython_panel.setAskExitHandler(self.OnExitDlg) |
|
52 | 52 | self.ipython_panel.setOptionTrackerHook(self.optionSave) |
|
53 | 53 | |
|
54 | 54 | #Create a notebook to display different IPython shell implementations |
|
55 | 55 | self.nb = wx.aui.AuiNotebook(self) |
|
56 | 56 | |
|
57 | 57 | self.optionLoad() |
|
58 | 58 | |
|
59 | 59 | self.statusbar = self.createStatus() |
|
60 | 60 | self.createMenu() |
|
61 | 61 | |
|
62 | 62 | ######################################################################## |
|
63 | 63 | ### add the panes to the manager |
|
64 | 64 | # main panels |
|
65 | 65 | self._mgr.AddPane(self.nb , wx.CENTER, "IPython Shells") |
|
66 | 66 | self.nb.AddPage(self.ipython_panel , "IPython0 Shell") |
|
67 | 67 | self.nb.AddPage(self.ipython_panel2, "IPython1 Synchroneous Shell") |
|
68 | 68 | |
|
69 | 69 | self._mgr.AddPane(self.history_panel , wx.RIGHT, "IPython history") |
|
70 | 70 | |
|
71 | 71 | # now we specify some panel characteristics |
|
72 | 72 | self._mgr.GetPane(self.ipython_panel).CaptionVisible(True); |
|
73 | 73 | self._mgr.GetPane(self.history_panel).CaptionVisible(True); |
|
74 | 74 | self._mgr.GetPane(self.history_panel).MinSize((200,400)); |
|
75 | 75 | |
|
76 | 76 | # tell the manager to "commit" all the changes just made |
|
77 | 77 | self._mgr.Update() |
|
78 | 78 | |
|
79 | 79 | #global event handling |
|
80 | 80 | self.Bind(wx.EVT_CLOSE, self.OnClose) |
|
81 | 81 | self.Bind(wx.EVT_MENU, self.OnClose,id=wx.ID_EXIT) |
|
82 | 82 | self.Bind(wx.EVT_MENU, self.OnShowIPythonPanel,id=wx.ID_HIGHEST+1) |
|
83 | 83 | self.Bind(wx.EVT_MENU, self.OnShowHistoryPanel,id=wx.ID_HIGHEST+2) |
|
84 | 84 | self.Bind(wx.EVT_MENU, self.OnShowAbout, id=wx.ID_HIGHEST+3) |
|
85 | 85 | self.Bind(wx.EVT_MENU, self.OnShowAllPanel,id=wx.ID_HIGHEST+6) |
|
86 | 86 | |
|
87 | 87 | warn_text = 'Hello from IPython and wxPython.\n' |
|
88 | 88 | warn_text +='Please Note that this work is still EXPERIMENTAL\n' |
|
89 | 89 | warn_text +='It does NOT emulate currently all the IPython functions.\n' |
|
90 | warn_text +="\nIf you use MATPLOTLIB with show() you'll need to deactivate the THREADING option.\n" | |
|
90 | 91 | |
|
91 | 92 | dlg = wx.MessageDialog(self, |
|
92 | 93 | warn_text, |
|
93 | 94 | 'Warning Box', |
|
94 | 95 | wx.OK | wx.ICON_INFORMATION |
|
95 | 96 | ) |
|
96 | 97 | dlg.ShowModal() |
|
97 | 98 | dlg.Destroy() |
|
98 | 99 | |
|
99 | 100 | def optionSave(self, name, value): |
|
100 | 101 | ip = get() |
|
101 | 102 | path = ip.IP.rc.ipythondir |
|
102 | 103 | opt = open(path + '/options.conf','w') |
|
103 | 104 | |
|
104 | 105 | try: |
|
105 | 106 | options_ipython_panel = self.ipython_panel.getOptions() |
|
106 | 107 | options_history_panel = self.history_panel.getOptions() |
|
107 | 108 | |
|
108 | 109 | for key in options_ipython_panel.keys(): |
|
109 | 110 | opt.write(key + '=' + options_ipython_panel[key]['value']+'\n') |
|
110 | 111 | for key in options_history_panel.keys(): |
|
111 | 112 | opt.write(key + '=' + options_history_panel[key]['value']+'\n') |
|
112 | 113 | finally: |
|
113 | 114 | opt.close() |
|
114 | 115 | |
|
115 | 116 | def optionLoad(self): |
|
116 | 117 | try: |
|
117 | 118 | ip = get() |
|
118 | 119 | path = ip.IP.rc.ipythondir |
|
119 | 120 | opt = open(path + '/options.conf','r') |
|
120 | 121 | lines = opt.readlines() |
|
121 | 122 | opt.close() |
|
122 | 123 | |
|
123 | 124 | options_ipython_panel = self.ipython_panel.getOptions() |
|
124 | 125 | options_history_panel = self.history_panel.getOptions() |
|
125 | 126 | |
|
126 | 127 | for line in lines: |
|
127 | 128 | key = line.split('=')[0] |
|
128 | 129 | value = line.split('=')[1].replace('\n','').replace('\r','') |
|
129 | 130 | if key in options_ipython_panel.keys(): |
|
130 | 131 | options_ipython_panel[key]['value'] = value |
|
131 | 132 | elif key in options_history_panel.keys(): |
|
132 | 133 | options_history_panel[key]['value'] = value |
|
133 | 134 | else: |
|
134 | 135 | print >>sys.__stdout__,"Warning: key ",key,"not found in widget options. Check Options.conf" |
|
135 | 136 | self.ipython_panel.reloadOptions(options_ipython_panel) |
|
136 | 137 | self.history_panel.reloadOptions(options_history_panel) |
|
137 | 138 | |
|
138 | 139 | except IOError: |
|
139 | 140 | print >>sys.__stdout__,"Could not open Options.conf, defaulting to default values." |
|
140 | 141 | |
|
141 | 142 | |
|
142 | 143 | def createMenu(self): |
|
143 | 144 | """local method used to create one menu bar""" |
|
144 | 145 | |
|
145 | 146 | mb = wx.MenuBar() |
|
146 | 147 | |
|
147 | 148 | file_menu = wx.Menu() |
|
148 | 149 | file_menu.Append(wx.ID_EXIT, "Exit") |
|
149 | 150 | |
|
150 | 151 | view_menu = wx.Menu() |
|
151 | 152 | view_menu.Append(wx.ID_HIGHEST+1, "Show IPython Panel") |
|
152 | 153 | view_menu.Append(wx.ID_HIGHEST+2, "Show History Panel") |
|
153 | 154 | view_menu.AppendSeparator() |
|
154 | 155 | view_menu.Append(wx.ID_HIGHEST+6, "Show All") |
|
155 | 156 | |
|
156 | 157 | about_menu = wx.Menu() |
|
157 | 158 | about_menu.Append(wx.ID_HIGHEST+3, "About") |
|
158 | 159 | |
|
159 | 160 | mb.Append(file_menu, "File") |
|
160 | 161 | mb.Append(view_menu, "View") |
|
161 | 162 | mb.Append(about_menu, "About") |
|
162 | 163 | #mb.Append(options_menu, "Options") |
|
163 | 164 | |
|
164 | 165 | self.SetMenuBar(mb) |
|
165 | 166 | |
|
166 | 167 | def createStatus(self): |
|
167 | 168 | statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP) |
|
168 | 169 | statusbar.SetStatusWidths([-2, -3]) |
|
169 | 170 | statusbar.SetStatusText("Ready", 0) |
|
170 | 171 | statusbar.SetStatusText("WxIPython "+str(__version__), 1) |
|
171 | 172 | return statusbar |
|
172 | 173 | |
|
173 | 174 | def updateStatus(self,text): |
|
174 | 175 | states = {'IDLE':'Idle', |
|
175 | 176 | 'DO_EXECUTE_LINE':'Send command', |
|
176 | 177 | 'WAIT_END_OF_EXECUTION':'Running command', |
|
177 | 178 | 'WAITING_USER_INPUT':'Waiting user input', |
|
178 | 179 | 'SHOW_DOC':'Showing doc', |
|
179 | 180 | 'SHOW_PROMPT':'Showing prompt'} |
|
180 | 181 | self.statusbar.SetStatusText(states[text], 0) |
|
181 | 182 | |
|
182 | 183 | def OnClose(self, event): |
|
183 | 184 | """#event used to close program """ |
|
184 | 185 | # deinitialize the frame manager |
|
185 | 186 | self._mgr.UnInit() |
|
186 | 187 | self.Destroy() |
|
187 | 188 | event.Skip() |
|
188 | 189 | |
|
189 | 190 | def OnExitDlg(self, event): |
|
190 | 191 | dlg = wx.MessageDialog(self, 'Are you sure you want to quit WxIPython', |
|
191 | 192 | 'WxIPython exit', |
|
192 | 193 | wx.ICON_QUESTION | |
|
193 | 194 | wx.YES_NO | wx.NO_DEFAULT |
|
194 | 195 | ) |
|
195 | 196 | if dlg.ShowModal() == wx.ID_YES: |
|
196 | 197 | dlg.Destroy() |
|
197 | 198 | self._mgr.UnInit() |
|
198 | 199 | self.Destroy() |
|
199 | 200 | dlg.Destroy() |
|
200 | 201 | |
|
201 | 202 | #event to display IPython pannel |
|
202 | 203 | def OnShowIPythonPanel(self,event): |
|
203 | 204 | """ #event to display Boxpannel """ |
|
204 | 205 | self._mgr.GetPane(self.ipython_panel).Show(True) |
|
205 | 206 | self._mgr.Update() |
|
206 | 207 | #event to display History pannel |
|
207 | 208 | def OnShowHistoryPanel(self,event): |
|
208 | 209 | self._mgr.GetPane(self.history_panel).Show(True) |
|
209 | 210 | self._mgr.Update() |
|
210 | 211 | |
|
211 | 212 | def OnShowAllPanel(self,event): |
|
212 | 213 | """#event to display all Pannels""" |
|
213 | 214 | self._mgr.GetPane(self.ipython_panel).Show(True) |
|
214 | 215 | self._mgr.GetPane(self.history_panel).Show(True) |
|
215 | 216 | self._mgr.Update() |
|
216 | 217 | |
|
217 | 218 | def OnShowAbout(self, event): |
|
218 | 219 | # First we create and fill the info object |
|
219 | 220 | info = wx.AboutDialogInfo() |
|
220 | 221 | info.Name = "WxIPython" |
|
221 | 222 | info.Version = str(__version__) |
|
222 | 223 | info.Copyright = "(C) 2007 Laurent Dufrechou" |
|
223 | 224 | info.Description = wordwrap( |
|
224 | 225 | "A Gui that embbed a multithreaded IPython Shell", |
|
225 | 226 | 350, wx.ClientDC(self)) |
|
226 | 227 | info.WebSite = ("http://ipython.scipy.org/", "IPython home page") |
|
227 | 228 | info.Developers = [ "Laurent Dufrechou" ] |
|
228 | 229 | licenseText="BSD License.\nAll rights reserved. This program and the accompanying materials are made available under the terms of the BSD which accompanies this distribution, and is available at http://www.opensource.org/licenses/bsd-license.php" |
|
229 | 230 | info.License = wordwrap(licenseText, 500, wx.ClientDC(self)) |
|
230 | 231 | |
|
231 | 232 | # Then we call wx.AboutBox giving it that info object |
|
232 | 233 | wx.AboutBox(info) |
|
233 | 234 | |
|
234 | 235 | #----------------------------------------- |
|
235 | 236 | #Creating our application |
|
236 | 237 | #----------------------------------------- |
|
237 | 238 | class MyApp(wx.PySimpleApp): |
|
238 | 239 | """Creating our application""" |
|
239 | 240 | def __init__(self): |
|
240 | 241 | wx.PySimpleApp.__init__(self) |
|
241 | 242 | |
|
242 | 243 | self.frame = MyFrame() |
|
243 | 244 | self.frame.Show() |
|
244 | 245 | |
|
245 | 246 | #----------------------------------------- |
|
246 | 247 | #Main loop |
|
247 | 248 | #----------------------------------------- |
|
248 | 249 | def main(): |
|
249 | 250 | app = MyApp() |
|
250 | 251 | app.SetTopWindow(app.frame) |
|
251 | 252 | app.MainLoop() |
|
252 | 253 | |
|
253 | 254 | #if launched as main program run this |
|
254 | 255 | if __name__ == '__main__': |
|
255 | 256 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now