[UI] Fix usage of 'with Image.open' in trackericons

* Revert changes made to fix 'too many files open' as Image.open does
   not return a file descriptor and generated the following error:
     exceptions.AttributeError: 'NoneType' object has no attribute 'startswith'
 * Also fix style for raising an exception.
This commit is contained in:
Calum Lind 2017-01-11 15:48:37 +00:00
parent bf01b53bda
commit af76abb038

View File

@ -359,13 +359,12 @@ class TrackerIcons(Component):
if PIL_INSTALLED:
try:
with Image.open(icon_name):
pass
Image.open(icon_name)
except IOError, e:
raise InvalidIconError(e)
else:
if os.stat(icon_name).st_size == 0L:
raise InvalidIconError, "empty icon"
raise InvalidIconError("empty icon")
return icon_name
@ -434,7 +433,7 @@ class TrackerIcons(Component):
"""
if icon:
filename = icon.get_filename()
with Image.open(filename) as img:
img = Image.open(filename)
if img.size > (16, 16):
new_filename = filename.rpartition('.')[0]+".png"
img = img.resize((16, 16), Image.ANTIALIAS)