Merge branch 'master' of git://git.assembla.com/fpdb-eric

Conflicts:

	pyfpdb/Configuration.py
This commit is contained in:
Worros 2009-03-09 19:22:54 +09:00
commit d6b5f5d019
6 changed files with 80 additions and 100 deletions

View File

@ -32,12 +32,6 @@ 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, node):
@ -47,7 +41,8 @@ class Layout:
self.height = int( node.getAttribute('height') )
self.location = []
for i in range(self.max + 1): self.location.append(None)
self.location = map(lambda x: None, range(self.max+1)) # there must be a better way to do this?
for location_node in node.getElementsByTagName('location'):
if location_node.getAttribute('seat') != "":
@ -62,7 +57,7 @@ class Layout:
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)):
for i in xrange(1, len(self.location)):
temp = temp + "(%d,%d)" % self.location[i]
return temp + "\n"
@ -91,16 +86,17 @@ class Site:
self.layout[lo.max] = lo
def __str__(self):
temp = "Site = " + self.site_name + "\n"
temp = "Site = %s\n" % self.site_name
for key in dir(self):
if key.startswith('__'): continue
if key == 'layout': continue
value = getattr(self, key)
if callable(value): continue
temp = "%s %s = %s\n" % (temp, key, str(value))
temp = temp + ' ' + key + " = " + str(value) + "\n"
for layout in self.layout:
temp = temp + "%s" % self.layout[layout]
temp = "%s%s" % (temp, self.layout[layout])
return temp
@ -141,14 +137,10 @@ class Game:
self.stats[stat.stat_name] = stat
def __str__(self):
temp = "Game = " + self.game_name + "\n"
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
temp = "Game = %s\n db = %s\n rows = %d\n cols = %d\n aux = %s\n" % (self.game_name, self.db, self.rows, self.cols, self.aux)
for stat in self.stats.keys():
temp = temp + "%s" % self.stats[stat]
temp = "%s%s" % (temp, self.stats[stat])
return temp
@ -412,7 +404,7 @@ class Config:
site_node = self.get_site_node(site_name)
layout_node = self.get_layout_node(site_node, max)
if layout_node == None: return
for i in range(1, max + 1):
for i in xrange(1, max + 1):
location_node = self.get_location_node(layout_node, i)
location_node.setAttribute("x", str( locations[i-1][0] ))
location_node.setAttribute("y", str( locations[i-1][1] ))
@ -492,35 +484,17 @@ class Config:
def get_default_colors(self, site = "PokerStars"):
colors = {}
if self.supported_sites[site].hudopacity == "":
colors['hudopacity'] = 0.90
else:
colors['hudopacity'] = float(self.supported_sites[site].hudopacity)
if self.supported_sites[site].hudbgcolor == "":
colors['hudbgcolor'] = "#FFFFFF"
else:
colors['hudbgcolor'] = self.supported_sites[site].hudbgcolor
if self.supported_sites[site].hudfgcolor == "":
colors['hudfgcolor'] = "#000000"
else:
colors['hudfgcolor'] = self.supported_sites[site].hudfgcolor
colors['hudopacity'] = float(self.supported_sites[site].hudopacity) if self.supported_sites[site].hudopacity != "" else 0.90
colors['hudbgcolor'] = self.supported_sites[site].hudbgcolor if self.supported_sites[site].hudbgcolor != "" else "#FFFFFF"
colors['hudfgcolor'] = self.supported_sites[site].hudfgcolor if self.supported_sites[site].hudfgcolor != "" else "#000000"
return colors
def get_default_font(self, site = 'PokerStars'):
(font, font_size) = ("Sans", "8")
if self.supported_sites[site].font == "":
font = "Sans"
else:
font = self.supported_sites[site].font
if self.supported_sites[site].font_size == "":
font_size = "8"
else:
font_size = self.supported_sites[site].font_size
font = self.supported_sites[site].font if self.supported_sites[site].font != "" else "Sans"
font_size = self.supported_sites[site].font_size if self.supported_sites[site].font != "" else "8"
return (font, font_size)
def get_locations(self, site = "PokerStars", max = "8"):
try:
locations = self.supported_sites[site].layout[max].location
except:
@ -609,7 +583,7 @@ class Config:
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):
if name in self.aux_windows:
for key in dir(self.aux_windows[name]):
if key.startswith('__'): continue
value = getattr(self.aux_windows[name], key)
@ -622,7 +596,7 @@ class Config:
def get_game_parameters(self, name):
"""Get the configuration parameters for the named game."""
param = {}
if self.supported_games.has_key(name):
if name in self.supported_games:
param['game_name'] = self.supported_games[name].game_name
param['db'] = self.supported_games[name].db
param['rows'] = self.supported_games[name].rows
@ -633,7 +607,7 @@ class Config:
def get_supported_games(self):
"""Get the list of supported games."""
sg = []
for game in c.supported_games.keys():
for game in c.supported_games:
sg.append(c.supported_games[game].game_name)
return sg

