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