Changeset 860

Show
Ignore:
Timestamp:
09/19/05 16:15:39 (3 years ago)
Author:
rkern
Message:

Restored output cache and input history

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nbshell/trunk/ChangeLog

    r852 r860  
     12005-09-19  Robert Kern  <robert.kern@gmail.com> 
     2 
     3    * IPythonLog.py (IPythonLog.__init__, displayhook, __run): Restored 
     4    output cache and input history functionality via the In and Out 
     5    variables. 
     6 
     7 
    182005-09-18  Tzanko Matev  <tsanko@gmail.com> 
    29 
  • nbshell/trunk/nbshell/IPythonLog.py

    r838 r860  
    1717import StringIO 
    1818import textwrap 
     19import __builtin__ 
     20import pprint 
    1921 
    2022from wx.py.buffer import Buffer 
     
    2830 
    2931from IPython import Shell 
     32from IPython import genutils 
     33from IPython.Magic import Macro 
    3034from notabene import notebook 
    3135 
     
    8791        excepthook_orig = sys.excepthook 
    8892        self.interp = Shell.IPShellGUI(argv=['-colors','NoColor'], user_ns=user_ns) 
     93 
     94        self.interp_log = self.interp.IP.log 
     95        def donothing(*args, **kwds): 
     96            pass 
     97        self.interp.IP.log = donothing 
     98        del self.interp.IP.input_hist[0] 
     99 
    89100        self.excepthook_IP = sys.excepthook 
    90101        sys.excepthook = excepthook_orig 
     
    241252        #TODO:this could be prettier 
    242253        self.currentcell = cell 
     254 
     255        # Add the whole input to the input history (ignoring the leading and 
     256        # trailing '\n') 
     257        self.interp_log(cell.input[1:-1], False) 
     258 
    243259        #The first and last characters of cell.input are '\n' 
    244260        retval = self.interp.runlines(cell.input[1:-1],\ 
     
    284300         
    285301    def displayhook(self, obj): 
     302        # RTK: modified from IPython.Prompts.CachedOutput.__call__() 
     303         
     304        slf = self.interp.IP.outputcache 
     305        slf.prompt_count = self.currentcell.number 
     306 
    286307        #print >> self.stdout_orig,  'displayhook called' #dbg 
    287308        # We want to keep only the last output 
    288309        if obj is not None: 
    289             self.output = '\n%s\n' % obj 
     310            if slf.Pprint: 
     311                self.output = '\n%s\n' % pprint.pformat(obj) 
     312            else: 
     313                self.output = '\n%r\n' % obj 
     314 
     315        # If something injected a '_' variable in __builtin__, delete 
     316        # ipython's automatic one so we don't clobber that.  gettext() in 
     317        # particular uses _, so we need to stay away from it. 
     318        if '_' in __builtin__.__dict__: 
     319            try: 
     320                del slf.user_ns['_'] 
     321            except KeyError: 
     322                pass 
     323        if obj is not None: 
     324            cout_write = genutils.Term.cout.write # fast lookup 
     325            # first handle the cache and counters 
     326            slf.update(obj) 
     327            # do not print output if input ends in ';' 
     328            if slf.input_hist[slf.prompt_count].endswith(';\n'): 
     329                return 
     330            # don't use print, puts an extra space 
     331            #cout_write(slf.output_sep) 
     332            #if slf.do_full_cache: 
     333            #    cout_write(str(slf.prompt_out)) 
     334 
     335            if isinstance(obj,Macro): 
     336                print 'Executing Macro...' 
     337                # in case the macro takes a long time to execute 
     338                genutils.Term.cout.flush() 
     339                exec obj.value in slf.user_ns 
     340                return None 
     341 
     342            # and now call a possibly user-defined print mechanism 
     343            #slf.display(obj) 
     344            #cout_write(slf.output_sep2) 
     345            #genutils.Term.cout.flush() 
     346 
     347 
     348