Skip to content

Commit

Permalink
Merge pull request #485 from newtonick/pillow-getsize-deprecations
Browse files Browse the repository at this point in the history
Fix Deprecations related to font.getsize in Pillow
  • Loading branch information
newtonick authored Feb 23, 2024
2 parents db16fa7 + 4e163fc commit 69cb6ac
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/seedsigner/gui/components.py
Original file line number Diff line number Diff line change
Expand Up @@ -610,7 +610,8 @@ def __post_init__(self):
self.accent_font = Fonts.get_font(GUIConstants.FIXED_WIDTH_EMPHASIS_FONT_NAME, self.font_size)

# Fixed width font means we only have to measure one max-height character
char_width, char_height = self.font.getsize("Q")
left, top, right, bottom = self.font.getbbox("Q")
char_width, char_height = right - left, bottom - top

n = 7
display_str = f"{self.address[:n]} {self.address[n:-1*n]} {self.address[-1*n:]}"
Expand Down
6 changes: 4 additions & 2 deletions src/seedsigner/gui/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -591,15 +591,17 @@ def render(self, cur_text=None, cursor_position=None):
if end_pos_x < self.width:
# The entire cur_text plus the cursor bar fits
self.text_offset = 3 + cursor_bar_serif_half_width
tw_left, th = self.font.getsize(self.cur_text[:cursor_position])
left, top, right, bottom = self.font.getbbox(self.cur_text[:cursor_position])
tw_left, th = right - left, bottom - top
cursor_bar_x = self.text_offset + tw_left

else:
if cursor_position is None:
cursor_position = len(self.cur_text)

# Is the cursor at either extreme?
tw_left, th = self.font.getsize(self.cur_text[:cursor_position])
left, top, right, bottom = self.font.getbbox(self.cur_text[:cursor_position])
tw_left, th = right - left, bottom - top

if self.text_offset + tw_left + cursor_bar_serif_half_width + 3 >= self.width:
# Cursor is at the extreme right; have to push the full tw_right off
Expand Down
18 changes: 12 additions & 6 deletions src/seedsigner/gui/screens/psbt_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ def __post_init__(self):

max_inputs_text_width = 0
for input in inputs_column:
tw, th = font.getsize(input)
left, top, right, bottom = font.getbbox(input)
tw, th = right - left, bottom - top
max_inputs_text_width = max(tw, max_inputs_text_width)

# Given how wide we want our curves on each side to be...
Expand Down Expand Up @@ -148,7 +149,8 @@ def truncate_destination_addr(addr):

max_destination_text_width = 0
for destination in destination_column:
tw, th = font.getsize(destination)
left, top, right, bottom = font.getbbox(destination)
tw, th = right - left, bottom - top
max_destination_text_width = max(tw, max_destination_text_width)

return (max_destination_text_width, destination_column)
Expand Down Expand Up @@ -194,7 +196,8 @@ def truncate_destination_addr(addr):
input_curves = []
for input in inputs_column:
# Calculate right-justified input display
tw, th = font.getsize(input)
left, top, right, bottom = font.getbbox(input)
tw, th = right - left, bottom - top
cur_x = inputs_x + max_inputs_text_width - tw
draw.text(
(cur_x, inputs_y),
Expand Down Expand Up @@ -503,7 +506,8 @@ def __post_init__(self):

body_font = Fonts.get_font(GUIConstants.BODY_FONT_NAME, (GUIConstants.BODY_FONT_SIZE)*ssf)
fixed_width_font = Fonts.get_font(GUIConstants.FIXED_WIDTH_FONT_NAME, (GUIConstants.BODY_FONT_SIZE + 6)*ssf)
digits_width, digits_height = fixed_width_font.getsize(self.input_amount + "+")
left, top, right, bottom = fixed_width_font.getbbox(self.input_amount + "+")
digits_width, digits_height = right - left, bottom - top

# Draw each line of the equation
cur_y = 0
Expand All @@ -520,8 +524,10 @@ def render_amount(cur_y, amount_str, info_text, info_text_color=GUIConstants.BOD
main_zone = display_str[:-6]
mid_zone = display_str[-6:-3]
end_zone = display_str[-3:]
main_zone_width, th = fixed_width_font.getsize(main_zone)
mid_zone_width, th = fixed_width_font.getsize(end_zone)
left, top, right, bottom = fixed_width_font.getbbox(main_zone)
main_zone_width, th = right - left, bottom - top
left, top, right, bottom = fixed_width_font.getbbox(end_zone)
mid_zone_width, th = right - left, bottom - top
draw.text((0, cur_y), text=main_zone, font=fixed_width_font, fill=GUIConstants.BODY_FONT_COLOR)
draw.text((main_zone_width + digit_group_spacing, cur_y), text=mid_zone, font=fixed_width_font, fill=secondary_digit_color)
draw.text((main_zone_width + digit_group_spacing + mid_zone_width + digit_group_spacing, cur_y), text=end_zone, font=fixed_width_font, fill=tertiary_digit_color)
Expand Down
3 changes: 2 additions & 1 deletion src/seedsigner/gui/screens/seed_screens.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ def __post_init__(self):
if found_solution:
break
font = Fonts.get_font(font_name=GUIConstants.FIXED_WIDTH_FONT_NAME, size=font_size)
char_width, char_height = font.getsize("X")
left, top, right, bottom = font.getbbox("X")
char_width, char_height = right - left, bottom - top
for num_lines in range(1, max_lines+1):
# Break the passphrase into n lines
chars_per_line = math.ceil(len(self.passphrase) / num_lines)
Expand Down

0 comments on commit 69cb6ac

Please sign in to comment.