def show_all(self): """Show entire demo on screen, block by block""" fname = self.title title = self.title nblocks = self.nblocks silent = self._silent marquee = self.marquee for index, block in enumerate(self.src_blocks_colored): if silent[index]: print( marquee( "<%s> SILENT block # %s (%s remaining)" % (title, index, nblocks - index - 1) ) ) else: print( marquee( "<%s> block # %s (%s remaining)" % (title, index, nblocks - index - 1) ) ) print(block, end=" ") sys.stdout.flush()
def __call__(self, index=None): """run a block of the demo. If index is given, it should be an integer >=1 and <= nblocks. This means that the calling convention is one off from typical Python lists. The reason for the inconsistency is that the demo always prints 'Block n/N, and N is the total, so it would be very odd to use zero-indexing here.""" index = self._get_index(index) if index is None: return try: marquee = self.marquee next_block = self.src_blocks[index] self.block_index += 1 if self._silent[index]: print( marquee('Executing silent block # %s (%s remaining)' % (index, self.nblocks - index - 1))) else: self.pre_cmd() self.show(index) if self.auto_all or self._auto[index]: print(marquee('output:')) else: print(marquee('Press <q> to quit, <Enter> to execute...'), end=' ') ans = py3compat.input().strip() if ans: print(marquee('Block NOT executed')) return try: save_argv = sys.argv sys.argv = self.sys_argv self.run_cell(next_block) self.post_cmd() finally: sys.argv = save_argv except: if self.inside_ipython: self.ip_showtb(filename=self.fname) else: if self.inside_ipython: self.ip_ns.update(self.user_ns) if self.block_index == self.nblocks: mq1 = self.marquee('END OF DEMO') if mq1: # avoid spurious print if empty marquees are used print() print(mq1) print( self.marquee( 'Use <demo_name>.reset() if you want to rerun it.')) self.finished = True
def __call__(self, index=None): """run a block of the demo. If index is given, it should be an integer >=1 and <= nblocks. This means that the calling convention is one off from typical Python lists. The reason for the inconsistency is that the demo always prints 'Block n/N, and N is the total, so it would be very odd to use zero-indexing here.""" index = self._get_index(index) if index is None: return try: marquee = self.marquee next_block = self.src_blocks[index] self.block_index += 1 if self._silent[index]: print(marquee('Executing silent block # %s (%s remaining)' % (index, self.nblocks - index - 1)), file=io.stdout) else: self.pre_cmd() self.show(index) if self.auto_all or self._auto[index]: print(marquee('output:'), file=io.stdout) else: print( marquee('Press <q> to quit, <Enter> to execute...'), end=' ', file=io.stdout) ans = py3compat.input().strip() if ans: print(marquee('Block NOT executed'), file=io.stdout) return try: save_argv = sys.argv sys.argv = self.sys_argv self.run_cell(next_block) self.post_cmd() finally: sys.argv = save_argv except: self.ip_showtb(filename=self.fname) else: self.ip_ns.update(self.user_ns) if self.block_index == self.nblocks: mq1 = self.marquee('END OF DEMO') if mq1: # avoid spurious print >>io.stdout,s if empty marquees are used print(file=io.stdout) print(mq1, file=io.stdout) print( self.marquee('Use <demo_name>.reset() if you want to rerun it.'), file=io.stdout) self.finished = True
def show_all(self): """Show entire demo on screen, block by block""" title = self.title nblocks = self.nblocks silent = self._silent marquee = self.marquee for index, block in enumerate(self.src_blocks_colored): if silent[index]: print(marquee('<%s> SILENT block # %s (%s remaining)' % (title, index, nblocks - index - 1)), file=io.stdout) else: print(marquee('<%s> block # %s (%s remaining)' % (title, index, nblocks - index - 1)), file=io.stdout) print(block, end=' ', file=io.stdout) sys.stdout.flush()
def show_all(self): """Show entire demo on screen, block by block""" fname = self.title title = self.title nblocks = self.nblocks silent = self._silent marquee = self.marquee for index,block in enumerate(self.src_blocks_colored): if silent[index]: print >>IPython.utils.io.Term.cout, marquee('<%s> SILENT block # %s (%s remaining)' % (title,index,nblocks-index-1)) else: print >>IPython.utils.io.Term.cout, marquee('<%s> block # %s (%s remaining)' % (title,index,nblocks-index-1)) print >>IPython.utils.io.Term.cout, block, sys.stdout.flush()
def marquee(self,txt='',width=78,mark='*'): """Return the input string centered in a 'marquee'.""" return marquee(txt,width,mark)
def marquee(self, txt='', width=78, mark='*'): """Return the input string centered in a 'marquee'.""" return marquee(txt, width, mark)