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