Thanks to the help of Robert Bradshaw, and to the file IPython/
hooks.py,  I've cobbled together the following sage.init file:

import IPython
from IPython import ipapi
from IPython.genutils import Term
from pprint import PrettyPrinter

pformat = PrettyPrinter().pformat

def repr_and_parent(self, arg):
    if hasattr(arg, 'parent'):
        try:
            print >>Term.cout, "%s\n\nParent: %s"%(repr(arg),repr
(arg.parent()))
            return
        except:
            pass
    raise ipapi.TryNext

def repr_only(self,arg):
    if self.rc.pprint:
        out = pformat(arg)
        if '\n' in out:
            Term.cout.write('\n')
        print >>Term.cout, out
    else:
        print >>Term.cout, repr(arg)
    return None

def show_parent():
    ipapi.get().set_hook("result_display", repr_and_parent)

def hide_parent():
    ipapi.get().set_hook("result_display", repr_only)

However, it doesn't work.  In console mode show_parent() should turn
the display of parents on, and hide_parent() should turn it off.  It
seems to work once - but not again.  That is, parent display can be
turned on, and then off, but not on again - show_parent() has no
effect after one "cycle". I'm not quite sure what's going on - my
python knowledge is limited.  And sometimes when parent display is on,
hide_parent() has no effect.

Any ideas?

Thanks,
Alasdair
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support-unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to