Merge branch 'master' of git://git.assembla.com/free_poker_tools

This commit is contained in:
eblade 2008-11-22 18:16:46 -05:00
commit 5642f4bafc
6 changed files with 184 additions and 48 deletions

View File

@ -58,6 +58,7 @@ class Site:
self.hudfgcolor = node.getAttribute("fgcolor")
self.converter = node.getAttribute("converter")
self.enabled = node.getAttribute("enabled")
self.aux_window = node.getAttribute("aux_window")
self.layout = {}
for layout_node in node.getElementsByTagName('layout'):
@ -100,6 +101,7 @@ class Game:
self.db = node.getAttribute("db")
self.rows = int( node.getAttribute("rows") )
self.cols = int( node.getAttribute("cols") )
self.aux = node.getAttribute("aux")
self.stats = {}
for stat_node in node.getElementsByTagName('stat'):
@ -120,6 +122,7 @@ class Game:
temp = temp + " db = %s\n" % self.db
temp = temp + " rows = %d\n" % self.rows
temp = temp + " cols = %d\n" % self.cols
temp = temp + " aux = %s\n" % self.aux
for stat in self.stats.keys():
temp = temp + "%s" % self.stats[stat]
@ -144,18 +147,20 @@ class Database:
temp = temp + ' ' + key + " = " + value + "\n"
return temp
class Mucked:
class Aux_window:
def __init__(self, node):
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")
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")
def __str__(self):
temp = 'Mucked = ' + self.name + "\n"
temp = 'Aux = ' + self.name + "\n"
for key in dir(self):
if key.startswith('__'): continue
value = getattr(self, key)
@ -238,7 +243,7 @@ class Config:
self.supported_sites = {}
self.supported_games = {}
self.supported_databases = {}
self.mucked_windows = {}
self.aux_windows = {}
self.popup_windows = {}
# s_sites = doc.getElementsByTagName("supported_sites")
@ -257,9 +262,9 @@ class Config:
self.supported_databases[db.db_name] = db
# s_dbs = doc.getElementsByTagName("mucked_windows")
for mw_node in doc.getElementsByTagName("mw"):
mw = Mucked(node = mw_node)
self.mucked_windows[mw.name] = mw
for aw_node in doc.getElementsByTagName("aw"):
aw = Aux_window(node = aw_node)
self.aux_windows[aw.name] = aw
# s_dbs = doc.getElementsByTagName("popup_windows")
for pu_node in doc.getElementsByTagName("pu"):
@ -503,6 +508,7 @@ class Config:
parms["HH_path"] = self.supported_sites[site].HH_path
parms["site_name"] = self.supported_sites[site].site_name
parms["enabled"] = self.supported_sites[site].enabled
parms["aux_window"] = self.supported_sites[site].aux_window
return parms
def set_site_parameters(self, site_name, converter = None, decoder = None,
@ -537,6 +543,44 @@ class Config:
if not enabled == None: self.supported_sites[site].enabled = enabled
return
def get_aux_windows(self):
"""Gets the list of mucked window formats in the configuration."""
mw = []
for w in self.aux_windows.keys():
mw.append(w)
return mw
def get_aux_parameters(self, name):
"""Gets a dict of mucked window parameters from the named mw."""
param = {}
if self.aux_windows.has_key(name):
for key in dir(self.aux_windows[name]):
if key.startswith('__'): continue
value = getattr(self.aux_windows[name], key)
if callable(value): continue
param[key] = value
return param
return None
def get_game_parameters(self, name):
"""Get the configuration parameters for the named game."""
param = {}
if self.supported_games.has_key(name):
param['game_name'] = self.supported_games[name].game_name
param['db'] = self.supported_games[name].db
param['rows'] = self.supported_games[name].rows
param['cols'] = self.supported_games[name].cols
param['aux'] = self.supported_games[name].aux
return param
def get_supported_games(self):
"""Get the list of supported games."""
sg = []
for game in c.supported_games.keys():
sg.append(c.supported_games[game].game_name)
return sg
if __name__== "__main__":
c = Config()
@ -557,15 +601,15 @@ if __name__== "__main__":
print c.supported_databases[db]
print "----------- END SUPPORTED DATABASES -----------"
print "\n----------- MUCKED WINDOW FORMATS -----------"
for w in c.mucked_windows.keys():
print c.mucked_windows[w]
print "----------- END MUCKED WINDOW FORMATS -----------"
print "\n----------- AUX WINDOW FORMATS -----------"
for w in c.aux_windows.keys():
print c.aux_windows[w]
print "----------- END AUX WINDOW FORMATS -----------"
print "\n----------- POPUP WINDOW FORMATS -----------"
for w in c.popup_windows.keys():
print c.popup_windows[w]
print "----------- END MUCKED WINDOW FORMATS -----------"
print "----------- END POPUP WINDOW FORMATS -----------"
print "\n----------- IMPORT -----------"
tmp = c.get_import_parameters()
@ -586,6 +630,12 @@ if __name__== "__main__":
print "paths = ", c.get_default_paths("PokerStars")
print "colors = ", c.get_default_colors("PokerStars")
print "locs = ", c.get_locations("PokerStars", 8)
for mw in c.get_aux_windows():
print c.get_aux_parameters(mw)
for site in c.supported_sites.keys():
print "site = ", site,
print c.get_site_parameters(site)
for game in c.get_supported_games():
print c.get_game_parameters(game)

View File

@ -83,6 +83,8 @@ def update_HUD(new_hand_id, table_name, config, stat_dict):
gtk.gdk.threads_enter()
try:
hud_dict[table_name].update(new_hand_id, config, stat_dict)
for m in hud_dict[table_name].aux_windows:
m.update_gui(new_hand_id)
return False
finally:
gtk.gdk.threads_leave()
@ -121,6 +123,9 @@ def read_stdin(): # This is the thread function
# if a hud for this CASH table exists, just update it
if hud_dict.has_key(table_name):
# update the data for the aux_windows
for aw in hud_dict[table_name].aux_windows:
aw.update_data(new_hand_id)
update_HUD(new_hand_id, table_name, config, stat_dict)
# if a hud for this TOURNAMENT table exists, just update it
elif hud_dict.has_key(tour_number):

View File

@ -59,6 +59,7 @@ class Hud:
self.stat_windows = {}
self.popup_windows = {}
self.aux_windows = []
self.font = pango.FontDescription("Sans 8")
# Set up a main window for this this instance of the HUD
@ -168,7 +169,6 @@ class Hud:
adj = self.adj_seats(hand, config)
loc = self.config.get_locations(self.table.site, self.max)
print "adj = ", adj
# create the stat windows
for i in range(1, self.max + 1):
@ -194,9 +194,11 @@ 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
# self.mucked_window = gtk.Window()
# self.m = Mucked.Mucked(self.mucked_window, self.db_connection)
# self.mucked_window.show_all()
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(), config, 'fpdb')" % (aux_params['module'], aux_params['class'])))
def update(self, hand, config, stat_dict):
self.hand = hand # this is the last hand, so it is available later
@ -217,7 +219,9 @@ class Hud:
tip = stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \
number[3] + ", " + number[4]
Stats.do_tip(self.stat_windows[stat_dict[s]['seat']].e_box[r][c], tip)
# self.m.update(hand)
# for m in self.aux_windows:
# m.update_data(hand)
# m.update_gui(hand)
def topify_window(self, window):
"""Set the specified gtk window to stayontop in MS Windows."""

