Edit a block. If no number is given, use the last block executed. This edits the in-memory copy of the demo, it does NOT modify the original source file. If you want to do that, simply open the file in an editor and use reload() when you make changes to the file.
(self,index=None)
| 385 | self() |
| 386 | |
| 387 | def edit(self,index=None): |
| 388 | """Edit a block. |
| 389 | |
| 390 | If no number is given, use the last block executed. |
| 391 | |
| 392 | This edits the in-memory copy of the demo, it does NOT modify the |
| 393 | original source file. If you want to do that, simply open the file in |
| 394 | an editor and use reload() when you make changes to the file. This |
| 395 | method is meant to let you change a block during a demonstration for |
| 396 | explanatory purposes, without damaging your original script.""" |
| 397 | |
| 398 | index = self._get_index(index) |
| 399 | if index is None: |
| 400 | return |
| 401 | # decrease the index by one (unless we're at the very beginning), so |
| 402 | # that the default demo.edit() call opens up the sblock we've last run |
| 403 | if index>0: |
| 404 | index -= 1 |
| 405 | |
| 406 | filename = self.shell.mktempfile(self.src_blocks[index]) |
| 407 | self.shell.hooks.editor(filename, 1) |
| 408 | with open(Path(filename), "r", encoding="utf-8") as f: |
| 409 | new_block = f.read() |
| 410 | # update the source and colored block |
| 411 | self.src_blocks[index] = new_block |
| 412 | self.src_blocks_colored[index] = self.highlight(new_block) |
| 413 | self.block_index = index |
| 414 | # call to run with the newly edited index |
| 415 | self() |
| 416 | |
| 417 | def show(self,index=None): |
| 418 | """Show a single block on screen""" |
nothing calls this directly
no test coverage detected