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