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