"ValueError: substring not found" in textbox draw
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 611
- Forks
- 211
- PR merge metrics
- No merged PRs in 30d
Description
Hey,
I was recently digging around the text fitting source (ptext.py) and found an issue.
When calling `screen.draw.textbox`, if you prefix the string with a space(s), it will cause a `ValueError` exception to be thrown.
Without the space at the beginning, it works just fine.
Thank you for your time.
### Source Code
```python
import pgzrun
WIDTH = 500
HEIGHT = 500
text = " ab"
def draw():
screen.draw.textbox(text, (0, 0, 500, 500))
pgzrun.go()
```
### Stack Trace
```
File "C:\..\issue.py", line 9, in draw
screen.draw.textbox(text, (0, 0, 500, 500))
File "C:\..\lib\site-packages\pgzero\screen.py", line 66, in textbox
ptext.drawbox(*args, surf=self._surf, **kwargs)
File "C:\..\lib\site-packages\pgzero\ptext.py", line 476, in drawbox
fontsize = _fitsize(text, fontname, sysfontname, bold, italic, underline,
File "C:\..\lib\site-packages\pgzero\ptext.py", line 162, in _fitsize
if not fits(a):
File "C:\..\lib\site-packages\pgzero\ptext.py", line 153, in fits
texts = wrap(text, fontname, fontsize, sysfontname,
File "C:\..\lib\site-packages\pgzero\ptext.py", line 109, in wrap
a = text.index(" ", a) if " " in text else len(text)
ValueError: substring not found
```
### System Information
>Pygame 2.0.1
SDL 2.0.14, Python 3.9.2
Windows 10.0.19041.867
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in ptext.py, especially wrap around the reported line 109 and the _fitsize/drawbox call path. Reproduce the failure with the supplied textbox example using text=" ab"; done means the leading-space input no longer raises ValueError and the textbox draws successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- game-dev
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100