From 7f7ad2a13e0e342468909fae20c5545474b2e91a Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 25 Jun 2009 10:07:40 -0400 Subject: [PATCH 1/4] Further on Aux_Seats interface. Works. Not ready for prime time. --- pyfpdb/Mucked.py | 85 +++++++++++++++++++++++++++--------------------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index eb1d7c86..4c8b2eb4 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -335,6 +335,7 @@ class Aux_Seats(Aux_Window): # placeholders that should be overridden--so we don't throw errors def create_contents(self): pass + def update_contents(self): pass def create(self): self.adj = self.hud.adj_seats(0, self.config) # move adj_seats to aux and get rid of it in Hud.py @@ -363,6 +364,11 @@ class Aux_Seats(Aux_Window): self.m_windows[i].show_all() self.m_windows[i].hide() + def update_gui(self, new_hand_id): + """Update the gui, LDO.""" + for i in self.m_windows.keys(): + self.update_contents(self.m_windows[i], i) + # Methods likely to be of use for any Seat_Window implementation def destroy(self): """Destroy all of the seat windows.""" @@ -377,6 +383,17 @@ class Aux_Seats(Aux_Window): w.hide() self.displayed = False + def save_layout(self, *args): + """Save new layout back to the aux element in the config file.""" + new_locs = {} +# print "adj =", self.adj + for (i, pos) in self.positions.iteritems(): + if i != 'common': + new_locs[self.adj[int(i)]] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) + else: + 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) + class Flop_Mucked(Aux_Seats): """Aux_Window class for displaying mucked cards for flop games.""" @@ -393,6 +410,33 @@ class Flop_Mucked(Aux_Seats): container.seen_cards = gtk.image_new_from_pixbuf(self.card_images[0]) container.eb.add(container.seen_cards) + def update_contents(self, container, i): + if not self.hud.cards.has_key(i): return + cards = self.hud.cards[i] + n_cards = self.has_cards(cards) + if n_cards > 1: + +# 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'])*n_cards, + int(self.params['card_ht'])) + x = 0 # x coord where the next card starts in scratch + for card in cards: +# concatenate each card image to scratch + if card == None or card ==0: + break + self.card_images[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']) + container.seen_cards.set_from_pixbuf(scratch) + container.resize(1,1) + container.show() + container.move(self.positions[i][0], self.positions[i][1]) # here is where I move back + self.displayed = True + if i != "common": + self.m_windows[i].eb.set_tooltip_text(self.hud.stat_dict[i]['screen_name']) + def update_gui(self, new_hand_id): """Prepare and show the mucked cards.""" if self.displayed: self.hide() @@ -403,33 +447,11 @@ class Flop_Mucked(Aux_Seats): n_cards = self.has_cards(cards) if n_cards > 0: n_sd = n_sd + 1 - if n_sd < 2: return + if n_sd < 2: + print "skipping, n_sd =", n_sd + return -# More than 1 player showed, so display the hole cards - for (i, cards) in self.hud.cards.iteritems(): - n_cards = self.has_cards(cards) - if n_cards > 0: -# 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'])*n_cards, - int(self.params['card_ht'])) - x = 0 # x coord where the next card starts in scratch - for card in cards: -# concatenate each card image to scratch - if card == None or card ==0: - break - self.card_images[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.m_windows[i].seen_cards.set_from_pixbuf(scratch) - self.m_windows[i].resize(1,1) - self.m_windows[i].show() - self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back - self.displayed = True - - for stats in self.hud.stat_dict.itervalues(): - self.m_windows[i].eb.set_tooltip_text(stats['screen_name']) + super(Flop_Mucked, self).update_gui(new_hand_id) if self.displayed and float(self.params['timeout']) > 0: self.timer_on = True @@ -478,14 +500,3 @@ class Flop_Mucked(Aux_Seats): self.m_windows[i].show() self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back self.displayed = True - - def save_layout(self, *args): - """Save new layout back to the aux element in the config file.""" - new_locs = {} -# print "adj =", self.adj - for (i, pos) in self.positions.iteritems(): - if i != 'common': - new_locs[self.adj[int(i)]] = (pos[0] - self.hud.table.x, pos[1] - self.hud.table.y) - else: - 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) From a8b8ff2f4d5542aa3fab36a923cb8e69f275058b Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 30 Jun 2009 11:43:47 -0400 Subject: [PATCH 2/4] More on Aux_Seats class. This seems to work OK. --- pyfpdb/Mucked.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 4c8b2eb4..c0715632 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -87,6 +87,13 @@ class Aux_Window(object): if c != None and c > 0: n = n + 1 return n + def get_id_from_seat(self, seat): + """Determine player id from seat number, given stat_dict.""" + for id, dict in self.hud.stat_dict.iteritems(): + if seat == dict['seat']: + return id + return None + class Stud_mucked(Aux_Window): def __init__(self, hud, config, params): @@ -356,13 +363,15 @@ class Aux_Seats(Aux_Window): self.m_windows[i].connect("configure_event", self.configure_event_cb, i) self.positions[i] = (int(x) + self.hud.table.x, int(y) + self.hud.table.y) self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) - self.m_windows[i].set_opacity(float(self.params['opacity'])) + if self.params.has_key('opacity'): + self.m_windows[i].set_opacity(float(self.params['opacity'])) # the create_contents method is supplied by the subclass self.create_contents(self.m_windows[i], i) self.m_windows[i].show_all() - self.m_windows[i].hide() + if self.uses_timer: + self.m_windows[i].hide() def update_gui(self, new_hand_id): """Update the gui, LDO.""" @@ -394,6 +403,10 @@ class Aux_Seats(Aux_Window): 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) + def configure_event_cb(self, widget, event, i, *args): + self.positions[i] = widget.get_position() +# self.rel_positions[i] = (self.positions[i][0] - self.hud.table.x, self.positions[i][1] - self.hud.table.y) + class Flop_Mucked(Aux_Seats): """Aux_Window class for displaying mucked cards for flop games.""" @@ -491,10 +504,6 @@ class Flop_Mucked(Aux_Seats): window = widget.get_parent() window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time) - def configure_event_cb(self, widget, event, i, *args): - self.positions[i] = widget.get_position() -# self.rel_positions[i] = (self.positions[i][0] - self.hud.table.x, self.positions[i][1] - self.hud.table.y) - def expose_all(self): for (i, cards) in self.hud.cards.iteritems(): self.m_windows[i].show() From 71d673f64f32c8ae1ef576fa5b6861d808eceee4 Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 30 Jun 2009 11:45:14 -0400 Subject: [PATCH 3/4] Added Hello_Seats to Hello.py. Demo of Aux_Seats class. --- pyfpdb/Hello.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/pyfpdb/Hello.py b/pyfpdb/Hello.py index 41262d6c..7f3f6442 100644 --- a/pyfpdb/Hello.py +++ b/pyfpdb/Hello.py @@ -34,10 +34,13 @@ import gobject # FreePokerTools modules from Mucked import Aux_Window +from Mucked import Seat_Window +from Mucked import Aux_Seats class Hello(Aux_Window): """A 'Hello World' Aux_Window demo.""" def create(self): + print "creating Hello" # This demo simply creates a label in a window. self.container = gtk.Window() self.container.add(gtk.Label("Hello World")) @@ -99,15 +102,18 @@ class Hello_plus(Aux_Window): # hands played that was updated in the "update_data()" function. self.label.set_text("Hello %s\nYou have played %d hands\n on %s." % (self.hero, self.hands_played, self.site)) -class Hello_Menu(Aux_Window): - """A 'Hello World' Aux_Window demo.""" - def create(self): -# This demo puts a menu item on the HUD mainwindow. - self.item = gtk.MenuItem('Print cards') - self.hud.menu.append(self.item) - self.item.connect("activate", self.print_cards) - self.item.show() +class Hello_Seats(Aux_Seats): + """A 'Hello World' Seat_Window demo.""" - def print_cards(self, *args): -# callback for the menu item - print "cards =", self.hud.cards + def create_contents(self, container, i): + container.label = gtk.Label("empty") + container.add(container.label) + container.show_all() + + def update_contents(self, container, i): + if i == "common": return + id = self.get_id_from_seat(i) + if id == None: + container.label.set_text("empty") + else: + container.label.set_text("player = %s" % self.hud.stat_dict[id]['screen_name']) From a3f233ca07e13bfa1c07ac8f7f44c7889792afae Mon Sep 17 00:00:00 2001 From: Ray Date: Tue, 30 Jun 2009 14:21:06 -0400 Subject: [PATCH 4/4] Comment out a DEBUG print. --- pyfpdb/Hand.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyfpdb/Hand.py b/pyfpdb/Hand.py index 38c3609b..b9272031 100644 --- a/pyfpdb/Hand.py +++ b/pyfpdb/Hand.py @@ -202,7 +202,7 @@ If a player has None chips he won't be added.""" def setCommunityCards(self, street, cards): logging.debug("setCommunityCards %s %s" %(street, cards)) self.board[street] = [self.card(c) for c in cards] - print "DEBUG: self.board: %s" % self.board +# print "DEBUG: self.board: %s" % self.board def card(self,c): """upper case the ranks but not suits, 'atjqk' => 'ATJQK'"""