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 i
(self,index=None)
| 450 | exec(source, self.user_ns) |
| 451 | |
| 452 | def __call__(self,index=None): |
| 453 | """run a block of the demo. |
| 454 | |
| 455 | If index is given, it should be an integer >=1 and <= nblocks. This |
| 456 | means that the calling convention is one off from typical Python |
| 457 | lists. The reason for the inconsistency is that the demo always |
| 458 | prints 'Block n/N, and N is the total, so it would be very odd to use |
| 459 | zero-indexing here.""" |
| 460 | |
| 461 | index = self._get_index(index) |
| 462 | if index is None: |
| 463 | return |
| 464 | try: |
| 465 | marquee = self.marquee |
| 466 | next_block = self.src_blocks[index] |
| 467 | self.block_index += 1 |
| 468 | if self._silent[index]: |
| 469 | print(marquee('Executing silent block # %s (%s remaining)' % |
| 470 | (index,self.nblocks-index-1))) |
| 471 | else: |
| 472 | self.pre_cmd() |
| 473 | self.show(index) |
| 474 | if self.auto_all or self._auto[index]: |
| 475 | print(marquee('output:')) |
| 476 | else: |
| 477 | print(marquee('Press <q> to quit, <Enter> to execute...'), end=' ') |
| 478 | ans = py3compat.input().strip() |
| 479 | if ans: |
| 480 | print(marquee('Block NOT executed')) |
| 481 | return |
| 482 | try: |
| 483 | save_argv = sys.argv |
| 484 | sys.argv = self.sys_argv |
| 485 | self.run_cell(next_block) |
| 486 | self.post_cmd() |
| 487 | finally: |
| 488 | sys.argv = save_argv |
| 489 | |
| 490 | except: |
| 491 | if self.inside_ipython: |
| 492 | self.ip_showtb(filename=self.fname) |
| 493 | else: |
| 494 | if self.inside_ipython: |
| 495 | self.ip_ns.update(self.user_ns) |
| 496 | |
| 497 | if self.block_index == self.nblocks: |
| 498 | mq1 = self.marquee('END OF DEMO') |
| 499 | if mq1: |
| 500 | # avoid spurious print if empty marquees are used |
| 501 | print() |
| 502 | print(mq1) |
| 503 | print(self.marquee('Use <demo_name>.reset() if you want to rerun it.')) |
| 504 | self.finished = True |
| 505 | |
| 506 | # These methods are meant to be overridden by subclasses who may wish to |
| 507 | # customize the behavior of of their demos. |