27
27
except TypeError :
28
28
raise TypeError ("You need to update the Inky library to >= v1.1.0" )
29
29
30
+ flip = inky_display .eeprom .display_variant == 23
31
+ BLACK = inky_display .BLACK if not flip else inky_display .WHITE
32
+ WHITE = inky_display .WHITE if not flip else inky_display .BLACK
30
33
31
34
if inky_display .resolution not in ((212 , 104 ), (250 , 122 )):
32
35
w , h = inky_display .resolution
33
36
raise RuntimeError ("This example does not support {}x{}" .format (w , h ))
34
37
35
- inky_display .set_border (inky_display . BLACK )
38
+ inky_display .set_border (BLACK )
36
39
37
40
# Uncomment the following if you want to rotate the display 180 degrees
38
41
# inky_display.h_flip = True
39
42
# inky_display.v_flip = True
40
43
41
44
42
- def create_mask (source , mask = (inky_display . WHITE , inky_display . BLACK , inky_display .RED )):
45
+ def create_mask (source , mask = (WHITE , BLACK , inky_display .RED )):
43
46
"""Create a transparency mask.
44
47
45
48
Takes a paletized source image and converts it into a mask
@@ -88,7 +91,7 @@ def print_number(position, number, colour):
88
91
89
92
# Load our sprite sheet and prepare a mask
90
93
text = Image .open (os .path .join (PATH , "resources/calendar.png" ))
91
- text_mask = create_mask (text , [inky_display . WHITE ])
94
+ text_mask = create_mask (text , [WHITE ])
92
95
93
96
# Note: The mask determines which pixels from our sprite sheet we want
94
97
# to actually use when calling img.paste().
@@ -116,7 +119,7 @@ def print_number(position, number, colour):
116
119
cal_y = 2
117
120
118
121
# Paint out a black rectangle onto which we'll draw our canvas
119
- draw .rectangle ((cal_x , cal_y , cal_x + cal_w - 1 , cal_y + cal_h - 1 ), fill = inky_display . BLACK , outline = inky_display . WHITE )
122
+ draw .rectangle ((cal_x , cal_y , cal_x + cal_w - 1 , cal_y + cal_h - 1 ), fill = BLACK , outline = WHITE )
120
123
121
124
# The starting position of the months in our spritesheet
122
125
months_x = 2
@@ -145,10 +148,10 @@ def print_number(position, number, colour):
145
148
monthyear_x = 28
146
149
147
150
# Paste in the month name we grabbed from our sprite sheet
148
- img .paste (inky_display . WHITE , (monthyear_x , cal_y + 4 ), month_mask )
151
+ img .paste (WHITE , (monthyear_x , cal_y + 4 ), month_mask )
149
152
150
153
# Print the year right below the month
151
- print_number ((monthyear_x , cal_y + 5 + col_h ), now .year , inky_display . WHITE )
154
+ print_number ((monthyear_x , cal_y + 5 + col_h ), now .year , WHITE )
152
155
153
156
# Draw the vertical lines which separate the columns
154
157
# and also draw the day names into the table header
@@ -162,7 +165,7 @@ def print_number(position, number, colour):
162
165
# Crop the relevant day name from our text image
163
166
crop_region = (crop_x , 0 , crop_x + 16 , 9 )
164
167
day_mask = text_mask .crop (crop_region )
165
- img .paste (inky_display . WHITE , (o_x + 4 , cal_y + 2 ), day_mask )
168
+ img .paste (WHITE , (o_x + 4 , cal_y + 2 ), day_mask )
166
169
167
170
# Offset to the right side of the column and draw the vertical line
168
171
o_x += col_w + 1
@@ -187,13 +190,13 @@ def print_number(position, number, colour):
187
190
# Draw in the day name.
188
191
# If it's the current day, invert the calendar background and text
189
192
if (day .day , day .month ) == (now .day , now .month ):
190
- draw .rectangle ((x , y , x + col_w - 1 , y + col_h - 1 ), fill = inky_display . WHITE )
191
- print_number ((x + 3 , y + 3 ), day .day , inky_display . BLACK )
193
+ draw .rectangle ((x , y , x + col_w - 1 , y + col_h - 1 ), fill = WHITE )
194
+ print_number ((x + 3 , y + 3 ), day .day , BLACK )
192
195
193
196
# If it's any other day, paint in as white if it's in the current month
194
197
# and red if it's in the previous or next month
195
198
else :
196
- print_number ((x + 3 , y + 3 ), day .day , inky_display . WHITE if day .month == now .month else inky_display .RED )
199
+ print_number ((x + 3 , y + 3 ), day .day , WHITE if day .month == now .month else inky_display .RED )
197
200
198
201
# Display the completed calendar on Inky pHAT
199
202
inky_display .set_image (img )
0 commit comments