From 0afd45265b498ce555b9c753e5ac637db2cf54f4 Mon Sep 17 00:00:00 2001 From: "D. MacCarthy" Date: Sat, 23 May 2020 14:50:14 -0600 Subject: [PATCH] Update __init__.py Bug in Canvas.__init__: did not work with Image argument --- sc8pr/__init__.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/sc8pr/__init__.py b/sc8pr/__init__.py index 916bc9d..69a20ae 100644 --- a/sc8pr/__init__.py +++ b/sc8pr/__init__.py @@ -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