예제 #1
0
파일: card.py 프로젝트: yegle/PySolFC
class _TwoImageCard(_HideableCard):
    # Private instance variables:
    #   __face, __back -- the canvas items making up the card
    def __init__(self, id, deck, suit, rank, game, x=0, y=0):
        _HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
        self.item = MfxCanvasGroup(game.canvas)
        self.__face = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardFaceImage(deck, suit, rank), anchor="nw")
        self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardBackImage(deck, suit, rank), anchor="nw")
        self.__face.addtag(self.item)
        self.__back.addtag(self.item)

    def showFace(self, unhide=1):
        if not self.face_up:
            self.__face.tkraise()
            self.tkraise(unhide)
            self.face_up = 1

    def showBack(self, unhide=1):
        if self.face_up:
            self.__back.tkraise()
            self.tkraise(unhide)
            self.face_up = 0

    def updateCardBackground(self, image):
        self.__back.config(image=image)
예제 #2
0
파일: card.py 프로젝트: yegle/PySolFC
 def __init__(self, id, deck, suit, rank, game, x=0, y=0):
     _HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
     self.item = MfxCanvasGroup(game.canvas)
     self.__face = MfxCanvasImage(game.canvas, self.x, self.y + 11000, image=game.getCardFaceImage(deck, suit, rank), anchor="nw")
     self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=game.getCardBackImage(deck, suit, rank), anchor="nw")
     self.__face.addtag(self.item)
     self.__back.addtag(self.item)
예제 #3
0
 def createCardLabel(self, suit, rank, x0, y0):
     dx, dy = self.label_width, self.label_height
     dir = self.images_dir
     canvas = self.canvas
     group = MfxCanvasGroup(canvas)
     #
     im = FindCardDialog.CARD_IMAGES.get((rank, suit))
     if im is None:
         r = '%02d' % (rank+1)
         s = 'cshd'[suit]
         fn = os.path.join(dir, r+s+'.gif')
         im = makeImage(file=fn)
         FindCardDialog.CARD_IMAGES[(rank, suit)] = im
     cim = MfxCanvasImage(canvas, x0, y0, image=im, anchor='nw')
     cim.addtag(group)
     cim.lower()
     #
     rect_width = 4
     x1, y1 = x0+dx, y0+dy
     rect = MfxCanvasRectangle(self.canvas, x0+1, y0+1, x1-1, y1-1,
                               width=rect_width,
                               fill=None,
                               outline='red',
                               state='hidden'
                               )
     rect.addtag(group)
     #
     bind(group, '<Enter>',
          lambda e, suit=suit, rank=rank, rect=rect:
              self.enterEvent(suit, rank, rect, group))
     bind(group, '<Leave>',
          lambda e, suit=suit, rank=rank, rect=rect:
              self.leaveEvent(suit, rank, rect, group))
     self.groups.append(group)
예제 #4
0
파일: card.py 프로젝트: hayate891/PySolFC
class _OneImageCard(_HideableCard):
    def __init__(self, id, deck, suit, rank, game, x=0, y=0):
        _HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
        self._face_image = game.getCardFaceImage(deck, suit, rank)
        self._back_image = game.getCardBackImage(deck, suit, rank)
        self._shade_image = game.getCardShadeImage()
        self._active_image = self._back_image
        self.item = MfxCanvasImage(game.canvas,
                                   self.x,
                                   self.y,
                                   image=self._active_image,
                                   anchor="nw")
        self.shade_item = None
        # self._setImage = self.item.config

    def _setImage(self, image):
        if image is not self._active_image:
            self.item.config(image=image)
            self._active_image = image

    def showFace(self, unhide=1):
        if not self.face_up:
            self._setImage(image=self._face_image)
            self.tkraise(unhide)
            self.face_up = 1

    def showBack(self, unhide=1):
        if self.face_up:
            self._setImage(image=self._back_image)
            self.tkraise(unhide)
            self.face_up = 0

    def updateCardBackground(self, image):
        self._back_image = image
        if not self.face_up:
            self._setImage(image=image)

    #
    # optimized by inlining
    #

    def moveBy(self, dx, dy):
        dx, dy = int(dx), int(dy)
        self.x = self.x + dx
        self.y = self.y + dy
        item = self.item
        item.canvas.tk.call(item.canvas._w, "move", item.id, dx, dy)

    # for resize
    def update(self, id, deck, suit, rank, game):
        self._face_image = game.getCardFaceImage(deck, suit, rank)
        self._back_image = game.getCardBackImage(deck, suit, rank)
        self._shade_image = game.getCardShadeImage()
        if self.face_up:
            img = self._face_image
        else:
            img = self._back_image
        self.item.config(image=img)
        self._active_image = img
예제 #5
0
파일: card.py 프로젝트: yegle/PySolFC
 def __init__(self, id, deck, suit, rank, game, x=0, y=0):
     _HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
     self._face_image = game.getCardFaceImage(deck, suit, rank)
     self._back_image = game.getCardBackImage(deck, suit, rank)
     self._shade_image = game.getCardShadeImage()
     self._active_image = self._back_image
     self.item = MfxCanvasImage(game.canvas, self.x, self.y, image=self._active_image, anchor="nw")
     self.shade_item = None
