Save the drawing as a PostScript file Arguments: filename -- a string, the path of the created file. Must end with '.ps' or '.eps'. Optional arguments: overwrite -- boolean, if true, then existing files will be overwritten Example (for a
(self, filename, *, overwrite=False)
| 1530 | return self._resize(canvwidth, canvheight, bg) |
| 1531 | |
| 1532 | def save(self, filename, *, overwrite=False): |
| 1533 | """Save the drawing as a PostScript file |
| 1534 | |
| 1535 | Arguments: |
| 1536 | filename -- a string, the path of the created file. |
| 1537 | Must end with '.ps' or '.eps'. |
| 1538 | |
| 1539 | Optional arguments: |
| 1540 | overwrite -- boolean, if true, then existing files will be overwritten |
| 1541 | |
| 1542 | Example (for a TurtleScreen instance named screen): |
| 1543 | >>> screen.save('my_drawing.eps') |
| 1544 | """ |
| 1545 | filename = Path(filename) |
| 1546 | if not filename.parent.exists(): |
| 1547 | raise FileNotFoundError( |
| 1548 | f"The directory '{filename.parent}' does not exist." |
| 1549 | " Cannot save to it." |
| 1550 | ) |
| 1551 | if not overwrite and filename.exists(): |
| 1552 | raise FileExistsError( |
| 1553 | f"The file '{filename}' already exists. To overwrite it use" |
| 1554 | " the 'overwrite=True' argument of the save function." |
| 1555 | ) |
| 1556 | if (ext := filename.suffix) not in {".ps", ".eps"}: |
| 1557 | raise ValueError( |
| 1558 | f"Unknown file extension: '{ext}'," |
| 1559 | " must be one of {'.ps', '.eps'}" |
| 1560 | ) |
| 1561 | |
| 1562 | postscript = self.cv.postscript() |
| 1563 | filename.write_text(postscript) |
| 1564 | |
| 1565 | onscreenclick = onclick |
| 1566 | resetscreen = reset |
nothing calls this directly
no test coverage detected