First commit of Mucked_Flop. Works, but needs polish.

This commit is contained in:
Ray 2009-03-07 20:44:10 -05:00
parent 5f60cfde7c
commit 1a417441f6

View File

@ -52,6 +52,32 @@ class Aux_Window:
def destroy(self): def destroy(self):
self.container.destroy() self.container.destroy()
############################################################################
# Some utility routines useful for Aux_Windows
#
def get_card_images(self):
card_images = {}
suits = ('S', 'H', 'D', 'C')
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B')
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck']))
for j in range(0, 14):
for i in range(0, 4):
temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42)
pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0)
card_images[(ranks[j], suits[i])] = temp_pb
return(card_images)
# cards are 30 wide x 42 high
def split_cards(self, card):
if card == 'xx': return ('B', 'S')
return (card[0], card[1].upper())
def has_cards(self, cards):
for c in cards:
if c in set('shdc'): return True
return False
class Stud_mucked(Aux_Window): class Stud_mucked(Aux_Window):
def __init__(self, hud, config, params): def __init__(self, hud, config, params):
@ -273,9 +299,6 @@ class Stud_cards:
return self.parent.hud.stat_dict[k]['screen_name'] return self.parent.hud.stat_dict[k]['screen_name']
return "No Name" return "No Name"
def split_cards(self, card):
return (card[0], card[1].upper())
def clear(self): def clear(self):
for r in range(0, self.rows): for r in range(0, self.rows):
self.grid_contents[(1, r)].set_text(" ") self.grid_contents[(1, r)].set_text(" ")
@ -283,19 +306,80 @@ class Stud_cards:
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')]) self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')])
self.eb[(c, r)].set_tooltip_text('') self.eb[(c, r)].set_tooltip_text('')
def get_card_images(self): class Flop_Mucked(Aux_Window):
card_images = {} """Aux_Window class for displaying mucked cards for flop games."""
suits = ('S', 'H', 'D', 'C')
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B')
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck']))
for j in range(0, 14): def __init__(self, hud, config, params):
for i in range(0, 4): self.hud = hud # hud object that this aux window supports
temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) self.config = config # configuration object for this aux window to use
pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) self.params = params # hash aux params from config
card_images[(ranks[j], suits[i])] = temp_pb self.card_images = self.get_card_images()
return(card_images)
# cards are 30 wide x 42 high def create(self):
adj = self.hud.adj_seats(0, self.config)
loc = self.config.get_aux_locations(self.params['name'], int(self.hud.max))
# make a scratch pixbuf 7 cards wide for creating our images
self.scratch = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
7* int(self.params['card_wd']), int(self.params['card_ht']))
# create the stat windows
self.m_windows = {} # windows to put the card images
self.eb = {} # event boxes so we can interact with the mucked cards
self.seen_cards = {} # pixbufs to stash the cards in
for i in range(1, self.hud.max + 1):
(x, y) = loc[adj[i]]
self.m_windows[i] = gtk.Window()
self.m_windows[i].set_decorated(0)
self.m_windows[i].set_property("skip-taskbar-hint", True)
self.m_windows[i].set_transient_for(self.hud.main_window)
self.eb[i] = gtk.EventBox()
self.m_windows[i].add(self.eb[i])
self.seen_cards[i] = gtk.image_new_from_pixbuf(self.card_images[('B', 'H')])
self.eb[i].add(self.seen_cards[i])
self.m_windows[i].move(int(x) + self.hud.table.x, int(y) + self.hud.table.y)
self.m_windows[i].set_opacity(float(self.params['opacity']))
self.m_windows[i].show_all()
self.m_windows[i].hide()
def update_data(self, new_hand_id, db_connection):
pass
def update_gui(self, new_hand_id):
"""Prepare and show the mucked cards."""
for (i, cards) in self.hud.cards.iteritems():
pos = self.m_windows[i].get_position() # need this to reposition later
if self.has_cards(cards):
# scratch is a working pixbuf, used to assemble the image
scratch = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
int(self.params['card_wd'])*len(cards)/2,
int(self.params['card_ht']))
x = 0 # x coord where the next card starts in scratch
for card in [cards[k:k+2] for k in xrange(0, len(cards), 2)]:
# concatenate each card image to scratch
self.card_images[self.split_cards(card)].copy_area(0, 0,
int(self.params['card_wd']), int(self.params['card_ht']),
scratch, x, 0)
x = x + int(self.params['card_wd'])
self.seen_cards[i].set_from_pixbuf(scratch)
self.m_windows[i].move(pos[0], pos[1]) # I don't know why I need this
self.m_windows[i].show_all()
gobject.timeout_add(int(1000*float(self.params['timeout'])), self.hide_mucked_cards)
def destroy(self):
"""Destroy all of the mucked windows."""
for w in self.m_windows.values():
w.destroy()
def hide_mucked_cards(self):
"""Hide the mucked card windows."""
# this is the callback from the timeout
for w in self.m_windows.values():
w.hide()
return False # this tells the system to NOT run this timeout again
if __name__== "__main__": if __name__== "__main__":