From a6d70e6e13f89747f11f57cc41e7e3972bc99d7e Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 4 Mar 2009 20:04:23 -0500 Subject: [PATCH 1/7] More tuning of the aux_window interface. --- pyfpdb/Configuration.py | 9 +++++++-- pyfpdb/HUD_main.py | 12 ++++++++---- pyfpdb/Hud.py | 27 +++++++++++++++++++------- pyfpdb/Mucked.py | 43 +++++++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index fb182f4b..7c6b9895 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -3,7 +3,7 @@ Handles HUD configuration files. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # This program is free software; you can redistribute it and/or modify @@ -105,7 +105,12 @@ class Game: self.db = node.getAttribute("db") self.rows = int( node.getAttribute("rows") ) self.cols = int( node.getAttribute("cols") ) - self.aux = node.getAttribute("aux") + + aux_text = node.getAttribute("aux") + aux_list = aux_text.split(',') + for i in range(0, len(aux_list)): + aux_list[i] = aux_list[i].strip() + self.aux = aux_list self.stats = {} for stat_node in node.getElementsByTagName('stat'): diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 7418cfc8..cb1f5ded 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -4,7 +4,7 @@ Main for FreePokerTools HUD. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # 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 @@ -31,8 +31,8 @@ Main for FreePokerTools HUD. import sys # redirect the stderr -errorfile = open('HUD-error.txt', 'w', 0) -sys.stderr = errorfile +#errorfile = open('HUD-error.txt', 'w', 0) +#sys.stderr = errorfile import os import thread @@ -97,7 +97,7 @@ class HUD_main(object): self.hud_dict[table_name].tablehudlabel = newlabel self.hud_dict[table_name].create(new_hand_id, self.config, stat_dict, cards) for m in self.hud_dict[table_name].aux_windows: - m.update_data(new_hand_id, self.db_connection) + m.create() m.update_gui(new_hand_id) self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].reposition_windows() @@ -106,6 +106,10 @@ class HUD_main(object): gtk.gdk.threads_leave() self.hud_dict[table_name] = Hud.Hud(self, table, max, poker_game, self.config, self.db_connection) + self.hud_dict[table_name].stat_dict = stat_dict + self.hud_dict[table_name].cards = cards + for aw in self.hud_dict[table_name].aux_windows: + aw.update_data(new_hand_id, self.db_connection) gobject.idle_add(idle_func) def update_HUD(self, new_hand_id, table_name, config): diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index ed43bea2..34d1b0cf 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -3,7 +3,7 @@ Create and manage the hud overlays. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009 Ray E. Barker # # This program is free software; you can redistribute it and/or modify @@ -45,6 +45,15 @@ import Mucked import Database import HUD_main +def importName(module_name, name): + """Import a named object 'name' from module 'module_name'.""" +# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! + try: + module = __import__(module_name, globals(), locals(), [name]) + except: + return None + return(getattr(module, name)) + class Hud: def __init__(self, parent, table, max, poker_game, config, db_connection): @@ -75,6 +84,15 @@ class Hud: self.font = pango.FontDescription(font + " " + font_size) # do we need to add some sort of condition here for dealing with a request for a font that doesn't exist? + game_params = config.get_game_parameters(self.poker_game) + if not game_params['aux'] == "": + for aux in game_params['aux']: + aux_params = config.get_aux_parameters(aux) + my_import = importName(aux_params['module'], aux_params['class']) + if my_import == None: + continue + self.aux_windows.append(my_import(self, config, aux_params)) + def create_mw(self): # Set up a main window for this this instance of the HUD @@ -135,7 +153,7 @@ class Hud: if os.name == 'nt': self.topify_window(self.main_window) else: - self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(self.table.number) # gets a gdk handle for poker client + self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gets a gdk handle for poker client self.main_window.gdkhandle = gtk.gdk.window_foreign_new(self.main_window.window.xid) # gets a gdk handle for the hud table window self.main_window.gdkhandle.set_transient_for(self.main_window.parentgdkhandle) # @@ -269,11 +287,6 @@ class Hud: self.stats[config.supported_games[self.poker_game].stats[stat].row] \ [config.supported_games[self.poker_game].stats[stat].col] = \ config.supported_games[self.poker_game].stats[stat].stat_name - - game_params = config.get_game_parameters(self.poker_game) - if not game_params['aux'] == "": - aux_params = config.get_aux_parameters(game_params['aux']) - self.aux_windows.append(eval("%s.%s(gtk.Window(), self, config, aux_params)" % (aux_params['module'], aux_params['class']))) if os.name == "nt": gobject.timeout_add(500, self.update_table_position) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 1e550edc..0b605e2f 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -3,7 +3,7 @@ Mucked cards display for FreePokerTools HUD. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # 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 @@ -36,29 +36,27 @@ import Configuration import Database class Aux_Window: - def __init__(self, container, hud, params, config): + def __init__(self, hud, params, config): self.config = hud self.config = config - self.container = container - self.vbox = gtk.VBox() - self.container.add(self.vbox) - - def update_data(self): + def update_data(self, *parms): pass - def update_gui(self): + def update_gui(self, *parms): + pass + + def create(self, *parms): pass def destroy(self): self.container.destroy() class Stud_mucked(Aux_Window): - def __init__(self, container, hud, config, params): + def __init__(self, hud, config, params): self.hud = hud # hud object that this aux window supports self.config = config # configuration object for this aux window to use - self.container = container # parent container for this aux window widget self.params = params # hash aux params from config try: @@ -67,12 +65,18 @@ class Stud_mucked(Aux_Window): except: self.hero = '' + self.mucked_list = Stud_list(self, params, config, self.hero) + self.mucked_cards = Stud_cards(self, params, config) + self.mucked_list.mucked_cards = self.mucked_cards + + def create(self): + + self.container =gtk.Window() self.vbox = gtk.VBox() self.container.add(self.vbox) - self.mucked_list = Stud_list(self.vbox, self, params, config, self.hero) - self.mucked_cards = Stud_cards(self.vbox, self, params, config) - self.mucked_list.mucked_cards = self.mucked_cards + self.mucked_list.create(self.vbox) + self.mucked_cards.create(self.vbox) self.container.show_all() def update_data(self, new_hand_id, db_connection): @@ -84,16 +88,16 @@ class Stud_mucked(Aux_Window): self.mucked_list.update_gui(new_hand_id) class Stud_list: - def __init__(self, container, parent, params, config, hero): + def __init__(self, parent, params, config, hero): - self.container = container self.parent = parent self.params = params self.config = config self.hero = hero -# self.db_name = db_name + def create(self, container): # set up a scrolled window to hold the listbox + self.container = container self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.container.add(self.scrolled_window) @@ -178,9 +182,8 @@ class Stud_list: vadj.set_value(vadj.upper) class Stud_cards: - def __init__(self, container, parent, params, config): + def __init__(self, parent, params, config): - self.container = container #this is the parent container of the mucked cards widget self.parent = parent self.params = params self.config = config @@ -193,6 +196,9 @@ class Stud_cards: self.rows = 8 self.cols = 7 + + def create(self, container): + self.container = container self.grid = gtk.Table(self.rows, self.cols + 4, homogeneous = False) for r in range(0, self.rows): @@ -289,7 +295,6 @@ class Stud_cards: 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 if __name__== "__main__": From 30ac181a360ce4526c89310a18d7298b82113403 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 4 Mar 2009 20:07:09 -0500 Subject: [PATCH 2/7] New file: Hello.py. Aux_window examples. --- pyfpdb/Hello.py | 101 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 pyfpdb/Hello.py diff --git a/pyfpdb/Hello.py b/pyfpdb/Hello.py new file mode 100644 index 00000000..b5d1d366 --- /dev/null +++ b/pyfpdb/Hello.py @@ -0,0 +1,101 @@ +#!/usr/bin/env python +"""Hello.py + +Hello World demostration for Aux_Window. +""" +# Copyright 2009, Ray E. Barker +# +# 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +######################################################################## + +# to do +# add another class that demonstrates querying the db + +# Standard Library modules +import sys + +# pyGTK modules +import pygtk +import gtk +import gobject + +# FreePokerTools modules +from Mucked import Aux_Window + +class Hello(Aux_Window): + """A 'Hello World' Aux_Window demo.""" + def create(self): +# This demo simply creates a label in a window. + self.container = gtk.Window() + self.container.add(gtk.Label("Hello World")) +# and shows it. There is no functionality. + self.container.show_all() + +class Hello_plus(Aux_Window): + """A slightly more complex 'Hello World demo.""" + def __init__(self, hud, config, params): + """Initialize a new aux_window object.""" +# Initialize the aux_window object. Do not interact with the gui +# in this function. + self.hud = hud # hud object that this aux window supports + self.config = config # configuration object for this aux window to use + self.params = params # hash aux params from config + + self.hands_played = 0 # initialize the hands played counter + +# get the site we are playing from the HUD + self.site = hud.site + print "site =", hud.site # print it to the terminal, to make sure + +# now get our screen name for that site from the configuration +# wrap it in a try/except in case screen name isn't set up in the config file + try: + site_params = self.config.get_site_parameters(self.hud.site) + self.hero = site_params['screen_name'] + except: + self.hero = 'YOUR NAME HERE' + print "hero =", self.hero + + + def create(self): + """Creates the gui.""" + self.container = gtk.Window() # create a gtk window for our container + self.label = gtk.Label("") # create a blank label to write in update_gui + self.container.add(self.label) # add it to our container + self.container.show_all() # show the container and its contents + + def update_data(self, new_hand_id, db_connection): + """Increment the hands.played attribute.""" +# This function will be called from the main program, in a thread separate from +# the gui. Therefore complex calculations can be done without slowing down the +# HUD. Long-running calculations will delay the appearance or updating of the HUD. +# This function should NOT interact with the gui--that will cause unpredictable +# results on some systems. + +# This long running calculation is incrementing the number of hands played. + self.hands_played = self.hands_played + 1 + + def update_gui(self, new_hand_id): + """Update the aux_window gui.""" +# This function runs inside the gui thread and should only be used for +# interacting with the gui. Long-running calculations should not be done +# in this function--they will prevent HUD interaction until they are +# complete. + +# Here, we just update the label in our aux_window from the number of +# 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)) + From e9861e18c8d9d8aad687487b5ce3fc19e22f7d69 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 5 Mar 2009 10:12:31 -0500 Subject: [PATCH 3/7] Fix error when no aux_windows are specified. --- pyfpdb/HUD_main.py | 4 ++-- pyfpdb/Hud.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index cf0583bb..dcb32c26 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -31,8 +31,8 @@ Main for FreePokerTools HUD. import sys # redirect the stderr -#errorfile = open('HUD-error.txt', 'w', 0) -#sys.stderr = errorfile +errorfile = open('HUD-error.txt', 'w', 0) +sys.stderr = errorfile import os import thread diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 34d1b0cf..05696a9d 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -85,7 +85,7 @@ class Hud: # do we need to add some sort of condition here for dealing with a request for a font that doesn't exist? game_params = config.get_game_parameters(self.poker_game) - if not game_params['aux'] == "": + if not game_params['aux'] == [""]: for aux in game_params['aux']: aux_params = config.get_aux_parameters(aux) my_import = importName(aux_params['module'], aux_params['class']) From baa8d145ae4d734ad4d662b8f452492e1daee556 Mon Sep 17 00:00:00 2001 From: Ray Date: Thu, 5 Mar 2009 20:10:56 -0500 Subject: [PATCH 4/7] Delay getting game type to support mixed games. --- pyfpdb/fpdb_parse_logic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyfpdb/fpdb_parse_logic.py b/pyfpdb/fpdb_parse_logic.py index f13b1d6d..dab3bcc4 100644 --- a/pyfpdb/fpdb_parse_logic.py +++ b/pyfpdb/fpdb_parse_logic.py @@ -22,6 +22,7 @@ import fpdb_save_to_db #parses a holdem hand def mainParser(backend, db, cursor, site, category, hand): + category=fpdb_simple.recogniseCategory(hand[0]) if (category=="holdem" or category=="omahahi" or category=="omahahilo"): base="hold" else: From 753754c92453bb1753e9a8257a7b1ab7fa5ab874 Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 6 Mar 2009 21:46:34 -0500 Subject: [PATCH 5/7] Allow Aux_windows to have layouts and some cleanup. --- pyfpdb/Configuration.py | 57 ++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 7c6b9895..eef67184 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -32,14 +32,35 @@ import shutil import xml.dom.minidom from xml.dom.minidom import Node +#class Layout: +# def __init__(self, max): +# self.max = int(max) +# self.location = [] +# for i in range(self.max + 1): self.location.append(None) + class Layout: - def __init__(self, max): - self.max = int(max) + def __init__(self, node): + + self.max = int( node.getAttribute('max') ) + if node.hasAttribute('fav_seat'): self.fav_seat = int( node.getAttribute('fav_seat') ) + self.width = int( node.getAttribute('width') ) + self.height = int( node.getAttribute('height') ) + self.location = [] for i in range(self.max + 1): self.location.append(None) - + + for location_node in node.getElementsByTagName('location'): + if location_node.getAttribute('seat') != "": + self.location[int( location_node.getAttribute('seat') )] = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y'))) + elif location_node.getAttribute('common') != "": + self.common = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y'))) + def __str__(self): - temp = " Layout = %d max, width= %d, height = %d, fav_seat = %d\n" % (self.max, self.width, self.height, self.fav_seat) + temp = " Layout = %d max, width= %d, height = %d" % (self.max, self.width, self.height) + if hasattr(self, 'fav_seat'): temp = temp + ", fav_seat = %d\n" % self.fav_seat + else: temp = temp + "\n" + if hasattr(self, "common"): + temp = temp + " Common = (%d, %d)\n" % (self.common[0], self.common[1]) temp = temp + " Locations = " for i in range(1, len(self.location)): temp = temp + "(%d,%d)" % self.location[i] @@ -64,17 +85,9 @@ class Site: self.font_size = node.getAttribute("font_size") self.use_frames = node.getAttribute("use_frames") self.layout = {} - + for layout_node in node.getElementsByTagName('layout'): - max = int( layout_node.getAttribute('max') ) - lo = Layout(max) - lo.fav_seat = int( layout_node.getAttribute('fav_seat') ) - lo.width = int( layout_node.getAttribute('width') ) - lo.height = int( layout_node.getAttribute('height') ) - - for location_node in layout_node.getElementsByTagName('location'): - lo.location[int( location_node.getAttribute('seat') )] = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y'))) - + lo = Layout(layout_node) self.layout[lo.max] = lo def __str__(self): @@ -161,21 +174,23 @@ class Aux_window: def __init__(self, node): for (name, value) in node.attributes.items(): setattr(self, name, value) -# self.name = node.getAttribute("mw_name") -# self.cards = node.getAttribute("deck") -# self.card_wd = node.getAttribute("card_wd") -# self.card_ht = node.getAttribute("card_ht") -# self.rows = node.getAttribute("rows") -# self.cols = node.getAttribute("cols") -# self.format = node.getAttribute("stud") + + self.layout = {} + for layout_node in node.getElementsByTagName('layout'): + lo = Layout(layout_node) + self.layout[lo.max] = lo def __str__(self): temp = 'Aux = ' + self.name + "\n" for key in dir(self): if key.startswith('__'): continue + if key == 'layout': continue value = getattr(self, key) if callable(value): continue temp = temp + ' ' + key + " = " + value + "\n" + + for layout in self.layout: + temp = temp + "%s" % self.layout[layout] return temp class Popup: From 5f60cfde7ccd34ace7ad48c64f5993dc93b00676 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 7 Mar 2009 17:02:51 -0500 Subject: [PATCH 6/7] Add get_aux_locations. --- pyfpdb/Configuration.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index eef67184..e7235da2 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -529,6 +529,16 @@ class Config: ( 0, 280), (121, 280), ( 46, 30) ) return locations + def get_aux_locations(self, aux = "mucked", max = "9"): + + try: + locations = self.aux_windows[aux].layout[max].location + except: + locations = ( ( 0, 0), (684, 61), (689, 239), (692, 346), + (586, 393), (421, 440), (267, 440), ( 0, 361), + ( 0, 280), (121, 280), ( 46, 30) ) + return locations + def get_supported_sites(self): """Returns the list of supported sites.""" return self.supported_sites.keys() @@ -680,6 +690,8 @@ if __name__== "__main__": print "locs = ", c.get_locations("PokerStars", 8) for mw in c.get_aux_windows(): print c.get_aux_parameters(mw) + + print "mucked locations =", c.get_aux_locations('mucked', 9) for site in c.supported_sites.keys(): print "site = ", site, From 1a417441f68918bbb6a1ed72ed39e6cf5cc31563 Mon Sep 17 00:00:00 2001 From: Ray Date: Sat, 7 Mar 2009 20:44:10 -0500 Subject: [PATCH 7/7] First commit of Mucked_Flop. Works, but needs polish. --- pyfpdb/Mucked.py | 114 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 15 deletions(-) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 0b605e2f..1598776c 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -52,6 +52,32 @@ class Aux_Window: def destroy(self): 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): def __init__(self, hud, config, params): @@ -273,9 +299,6 @@ class Stud_cards: return self.parent.hud.stat_dict[k]['screen_name'] return "No Name" - def split_cards(self, card): - return (card[0], card[1].upper()) - def clear(self): for r in range(0, self.rows): 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.eb[(c, r)].set_tooltip_text('') - 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'])) +class Flop_Mucked(Aux_Window): + """Aux_Window class for displaying mucked cards for flop games.""" + + def __init__(self, hud, config, params): + self.hud = hud # hud object that this aux window supports + self.config = config # configuration object for this aux window to use + self.params = params # hash aux params from config + self.card_images = self.get_card_images() + + def create(self): + + adj = self.hud.adj_seats(0, self.config) + loc = self.config.get_aux_locations(self.params['name'], int(self.hud.max)) - 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 +# 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__":