Beispiel #1
0
 def setBackgroundImage(self, event=None):
     # print 'setBackgroundImage', self._bg_img
     if not hasattr(self, '_bg_img'):
         return
     if not self._bg_img:  # solid color
         return
     stretch = self._stretch_bg_image
     save_aspect = self._save_aspect_bg_image
     if Image:
         if stretch:
             w, h = self._geometry()
             if save_aspect:
                 w0, h0 = self._bg_img.size
                 a = min(float(w0) / w, float(h0) / h)
                 w0, h0 = int(w0 / a), int(h0 / a)
                 im = self._bg_img.resize((w0, h0))
             else:
                 im = self._bg_img.resize((w, h))
             image = ImageTk.PhotoImage(im)
         else:
             image = ImageTk.PhotoImage(self._bg_img)
     else:  # not Image
         stretch = 0
         image = self._bg_img
     for id in self.__tiles:
         self.delete(id)
     self.__tiles = []
     # must keep a reference to the image, otherwise Python will
     # garbage collect it...
     self.__tileimage = image
     if stretch:
         #
         if self.preview:
             dx, dy = 0, 0
         else:
             dx, dy = -self.xmargin, -self.ymargin
         id = self._x_create("image", dx, dy, image=image, anchor="nw")
         self.tag_lower(id)  # also see tag_lower above
         self.__tiles.append(id)
     else:
         iw, ih = image.width(), image.height()
         sw, sh = self._geometry()
         for x in range(-self.xmargin, sw, iw):
             for y in range(-self.ymargin, sh, ih):
                 id = self._x_create("image",
                                     x,
                                     y,
                                     image=image,
                                     anchor="nw")
                 self.tag_lower(id)  # also see tag_lower above
                 self.__tiles.append(id)
     return 1
Beispiel #2
0
 def getShadowPIL(self, stack, cards):
     x0, y0 = stack.getPositionFor(cards[0])
     x1, y1 = stack.getPositionFor(cards[-1])
     x0, x1 = min(x1, x0), max(x1, x0)
     y0, y1 = min(y1, y0), max(y1, y0)
     cw, ch = self.getSize()
     x1 += cw
     y1 += ch
     w, h = x1 - x0, y1 - y0
     if (w, h) in self._pil_shadow:
         return self._pil_shadow[(w, h)]
     # create mask
     mask = Image.new('RGBA', (w, h))
     for c in cards:
         x, y = stack.getPositionFor(c)
         x, y = x - x0, y - y0
         im = c._active_image._pil_image
         mask.paste(im, (x, y), im)
     # create shadow
     sh_color = (0x00, 0x00, 0x00, 0x50)
     shadow = Image.new('RGBA', (w, h))
     shadow.paste(sh_color, (0, 0, w, h), mask)
     sx, sy = self.SHADOW_XOFFSET, self.SHADOW_YOFFSET
     mask = mask.crop((sx, sy, w, h))
     tmp = Image.new('RGBA', (w - sx, h - sy))
     shadow.paste(tmp, (0, 0), mask)
     shadow = ImageTk.PhotoImage(shadow)
     self._pil_shadow[(w, h)] = shadow
     return shadow
Beispiel #3
0
 def _loadImage(self, name):
     file = os.path.join(self.dir, name)
     image = None
     for ext in IMAGE_EXTENSIONS:
         file = os.path.join(self.dir, name + ext)
         if os.path.isfile(file):
             if Image:
                 image = ImageTk.PhotoImage(Image.open(file))
             else:
                 image = tkinter.PhotoImage(file=file)
             break
     return image
Beispiel #4
0
def copyImage(image, x, y, width, height):
    if Image:
        if isinstance(image, PIL_Image):
            return ImageTk.PhotoImage(
                image._pil_image.crop((x, y, x+width, y+height)))
    dest = tkinter.PhotoImage(width=width, height=height)
    assert dest.width() == width
    assert dest.height() == height
    dest.blank()
    image.tk.call(dest, "copy", image.name, "-from", x, y, x+width, y+height)
    assert dest.width() == width
    assert dest.height() == height
    return dest
Beispiel #5
0
 def _createDisabledButtonImage(self, tkim):
     # grayscale and light-up image
     if not tkim:
         return None
     im = tkim._pil_image
     dis_im = ImageOps.grayscale(im)
     # color = '#ffffff'
     # factor = 0.6
     color = '#dedede'
     factor = 0.7
     sh = Image.new(dis_im.mode, dis_im.size, color)
     tmp = Image.blend(dis_im, sh, factor)
     dis_im = Image.composite(tmp, im, im)
     dis_tkim = ImageTk.PhotoImage(image=dis_im)
     return dis_tkim