Line wrapping for "Location"
example: http://wttr.in/Paris_1pnF.png
for png generation, can the location line at the bottom be wrapped to the width of the other parts of the image? As it stands now it can lead to inconvenient image dimensions.
Yes, it is not good indeed. Should we probably just cut it off?
Hmm that might remove useful data on occasion. A hard wrap would better I think, but I'm not sure.
maybe, we should remove /([0-9]+;)*/from the full location name?
What do you think?
That could work, but there might still be very long locations just from the words
At least for Paris :)
Ok this issue is a bit old but I think I may have somewhat of a solution. Might not be fully complete but I think it's better than it was before. I was thinking it would fit somewhere around here
import textwrap
import re
def _wrap_buf(buf):
# remove the last line (with the .)
_buf = buf[:-1]
# find the max length of everything but the last line (with the the location data)
cols = max(len(x) for x in _buf[:-1])
# remove the long string of numbers
_buf[-1] = re.sub(r"([0-9]+;)+([0-9]+,)? ", "", _buf[-1])
# use the built-in module textwrap to wrap too-long lines
for x in _buf:
if len(x) > cols:
_buf[-1] = textwrap.fill(_buf[-1], width=cols, replace_whitespace=False, subsequent_indent=" ")
# re-add that last line
pbuf.append(" "*(cols+1) + ".")
return _buf
@classabbyamp it looks interesting;
let us test it with several real locations, what do you think? We should test how it handles different languages, especially RTL languages, and language with complex writing scripts, like Devangari etc. If it will not work with them, we could use this implementation at least for Latin/Cyrillic/Greek scripts
Here is how it looks for Brasilia, DF, Brazil. I feel that there is a lot of secondary information which can be removed. All the lines "Região ... " could possible be removed. I think something like "place", "city", "state", "ZIP", "country", "coordinates" could minimize the amount of information and probably prevent the need for wrapping. Regarding language it seems all good (Portuguese-Brazil).

I think the location line must be cut by the width of the main view at some appropriate place for that (like a comma, for example). Also, it should be possible to switch the location line fully off.