ppannuto / python-titlecase

Python library to capitalize strings as specified by the New York Times Manual of Style
MIT License
249 stars 38 forks source link

Abbreviations causing problems with tkinter entry gadget #87

Closed chrisperver closed 3 years ago

chrisperver commented 3 years ago

Titlecase recognizes three letter abbreviations and makes them capital letters. But when used in conjunction with tkinter, this is causing an issue.

If I type the word "street", as soon as I type the letters "str", titlecase converts it to "STR". If I continue typing I end up with the word "STReet", as the beginning capital letters are not dropped to lowercase upon completing the word.

Using the callback function, it is possible to avoid this issue for known words, but there are many words this could happen with. For example, SPLash, SPRay, etc. It would be impossible to list them all.

There should be a way of recognizing if a word has been mistakenly entered partially uppercase and partially lowercase.

ppannuto commented 3 years ago

I don't think there is a way to reliably distinguish between a typo and a brand or other intentional use of mixed-case entry. As a heuristic goes, mixed case is rare, so assuming it was intentional seems reasonable to me.

For this use case specifically, I think you would be better served by re-architecting the application a bit to avoid calling the titlecase method until text entry is complete.

If you have a concrete proposal, I'm happy to look over a PR; but I don't think this is something this library will likely support.