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