diff --git a/pysollib/images.py b/pysollib/images.py index 33f126a5..dc6c8232 100644 --- a/pysollib/images.py +++ b/pysollib/images.py @@ -25,7 +25,8 @@ import os from pysollib.mfxutil import Image, ImageTk, USE_PIL, print_err -from pysollib.pysoltk import copyImage, createBottom, createImage, loadImage +from pysollib.pysoltk import copyImage, createBottom, createImage,\ + createImagePIL, loadImage from pysollib.pysoltk import shadowImage from pysollib.resource import CSI from pysollib.settings import TOOLKIT @@ -136,7 +137,8 @@ class Images: cw, ch = self.getSize() # back if not self._back: - im = createImage(cw, ch, fill="#a0a0a0", outline="#000000") + im = self.createMissingImage(cw, ch, fill="#a0a0a0", + outline="#000000") name = "" self.__addBack(im, name) self.cs.backnames = tuple(self.cs.backnames) + (name,) @@ -145,21 +147,32 @@ class Images: neg_bottom = None while len(self._bottom_positive) < max(7, self.cs.nbottoms): if bottom is None: - bottom = createImage(cw, ch, fill=None, outline="#000000") + bottom = self.createMissingImage(cw, ch, fill=None, + outline="#000000") self._bottom_positive.append(bottom) while len(self._bottom_negative) < max(7, self.cs.nbottoms): if neg_bottom is None: - neg_bottom = createImage(cw, ch, fill=None, outline="#ffffff") + neg_bottom = self.createMissingImage(cw, ch, fill=None, + outline="#ffffff") self._bottom_negative.append(neg_bottom) while len(self._letter_positive) < 4: if bottom is None: - bottom = createImage(cw, ch, fill=None, outline="#000000") + bottom = self.createMissingImage(cw, ch, fill=None, + outline="#000000") self._letter_positive.append(bottom) while len(self._letter_negative) < 4: if neg_bottom is None: - neg_bottom = createImage(cw, ch, fill=None, outline="#ffffff") + neg_bottom = self.createMissingImage(cw, ch, fill=None, + outline="#ffffff") self._letter_negative.append(neg_bottom) - self._blank_bottom = createImage(cw, ch, fill=None, outline=None) + self._blank_bottom = self.createMissingImage(cw, ch, fill=None, + outline=None) + + def createMissingImage(self, width, height, fill, outline=None): + if USE_PIL: + return createImagePIL(width, height, fill=fill, outline=outline) + else: + return createImage(width, height, fill=fill, outline=outline) def load(self, app, progress=None): ext = self.cs.ext[1:] diff --git a/pysollib/mfxutil.py b/pysollib/mfxutil.py index 65f192e6..0a5b00f8 100644 --- a/pysollib/mfxutil.py +++ b/pysollib/mfxutil.py @@ -40,6 +40,7 @@ if TOOLKIT == 'tk': from PIL import Image from PIL import ImageTk # noqa: F401 from PIL import ImageOps # noqa: F401 + from PIL import ImageDraw # noqa: F401 except ImportError: Image = None else: diff --git a/pysollib/ui/tktile/tkutil.py b/pysollib/ui/tktile/tkutil.py index 636ba7d2..720985f7 100644 --- a/pysollib/ui/tktile/tkutil.py +++ b/pysollib/ui/tktile/tkutil.py @@ -24,7 +24,7 @@ import os import re -from pysollib.mfxutil import Image, ImageOps, ImageTk +from pysollib.mfxutil import Image, ImageDraw, ImageOps, ImageTk from pysollib.settings import TITLE, WIN_SYSTEM from six.moves import tkinter @@ -412,6 +412,19 @@ def createImage(width, height, fill, outline=None): return image +def createImagePIL(width, height, fill, outline=None): + if not fill: + image = Image.new('RGBA', (width, height)) + else: + image = Image.new('RGBA', (width, height), color=fill) + if outline is not None: + draw = ImageDraw.Draw(image) + draw.rectangle([0, 0, width - 1, height - 1], fill=None, + outline=outline, width=1) + + return PIL_Image(image=image) + + def shadowImage(image, color='#3896f8', factor=0.3): if not hasattr(image, '_pil_image'): return None