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