Show More
@@ -1,80 +1,73 b'' | |||||
1 | """ |
|
1 | """ | |
2 | Entry point for a simple application giving a graphical frontend to |
|
2 | Entry point for a simple application giving a graphical frontend to | |
3 | ipython. |
|
3 | ipython. | |
4 | """ |
|
4 | """ | |
5 |
|
5 | |||
6 | import wx |
|
6 | import wx | |
7 | from wx_frontend import WxController |
|
7 | from wx_frontend import WxController | |
8 |
|
8 | |||
9 | class WIPythonController(WxController): |
|
9 | class WIPythonController(WxController): | |
10 | """ Sub class of WxController that adds some application-specific |
|
10 | """ Sub class of WxController that adds some application-specific | |
11 | bindings. |
|
11 | bindings. | |
12 | """ |
|
12 | """ | |
13 |
|
13 | |||
14 | def __init__(self, *args, **kwargs): |
|
14 | def __init__(self, *args, **kwargs): | |
15 | WxController.__init__(self, *args, **kwargs) |
|
15 | WxController.__init__(self, *args, **kwargs) | |
16 | self.ipython0.ask_exit = self.do_exit |
|
16 | self.ipython0.ask_exit = self.do_exit | |
17 |
|
17 | |||
18 |
|
18 | |||
19 | def _on_key_down(self, event, skip=True): |
|
19 | def _on_key_down(self, event, skip=True): | |
20 | # Intercept Ctrl-D to quit |
|
20 | # Intercept Ctrl-D to quit | |
21 | if event.KeyCode == ord('D') and event.ControlDown() and \ |
|
21 | if event.KeyCode == ord('D') and event.ControlDown() and \ | |
22 | self.get_current_edit_buffer()=='': |
|
22 | self.get_current_edit_buffer()=='': | |
23 | wx.CallAfter(self.ask_exit) |
|
23 | wx.CallAfter(self.ask_exit) | |
24 | else: |
|
24 | else: | |
25 | WxController._on_key_down(self, event, skip=skip) |
|
25 | WxController._on_key_down(self, event, skip=skip) | |
26 |
|
26 | |||
27 |
|
27 | |||
28 | def ask_exit(self): |
|
28 | def ask_exit(self): | |
29 | """ Ask the user whether to exit. |
|
29 | """ Ask the user whether to exit. | |
30 | """ |
|
30 | """ | |
31 | self.write('\n') |
|
31 | self.write('\n') | |
32 | self.capture_output() |
|
32 | self.capture_output() | |
33 | self.ipython0.shell.exit() |
|
33 | self.ipython0.shell.exit() | |
34 | self.release_output() |
|
34 | self.release_output() | |
35 | wx.Yield() |
|
35 | wx.Yield() | |
36 | if not self.ipython0.exit_now: |
|
36 | if not self.ipython0.exit_now: | |
37 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) |
|
37 | self.new_prompt(self.prompt % (self.last_result['number'] + 1)) | |
38 |
|
38 | |||
39 |
|
39 | |||
40 | def do_exit(self): |
|
40 | def do_exit(self): | |
41 | """ Exits the interpreter, kills the windows. |
|
41 | """ Exits the interpreter, kills the windows. | |
42 | """ |
|
42 | """ | |
43 | WxController.do_exit(self) |
|
43 | WxController.do_exit(self) | |
44 | # Remove the callbacks, to avoid PyDeadObjectErrors |
|
|||
45 | do_nothing = lambda *args, **kwargs: True |
|
|||
46 | self.release_output() |
|
44 | self.release_output() | |
47 | self._on_key_down = do_nothing |
|
45 | wx.CallAfter(wx.Exit) | |
48 | self._on_key_up = do_nothing |
|
|||
49 | self._on_enter = do_nothing |
|
|||
50 | self.after_execute = do_nothing |
|
|||
51 | wx.Yield() |
|
|||
52 | wx.CallAfter(self.Parent.Destroy) |
|
|||
53 |
|
46 | |||
54 |
|
47 | |||
55 |
|
48 | |||
56 | class WIPython(wx.Frame): |
|
49 | class WIPython(wx.Frame): | |
57 | """ Main frame of the WIPython app. |
|
50 | """ Main frame of the WIPython app. | |
58 | """ |
|
51 | """ | |
59 |
|
52 | |||
60 | def __init__(self, parent, id, title): |
|
53 | def __init__(self, parent, id, title): | |
61 | wx.Frame.__init__(self, parent, id, title, size=(300,250)) |
|
54 | wx.Frame.__init__(self, parent, id, title, size=(300,250)) | |
62 | self._sizer = wx.BoxSizer(wx.VERTICAL) |
|
55 | self._sizer = wx.BoxSizer(wx.VERTICAL) | |
63 | self.shell = WIPythonController(self) |
|
56 | self.shell = WIPythonController(self) | |
64 | self._sizer.Add(self.shell, 1, wx.EXPAND) |
|
57 | self._sizer.Add(self.shell, 1, wx.EXPAND) | |
65 | self.SetSizer(self._sizer) |
|
58 | self.SetSizer(self._sizer) | |
66 | self.SetAutoLayout(1) |
|
59 | self.SetAutoLayout(1) | |
67 | self.Show(True) |
|
60 | self.Show(True) | |
68 |
|
61 | |||
69 |
|
62 | |||
70 | def main(): |
|
63 | def main(): | |
71 | app = wx.PySimpleApp() |
|
64 | app = wx.PySimpleApp() | |
72 |
frame = WIPython(None, wx.ID_ANY, 'WI |
|
65 | frame = WIPython(None, wx.ID_ANY, 'WIPython') | |
73 | frame.shell.SetFocus() |
|
66 | frame.shell.SetFocus() | |
74 | frame.shell.app = app |
|
67 | frame.shell.app = app | |
75 | frame.SetSize((680, 460)) |
|
68 | frame.SetSize((680, 460)) | |
76 |
|
69 | |||
77 | app.MainLoop() |
|
70 | app.MainLoop() | |
78 |
|
71 | |||
79 | if __name__ == '__main__': |
|
72 | if __name__ == '__main__': | |
80 | main() |
|
73 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now