diff --git a/adafruit_pyoa.py b/adafruit_pyoa.py index c456d02..74de231 100755 --- a/adafruit_pyoa.py +++ b/adafruit_pyoa.py @@ -227,12 +227,23 @@ def _display_text_for(self, card): """ text = card.get("text", None) text_color = card.get("text_color", 0x0) # default to black + text_background_color = card.get("text_background_color", None) if text: try: text_color = int(text_color) # parse the JSON string to hex int except ValueError: text_color = 0x0 - self.set_text(text, text_color) + + try: + text_background_color = int( + text_background_color + ) # parse the JSON string to hex int + except ValueError: + text_background_color = None + except TypeError: + text_background_color = None + + self.set_text(text, text_color, background_color=text_background_color) def _play_sound_for(self, card): """If there's a sound, start playing it. @@ -356,7 +367,7 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False): self._wavfile = None self._speaker_enable.value = False - def set_text(self, text, color): + def set_text(self, text, color, background_color=None): """Display the test for a card. :param Union(None,str) text: the text to display @@ -385,6 +396,8 @@ def set_text(self, text, color): self._text.x = text_x self._text.y = text_y self._text.color = color + if background_color: + self._text.background_color = background_color self._text_group.append(self._text) def set_background(self, filename, *, with_fade=True): diff --git a/examples/cyoa/cyoa.json b/examples/cyoa/cyoa.json index cec013c..ee8d0a3 100755 --- a/examples/cyoa/cyoa.json +++ b/examples/cyoa/cyoa.json @@ -21,6 +21,7 @@ "background_image": "page01.bmp", "text": "You do not have any friends so you decide that it might be a good idea to build a robot friend. You're unsure if you want to do this, so now is the time to decide. Do you want to build a robot friend?", "text_color": "0x000001", + "text_background_color": "0xeeeeee", "sound": "sound_01.wav", "button01_text": "Yes", "button01_goto_card_id": "continue?",