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