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:
parent
4a7c9a761d
commit
9c7df57ba8
5 changed files with 51 additions and 5 deletions
|
@ -180,6 +180,9 @@ class Application:
|
||||||
|
|
||||||
# the PySol mainloop
|
# the PySol mainloop
|
||||||
def mainloop(self):
|
def mainloop(self):
|
||||||
|
approc = self.mainproc() # setup process
|
||||||
|
approc.send(None) # and go
|
||||||
|
return
|
||||||
try:
|
try:
|
||||||
approc = self.mainproc() # setup process
|
approc = self.mainproc() # setup process
|
||||||
approc.send(None) # and go
|
approc.send(None) # and go
|
||||||
|
@ -202,6 +205,7 @@ class Application:
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
game = None
|
game = None
|
||||||
|
sys.exit()
|
||||||
if game:
|
if game:
|
||||||
if game.id == self.opt.game_holded and game.gstats.holded:
|
if game.id == self.opt.game_holded and game.gstats.holded:
|
||||||
game.gstats.loaded = game.gstats.loaded - 1
|
game.gstats.loaded = game.gstats.loaded - 1
|
||||||
|
@ -237,6 +241,7 @@ class Application:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.nextgame.id = 2
|
self.nextgame.id = 2
|
||||||
self.freeGame()
|
self.freeGame()
|
||||||
|
sys.exit()
|
||||||
continue
|
continue
|
||||||
if self.nextgame.holdgame:
|
if self.nextgame.holdgame:
|
||||||
assert self.nextgame.id <= 0
|
assert self.nextgame.id <= 0
|
||||||
|
@ -267,9 +272,11 @@ class Application:
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
sys.exit()
|
||||||
pass
|
pass
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
|
sys.exit()
|
||||||
# hide main window
|
# hide main window
|
||||||
self.wm_withdraw()
|
self.wm_withdraw()
|
||||||
#
|
#
|
||||||
|
@ -326,6 +333,7 @@ class Application:
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
self.nextgame.loadedgame = None
|
self.nextgame.loadedgame = None
|
||||||
|
sys.exit()
|
||||||
elif self.commandline.game is not None:
|
elif self.commandline.game is not None:
|
||||||
gameid = self.gdb.getGameByName(self.commandline.game)
|
gameid = self.gdb.getGameByName(self.commandline.game)
|
||||||
if gameid is None:
|
if gameid is None:
|
||||||
|
@ -702,6 +710,7 @@ class Application:
|
||||||
r = 1
|
r = 1
|
||||||
except (Exception, TclError, UnpicklingError) as ex:
|
except (Exception, TclError, UnpicklingError) as ex:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
sys.exit()
|
||||||
cs.error = 1
|
cs.error = 1
|
||||||
# restore settings
|
# restore settings
|
||||||
self.nextgame.cardset = self.cardset
|
self.nextgame.cardset = self.cardset
|
||||||
|
|
|
@ -115,6 +115,7 @@ class Images:
|
||||||
if ((check_w and w != self.CARDW) or
|
if ((check_w and w != self.CARDW) or
|
||||||
(check_h and h != self.CARDH)):
|
(check_h and h != self.CARDH)):
|
||||||
raise ValueError("Invalid size %dx%d of image %s" % (w, h, f))
|
raise ValueError("Invalid size %dx%d of image %s" % (w, h, f))
|
||||||
|
assert img
|
||||||
return img
|
return img
|
||||||
|
|
||||||
def __loadBottom(self, filename, check_w=1, check_h=1, color='white'):
|
def __loadBottom(self, filename, check_w=1, check_h=1, color='white'):
|
||||||
|
@ -145,6 +146,9 @@ class Images:
|
||||||
def __addBack(self, im1, name):
|
def __addBack(self, im1, name):
|
||||||
r = max(self.CARDW / 40.0, self.CARDH / 60.0)
|
r = max(self.CARDW / 40.0, self.CARDH / 60.0)
|
||||||
r = max(2, int(round(r)))
|
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)
|
im2 = im1.subsample(r)
|
||||||
self._back.append(ImagesCardback(len(self._back), name, im1, im2))
|
self._back.append(ImagesCardback(len(self._back), name, im1, im2))
|
||||||
|
|
||||||
|
|
|
@ -862,6 +862,12 @@ class Stack:
|
||||||
# bottom and shade
|
# bottom and shade
|
||||||
if self.images.bottom:
|
if self.images.bottom:
|
||||||
img = self.getBottomImage()
|
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['image'] = img
|
||||||
self.images.bottom.moveTo(x, y)
|
self.images.bottom.moveTo(x, y)
|
||||||
if self.items.bottom:
|
if self.items.bottom:
|
||||||
|
|
|
@ -59,7 +59,10 @@ class MfxCanvasImage(ImageItem2):
|
||||||
group = kwargs['group']
|
group = kwargs['group']
|
||||||
del kwargs['group']
|
del kwargs['group']
|
||||||
if 'image' in kwargs:
|
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)
|
ImageItem2.__init__(self, canvas, x, y, **kwargs)
|
||||||
if group:
|
if group:
|
||||||
self.addtag(group)
|
self.addtag(group)
|
||||||
|
|
|
@ -42,6 +42,15 @@ def wm_deiconify(window):
|
||||||
window.wm_deiconify()
|
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):
|
def wm_map(window, maximized=0):
|
||||||
if window.wm_state() != "iconic":
|
if window.wm_state() != "iconic":
|
||||||
if maximized and WIN_SYSTEM == "win32":
|
if maximized and WIN_SYSTEM == "win32":
|
||||||
|
@ -249,13 +258,21 @@ if Image:
|
||||||
def __init__(self, file=None, image=None, pil_image_orig=None):
|
def __init__(self, file=None, image=None, pil_image_orig=None):
|
||||||
if file:
|
if file:
|
||||||
image = Image.open(file).convert('RGBA')
|
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
|
self._pil_image = image
|
||||||
if pil_image_orig:
|
if pil_image_orig:
|
||||||
self._pil_image_orig = pil_image_orig
|
self._pil_image_orig = pil_image_orig
|
||||||
else:
|
else:
|
||||||
self._pil_image_orig = image
|
self._pil_image_orig = image
|
||||||
|
|
||||||
|
def getTk(self):
|
||||||
|
return ImageTk.PhotoImage(self._pil_image)
|
||||||
|
|
||||||
def subsample(self, r):
|
def subsample(self, r):
|
||||||
im = self._pil_image
|
im = self._pil_image
|
||||||
w, h = im.size
|
w, h = im.size
|
||||||
|
@ -341,9 +358,16 @@ def fillImage(image, fill, outline=None):
|
||||||
|
|
||||||
|
|
||||||
def createImage(width, height, fill, outline=None):
|
def createImage(width, height, fill, outline=None):
|
||||||
image = tkinter.PhotoImage(width=width, height=height)
|
image = ImageTk.PhotoImage(size=(width, height), image='RGBA')
|
||||||
assert image.width() == width
|
image = Image.new('RGBA', (width, height), fill)
|
||||||
assert image.height() == height
|
# 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()
|
image.blank()
|
||||||
fillImage(image, fill, outline)
|
fillImage(image, fill, outline)
|
||||||
return image
|
return image
|
||||||
|
|
Loading…
Add table
Reference in a new issue