Make Stud_Mucked work with the new card encoding scheme.

This commit is contained in:
Ray 2009-06-17 14:24:16 -04:00
parent 4a6c257b0f
commit 63efc13cc9

View File

@ -35,6 +35,7 @@ import gobject
# FreePokerTools modules # FreePokerTools modules
import Configuration import Configuration
import Database import Database
import Card
class Aux_Window: class Aux_Window:
def __init__(self, hud, params, config): def __init__(self, hud, params, config):
@ -67,16 +68,23 @@ class Aux_Window:
# Some utility routines useful for Aux_Windows # Some utility routines useful for Aux_Windows
# #
def get_card_images(self): def get_card_images(self):
card_images = {}
suits = ('S', 'H', 'D', 'C') card_images = 53 * [0]
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B') suits = ('s', 'h', 'd', 'c')
ranks = (14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2)
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck'])) pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck']))
for j in range(0, 14): for j in range(0, 13):
for i in range(0, 4): 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) 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) pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0)
card_images[(ranks[j], suits[i])] = temp_pb card_images[Card.cardFromValueSuit(ranks[j], suits[i])] = temp_pb
temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42)
# also pick out a card back and store in [0]
j = 13
i = 2
pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0)
card_images[0] = temp_pb
return(card_images) return(card_images)
# cards are 30 wide x 42 high # cards are 30 wide x 42 high
@ -111,6 +119,7 @@ class Stud_mucked(Aux_Window):
self.container = gtk.Window() self.container = gtk.Window()
self.vbox = gtk.VBox() self.vbox = gtk.VBox()
self.container.add(self.vbox) self.container.add(self.vbox)
self.container.set_title(self.hud.table.name)
self.mucked_list.create(self.vbox) self.mucked_list.create(self.vbox)
self.mucked_cards.create(self.vbox) self.mucked_cards.create(self.vbox)
@ -207,7 +216,9 @@ class Stud_list:
# find the hero's seat from the stat_dict # find the hero's seat from the stat_dict
for stat in self.parent.hud.stat_dict.itervalues(): for stat in self.parent.hud.stat_dict.itervalues():
if stat['screen_name'] == hero: if stat['screen_name'] == hero:
return self.parent.hud.cards[stat['seat']][0:6] return Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][0]) +\
Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][1]) +\
Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][2])
return "xxxxxx" return "xxxxxx"
def update_gui(self, new_hand_id): def update_gui(self, new_hand_id):
@ -240,7 +251,7 @@ class Stud_cards:
for r in range(0, self.rows): for r in range(0, self.rows):
for c in range(0, self.cols): for c in range(0, self.cols):
self.seen_cards[(c, r)] = gtk.image_new_from_pixbuf(self.card_images[('B', 'S')]) self.seen_cards[(c, r)] = gtk.image_new_from_pixbuf(self.card_images[(0)])
self.eb[(c, r)]= gtk.EventBox() self.eb[(c, r)]= gtk.EventBox()
# set up the contents for the cells # set up the contents for the cells
@ -287,11 +298,11 @@ class Stud_cards:
self.clear() self.clear()
for c, cards in self.parent.hud.cards.iteritems(): for c, cards in self.parent.hud.cards.iteritems():
self.grid_contents[(1, c - 1)].set_text(self.get_screen_name(c)) self.grid_contents[(1, c - 1)].set_text(self.get_screen_name(c))
for i in ((0, cards[0:2]), (1, cards[2:4]), (2, cards[4:6]), (3, cards[6:8]), for i in ((0, cards[0]), (1, cards[1]), (2, cards[2]), (3, cards[3]),
(4, cards[8:10]), (5, cards[10:12]), (6, cards[12:14])): (4, cards[4]), (5, cards[5]), (6, cards[6])):
if not i[1] == "xx": if not i[1] == 0:
self.seen_cards[(i[0], c - 1)]. \ self.seen_cards[(i[0], c - 1)]. \
set_from_pixbuf(self.card_images[self.parent.split_cards(i[1])]) set_from_pixbuf(self.card_images[i[1]])
## action in tool tips for 3rd street cards ## action in tool tips for 3rd street cards
for c in (0, 1, 2): for c in (0, 1, 2):
for r in range(0, self.rows): for r in range(0, self.rows):
@ -314,7 +325,7 @@ class Stud_cards:
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(" ")
for c in range(0, 7): for c in range(0, 7):
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')]) self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[0])
self.eb[(c, r)].set_tooltip_text('') self.eb[(c, r)].set_tooltip_text('')
class Flop_Mucked(Aux_Window): class Flop_Mucked(Aux_Window):
@ -459,29 +470,31 @@ class Flop_Mucked(Aux_Window):
new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) new_locs[i] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y)
self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs) self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs)
if __name__== "__main__": # This test program doesn't work
def destroy(*args): # call back for terminating the main eventloop #if __name__== "__main__":
gtk.main_quit() # used only for testing #
# def destroy(*args): # call back for terminating the main eventloop
def process_new_hand(source, condition, db_connection): #callback from stdin watch -- testing only # gtk.main_quit() # used only for testing
# there is a new hand_id to be processed #
# just read it and pass it to update # def process_new_hand(source, condition, db_connection): #callback from stdin watch -- testing only
new_hand_id = sys.stdin.readline() ## there is a new hand_id to be processed
new_hand_id = new_hand_id.rstrip() # remove trailing whitespace ## just read it and pass it to update
m.update_data(new_hand_id, db_connection) # new_hand_id = sys.stdin.readline()
m.update_gui(new_hand_id) # new_hand_id = new_hand_id.rstrip() # remove trailing whitespace
return(True) # m.update_data(new_hand_id, db_connection)
# m.update_gui(new_hand_id)
config = Configuration.Config() # return(True)
db_connection = Database.Database(config, 'fpdb', '') #
main_window = gtk.Window() # config = Configuration.Config()
main_window.set_keep_above(True) # db_connection = Database.Database(config, 'fpdbTEST', '')
main_window.connect("destroy", destroy) # main_window = gtk.Window()
# main_window.set_keep_above(True)
aux_to_call = "stud_mucked" # main_window.connect("destroy", destroy)
aux_params = config.get_aux_parameters(aux_to_call) #
m = eval("%s(main_window, None, config, aux_params)" % aux_params['class']) # aux_to_call = "stud_mucked"
# aux_params = config.get_aux_parameters(aux_to_call)
s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand, db_connection) # m = eval("%s(None, config, aux_params)" % aux_params['class'])
gtk.main() #
# s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand, db_connection)
# gtk.main()