From: <umg...@us...> - 2006-09-20 10:56:56
|
Revision: 343 http://svn.sourceforge.net/pybridge/?rev=343&view=rev Author: umgangee Date: 2006-09-20 03:56:47 -0700 (Wed, 20 Sep 2006) Log Message: ----------- Rewritten CardArea widget for Cairo. Introduction of a "canvas" layer, which manages positioning and redrawing of graphics. Modifications to WindowBridgetable in line with CardArea. Modified Paths: -------------- trunk/pybridge/pybridge/ui/cardarea.py trunk/pybridge/pybridge/ui/window_bridgetable.py Added Paths: ----------- trunk/pybridge/pybridge/ui/canvas.py Added: trunk/pybridge/pybridge/ui/canvas.py =================================================================== --- trunk/pybridge/pybridge/ui/canvas.py (rev 0) +++ trunk/pybridge/pybridge/ui/canvas.py 2006-09-20 10:56:47 UTC (rev 343) @@ -0,0 +1,160 @@ +# PyBridge -- online contract bridge made easy. +# Copyright (C) 2004-2006 PyBridge Project. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + +import gtk +import cairo + +from pybridge.environment import environment + + +class CairoCanvas(gtk.DrawingArea): + """Provides a simple canvas layer for . + + Overlapping items. + """ + + background_path = environment.find_pixmap('baize.png') + background = cairo.ImageSurface.create_from_png(background_path) + pattern = cairo.SurfacePattern(background) + pattern.set_extend(cairo.EXTEND_REPEAT) + + + def __init__(self): + super(CairoCanvas, self).__init__() # Initialise parent. + + self.items = {} + + # Set up gtk.Widget signals. + self.connect('configure_event', self.configure) + self.connect('expose_event', self.expose) + + + def clear(self): + """Clears all items from canvas.""" + self.items = {} # Remove all item references. + + # Redraw background pattern on backing. + width, height = self.window.get_size() + context = cairo.Context(self.backing) + context.rectangle(0, 0, width, height) + context.set_source(self.pattern) + context.paint() + self.window.invalidate_rect((0, 0, width, height), False) # Expose. + + + def add_item(self, id, source, xy, z_index): + """Places source item into items list. + + @param id: unique identifier for source. + @param source: ImageSurface. + @param xy: function providing (x, y) coords for source in backing. + @param z_index: integer. + """ + pos_x, pos_y = xy(*self.window.get_size()) + area = (pos_x, pos_y, source.get_width(), source.get_height()) + self.items[id] = {'source': source, 'area': area, + 'xy' : xy, 'z-index': z_index, } + self.redraw(*area) + + + def remove_item(self, id): + """Removes source item with identifier from items list. + + @param id: unique identifier for source. + """ + if self.items.get(id): + area = self.items[id]['area'] + del self.item[id] + self.redraw(*area) + + + def update_item(self, id, source=None, xy=None, z_index=0): + """ + + """ + # If optional parameters are not specified, use previous values. + source = source or self.items[id]['source'] + xy = xy or self.items[id]['xy'] + z_index = z_index or self.items[id]['z-index'] + + oldarea = self.items[id]['area'] # Current position of item. + pos_x, pos_y = xy(*self.window.get_size()) + area = (pos_x, pos_y, source.get_width(), source.get_height()) + if area != oldarea: # If position has changed, clear previous area. + del self.items[id] + self.redraw(*oldarea) + self.items[id] = {'source': source, 'area': area, + 'xy' : xy, 'z-index': z_index, } + self.redraw(*area) + + + def redraw(self, x, y, width, height): + """Redraws sources in area (x, y, width, height) to backing canvas. + + @param x: + @param y: + @param width: + @param height: + """ + context = cairo.Context(self.backing) + context.rectangle(x, y, width, height) + context.clip() # Set clip region. + + # Redraw background pattern in area. + context.set_source(self.pattern) + context.paint() + + # Build list of sources to redraw in area, in order of z-index. + # TODO: Find sources which intersect with area. + area = gtk.gdk.Rectangle(x, y, width, height) + items = self.items.values() + items.sort(lambda i, j : cmp(i['z-index'], j['z-index']), reverse=True) + + for item in items: + pos_x, pos_y = item['area'][0:2] + context.set_source_surface(item['source'], pos_x, pos_y) + context.paint() + + context.reset_clip() + self.window.invalidate_rect((x, y, width, height), False) # Expose. + + + + def configure(self, widget, event): + width, height = self.window.get_size() + self.backing = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + + # Recalculate position of all items. + for id, item in self.items.items(): + pos_x, pos_y = item['xy'](width, height) + area = (pos_x, pos_y, item['area'][2], item['area'][3]) + self.items[id]['area'] = area + + self.redraw(0, 0, width, height) # Full redraw required. + return True # Expected to return True. + + + def expose(self, widget, event): + context = widget.window.cairo_create() + context.rectangle(*event.area) + context.clip() # Only redraw the exposed area. + context.set_source_surface(self.backing, 0, 0) + context.paint() + context.reset_clip() + return False # Expected to return False. + Modified: trunk/pybridge/pybridge/ui/cardarea.py =================================================================== --- trunk/pybridge/pybridge/ui/cardarea.py 2006-08-16 14:02:03 UTC (rev 342) +++ trunk/pybridge/pybridge/ui/cardarea.py 2006-09-20 10:56:47 UTC (rev 343) @@ -16,13 +16,12 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. -import gc, gtk +import gtk +import cairo from pybridge.environment import environment +from canvas import CairoCanvas -BACKGROUND_PATH = environment.find_pixmap("baize.png") -CARD_MASK_PATH = environment.find_pixmap("bonded.png") - from pybridge.bridge.card import Card, Rank, Suit from pybridge.bridge.deck import Seat @@ -35,73 +34,108 @@ # The red-black-red-black ordering convention. RED_BLACK = [Suit.Diamond, Suit.Club, Suit.Heart, Suit.Spade] -BORDER_X = BORDER_Y = 12 +class CardArea(CairoCanvas): + """This widget. -class CardArea(gtk.DrawingArea): + This widget uses Cairo and requires >= GTK 2.8. + """ - # TODO: when PyGTK 2.8 becomes widespread, adapt this module to Cairo. + # Load card mask. + card_mask_path = environment.find_pixmap('bonded.png') + card_mask = cairo.ImageSurface.create_from_png(card_mask_path) + + border_x = border_y = 10 + card_width = card_mask.get_width() / 13 + card_height = card_mask.get_height() / 5 + spacing_x = int(card_width * 0.4) + spacing_y = int(card_height * 0.2) - # Load table background and card pixbufs. - background = gtk.gdk.pixbuf_new_from_file(BACKGROUND_PATH).render_pixmap_and_mask()[0] - card_mask = gtk.gdk.pixbuf_new_from_file_at_size(CARD_MASK_PATH, 1028, 615) - def __init__(self): - gtk.DrawingArea.__init__(self) + super(CardArea, self).__init__() # Initialise parent. - self.backing = None # Placeholder for backing pixbuf. - self.hand_pixbufs = {} # Hand pixbufs, keyed by seat. - self.hand_coords = {} # Positions of hand pixbufs on backing. - self.card_coords = {} # Positions of cards on hand pixbufs. - self.trick_pixbuf = None # + # To receive card clicked events, override this with external method. + self.on_card_clicked = lambda card, seat: True - # Expect cards of unit size 13 x 5. - self.card_width = self.card_mask.get_width() / 13 - self.card_height = self.card_mask.get_height() / 5 - self.spacing_x = int(self.card_width * 0.4) - self.spacing_y = int(self.card_height * 0.2) + self.hands = {} + self.trick = None + self.set_seat_mapping(Seat.South) - # Method to call when a card is clicked. - self.on_card_clicked = None - - # Set up events. - self.connect('configure_event', self.configure) - self.connect('expose_event', self.expose) - self.connect('button_press_event', self.button_press) - self.add_events(gtk.gdk.BUTTON_PRESS_MASK) + self.connect('button_release_event', self.button_release) + self.add_events(gtk.gdk.BUTTON_PRESS_MASK | gtk.gdk.BUTTON_RELEASE_MASK) - def draw_card(self, dest_pixbuf, pos_x, pos_y, card): - """Draws graphic of specified card to dest_pixbuf at (pos_x, pos_y).""" - if isinstance(card, Card): # Determine coordinates of graphic in card_mask. + def draw_card(self, context, pos_x, pos_y, card): + """Draws graphic of specified card to context at (pos_x, pos_y). + + @param context: a cairo.Context + @param pos_x: + @param pos_y: + @param card: the Card to draw. + """ + if isinstance(card, Card): # Determine coordinates of card graphic. src_x = CARD_MASK_RANKS.index(card.rank) * self.card_width src_y = CARD_MASK_SUITS.index(card.suit) * self.card_height else: # Draw a face-down card. src_x, src_y = self.card_width*2, self.card_height*4 - self.card_mask.copy_area(src_x, src_y, self.card_width, self.card_height, - dest_pixbuf, pos_x, pos_y) + context.rectangle(pos_x, pos_y, self.card_width, self.card_height) + context.clip() + context.set_source_surface(self.card_mask, pos_x-src_x, pos_y-src_y) + context.paint() + context.reset_clip() - def build_hand(self, seat, hand, facedown=False, omit=[]): - """Builds and saves a pixbuf of card images. + def set_hand(self, hand, seat, facedown=False, omit=[]): + """Sets the hand of player at seat. + Draws representation of cards in hand to context. - @param seat: the seat of player holding hand. - @param hand: a list of Card objects representing the hand. - @param facedown: if True, card elements of hand are drawn face down. - @param omit: a list of Card objects in hand not to draw. + The hand is buffered into an ImageSurface, since hands change + infrequently and multiple calls to draw_card() are expensive. + + @param hand: a list of Card objects. + @param seat: a member of Seat. + @param facedown: if True, cards are drawn face-down. + @param omit: a list of elements of hand not to draw. """ - # Filters out cards in hand that appear in omit. - ef = lambda hand: [(i, c) for i, c in enumerate(hand) if c not in omit] - - coords = [] + # TODO: coords should be dict (card : (pos_x, pos_y)), but this breaks when hashing. + def get_coords_for_hand(): + coords = [] + if seat in (self.TOP, self.BOTTOM): + pos_y = 0 + if facedown is True: # Draw cards in one continuous row. + for index, card in enumerate(hand): + pos_x = index * self.spacing_x + coords.append((card, pos_x, pos_y)) + else: # Insert a space between each suit. + spaces = sum([1 for suitcards in suits.values() if len(suitcards) > 0]) - 1 + for index, card in enumerate(hand): + # Insert a space for each suit in hand which appears before this card's suit. + insert = sum([1 for suit, suitcards in suits.items() if len(suitcards) > 0 + and RED_BLACK.index(card.suit) > RED_BLACK.index(suit)]) + pos_x = (index + insert) * self.spacing_x + coords.append((card, pos_x, pos_y)) + else: # LEFT or RIGHT. + if facedown is True: # Wrap cards to a 4x4 grid. + for index, card in enumerate(hand): + adjust = seat is self.RIGHT and index == 12 and 3 + pos_x = ((index % 4) + adjust) * self.spacing_x + pos_y = (index / 4) * self.spacing_y + coords.append((card, pos_x, pos_y)) + else: + longest = max([len(cards) for cards in suits.values()]) + for index, card in enumerate(hand): + adjust = seat is self.RIGHT and longest - len(suits[card.suit]) + pos_x = (suits[card.suit].index(card) + adjust) * self.spacing_x + pos_y = RED_BLACK.index(card.suit) * self.spacing_y + coords.append((card, pos_x, pos_y)) + return coords + if facedown is False: # Split hand into suits. - suits = {} - for suit in Suit: - suits[suit] = [] + suits = dict([(suit, []) for suit in Suit]) for card in hand: suits[card.suit].append(card) # Sort suits. @@ -111,178 +145,147 @@ hand = [] for suit in RED_BLACK: hand.extend(suits[suit]) + + saved = self.hands.get(seat) + if saved and saved['hand'] == hand: + # If hand has been set previously, do not recalculate coords. + coords = saved['coords'] + else: + coords = get_coords_for_hand() - if seat in (Seat.North, Seat.South): - height = self.card_height # Draw cards in one continuous row. - pos_y = 0 - - if facedown is True: - width = self.card_width + (self.spacing_x * 12) - for index, card in ef(hand): - pos_x = index * self.spacing_x - coords.append((card, pos_x, pos_y)) - - else: # Insert a space between each suit. - spaces = sum([1 for suitcards in suits.values() if len(suitcards) > 0]) - 1 - width = self.card_width + (self.spacing_x * (12 + spaces)) - for index, card in ef(hand): - # Insert a space for each suit in hand which appears before this card's suit. - insert = sum([1 for suit, suitcards in suits.items() if len(suitcards) > 0 - and RED_BLACK.index(card.suit) > RED_BLACK.index(suit)]) - pos_x = (index + insert) * self.spacing_x - coords.append((card, pos_x, pos_y)) + # Determine dimensions of hand. + width = max([x for card, x, y in coords]) + self.card_width + height = max([y for card, x, y in coords]) + self.card_height + # Create new ImageSurface for hand. + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + context = cairo.Context(surface) + # Clear ImageSurface - in Cairo 1.2+, this is done automatically. + if cairo.version_info < (1, 2): + context.set_operator(cairo.OPERATOR_CLEAR) + context.paint() + context.set_operator(cairo.OPERATOR_OVER) # Restore. - else: # West or East. - if facedown is True: # Wrap cards to a 4x4 grid. - width = self.card_width + (self.spacing_x * 3) - height = self.card_height + (self.spacing_y * 3) - for index, card in ef(hand): - adjust = seat is Seat.East and index == 12 and 3 - pos_x = ((index % 4) + adjust) * self.spacing_x - pos_y = (index / 4) * self.spacing_y - coords.append((card, pos_x, pos_y)) - - else: - longest = max([len(cards) for cards in suits.values()]) - width = self.card_width + (self.spacing_x * (longest - 1)) - height = self.card_height + (self.spacing_y * (len(suits) - 1)) - for index, card in ef(hand): - adjust = seat is Seat.East and longest - len(suits[card.suit]) - pos_x = (suits[card.suit].index(card) + adjust) * self.spacing_x - pos_y = RED_BLACK.index(card.suit) * self.spacing_y - coords.append((card, pos_x, pos_y)) + # Draw cards to surface. + visible = [(i, card) for i, card in enumerate(hand) if card not in omit] + for i, card in visible: + pos_x, pos_y = coords[i][1:] + self.draw_card(context, pos_x, pos_y, card) - self.hand_pixbufs[seat] = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) - self.hand_pixbufs[seat].fill(0x00000000) # Clear pixbuf. + # Save + self.hands[seat] = {'hand' : hand, 'visible' : visible, + 'surface' : surface, 'coords' : coords, } - # Draw cards to pixbuf. - for card, pos_x, pos_y in coords: - self.draw_card(self.hand_pixbufs[seat], pos_x, pos_y, card) - self.card_coords[seat] = coords - - - def draw_hand(self, seat): - """""" - x, y, width, height = self.get_allocation() + # + if seat is self.TOP: + xy = lambda w, h: ((w - width)/2, self.border_y) + elif seat is self.RIGHT: + xy = lambda w, h: ((w - width - self.border_x), (h - height)/2) + elif seat is self.BOTTOM: + xy = lambda w, h: ((w - width)/2, (h - height - self.border_y)) + elif seat is self.LEFT: + xy = lambda w, h: (self.border_x, (h - height)/2) - # Determine coordinates in backing pixmap to draw hand pixbuf. - hand_pixbuf = self.hand_pixbufs[seat] - hand_width = hand_pixbuf.get_width() - hand_height = hand_pixbuf.get_height() - - if seat is Seat.North: - pos_x = (width - hand_width) / 2 - pos_y = BORDER_Y - elif seat is Seat.East: - pos_x = width - hand_width - BORDER_X - pos_y = (height - hand_height) / 2 - elif seat is Seat.South: - pos_x = (width - hand_width) / 2 - pos_y = height - hand_height - BORDER_Y - elif seat is Seat.West: - pos_x = BORDER_X - pos_y = (height - hand_height) / 2 - - # Draw hand pixbuf and save hand coordinates. - self.backing.draw_rectangle(self.backingGC, True, pos_x, pos_y, hand_width, hand_height) - self.backing.draw_pixbuf(self.backingGC, hand_pixbuf, 0, 0, pos_x, pos_y) - self.hand_coords[seat] = (pos_x, pos_y, pos_x+hand_width, pos_y+hand_height) - - # Redraw modified area of backing pixbuf. - self.window.invalidate_rect((pos_x, pos_y, hand_width, hand_height), False) + id = 'hand-%s' % seat # Identifier for this item. + if id in self.items: + self.update_item(id, source=surface, xy=xy) + else: + self.add_item(id, surface, xy, 0) - def build_trick(self, trick): - """Builds and saves a pixbuf of trick.""" - width = self.card_width + self.spacing_x*2 - height = self.card_height + self.spacing_y*2 - self.trick_pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8, width, height) - self.trick_pixbuf.fill(0x00000000) # Clear pixbuf. - - # When called, returns (x, y) start point to draw card. - coords = {Seat.North : lambda: ((width-self.card_width)/2, 0), - Seat.East : lambda: (width-self.card_width, (height-self.card_height)/2), - Seat.South : lambda: ((width-self.card_width)/2, height-self.card_height), - Seat.West : lambda: (0, (height-self.card_height)/2), } + def set_seat_mapping(self, focus=Seat.South): + """Sets the mapping between seats at table and positions of hands. - # Draw cards in order of play, to permit overlapping of cards. - leader, cards = trick - seatorder = Seat[leader.index:] + Seat[:leader.index] - for seat in [s for s in seatorder if s in cards]: - pos_x, pos_y = coords[seat]() - self.draw_card(self.trick_pixbuf, pos_x, pos_y, cards[seat]) + @param focus: the Seat to be drawn "closest" to the observer. + """ + # Assumes Seat elements are ordered clockwise from North. + order = Seat[focus.index:] + Seat[:focus.index] + for seat, attr in zip(order, ('BOTTOM', 'LEFT', 'TOP', 'RIGHT')): + setattr(self, attr, seat) + # TODO: set seat labels. - def draw_trick(self): - """""" - x, y, width, height = self.get_allocation() + def set_trick(self, trick): + """Sets the current trick. + Draws representation of current trick to context. - trick_width = self.trick_pixbuf.get_width() - trick_height = self.trick_pixbuf.get_height() - pos_x = (width - trick_width) / 2 - pos_y = (height - trick_height) / 2 - self.backing.draw_rectangle(self.backingGC, True, pos_x, pos_y, trick_width, trick_height) - self.backing.draw_pixbuf(self.backingGC, self.trick_pixbuf, 0, 0, pos_x, pos_y) + @param trick: a (leader, cards_played) pair. + """ + width, height = 200, 200 + # (x, y) positions to fit within (width, height) bound box. + pos = {Seat.North : ((width - self.card_width)/2, 0 ), + Seat.East : ((width - self.card_width), (height - self.card_height)/2 ), + Seat.South : ((width - self.card_width)/2, (height - self.card_height) ), + Seat.West : (0, (height - self.card_height)/2 ), } - # Redraw modified area of backing pixbuf. - self.window.invalidate_rect((pos_x, pos_y, trick_width, trick_height), False) + # Create new ImageSurface for trick. + surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, width, height) + context = cairo.Context(surface) + # Clear ImageSurface - in Cairo 1.2+, this is done automatically. + if cairo.version_info < (1, 2): + context.set_operator(cairo.OPERATOR_CLEAR) + context.paint() + context.set_operator(cairo.OPERATOR_OVER) # Restore. + + if trick: + leader, cards_played = trick + # The order of play is the leader, then clockwise around Seat. + for seat in Seat[leader.index:] + Seat[:leader.index]: + card = cards_played.get(seat) + if card: + pos_x, pos_y = pos[seat] + self.draw_card(context, pos_x, pos_y, card) + + id = 'trick' + if id in self.items: + self.update_item(id, source=surface) + else: + xy = lambda w, h: ((w - width)/2, (h - height)/2) + self.add_item(id, surface, xy, 0) - def clear(self): - """Clears backing pixmap and pixbufs.""" - self.hand_pixbufs = {} - self.trick_pixbuf = None - x, y, width, height = self.get_allocation() - self.backing.draw_rectangle(self.backingGC, True, 0, 0, width, height) - self.window.invalidate_rect((0, 0, width, height), False) - - def configure(self, widget, event): - """Creates backing pixmap of the appropriate size, containing pixbufs.""" - x, y, width, height = widget.get_allocation() - self.backing = gtk.gdk.Pixmap(widget.window, width, height) - self.backingGC = gtk.gdk.GC(self.backing, fill=gtk.gdk.TILED, tile=self.background) - self.backing.draw_rectangle(self.backingGC, True, 0, 0, width, height) + def set_turn(self, seat): + """ - for seat in self.hand_pixbufs: - self.draw_hand(seat) - if self.trick_pixbuf: - self.draw_trick() + @param seat: a member of Seat. + """ +# hand_surface = self.hands[seat]['surface'] +# x = self.hands[seat]['xy'] - 10 +# y = self.hands[seat]['xy'] - 10 +# width = surface.get_width() + 20 +# height = surface.get_height() + 20 +# args = ('turn', surface, pos_x, pos_y, -1) +# if self.items.get('turn'): +# self.update_item(*args) +# else: +# self.add_item(*args) - gc.collect() # Manual garbage collection. See PyGTK FAQ, section 8.4. - return True # Configure event is expected to return true. - - def expose(self, widget, event): - """Redraws card table widget from the backing pixmap.""" - x, y, width, height = event.area - gc = widget.get_style().bg_gc[gtk.STATE_NORMAL] - widget.window.draw_drawable(gc, self.backing, x, y, x, y, width, height) - return False # Expose event is expected to return false. - - - def button_press(self, widget, event): - """Determines which card was clicked, then calls external handler method.""" + def button_release(self, widget, event): + """Determines if a card was clicked: if so, calls card_selected.""" + if event.button == 1: + found_hand = False + + # Determine the hand which was clicked. + for seat in self.hands: + card_coords = self.hands[seat]['coords'] + surface = self.hands[seat]['surface'] + hand_x, hand_y = self.items['hand-%s' % seat]['area'][0:2] + if (hand_x <= event.x <= hand_x + surface.get_width()) and \ + (hand_y <= event.y <= hand_y + surface.get_height()): + found_hand = True + break + + if found_hand: + # Determine the card in hand which was clicked. + pos_x, pos_y = event.x - hand_x, event.y - hand_y + # Iterate through visible cards backwards. + for i, card in self.hands[seat]['visible'][::-1]: + x, y = card_coords[i][1:] + if (x <= pos_x <= x + self.card_width) and \ + (y <= pos_y <= y + self.card_height): + self.on_card_clicked(card, seat) + break - def get_hand_xy(): - for seat, hand in self.hand_coords.items(): - start_x, start_y, finish_x, finish_y = hand - if (start_x <= event.x <= finish_x) and (start_y <= event.y <= finish_y): - return seat, start_x, start_y - - def get_card_in_hand(seat, start_x, start_y): - pos_x = event.x - start_x - pos_y = event.y - start_y - for card, x, y in self.card_coords[seat][::-1]: # Iterate backwards. - if (x <= pos_x <= x+self.card_width) and (y <= pos_y <= y+self.card_height): - return card - - if event.button == 1 and self.on_card_clicked: - hand_xy = get_hand_xy() - if hand_xy: - card = get_card_in_hand(*hand_xy) - if isinstance(card, Card): - self.on_card_clicked(card, hand_xy[0]) # External handler. - - return True # Button press event is expected to return true. + return True # Expected to return True. Modified: trunk/pybridge/pybridge/ui/window_bridgetable.py =================================================================== --- trunk/pybridge/pybridge/ui/window_bridgetable.py 2006-08-16 14:02:03 UTC (rev 342) +++ trunk/pybridge/pybridge/ui/window_bridgetable.py 2006-09-20 10:56:47 UTC (rev 343) @@ -35,7 +35,7 @@ CALLTYPE_SYMBOLS = {Pass : _('pass'), Double : _('dbl'), Redouble : _('rdbl') } -LEVEL_SYMBOLS = {Level.One : _('1'), Level.Two : _('2'), Level.Three : _('3'), +LEVEL_SYMBOLS = {Level.One : _('1'), Level.Two : _('2'), Level.Three : _('3'), Level.Four : _('4'), Level.Five : _('5'), Level.Six : _('6'), Level.Seven : _('7'), } @@ -191,7 +191,7 @@ def resetGame(self): """Clears bidding history, contract, trick counts.""" - self.cardarea.clear() +# self.cardarea.clear() self.call_store.clear() # Reset bidding history. self.trick_store.clear() # Reset trick history. self.setContract(None) # Reset contract. @@ -263,28 +263,22 @@ if hand: # Own or known hand. if all is True: # Show all cards. played = [] - self.cardarea.build_hand(position, hand, omit=played) + self.cardarea.set_hand(hand, position, omit=played) else: # Unknown hand: draw cards face down, use integer placeholders. - cards = range(13) - played = range(len(played)) - self.cardarea.build_hand(position, cards, facedown=True, omit=played) - - self.cardarea.draw_hand(position) + cards, played = range(13), range(len(played)) + self.cardarea.set_hand(cards, position, facedown=True, omit=played) - def redrawTrick(self, trick=None): + def redrawTrick(self): """Redraws trick. @param table: @param trick: """ - # TODO: this cannot be called until playing in progress - # perhaps put a clear() method in cardarea? - if trick is None: + trick = None + if self.table.game.playing: trick = self.table.game.playing.getCurrentTrick() - - self.cardarea.build_trick(trick) - self.cardarea.draw_trick() + self.cardarea.set_trick(trick) def setTurnIndicator(self): @@ -391,6 +385,7 @@ self.setDealer(table.dealer) self.setVuln(table.game.vulnNS, table.game.vulnEW) + self.redrawTrick() for position in table.game.deal: self.redrawHand(position) if table.seated: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |