Skip to content

Commit

Permalink
Switch to getbbox for pillow versions 9.2.0 and above
Browse files Browse the repository at this point in the history
Also force pystray 0.19.4 or later to make addressing #11 easier
  • Loading branch information
simonrob committed Aug 3, 2022
1 parent b6ab557 commit 4722df0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions emailproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__author__ = 'Simon Robinson'
__copyright__ = 'Copyright (c) 2022 Simon Robinson'
__license__ = 'Apache 2.0'
__version__ = '2022-07-09' # ISO 8601 (YYYY-MM-DD)
__version__ = '2022-08-03' # ISO 8601 (YYYY-MM-DD)

import argparse
import asyncore
Expand Down Expand Up @@ -38,6 +38,8 @@
import pkg_resources
import pystray
import timeago

# noinspection PyPackageRequirements
import webview

# for drawing the menu bar icon
Expand Down Expand Up @@ -1638,8 +1640,15 @@ def get_image():
@staticmethod
def get_icon_size(font_file, text, font_size):
font = ImageFont.truetype(font_file, size=font_size)
font_width, font_height = font.getsize(text)
return font, font_width, font_height

# pillow's getsize method was deprecated in 9.2.0 (see docs for PIL.ImageFont.ImageFont.getsize)
if pkg_resources.parse_version(
pkg_resources.get_distribution('pillow').version) < pkg_resources.parse_version('9.2.0'):
font_width, font_height = font.getsize(text)
return font, font_width, font_height
else:
left, top, right, bottom = font.getbbox(text)
return font, right, bottom

def create_config_menu(self):
items = [pystray.MenuItem('Servers:', None, enabled=False)]
Expand Down Expand Up @@ -1760,6 +1769,7 @@ def handle_authorisation_windows(self):

# on macOS we need to add extra webview functions to detect when redirection starts, because otherwise the
# pywebview window can get into a state in which http://localhost navigation, rather than failing, just hangs
# noinspection PyPackageRequirements
import webview.platforms.cocoa
setattr(webview.platforms.cocoa.BrowserView.BrowserDelegate, 'webView_didStartProvisionalNavigation_',
ProvisionalNavigationBrowserDelegate.webView_didStartProvisionalNavigation_)
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
configobj
cryptography
pillow
pystray
pystray>=0.19.4 # force pystray version with dummy GUI fix (https://github.com/moses-palmer/pystray/issues/118)
pywebview; sys_platform != 'win32' # specify platform to avoid double requirement error with older pip versions
timeago

Expand Down

0 comments on commit 4722df0

Please sign in to comment.