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