Skip to content

Commit 11100c8

Browse files
authored
Merge pull request #1724 from lesamouraipourpre/electioncal-us
PyPortal Electioncal US: Update for CP7
2 parents 0e523de + b3272b2 commit 11100c8

File tree

1 file changed

+22
-18
lines changed

1 file changed

+22
-18
lines changed

PyPortal_Electioncal_US/electioncal_graphics.py

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111

1212
class Electioncal_Graphics(displayio.Group):
1313
def __init__(self, root_group, *, am_pm=True):
14-
super().__init__(max_size=2)
14+
super().__init__()
1515
self.am_pm = am_pm
1616
root_group.append(self)
17-
self._icon_group = displayio.Group(max_size=1)
17+
self._icon_group = displayio.Group()
1818
self.append(self._icon_group)
19-
self._text_group = displayio.Group(max_size=9)
19+
self._text_group = displayio.Group()
2020
self.append(self._text_group)
2121

2222
self._icon_sprite = None
23-
self._icon_file = None
23+
self._icon_file = None # Remove when CircuitPython 6 support is dropped
2424
self.set_icon(cwd+"/icons/electioncal.bmp")
2525

2626
self.small_font = bitmap_font.load_font(small_font)
@@ -29,38 +29,38 @@ def __init__(self, root_group, *, am_pm=True):
2929
self.small_font.load_glyphs(glyphs)
3030
self.medium_font.load_glyphs(glyphs)
3131

32-
self.date_text = Label(self.small_font, max_glyphs=21)
32+
self.date_text = Label(self.small_font)
3333
self.date_text.x = 15
3434
self.date_text.y = 195
3535
self.date_text.color = 0xFFFFFF
3636
self._text_group.append(self.date_text)
3737

38-
self.url_text = Label(self.small_font, max_glyphs=35)
38+
self.url_text = Label(self.small_font)
3939
self.url_text.x = 15
4040
self.url_text.y = 220
4141
self.url_text.color = 0xFFFFFF
4242
self._text_group.append(self.url_text)
4343
self.url_text.text = "Visit us at https://electioncal.us"
4444

45-
self.state_text = Label(self.small_font, max_glyphs=60)
45+
self.state_text = Label(self.small_font)
4646
self.state_text.x = 15
4747
self.state_text.y = 10
4848
self.state_text.color = 0xFFFFFF
4949
self._text_group.append(self.state_text)
5050

51-
self.election_date_text = Label(self.medium_font, max_glyphs=11)
51+
self.election_date_text = Label(self.medium_font)
5252
self.election_date_text.x = 15
5353
self.election_date_text.y = 60
5454
self.election_date_text.color = 0xFFFFFF
5555
self._text_group.append(self.election_date_text)
5656

57-
self.election_name_text = Label(self.small_font, max_glyphs=60)
57+
self.election_name_text = Label(self.small_font)
5858
self.election_name_text.x = 15
5959
self.election_name_text.y = 95
6060
self.election_name_text.color = 0xFFFFFF
6161
self._text_group.append(self.election_name_text)
6262

63-
self.election_name_text_line2 = Label(self.small_font, max_glyphs=60)
63+
self.election_name_text_line2 = Label(self.small_font)
6464
self.election_name_text_line2.x = 15
6565
self.election_name_text_line2.y = 120
6666
self.election_name_text_line2.color = 0xFFFFFF
@@ -137,15 +137,19 @@ def set_icon(self, filename):
137137

138138
if not filename:
139139
return # we're done, no icon desired
140+
141+
# CircuitPython 6 & 7 compatible
140142
if self._icon_file:
141143
self._icon_file.close()
142144
self._icon_file = open(filename, "rb")
143145
icon = displayio.OnDiskBitmap(self._icon_file)
144-
try:
145-
self._icon_sprite = displayio.TileGrid(icon,
146-
pixel_shader=getattr(icon, 'pixel_shader', displayio.ColorConverter()))
147-
except TypeError:
148-
self._icon_sprite = displayio.TileGrid(icon,
149-
pixel_shader=getattr(icon, 'pixel_shader', displayio.ColorConverter()),
150-
position=(0,0))
151-
self._icon_group.append(self._icon_sprite)
146+
self._icon_sprite = displayio.TileGrid(
147+
icon,
148+
pixel_shader=getattr(icon, 'pixel_shader', displayio.ColorConverter())
149+
)
150+
151+
# # CircuitPython 7+ compatible
152+
# icon = displayio.OnDiskBitmap(filename)
153+
# self._icon_sprite = displayio.TileGrid(icon, pixel_shader=icon.pixel_shader)
154+
155+
self._icon_group.append(self._icon_sprite)

0 commit comments

Comments
 (0)