def show(self, index=None): """Show a single block on screen""" index = self._get_index(index) if index is None: return print marquee('<%s> block # %s (%s remaining)' % (self.fname, index, self.nblocks - index - 1)) print self.src_blocks_colored[index], 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 >> Term.cout, 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 >> Term.cout, marquee('output:') else: print >> Term.cout, marquee( 'Press <q> to quit, <Enter> to execute...'), ans = raw_input().strip() if ans: print >> Term.cout, marquee('Block NOT executed') return try: save_argv = sys.argv sys.argv = self.sys_argv self.runlines(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 >>Term.cout,s if empty marquees are used print >> Term.cout print >> Term.cout, mq1 print >> Term.cout, self.marquee( 'Use <demo_name>.reset() if you want to rerun it.') self.finished = True
def show(self, index=None): """Show a single block on screen""" if index is None: if self.finished: print 'Demo finished. Use reset() if you want to rerun it.' return index = self.block_index else: self._validate_index(index) print marquee('<%s> block # %s (%s remaining)' % (self.fname, index, self.nblocks - index - 1)) print self.src_blocks_colored[index],
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 >>Term.cout, 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 >>Term.cout, marquee("output:") else: print >>Term.cout, marquee("Press <q> to quit, <Enter> to execute..."), ans = raw_input().strip() if ans: print >>Term.cout, marquee("Block NOT executed") return try: save_argv = sys.argv sys.argv = self.sys_argv self.runlines(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 >>Term.cout,s if empty marquees are used print >>Term.cout print >>Term.cout, mq1 print >>Term.cout, self.marquee("Use <demo_name>.reset() if you want to rerun it.") self.finished = True
def show_all(self): """Show entire demo on screen, block by block""" fname = self.fname nblocks = self.nblocks silent = self._silent for index, block in enumerate(self.src_blocks_colored): if silent[index]: print marquee('<%s> SILENT block # %s (%s remaining)' % (fname, index, nblocks - index - 1)) else: print marquee('<%s> block # %s (%s remaining)' % (fname, index, nblocks - index - 1)) print block,
def show_all(self): """Show entire demo on screen, block by block""" fname = self.fname 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)' % (fname,index,nblocks-index-1)) else: print marquee('<%s> block # %s (%s remaining)' % (fname,index,nblocks-index-1)) print block, 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 >> Term.cout, marquee( '<%s> SILENT block # %s (%s remaining)' % (title, index, nblocks - index - 1)) else: print >> Term.cout, marquee( '<%s> block # %s (%s remaining)' % (title, index, nblocks - index - 1)) print >> 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)
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.""" if index is None and self.finished: print 'Demo finished. Use reset() if you want to rerun it.' return if index is None: index = self.block_index self._validate_index(index) try: 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.show(index) if self.auto_all or self._auto[index]: print marquee('output') else: print marquee('Press <q> to quit, <Enter> to execute...'), ans = raw_input().strip() if ans: print marquee('Block NOT executed') return try: save_argv = sys.argv sys.argv = self.sys_argv exec next_block in self.user_ns 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: print print marquee(' END OF DEMO ') print marquee('Use reset() if you want to rerun it.') self.finished = True