diff --git a/IPython/frontend/qt/console/rich_ipython_widget.py b/IPython/frontend/qt/console/rich_ipython_widget.py index 9003af7..9b89c4b 100644 --- a/IPython/frontend/qt/console/rich_ipython_widget.py +++ b/IPython/frontend/qt/console/rich_ipython_widget.py @@ -1,3 +1,5 @@ +import os + # System library imports from PyQt4 import QtCore, QtGui @@ -61,7 +63,7 @@ class RichIPythonWidget(IPythonWidget): """ payload = msg['content']['payload'] for item in payload: - if item['type'] == 'plot': + if item['source'] == 'IPython.zmq.pylab.backend_payload.add_plot_payload': if item['format'] == 'svg': svg = item['data'] try: @@ -78,6 +80,24 @@ class RichIPythonWidget(IPythonWidget): else: # Add other plot formats here! pass + elif item['source'] == 'IPython.zmq.zmqshell.ZMQInteractiveShell.edit_magic': + # TODO: I have implmented the logic for TextMate on the Mac. + # But, we need to allow payload handlers on the non-rich + # text IPython widget as well. Furthermore, we should probably + # move these handlers to separate methods. But, we need to + # be very careful to process the payload list in order. Thus, + # we will probably need a _handle_payload method of the + # base class that dispatches to the separate handler methods + # for each payload source. If a particular subclass doesn't + # have a handler for a payload source, it should at least + # print a nice message. + filename = item['filename'] + line_number = item['line_number'] + if line_number is None: + cmd = 'mate %s' % filename + else: + cmd = 'mate -l %s %s' % (line_number, filename) + os.system(cmd) else: # Add other payload types here! pass diff --git a/IPython/zmq/pylab/backend_payload.py b/IPython/zmq/pylab/backend_payload.py index 8ad92d5..74d4de6 100644 --- a/IPython/zmq/pylab/backend_payload.py +++ b/IPython/zmq/pylab/backend_payload.py @@ -19,5 +19,8 @@ def add_plot_payload(format, data, metadata={}): metadata : dict, optional [default empty] Allows for specification of additional information about the plot data. """ - payload = dict(type='plot', format=format, data=data, metadata=metadata) + payload = dict( + source='IPython.zmq.pylab.backend_payload.add_plot_payload', + format=format, data=data, metadata=metadata + ) InteractiveShell.instance().payload_manager.write_payload(payload) diff --git a/IPython/zmq/zmqshell.py b/IPython/zmq/zmqshell.py index c3789b0..b1ddefa 100644 --- a/IPython/zmq/zmqshell.py +++ b/IPython/zmq/zmqshell.py @@ -1,3 +1,5 @@ +import inspect +import re import sys from subprocess import Popen, PIPE @@ -5,7 +7,11 @@ from IPython.core.interactiveshell import ( InteractiveShell, InteractiveShellABC ) from IPython.core.displayhook import DisplayHook +from IPython.core.macro import Macro +from IPython.utils.path import get_py_filename +from IPython.utils.text import StringTypes from IPython.utils.traitlets import Instance, Type, Dict +from IPython.utils.warn import warn from IPython.zmq.session import extract_header @@ -341,43 +347,6 @@ class ZMQInteractiveShell(InteractiveShell): } self.payload_manager.write_payload(payload) - # # do actual editing here - # print 'Editing...', - # sys.stdout.flush() - # try: - # # Quote filenames that may have spaces in them - # if ' ' in filename: - # filename = "%s" % filename - # self.shell.hooks.editor(filename,lineno) - # except TryNext: - # warn('Could not open editor') - # return - # - # # XXX TODO: should this be generalized for all string vars? - # # For now, this is special-cased to blocks created by cpaste - # if args.strip() == 'pasted_block': - # self.shell.user_ns['pasted_block'] = file_read(filename) - # - # if opts.has_key('x'): # -x prevents actual execution - # print - # else: - # print 'done. Executing edited code...' - # if opts_r: - # self.shell.runlines(file_read(filename)) - # else: - # self.shell.safe_execfile(filename,self.shell.user_ns, - # self.shell.user_ns) - # - # - # if use_temp: - # try: - # return open(filename).read() - # except IOError,msg: - # if msg.filename == filename: - # warn('File not found. Did you forget to save?') - # return - # else: - # self.shell.showtraceback() InteractiveShellABC.register(ZMQInteractiveShell)