View File

@ -41,30 +41,47 @@ import Configuration
import Database
import Tables
import Hud
import Mucked
import HandHistory
class Mucked:
def __init__(self, parent, db_connection):
self.parent = parent #this is the parent of the mucked cards widget
self.db_connection = db_connection
class Aux_Window:
def __init__(self, parent, config, db_name):
self.config = config
self.parent = parent #this is the parent of the mucked cards widget
self.db_name = db_name
self.vbox = gtk.VBox()
self.parent.add(self.vbox)
self.mucked_list = MuckedList (self.vbox, db_connection)
self.mucked_cards = MuckedCards(self.vbox, db_connection)
def update(self):
pass
class Stud_mucked(Aux_Window):
def __init__(self, parent, config, db_name):
self.config = config
self.parent = parent #this is the parent of the mucked cards widget
self.db_name = db_name
self.vbox = gtk.VBox()
self.parent.add(self.vbox)
self.mucked_list = Stud_list(self.vbox, config, db_name)
self.mucked_cards = Stud_cards(self.vbox, config, db_name)
self.mucked_list.mucked_cards = self.mucked_cards
self.parent.show_all()
def update(self, new_hand_id):
self.mucked_list.update(new_hand_id)
def update_data(self, new_hand_id):
self.mucked_list.update_data(new_hand_id)
class MuckedList:
def __init__(self, parent, db_connection):
def update_gui(self, new_hand_id):
self.mucked_list.update_gui(new_hand_id)
class Stud_list:
def __init__(self, parent, config, db_name):
self.parent = parent
self.db_connection = db_connection
self.parent = parent
self.config = config
self.db_name = db_name
# set up a scrolled window to hold the listbox
self.scrolled_window = gtk.ScrolledWindow()
@ -114,12 +131,26 @@ class MuckedList:
vadj = self.scrolled_window.get_vadjustment()
vadj.set_value(vadj.upper)
self.mucked_cards.update(new_hand_id)
def update_data(self, new_hand_id):
self.info_row = ((new_hand_id, "xxxx", 0), )
self.mucked_cards.update_data(new_hand_id)
class MuckedCards:
def __init__(self, parent, db_connection):
def update_gui(self, new_hand_id):
iter = self.liststore.append(self.info_row[0])
sel = self.treeview.get_selection()
sel.select_iter(iter)
self.parent = parent #this is the parent of the mucked cards widget
self.db_connection = db_connection
vadj = self.scrolled_window.get_vadjustment()
vadj.set_value(vadj.upper)
self.mucked_cards.update_gui(new_hand_id)
class Stud_cards:
def __init__(self, parent, config, db_name = 'fpdb'):
self.parent = parent #this is the parent of the mucked cards widget
self.config = config
self.db_name = db_name
self.card_images = self.get_card_images()
self.seen_cards = {}
@ -173,7 +204,8 @@ class MuckedCards:
return old_cards
def update(self, new_hand_id):
cards = self.db_connection.get_cards(new_hand_id)
db_connection = Database.Database(self.config, 'fpdb', '')
cards = db_connection.get_cards(new_hand_id)
self.clear()
cards = self.translate_cards(cards)
for c in cards.keys():
@ -185,7 +217,7 @@ class MuckedCards:
set_from_pixbuf(self.card_images[self.split_cards(cards[c][i[1]])])
tips = []
action = self.db_connection.get_action_from_hand(new_hand_id)
action = db_connection.get_action_from_hand(new_hand_id)
for street in action:
temp = ''
for act in street:
@ -209,6 +241,48 @@ class MuckedCards:
for round in range(1, len(tips)):
for r in range(0, self.rows):
self.eb[(round_to_col[round], r)].set_tooltip_text(tips[round])
db_connection.close_connection()
def update_data(self, new_hand_id):
db_connection = Database.Database(self.config, 'fpdb', '')
cards = db_connection.get_cards(new_hand_id)
self.clear()
self.cards = self.translate_cards(cards)
self.tips = []
action = db_connection.get_action_from_hand(new_hand_id)
for street in action:
temp = ''
for act in street:
temp = temp + act[0] + " " + act[1] + "s "
if act[2] > 0:
if act[2]%100 > 0:
temp = temp + "%4.2f\n" % (float(act[2])/100)
else:
temp = temp + "%d\n" % (act[2]/100)
else:
temp = temp + "\n"
self.tips.append(temp)
db_connection.close_connection()
def update_gui(self, new_hand_id):
for c in self.cards.keys():
self.grid_contents[(1, self.cards[c]['seat_number'] - 1)].set_text(self.cards[c]['screen_name'])
for i in ((0, 'hole_card_1'), (1, 'hole_card_2'), (2, 'hole_card_3'), (3, 'hole_card_4'),
(4, 'hole_card_5'), (5, 'hole_card_6'), (6, 'hole_card_7')):
if not self.cards[c][i[1]] == "xx":
self.seen_cards[(i[0], self.cards[c]['seat_number'] - 1)]. \
set_from_pixbuf(self.card_images[self.split_cards(self.cards[c][i[1]])])
## action in tool tips for 3rd street cards
for c in (0, 1, 2):
for r in range(0, self.rows):
self.eb[(c, r)].set_tooltip_text(self.tips[0])
# action in tools tips for later streets
round_to_col = (0, 3, 4, 5, 6)
for round in range(1, len(self.tips)):
for r in range(0, self.rows):
self.eb[(round_to_col[round], r)].set_tooltip_text(self.tips[round])
def split_cards(self, card):
return (card[0], card[1].upper())
@ -244,16 +318,18 @@ if __name__== "__main__":
# just read it and pass it to update
new_hand_id = sys.stdin.readline()
new_hand_id = new_hand_id.rstrip() # remove trailing whitespace
m.update(new_hand_id)
m.update_data(new_hand_id)
m.update_gui(new_hand_id)
return(True)
config = Configuration.Config()
db_connection = Database.Database(config, 'fpdb', '')
# db_connection = Database.Database(config, 'fpdb', '')
main_window = gtk.Window()
main_window.set_keep_above(True)
main_window.connect("destroy", destroy)
m = Mucked(main_window, db_connection)
aux_to_call = "Stud_mucked"
m = eval("%s(main_window, config, 'fpdb')" % aux_to_call)
main_window.show_all()
s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand)