예제 #6
0
파일: card.py 프로젝트: jimsize/PySolFC
class _OneImageCard(_HideableCard):
    def __init__(self, id, deck, suit, rank, game, x=0, y=0):
        _HideableCard.__init__(self, id, deck, suit, rank, game, x=x, y=y)
        self._face_image = game.getCardFaceImage(deck, suit, rank)
        self._back_image = game.getCardBackImage(deck, suit, rank)
        self._shade_image = game.getCardShadeImage()
        self._active_image = self._back_image
        self.item = MfxCanvasImage(
            game.canvas, self.x, self.y, image=self._active_image, anchor="nw")
        self.shade_item = None
        # self._setImage = self.item.config

    def _setImage(self, image):
        if image is not self._active_image:
            self.item.config(image=image)
            self._active_image = image

    def showFace(self, unhide=1):
        if not self.face_up:
            self._setImage(image=self._face_image)
            self.tkraise(unhide)
            self.face_up = 1

    def showBack(self, unhide=1):
        if self.face_up:
            self._setImage(image=self._back_image)
            self.tkraise(unhide)
            self.face_up = 0

    def updateCardBackground(self, image):
        self._back_image = image
        if not self.face_up:
            self._setImage(image=image)

    #
    # optimized by inlining
    #

    def moveBy(self, dx, dy):
        dx, dy = int(dx), int(dy)
        self.x = self.x + dx
        self.y = self.y + dy
        item = self.item
        item.canvas.tk.call(item.canvas._w, "move", item.id, dx, dy)

    # for resize
    def update(self, id, deck, suit, rank, game):
        self._face_image = game.getCardFaceImage(deck, suit, rank)
        self._back_image = game.getCardBackImage(deck, suit, rank)
        self._shade_image = game.getCardShadeImage()
        if self.face_up:
            img = self._face_image
        else:
            img = self._back_image
        self.item.config(image=img)
        self._active_image = img
예제 #7
0
    def updatePreview(self, key=None):
        if key == self.preview_key:
            return
        if key is None:
            key = self.key
        canvas = self.preview.canvas
        canvas.deleteAllItems()
        self.preview_images = []
        cs = self.manager.get(key)
        if not cs:
            self.preview_key = -1
            return
        names, columns = cs.getPreviewCardNames()

        # if cardset has changed, set default values
        if key != self.preview_key and USE_PIL:
            self.x_offset.config(value=cs.CARD_XOFFSET)
            self.x_offset.set(cs.CARD_XOFFSET)

            self.y_offset.config(value=cs.CARD_YOFFSET)
            self.y_offset.set(cs.CARD_YOFFSET)

        try:
            # ???names, columns = cs.getPreviewCardNames()
            for n in names:
                f = os.path.join(cs.dir, n + cs.ext)
                self.preview_images.append(loadImage(file=f))
        except Exception:
            self.preview_key = -1
            self.preview_images = []
            return
        i, x, y, sx, sy, dx, dy = 0, 10, 10, 0, 0, cs.CARDW + 10, cs.CARDH + 10
        if USE_PIL:
            xf = self.scale_x.get()
            yf = self.scale_y.get()
            dx = int(dx * xf)
            dy = int(dy * yf)
            self.scale_images = []
        for image in self.preview_images:
            if USE_PIL:
                image = image.resize(xf, yf)
                self.scale_images.append(image)
            MfxCanvasImage(canvas, x, y, anchor="nw", image=image)
            sx, sy = max(x, sx), max(y, sy)
            i = i + 1
            if i % columns == 0:
                x, y = 10, y + dy
            else:
                x = x + dx
        canvas.config(scrollregion=(0, 0, sx + dx, sy + dy),
                      width=sx + dx,
                      height=sy + dy)
        # canvas.config(xscrollincrement=dx, yscrollincrement=dy)
        canvas.event_generate('<Configure>')  # update bg image
        self.preview_key = key
        self.key = key
예제 #8
0
 def createCardLabel(self, suit, rank, x0, y0):
     dx, dy = self.label_width, self.label_height
     dir = self.images_dir
     canvas = self.canvas
     group = MfxCanvasGroup(canvas)
     #
     im = FindCardDialog.CARD_IMAGES.get((rank, suit))
     if im is None:
         r = '%02d' % (rank+1)
         s = 'cshd'[suit]
         fn = os.path.join(dir, r+s+'.gif')
         im = makeImage(file=fn)
         FindCardDialog.CARD_IMAGES[(rank, suit)] = im
     cim = MfxCanvasImage(canvas, x0, y0, image=im, anchor='nw')
     cim.addtag(group)
     cim.lower()
     #
     rect_width = 4
     x1, y1 = x0+dx, y0+dy
     rect = MfxCanvasRectangle(self.canvas, x0+1, y0+1, x1-1, y1-1,
                               width=rect_width,
                               fill=None,
                               outline='red',
                               state='hidden'
                               )
     rect.addtag(group)
     #
     bind(group, '<Enter>',
          lambda e, suit=suit, rank=rank, rect=rect:
              self.enterEvent(suit, rank, rect, group))
     bind(group, '<Leave>',
          lambda e, suit=suit, rank=rank, rect=rect:
              self.leaveEvent(suit, rank, rect, group))
     self.groups.append(group)