matplotlib / matplotlib/matplotlib
TextBox does not accept dead keys
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 23.2k
- Forks
- 8.5k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 66
Description
### Bug report
**Bug summary**
Typing a dead key (a key which is not written directly after a keypress, e.g. ^, ´, `) into a TextBox widget raises a TypeError. This also occurs when you press CapsLock. This prevents the user from entering some characters like "^" or using CapsLock.
Edit: After about version `3.4` no error is being raised. Now CapsLock works but the TextBox just ignores dead keys.
**Code for reproduction**
```python
from matplotlib import pyplot as plt
from matplotlib.widgets import TextBox
fig, ax = plt.subplots(figsize=(6, 3))
fig.subplots_adjust(bottom=0.2)
text_box_ax = fig.add_axes([0.4, 0.02, 0.5, 0.06])
text_box = TextBox(text_box_ax, "Type diacritic character (e.g. ^): ")
plt.show()
```
**Actual outcome**
```
Traceback (most recent call last):
File "\matplotlib\cbook\__init__.py", line 196, in process
func(*args, **kwargs)
File "\matplotlib\widgets.py", line 790, in _keypress
if len(key) == 1:
TypeError: object of type 'NoneType' has no len()
```
**Expected outcome**
Normal behaviour of those characters when typing them in editors or searchbars etc.
**Matplotlib version**
* Operating system: windows 10, build 19041.867
* Matplotlib version: `3.2.2`
* Matplotlib backend: `TkAgg`
* Python version: 3.8
* Jupyter version (if applicable):
* Other libraries:
Contributor guide
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 with the TextBox._keypress handler in matplotlib/widgets.py and run the provided TextBox reproduction using the TkAgg backend. Trace how dead keys and CapsLock are represented, then verify that typing diacritics no longer raises an error or silently ignores the key and that ordinary TextBox editing still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100