##// END OF EJS Templates
Helpful error message if trying to run the ipythonx entry point without...
gvaroquaux -
Show More
@@ -1,91 +1,100
1 1 #!/usr/bin/env python
2 2 """
3 3 Entry point for a simple application giving a graphical frontend to
4 4 ipython.
5 5 """
6 6
7 import wx
7 try:
8 import wx
9 except ImportError, e:
10 e.message = """%s
11 ________________________________________________________________________________
12 You need wxPython to run this application.
13 """ % e.message
14 e.args = (e.message, ) + e.args[1:]
15 raise e
16
8 17 from wx_frontend import WxController
9 18 import __builtin__
10 19
11 20 class IPythonXController(WxController):
12 21 """ Sub class of WxController that adds some application-specific
13 22 bindings.
14 23 """
15 24
16 25 debug = False
17 26
18 27 def __init__(self, *args, **kwargs):
19 28 WxController.__init__(self, *args, **kwargs)
20 29 self.ipython0.ask_exit = self.do_exit
21 30
22 31
23 32 def _on_key_down(self, event, skip=True):
24 33 # Intercept Ctrl-D to quit
25 34 if event.KeyCode == ord('D') and event.ControlDown() and \
26 35 self.input_buffer == '' and \
27 36 self._input_state == 'readline':
28 37 wx.CallAfter(self.ask_exit)
29 38 else:
30 39 WxController._on_key_down(self, event, skip=skip)
31 40
32 41
33 42 def ask_exit(self):
34 43 """ Ask the user whether to exit.
35 44 """
36 45 self.write('\n')
37 46 self.capture_output()
38 47 self.ipython0.shell.exit()
39 48 self.release_output()
40 49 wx.Yield()
41 50 if not self.ipython0.exit_now:
42 51 self.new_prompt(self.input_prompt_template.substitute(
43 52 number=self.last_result['number'] + 1))
44 53
45 54
46 55 def do_exit(self):
47 56 """ Exits the interpreter, kills the windows.
48 57 """
49 58 WxController.do_exit(self)
50 59 self.release_output()
51 60 wx.CallAfter(wx.Exit)
52 61
53 62
54 63
55 64 class IPythonX(wx.Frame):
56 65 """ Main frame of the IPythonX app.
57 66 """
58 67
59 68 def __init__(self, parent, id, title):
60 69 wx.Frame.__init__(self, parent, id, title, size=(300,250))
61 70 self._sizer = wx.BoxSizer(wx.VERTICAL)
62 71 self.shell = IPythonXController(self)
63 72 self._sizer.Add(self.shell, 1, wx.EXPAND)
64 73 self.SetSizer(self._sizer)
65 74 self.SetAutoLayout(1)
66 75 self.Show(True)
67 76
68 77
69 78 def main():
70 79 from optparse import OptionParser
71 80 usage = """usage: %prog [options]
72 81
73 82 Simple graphical frontend to IPython, using WxWidgets."""
74 83 parser = OptionParser(usage=usage)
75 84 parser.add_option("-d", "--debug",
76 85 action="store_true", dest="debug", default=False,
77 86 help="Enable debug message for the wx frontend.")
78 87
79 88 options, args = parser.parse_args()
80 89
81 90 app = wx.PySimpleApp()
82 91 frame = IPythonX(None, wx.ID_ANY, 'IPythonX')
83 92 frame.shell.debug = options.debug
84 93 frame.shell.SetFocus()
85 94 frame.shell.app = app
86 95 frame.SetSize((680, 460))
87 96
88 97 app.MainLoop()
89 98
90 99 if __name__ == '__main__':
91 100 main()
General Comments 0
You need to be logged in to leave comments. Login now