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