View File

@ -229,6 +229,7 @@ def discover_nt_by_name(c, tablename):
if titles[hwnd].find(tablename) == -1: continue
if titles[hwnd].find("History for table:") > -1: continue
if titles[hwnd].find("HUD:") > -1: continue
if titles[hwnd].find("Chat:") > -1: continue
return decode_windows(c, titles[hwnd], hwnd)
return False
@ -428,7 +429,7 @@ def discover_mac_by_name(c, tablename):
if __name__=="__main__":
c = Configuration.Config()
print discover_table_by_name(c, "Ostara V")
print discover_table_by_name(c, "Howard Lederer")
print discover_tournament_table(c, "118942908", "3")
tables = discover(c)

View File

@ -734,7 +734,7 @@ def parseCardLine(site, category, street, line, names, cardValues, cardSuits, bo
print "line:",line,"cardValues[playerNo]:",cardValues[playerNo]
raise FpdbError("read too many/too few holecards in parseCardLine")
elif (category=="razz" or category=="studhi" or category=="studhilo"):
if (line.find("shows")==-1):
if (line.find("shows")==-1 and line.find("mucked") == -1):
#print "parseCardLine(in stud if), street:", street
if line[pos+2]=="]": #-> not (hero and 3rd street)
cardValues[playerNo][street+2]=line[pos:pos+1]