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