class _TwoImageCard(_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) images = game.app.images self.item = MfxCanvasGroup(game.canvas) self.__face = MfxCanvasImage(game.canvas, self.x, self.y, image=images.getFace(deck, suit, rank), anchor='nw') self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=images.getBack(), anchor='nw') self.__face.addtag(self.item) self.__back.addtag(self.item) self.__face.hide() def showFace(self, unhide=1): if not self.face_up: self.__back.hide() self.__face.show() # self.tkraise(unhide) self.face_up = 1 def showBack(self, unhide=1): if self.face_up: self.__face.hide() self.__back.show() # self.tkraise(unhide) self.face_up = 0 def updateCardBackground(self, image): self.__back.config(image=image)
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) images = game.app.images self.__face_image = images.getFace(deck, suit, rank) self.__back_image = images.getBack() self.__image = MfxCanvasImage(game.canvas, self.x, self.y, image=self.__back_image, anchor=gtk.ANCHOR_NW) if 0: # using a group for a single image doesn't gain much self.item = MfxCanvasGroup(game.canvas) self.__image.addtag(self.item) else: self.item = self.__image def showFace(self, unhide=1): if not self.face_up: self.__image.config(image=self.__face_image) self.tkraise(unhide) self.face_up = 1 def showBack(self, unhide=1): if self.face_up: self.__image.config(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.__image.config(image=image)
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) images = game.app.images self.__face_image = images.getFace(deck, suit, rank) self.__back_image = images.getBack() self.__image = MfxCanvasImage(game.canvas, self.x, self.y, image=self.__back_image, anchor=gtk.ANCHOR_NW) if 0: # using a group for a single image doesn't gain much self.item = MfxCanvasGroup(game.canvas) self.__image.addtag(self.item) else: self.item = self.__image def showFace(self, unhide=1): if not self.face_up: self.__image.config(image=self.__face_image) self.tkraise(unhide) self.face_up = 1 def showBack(self, unhide=1): if self.face_up: self.__image.config(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.__image.config(image=image)
class _TwoImageCard(_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) images = game.app.images self.item = MfxCanvasGroup(game.canvas) self.__face = MfxCanvasImage(game.canvas, self.x, self.y, image=images.getFace(deck, suit, rank), anchor='nw') self.__back = MfxCanvasImage(game.canvas, self.x, self.y, image=images.getBack(), anchor='nw') self.__face.addtag(self.item) self.__back.addtag(self.item) self.__face.hide() def showFace(self, unhide=1): if not self.face_up: self.__back.hide() self.__face.show() # self.tkraise(unhide) self.face_up = 1 def showBack(self, unhide=1): if self.face_up: self.__face.hide() self.__back.show() # self.tkraise(unhide) self.face_up = 0 def updateCardBackground(self, image): self.__back.config(image=image)
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)