Skip to content

Commit 9630ae4

Browse files
authored
Merge pull request #30 from FoamyGuy/text_background_color
support optional text_background_color for cards
2 parents 7de9f43 + 7885692 commit 9630ae4

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

adafruit_pyoa.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,12 +227,23 @@ def _display_text_for(self, card):
227227
"""
228228
text = card.get("text", None)
229229
text_color = card.get("text_color", 0x0) # default to black
230+
text_background_color = card.get("text_background_color", None)
230231
if text:
231232
try:
232233
text_color = int(text_color) # parse the JSON string to hex int
233234
except ValueError:
234235
text_color = 0x0
235-
self.set_text(text, text_color)
236+
237+
try:
238+
text_background_color = int(
239+
text_background_color
240+
) # parse the JSON string to hex int
241+
except ValueError:
242+
text_background_color = None
243+
except TypeError:
244+
text_background_color = None
245+
246+
self.set_text(text, text_color, background_color=text_background_color)
236247

237248
def _play_sound_for(self, card):
238249
"""If there's a sound, start playing it.
@@ -356,7 +367,7 @@ def play_sound(self, filename, *, wait_to_finish=True, loop=False):
356367
self._wavfile = None
357368
self._speaker_enable.value = False
358369

359-
def set_text(self, text, color):
370+
def set_text(self, text, color, background_color=None):
360371
"""Display the test for a card.
361372
362373
:param Union(None,str) text: the text to display
@@ -385,6 +396,8 @@ def set_text(self, text, color):
385396
self._text.x = text_x
386397
self._text.y = text_y
387398
self._text.color = color
399+
if background_color:
400+
self._text.background_color = background_color
388401
self._text_group.append(self._text)
389402

390403
def set_background(self, filename, *, with_fade=True):

examples/cyoa/cyoa.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"background_image": "page01.bmp",
2222
"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?",
2323
"text_color": "0x000001",
24+
"text_background_color": "0xeeeeee",
2425
"sound": "sound_01.wav",
2526
"button01_text": "Yes",
2627
"button01_goto_card_id": "continue?",

0 commit comments

Comments
 (0)