View File

@ -132,13 +132,15 @@ class Database:
def convert_cards(self, d):
ranks = ('', '', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')
cards = ""
for i in range(1, 8):
if d['card' + str(i) + 'Value'] == None:
for i in xrange(1, 8):
cv = "card%dValue" % i
if d[cv] == None:
break
elif d['card' + str(i) + 'Value'] == 0:
cards += "xx"
elif d[cv] == 0:
cards = "%sxx" % cards
else:
cards += ranks[d['card' + str(i) + 'Value']] + d['card' +str(i) + 'Suit']
cs = "card%dSuit" % i
cards = "%s%s%s" % (cards, ranks[d[cv]], cs)
return cards
def get_action_from_hand(self, hand_no):

View File

@ -123,8 +123,7 @@ class HUD_main(object):
gtk.gdk.threads_enter()
try:
self.hud_dict[table_name].update(new_hand_id, config)
for m in self.hud_dict[table_name].aux_windows:
m.update_gui(new_hand_id)
map(lambda aw: aw.update_gui(new_hand_id), self.hud_dict[table_name].aux_windows)
return False
finally:
gtk.gdk.threads_leave()
@ -140,7 +139,7 @@ class HUD_main(object):
self.db_connection = Database.Database(self.config, self.db_name, 'temp')
tourny_finder = re.compile('(\d+) (\d+)')
while True: # wait for a new hand number on stdin
while 1: # wait for a new hand number on stdin
new_hand_id = sys.stdin.readline()
new_hand_id = string.rstrip(new_hand_id)
if new_hand_id == "": # blank line means quit
@ -187,7 +186,7 @@ class HUD_main(object):
if tablewindow == None:
# If no client window is found on the screen, complain and continue
if is_tournament:
table_name = tour_number + " " + tab_number
table_name = "%s %s" % (tour_number, tab_number)
sys.stderr.write("table name "+table_name+" not found, skipping.\n")
else:
self.create_HUD(new_hand_id, tablewindow, temp_key, max, poker_game, is_tournament, stat_dict, cards)

View File

@ -172,7 +172,7 @@ class HandHistoryConverter(threading.Thread):
return
self.obs = self.obs.replace('\r\n', '\n')
self.gametype = self.determineGameType()
self.gametype = self.determineGameType(self.obs)
if self.gametype == None:
print "Unknown game type from file, aborting on this file."
return
@ -208,7 +208,7 @@ class HandHistoryConverter(threading.Thread):
# Read actions in street order
for street in hand.streetList: # go through them in order
print "DEBUG: ", street
# print "DEBUG: ", street
if hand.streets.group(street) is not None:
if self.gametype[1] == "hold" or self.gametype[1] == "omahahi":
self.readCommunityCards(hand, street) # read community cards
@ -247,7 +247,7 @@ class HandHistoryConverter(threading.Thread):
# type base limit
# [ ring, hold, nl , sb, bb ]
# Valid types specified in docs/tabledesign.html in Gametypes
def determineGameType(self): abstract
def determineGameType(self, handText): abstract
# Read any of:
# HID HandID

View File

@ -98,8 +98,7 @@ class Hud:
# Set up a main window for this this instance of the HUD
self.main_window = gtk.Window()
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
self.main_window.set_title(self.table.name + " FPDBHUD")
# self.main_window.destroyhandler = self.main_window.connect("destroy", self.kill_hud)
self.main_window.set_title("%s FPDBHUD" % (self.table.name))
self.main_window.set_decorated(False)
self.main_window.set_opacity(self.colors["hudopacity"])
@ -171,7 +170,7 @@ class Hud:
self.main_window.move(x, y)
adj = self.adj_seats(self.hand, self.config)
loc = self.config.get_locations(self.table.site, self.max)
for i in range(1, self.max + 1):
for i in xrange(1, self.max + 1):
(x, y) = loc[adj[i]]
if i in self.stat_windows:
self.stat_windows[i].relocate(x, y)
@ -190,18 +189,15 @@ class Hud:
# kill all stat_windows, popups and aux_windows in this HUD
# heap dead, burnt bodies, blood 'n guts, veins between my teeth
for s in self.stat_windows.itervalues():
for p in s.popups:
s.kill_popup(p)
s.window.destroy()
self.stat_windows = {}
s.kill_popups()
s.window.destroy()
self.stat_windows = {}
# also kill any aux windows
for m in self.aux_windows:
m.destroy()
map(lambda m: m.destroy(), self.aux_windows)
self.aux_windows = []
def reposition_windows(self, *args):
for w in self.stat_windows:
self.stat_windows[w].window.move(self.stat_windows[w].x, self.stat_windows[w].y)
map(lambda x: x.window.move(x.x, x.y), self.stat_windows)
return True
def debug_stat_windows(self, *args):
@ -220,7 +216,7 @@ class Hud:
def adj_seats(self, hand, config):
adj = range(0, self.max + 1) # default seat adjustments = no adjustment
adj = xrange(0, self.max + 1) # default seat adjustments = no adjustment
# does the user have a fav_seat?
try:
sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat))
@ -230,7 +226,7 @@ class Hud:
# actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
actual_seat = self.get_actual_seat(config.supported_sites[self.table.site].screen_name)
sys.stderr.write("found actual seat = %d\n" % actual_seat)
for i in range(0, self.max + 1):
for i in xrange(0, self.max + 1):
j = actual_seat + i
if j > self.max: j = j - self.max
adj[j] = fav_seat + i
@ -241,7 +237,7 @@ class Hud:
return adj
def get_actual_seat(self, name):
for key in self.stat_dict.keys():
for key in self.stat_dict:
if self.stat_dict[key]['screen_name'] == name:
return self.stat_dict[key]['seat']
sys.stderr.write("Error finding actual seat.\n")
@ -263,7 +259,7 @@ class Hud:
loc = self.config.get_locations(self.table.site, self.max)
# create the stat windows
for i in range(1, self.max + 1):
for i in xrange(1, self.max + 1):
(x, y) = loc[adj[i]]
if i in self.stat_windows:
self.stat_windows[i].relocate(x, y)
@ -280,7 +276,7 @@ class Hud:
font = self.font)
self.stats = []
for i in range(0, config.supported_games[self.poker_game].rows + 1):
for i in xrange(0, config.supported_games[self.poker_game].rows + 1):
row_list = [''] * config.supported_games[self.poker_game].cols
self.stats.append(row_list)
for stat in config.supported_games[self.poker_game].stats:
@ -304,8 +300,8 @@ class Hud:
self.create(hand, config, self.stat_dict, self.cards)
self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id']
for r in range(0, config.supported_games[self.poker_game].rows):
for c in range(0, config.supported_games[self.poker_game].cols):
for r in xrange(0, config.supported_games[self.poker_game].rows):
for c in xrange(0, config.supported_games[self.poker_game].cols):
this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]]
number = Stats.do_stat(self.stat_dict, player = self.stat_dict[s]['player_id'], stat = self.stats[r][c])
statstring = this_stat.hudprefix + str(number[1]) + this_stat.hudsuffix
@ -369,6 +365,10 @@ class Stat_Window:
def kill_popup(self, popup):
popup.window.destroy()
self.popups.remove(popup)
def kill_popups(self):
map(lambda x: x.window.destroy(), self.popups)
self.popups = { }
def relocate(self, x, y):
self.x = x + self.table.x
@ -403,35 +403,38 @@ class Stat_Window:
self.e_box = []
self.frame = []
self.label = []
for r in range(self.game.rows):
if self.useframes:
usegtkframes = self.useframes
e_box = self.e_box
label = self.label
for r in xrange(self.game.rows):
if usegtkframes:
self.frame.append([])
self.e_box.append([])
self.label.append([])
for c in range(self.game.cols):
if self.useframes:
e_box.append([])
label.append([])
for c in xrange(self.game.cols):
if usegtkframes:
self.frame[r].append( gtk.Frame() )
self.e_box[r].append( gtk.EventBox() )
e_box[r].append( gtk.EventBox() )
self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
e_box[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
e_box[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
Stats.do_tip(self.e_box[r][c], 'stuff')
if self.useframes:
Stats.do_tip(e_box[r][c], 'stuff')
if usegtkframes:
self.grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
self.frame[r][c].add(self.e_box[r][c])
self.frame[r][c].add(e_box[r][c])
else:
self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
self.label[r].append( gtk.Label('xxx') )
self.grid.attach(e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0)
label[r].append( gtk.Label('xxx') )
if self.useframes:
if usegtkframes:
self.frame[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
self.label[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor)
label[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor)
self.e_box[r][c].add(self.label[r][c])
self.e_box[r][c].connect("button_press_event", self.button_press_cb)
self.label[r][c].modify_font(font)
e_box[r][c].add(self.label[r][c])
e_box[r][c].connect("button_press_event", self.button_press_cb)
label[r][c].modify_font(font)
self.window.set_opacity(parent.colors['hudopacity'])
@ -475,8 +478,8 @@ class Popup_window:
# figure out the row, col address of the click that activated the popup
row = 0
col = 0
for r in range(0, stat_window.game.rows):
for c in range(0, stat_window.game.cols):
for r in xrange(0, stat_window.game.rows):
for c in xrange(0, stat_window.game.cols):
if stat_window.e_box[r][c] == parent:
row = r
col = c
@ -557,8 +560,11 @@ class Popup_window:
for w in tl_windows:
if w[1] == unique_name:
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
window.set_transient_for(self.parent.main_window)
style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE)
style |= win32con.WS_CLIPCHILDREN
win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style)
window.set_title(real_name)
if __name__== "__main__":

View File

@ -208,8 +208,7 @@ class Importer:
#if os.path.isdir(file):
#self.import_file_dict(file, self.filelist[file][0], self.filelist[file][1])
for dir in self.addToDirList:
self.addImportDirectory(dir, True, self.addToDirList[dir][0], self.addToDirList[dir][1])
self.addToDirList = filter(lambda x: self.addImportDirectory(x, True, self.addToDirList[x][0], self.addToDirList[x][1]), self.addToDirList)
for file in self.removeFromFileList:
if file in self.filelist:
@ -309,7 +308,7 @@ class Importer:
partial=0 #counter
errors=0 #counter
for i in range (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
for i in xrange (len(self.lines)): #main loop, iterates through the lines of a file and calls the appropriate parser method
if (len(self.lines[i])<2):
endpos=i
hand=self.lines[startpos:endpos]