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

Fix Golf and other games.

And broke a lot of stuff. Consolidate _pil_image on PIL.Image.
This commit is contained in:
Shlomi Fish 2019-05-16 21:51:20 +03:00
parent 4a7c9a761d
commit 9c7df57ba8
5 changed files with 51 additions and 5 deletions

View file

@ -180,6 +180,9 @@ class Application:
# the PySol mainloop
def mainloop(self):
approc = self.mainproc() # setup process
approc.send(None) # and go
return
try:
approc = self.mainproc() # setup process
approc.send(None) # and go
@ -202,6 +205,7 @@ class Application:
except Exception:
traceback.print_exc()
game = None
sys.exit()
if game:
if game.id == self.opt.game_holded and game.gstats.holded:
game.gstats.loaded = game.gstats.loaded - 1
@ -237,6 +241,7 @@ class Application:
traceback.print_exc()
self.nextgame.id = 2
self.freeGame()
sys.exit()
continue
if self.nextgame.holdgame:
assert self.nextgame.id <= 0
@ -267,9 +272,11 @@ class Application:
except Exception:
traceback.print_exc()
sys.exit()
pass
finally:
sys.exit()
# hide main window
self.wm_withdraw()
#
@ -326,6 +333,7 @@ class Application:
except Exception:
traceback.print_exc()
self.nextgame.loadedgame = None
sys.exit()
elif self.commandline.game is not None:
gameid = self.gdb.getGameByName(self.commandline.game)
if gameid is None:
@ -702,6 +710,7 @@ class Application:
r = 1
except (Exception, TclError, UnpicklingError) as ex:
traceback.print_exc()
sys.exit()
cs.error = 1
# restore settings
self.nextgame.cardset = self.cardset

View file

@ -115,6 +115,7 @@ class Images:
if ((check_w and w != self.CARDW) or
(check_h and h != self.CARDH)):
raise ValueError("Invalid size %dx%d of image %s" % (w, h, f))
assert img
return img
def __loadBottom(self, filename, check_w=1, check_h=1, color='white'):
@ -145,6 +146,9 @@ class Images:
def __addBack(self, im1, name):
r = max(self.CARDW / 40.0, self.CARDH / 60.0)
r = max(2, int(round(r)))
# im2 = PIL_Image(image=im1.subsample(r))
print(type(im1))
im1 = PIL_Image(image=im1)
im2 = im1.subsample(r)
self._back.append(ImagesCardback(len(self._back), name, im1, im2))

View file

@ -862,6 +862,12 @@ class Stack:
# bottom and shade
if self.images.bottom:
img = self.getBottomImage()
img2 = img
try:
from pysollib.pysoltk import get_image_tk
img = get_image_tk(img)
except Exception:
img = img2
self.images.bottom['image'] = img
self.images.bottom.moveTo(x, y)
if self.items.bottom:

View file

@ -59,7 +59,10 @@ class MfxCanvasImage(ImageItem2):
group = kwargs['group']
del kwargs['group']
if 'image' in kwargs:
self._image = kwargs['image']
im = kwargs['image']
from pysollib.ui.tktile.tkutil import get_image_tk
im = get_image_tk(im)
kwargs['image'] = self._image = im
ImageItem2.__init__(self, canvas, x, y, **kwargs)
if group:
self.addtag(group)

View file

@ -42,6 +42,15 @@ def wm_deiconify(window):
window.wm_deiconify()
def get_image_tk(self):
try:
return self.getTk()
except Exception:
if isinstance(self, ImageTk.PhotoImage):
return self
return ImageTk.PhotoImage(self)
def wm_map(window, maximized=0):
if window.wm_state() != "iconic":
if maximized and WIN_SYSTEM == "win32":
@ -249,13 +258,21 @@ if Image:
def __init__(self, file=None, image=None, pil_image_orig=None):
if file:
image = Image.open(file).convert('RGBA')
ImageTk.PhotoImage.__init__(self, image)
if isinstance(image, type(self)):
assert 0
image = image._pil_image
print(type(image))
# if not isinstance(image, ImageTk.PhotoImage):
ImageTk.PhotoImage.__init__(self, image=image)
self._pil_image = image
if pil_image_orig:
self._pil_image_orig = pil_image_orig
else:
self._pil_image_orig = image
def getTk(self):
return ImageTk.PhotoImage(self._pil_image)
def subsample(self, r):
im = self._pil_image
w, h = im.size
@ -341,9 +358,16 @@ def fillImage(image, fill, outline=None):
def createImage(width, height, fill, outline=None):
image = tkinter.PhotoImage(width=width, height=height)
assert image.width() == width
assert image.height() == height
image = ImageTk.PhotoImage(size=(width, height), image='RGBA')
image = Image.new('RGBA', (width, height), fill)
# image = tkinter.PhotoImage(width=width, height=height)
assert image.width == width
assert image.height == height
from PIL import ImageDraw
idraw = ImageDraw.Draw(image)
idraw.rectangle((0, 0, width, height), fill=fill)
# return ImageTk.PhotoImage(image=image)
return image
image.blank()
fillImage(image, fill, outline)
return image