1
0
Fork 0
mirror of https://github.com/shlomif/PySolFC.git synced 2025-04-05 00:02:29 -04:00

Added Pillow logic for creating missing images.

This commit is contained in:
Joe R 2022-02-20 11:01:42 -05:00
parent 4c2dd59928
commit 72c979d00f
3 changed files with 35 additions and 8 deletions

View file

@ -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:]

View file

@ -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:

View file

@ -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