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