##// END OF EJS Templates
changed main script to be compliant back to ipython script directory call
laurent.dufrechou@gmail.com -
Show More
@@ -1,265 +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 if(not sync_ok):
98 if(not sync_ok):
99 warn_text +="\n->No twisted package detected, IPython1 example deactivated."
99 warn_text +="\n->No twisted package detected, IPython1 example deactivated."
100
100
101 dlg = wx.MessageDialog(self,
101 dlg = wx.MessageDialog(self,
102 warn_text,
102 warn_text,
103 'Warning Box',
103 'Warning Box',
104 wx.OK | wx.ICON_INFORMATION
104 wx.OK | wx.ICON_INFORMATION
105 )
105 )
106 dlg.ShowModal()
106 dlg.ShowModal()
107 dlg.Destroy()
107 dlg.Destroy()
108
108
109 def optionSave(self, name, value):
109 def optionSave(self, name, value):
110 ip = get()
110 ip = get()
111 path = ip.IP.rc.ipythondir
111 path = ip.IP.rc.ipythondir
112 opt = open(path + '/options.conf','w')
112 opt = open(path + '/options.conf','w')
113
113
114 try:
114 try:
115 options_ipython_panel = self.ipython_panel.getOptions()
115 options_ipython_panel = self.ipython_panel.getOptions()
116 options_history_panel = self.history_panel.getOptions()
116 options_history_panel = self.history_panel.getOptions()
117
117
118 for key in options_ipython_panel.keys():
118 for key in options_ipython_panel.keys():
119 opt.write(key + '=' + options_ipython_panel[key]['value']+'\n')
119 opt.write(key + '=' + options_ipython_panel[key]['value']+'\n')
120 for key in options_history_panel.keys():
120 for key in options_history_panel.keys():
121 opt.write(key + '=' + options_history_panel[key]['value']+'\n')
121 opt.write(key + '=' + options_history_panel[key]['value']+'\n')
122 finally:
122 finally:
123 opt.close()
123 opt.close()
124
124
125 def optionLoad(self):
125 def optionLoad(self):
126 try:
126 try:
127 ip = get()
127 ip = get()
128 path = ip.IP.rc.ipythondir
128 path = ip.IP.rc.ipythondir
129 opt = open(path + '/options.conf','r')
129 opt = open(path + '/options.conf','r')
130 lines = opt.readlines()
130 lines = opt.readlines()
131 opt.close()
131 opt.close()
132
132
133 options_ipython_panel = self.ipython_panel.getOptions()
133 options_ipython_panel = self.ipython_panel.getOptions()
134 options_history_panel = self.history_panel.getOptions()
134 options_history_panel = self.history_panel.getOptions()
135
135
136 for line in lines:
136 for line in lines:
137 key = line.split('=')[0]
137 key = line.split('=')[0]
138 value = line.split('=')[1].replace('\n','').replace('\r','')
138 value = line.split('=')[1].replace('\n','').replace('\r','')
139 if key in options_ipython_panel.keys():
139 if key in options_ipython_panel.keys():
140 options_ipython_panel[key]['value'] = value
140 options_ipython_panel[key]['value'] = value
141 elif key in options_history_panel.keys():
141 elif key in options_history_panel.keys():
142 options_history_panel[key]['value'] = value
142 options_history_panel[key]['value'] = value
143 else:
143 else:
144 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"
145 self.ipython_panel.reloadOptions(options_ipython_panel)
145 self.ipython_panel.reloadOptions(options_ipython_panel)
146 self.history_panel.reloadOptions(options_history_panel)
146 self.history_panel.reloadOptions(options_history_panel)
147
147
148 except IOError:
148 except IOError:
149 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."
150
150
151
151
152 def createMenu(self):
152 def createMenu(self):
153 """local method used to create one menu bar"""
153 """local method used to create one menu bar"""
154
154
155 mb = wx.MenuBar()
155 mb = wx.MenuBar()
156
156
157 file_menu = wx.Menu()
157 file_menu = wx.Menu()
158 file_menu.Append(wx.ID_EXIT, "Exit")
158 file_menu.Append(wx.ID_EXIT, "Exit")
159
159
160 view_menu = wx.Menu()
160 view_menu = wx.Menu()
161 view_menu.Append(wx.ID_HIGHEST+1, "Show IPython Panel")
161 view_menu.Append(wx.ID_HIGHEST+1, "Show IPython Panel")
162 view_menu.Append(wx.ID_HIGHEST+2, "Show History Panel")
162 view_menu.Append(wx.ID_HIGHEST+2, "Show History Panel")
163 view_menu.AppendSeparator()
163 view_menu.AppendSeparator()
164 view_menu.Append(wx.ID_HIGHEST+6, "Show All")
164 view_menu.Append(wx.ID_HIGHEST+6, "Show All")
165
165
166 about_menu = wx.Menu()
166 about_menu = wx.Menu()
167 about_menu.Append(wx.ID_HIGHEST+3, "About")
167 about_menu.Append(wx.ID_HIGHEST+3, "About")
168
168
169 mb.Append(file_menu, "File")
169 mb.Append(file_menu, "File")
170 mb.Append(view_menu, "View")
170 mb.Append(view_menu, "View")
171 mb.Append(about_menu, "About")
171 mb.Append(about_menu, "About")
172 #mb.Append(options_menu, "Options")
172 #mb.Append(options_menu, "Options")
173
173
174 self.SetMenuBar(mb)
174 self.SetMenuBar(mb)
175
175
176 def createStatus(self):
176 def createStatus(self):
177 statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
177 statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
178 statusbar.SetStatusWidths([-2, -3])
178 statusbar.SetStatusWidths([-2, -3])
179 statusbar.SetStatusText("Ready", 0)
179 statusbar.SetStatusText("Ready", 0)
180 statusbar.SetStatusText("WxIPython "+str(__version__), 1)
180 statusbar.SetStatusText("WxIPython "+str(__version__), 1)
181 return statusbar
181 return statusbar
182
182
183 def updateStatus(self,text):
183 def updateStatus(self,text):
184 states = {'IDLE':'Idle',
184 states = {'IDLE':'Idle',
185 'DO_EXECUTE_LINE':'Send command',
185 'DO_EXECUTE_LINE':'Send command',
186 'WAIT_END_OF_EXECUTION':'Running command',
186 'WAIT_END_OF_EXECUTION':'Running command',
187 'WAITING_USER_INPUT':'Waiting user input',
187 'WAITING_USER_INPUT':'Waiting user input',
188 'SHOW_DOC':'Showing doc',
188 'SHOW_DOC':'Showing doc',
189 'SHOW_PROMPT':'Showing prompt'}
189 'SHOW_PROMPT':'Showing prompt'}
190 self.statusbar.SetStatusText(states[text], 0)
190 self.statusbar.SetStatusText(states[text], 0)
191
191
192 def OnClose(self, event):
192 def OnClose(self, event):
193 """#event used to close program """
193 """#event used to close program """
194 # deinitialize the frame manager
194 # deinitialize the frame manager
195 self._mgr.UnInit()
195 self._mgr.UnInit()
196 self.Destroy()
196 self.Destroy()
197 event.Skip()
197 event.Skip()
198
198
199 def OnExitDlg(self, event):
199 def OnExitDlg(self, event):
200 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',
201 'WxIPython exit',
201 'WxIPython exit',
202 wx.ICON_QUESTION |
202 wx.ICON_QUESTION |
203 wx.YES_NO | wx.NO_DEFAULT
203 wx.YES_NO | wx.NO_DEFAULT
204 )
204 )
205 if dlg.ShowModal() == wx.ID_YES:
205 if dlg.ShowModal() == wx.ID_YES:
206 dlg.Destroy()
206 dlg.Destroy()
207 self._mgr.UnInit()
207 self._mgr.UnInit()
208 self.Destroy()
208 self.Destroy()
209 dlg.Destroy()
209 dlg.Destroy()
210
210
211 #event to display IPython pannel
211 #event to display IPython pannel
212 def OnShowIPythonPanel(self,event):
212 def OnShowIPythonPanel(self,event):
213 """ #event to display Boxpannel """
213 """ #event to display Boxpannel """
214 self._mgr.GetPane(self.ipython_panel).Show(True)
214 self._mgr.GetPane(self.ipython_panel).Show(True)
215 self._mgr.Update()
215 self._mgr.Update()
216 #event to display History pannel
216 #event to display History pannel
217 def OnShowHistoryPanel(self,event):
217 def OnShowHistoryPanel(self,event):
218 self._mgr.GetPane(self.history_panel).Show(True)
218 self._mgr.GetPane(self.history_panel).Show(True)
219 self._mgr.Update()
219 self._mgr.Update()
220
220
221 def OnShowAllPanel(self,event):
221 def OnShowAllPanel(self,event):
222 """#event to display all Pannels"""
222 """#event to display all Pannels"""
223 self._mgr.GetPane(self.ipython_panel).Show(True)
223 self._mgr.GetPane(self.ipython_panel).Show(True)
224 self._mgr.GetPane(self.history_panel).Show(True)
224 self._mgr.GetPane(self.history_panel).Show(True)
225 self._mgr.Update()
225 self._mgr.Update()
226
226
227 def OnShowAbout(self, event):
227 def OnShowAbout(self, event):
228 # First we create and fill the info object
228 # First we create and fill the info object
229 info = wx.AboutDialogInfo()
229 info = wx.AboutDialogInfo()
230 info.Name = "WxIPython"
230 info.Name = "WxIPython"
231 info.Version = str(__version__)
231 info.Version = str(__version__)
232 info.Copyright = "(C) 2007 Laurent Dufrechou"
232 info.Copyright = "(C) 2007 Laurent Dufrechou"
233 info.Description = wordwrap(
233 info.Description = wordwrap(
234 "A Gui that embbed a multithreaded IPython Shell",
234 "A Gui that embbed a multithreaded IPython Shell",
235 350, wx.ClientDC(self))
235 350, wx.ClientDC(self))
236 info.WebSite = ("http://ipython.scipy.org/", "IPython home page")
236 info.WebSite = ("http://ipython.scipy.org/", "IPython home page")
237 info.Developers = [ "Laurent Dufrechou" ]
237 info.Developers = [ "Laurent Dufrechou" ]
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"
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"
239 info.License = wordwrap(licenseText, 500, wx.ClientDC(self))
239 info.License = wordwrap(licenseText, 500, wx.ClientDC(self))
240
240
241 # Then we call wx.AboutBox giving it that info object
241 # Then we call wx.AboutBox giving it that info object
242 wx.AboutBox(info)
242 wx.AboutBox(info)
243
243
244 #-----------------------------------------
244 #-----------------------------------------
245 #Creating our application
245 #Creating our application
246 #-----------------------------------------
246 #-----------------------------------------
247 class MyApp(wx.PySimpleApp):
247 class MyApp(wx.PySimpleApp):
248 """Creating our application"""
248 """Creating our application"""
249 def __init__(self, sync_ok=False):
249 def __init__(self, sync_ok=False):
250 wx.PySimpleApp.__init__(self)
250 wx.PySimpleApp.__init__(self)
251
251
252 self.frame = MyFrame(sync_ok=sync_ok)
252 self.frame = MyFrame(sync_ok=sync_ok)
253 self.frame.Show()
253 self.frame.Show()
254
254
255 #-----------------------------------------
255 #-----------------------------------------
256 #Main loop
256 #Main loop
257 #-----------------------------------------
257 #-----------------------------------------
258 def main(sync_ok):
258 def main():
259 app = MyApp(sync_ok)
259 app = MyApp(is_sync_frontend_ok)
260 app.SetTopWindow(app.frame)
260 app.SetTopWindow(app.frame)
261 app.MainLoop()
261 app.MainLoop()
262
262
263 #if launched as main program run this
263 #if launched as main program run this
264 if __name__ == '__main__':
264 if __name__ == '__main__':
265 main(is_sync_frontend_ok)
265 main()
General Comments 0
You need to be logged in to leave comments. Login now