Skip to content

Commit

Permalink
Update __init__.py
Browse files Browse the repository at this point in the history
Bug in Canvas.__init__: did not work with Image argument
  • Loading branch information
dmaccarthy authored May 23, 2020
1 parent a55eb9b commit 0afd452
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions sc8pr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -631,11 +631,25 @@ class Canvas(Graphic):
_border = rgba("black")
weight = 0

# def __init__(self, image, bg=None):
# if type(image) is str: bg = Image(image, bg)
# self._size = bg.size if isinstance(bg, Image) else image
# self.bg = bg
# self._items = []

def __init__(self, image, bg=None):
if type(image) is str: bg = Image(image, bg)
self._size = bg.size if isinstance(bg, Image) else image
self.bg = bg
mode = 0 if type(image) is str else 1 if isinstance(image, Image) else 2
if mode == 2: # tuple or list
size = image
elif bg:
bg = Image(image, bg)
size = bg.size
else: # str or Image
bg = image if mode else Image(image)
size = bg.size
self._size = size
self._items = []
self.bg = bg

@property
def border(self): return self._border
Expand Down

0 comments on commit 0afd452

Please sign in to comment.