Skip to content

Conversation

FoamyGuy
Copy link
Contributor

@FoamyGuy FoamyGuy commented Jul 21, 2025

setting values = text meant that a string was returned instead of a list.

The code here:

def _fill_text_labels(self, values):
# fill out all the text blocks
if self._text:
value_index = 0 # In case values and text is not the same
for i in range(len(self._text)):
if (not self._text[i]["is_data"]) or (value_index > (len(values) - 1)):
continue
string = None
if self._text[i]["transform"]:
func = self._text[i]["transform"]
string = func(values[value_index])
else:
try:
string = f"{int(values[value_index]):,d}"
except (TypeError, ValueError):
string = values[value_index] # ok it's a string
self._fetch_set_text(string, index=i)
value_index += 1

Seems to have been written assuming values will be a list. Since string in python behaves sort of like a list this results in it trying to put individual characters from the text into labels on the display. So if the user had only declared 1 text position this would put a label there with just the first letter of the response.

The fix is to add text to the list of values that gets returned, that way a list containing text, [text], is being returned instead of text itself. So the code inside the fill text labels function will then place the entire text response into a single label.

Copy link
Contributor

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An aside: I am kind of confused by what the second argument to process_text() might actually be. It's a list of regular expressions? A "path" to what, exactly? A file path? I can't find an example of that argument.

@FoamyGuy
Copy link
Contributor Author

FoamyGuy commented Jul 22, 2025

@dhalbert I think it means a more general usage of the term path, not something specific like a file path. I believe it's talking about the "path" to take within the data to find the part(s) that we care about. I think it can be used to fetch specific pieces of data out of plain text, or perhaps even basic HTML by specifying appropriate regex to isolate the parts that your interested in for a given project.

The similar process_json() has a json_path, which as I understand it is basically a mapping of which keys and indexes within the JSON to access to find the piece of data that we care about. I think about regexp_path for process_text() essentially the same way, but since text data is less structured than JSON it uses regex instead of simple keys and indexes.

@dhalbert dhalbert merged commit bbae5e4 into adafruit:main Jul 22, 2025
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Jul 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants