donkirkby / donkirkby/live-py-plugin
Make turtle font more flexible
- Dominant language
- Python
- Stars
- 302
- Forks
- 63
- Avg merge
- 6h 50m
- Merged PRs (30d)
- 2
Description
The [`turtle.write()`](https://docs.python.org/3/library/turtle.html#turtle.write) method is supposed to accept a font as a tuple of name, size, and style. The turtle module accepts tuples of one, two, or three items, as well as just a string with the font name. The mock turtle only accepts the full tuple, so make it accept all the other variants.
Some other font parameter values to try: 'x', None, empty tuple, and empty string. The last two cause errors.
Another feature that should be supported: the `move` parameter. If `tkinter` is available, use font's [`measure()`] method, otherwise make a rough calculation of text width based on font size.
Tabs and newlines aren't supported at all in the browser turtle, and there's a bug in the PyCharm tab support. In PyCharm, tabs only move forward if you're not already at a tab stop. Is it worth doing the tab and newline support in the Python code, so it doesn't need to be done in every client? Font differences may mess it up. Browser could use canvas's [`measureText()`] method.
* [ ] different lengths of tuple in font parameter
* [ ] tab bug in PyCharm
* [ ] tabs and newlines in browser
* [ ] `move` parameter
Here's an example script with the turtle module display on the left, and the mock turtle display on the right.
```
from turtle import * # @UnusedWildImport
right(90)
up()
write('Hello, World!',
font=('Courier', 20, 'italic'))
forward(20)
write('Hello, World!',
font=('Courier', 20))
forward(20)
write('Hello, World!',
font=('Courier', ))
forward(20)
write('Hello, World!',
font='Courier')
forward(20)
write('Hello, World!')
forward(20)
stamp()
mainloop()
```

[`measure()`]: https://docs.python.org/3/library/tkinter.font.html#tkinter.font.Font.measure
[`measureText()`]: https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/measureText
Contributor guide
Research direction
Start by locating the mock turtle implementation of write() and the browser and PyCharm turtle clients, then compare their behavior with Python's turtle.write() and the linked font APIs. The issue's checklist defines done: accept the documented font variants, support move, and decide how tabs and newlines should behave consistently across clients.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools, frontend
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100