##// END OF EJS Templates
Full patch for better user color tweaking + patch for 'enter' synchro bug
Full patch for better user color tweaking + patch for 'enter' synchro bug

File last commit:

r1834:d1575c19
r1834:d1575c19
Show More
ipythonx.py
175 lines | 5.7 KiB | text/x-python | PythonLexer
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 """
Entry point for a simple application giving a graphical frontend to
ipython.
"""
gvaroquaux
Helpful error message if trying to run the ipythonx entry point without...
r1477 try:
import wx
except ImportError, e:
e.message = """%s
________________________________________________________________________________
You need wxPython to run this application.
""" % e.message
e.args = (e.message, ) + e.args[1:]
raise e
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834 import wx.stc as stc
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 from wx_frontend import WxController
Gael Varoquaux
First cut of subprocess execution with redirection of stdin/stdout.
r1437 import __builtin__
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391
Gael Varoquaux
Add a banner.
r1495
Gael Varoquaux
Fixed a race-condition in subprocess execution....
r1438 class IPythonXController(WxController):
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 """ Sub class of WxController that adds some application-specific
bindings.
"""
gvaroquaux
Clean up the test application for the wx frontend.
r1475 debug = False
Gael Varoquaux
Proper redirection of keystrokes to subprocesses.
r1450
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 def __init__(self, *args, **kwargs):
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834
if kwargs['colorset'] == 'black':
self.prompt_in1 = \
'\n\x01\x1b[0;30m\x02In [\x01\x1b[1;34m\x02$number\x01\x1b[0;30m\x02]: \x01\x1b[0m\x02'
self.prompt_out = \
'\x01\x1b[0;31m\x02Out[\x01\x1b[1;31m\x02$number\x01\x1b[0;31m\x02]: \x01\x1b[0m\x02'
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 WxController.__init__(self, *args, **kwargs)
self.ipython0.ask_exit = self.do_exit
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834
if kwargs['colorset'] == 'black':
self.carret_color = 'WHITE'
self.background_color = 'BLACK'
self.SetEdgeMode(stc.STC_EDGE_LINE)
self.SetEdgeColumn(88)
self.style = {
#'stdout' : '',#fore:#0000FF',
#'stderr' : '',#fore:#007f00',
#'trace' : '',#fore:#FF0000',
#'bracegood' : 'fore:#0000FF,back:#0000FF,bold',
#'bracebad' : 'fore:#FF0000,back:#0000FF,bold',
'default' : "fore:%s,back:%s,size:%d,face:%s,bold"
% ("#EEEEEE", self.background_color,
self.faces['size'], self.faces['mono']),
# properties for the various Python lexer styles
'comment' : 'fore:#BBBBBB,italic',
'number' : 'fore:#FF9692',
'string' : 'fore:#ed9d13,italic',
'char' : 'fore:#FFFFFF,italic',
'keyword' : 'fore:#6AB825,bold',
'triple' : 'fore:#FF7BDD',
'tripledouble' : 'fore:#FF7BDD',
'class' : 'fore:#FF00FF,bold,underline',
'def' : 'fore:#FFFF00,bold',
'operator' : 'bold'
}
#we define the background of old inputs
self._COMPLETE_BUFFER_BG = '#000000' # RRGGBB: Black
#we define the background of current input
self._INPUT_BUFFER_BG = '#444444' # RRGGBB: Light black
#we define the background when an error is reported
self._ERROR_BG = '#800000' #'#d22323' #'#AE0021' # RRGGBB: Black
self.set_new_style()
Gael Varoquaux
Add a banner.
r1495 # Scroll to top
maxrange = self.GetScrollRange(wx.VERTICAL)
self.ScrollLines(-maxrange)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391
def _on_key_down(self, event, skip=True):
# Intercept Ctrl-D to quit
if event.KeyCode == ord('D') and event.ControlDown() and \
gvaroquaux
More code reuse between GUI-independant frontend and Wx frontend: getting...
r1462 self.input_buffer == '' and \
gvaroquaux
Make process execution work under windows.
r1449 self._input_state == 'readline':
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 wx.CallAfter(self.ask_exit)
else:
WxController._on_key_down(self, event, skip=skip)
def ask_exit(self):
""" Ask the user whether to exit.
"""
gvaroquaux
Fix segfaults under windows.
r1479 self._input_state = 'subprocess'
self.write('\n', refresh=False)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 self.capture_output()
self.ipython0.shell.exit()
self.release_output()
if not self.ipython0.exit_now:
gvaroquaux
Fix segfaults under windows.
r1479 wx.CallAfter(self.new_prompt,
self.input_prompt_template.substitute(
Gael Varoquaux
More tests of the frontend. Improve the ease of testing.
r1458 number=self.last_result['number'] + 1))
gvaroquaux
Better fonts on MacOSX....
r1502 else:
wx.CallAfter(wx.GetApp().Exit)
self.write('Exiting ...', refresh=False)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391
def do_exit(self):
""" Exits the interpreter, kills the windows.
"""
WxController.do_exit(self)
self.release_output()
Gael Varoquaux
Clean up exit code.
r1392 wx.CallAfter(wx.Exit)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391
Gael Varoquaux
Fixed a race-condition in subprocess execution....
r1438 class IPythonX(wx.Frame):
""" Main frame of the IPythonX app.
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 """
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834 def __init__(self, parent, id, title, debug=False, colorset='white'):
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 wx.Frame.__init__(self, parent, id, title, size=(300,250))
self._sizer = wx.BoxSizer(wx.VERTICAL)
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834 self.shell = IPythonXController(self, debug=debug, colorset=colorset)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 self._sizer.Add(self.shell, 1, wx.EXPAND)
self.SetSizer(self._sizer)
self.SetAutoLayout(1)
self.Show(True)
Gael Varoquaux
IPythonX: terminate the mainloop when exiting, to close the child windows...
r1732 wx.EVT_CLOSE(self, self.on_close)
def on_close(self, event):
""" Called on closing the windows.
Stops the event loop, to close all the child windows.
"""
wx.CallAfter(wx.Exit)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391
def main():
gvaroquaux
Clean up the test application for the wx frontend.
r1475 from optparse import OptionParser
usage = """usage: %prog [options]
Simple graphical frontend to IPython, using WxWidgets."""
parser = OptionParser(usage=usage)
parser.add_option("-d", "--debug",
action="store_true", dest="debug", default=False,
help="Enable debug message for the wx frontend.")
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834 parser.add_option("-s", "--style",
dest="colorset", default="white",
help="style: white, black")
gvaroquaux
Clean up the test application for the wx frontend.
r1475 options, args = parser.parse_args()
gvaroquaux
Fix segfaults under windows.
r1479 # Clear the options, to avoid having the ipython0 instance complain
import sys
sys.argv = sys.argv[:1]
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 app = wx.PySimpleApp()
Laurent Dufrechou
Full patch for better user color tweaking + patch for 'enter' synchro bug
r1834 frame = IPythonX(None, wx.ID_ANY, 'IPythonX', debug=options.debug, colorset=options.colorset)
Gael Varoquaux
Add demo app. Add callback for exit to the ipython0 code.
r1391 frame.shell.SetFocus()
frame.shell.app = app
frame.SetSize((680, 460))
app.MainLoop()
if __name__ == '__main__':
main()