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