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

Conflicts:
	pyfpdb/Configuration.py
This commit is contained in:
eblade 2009-03-09 06:31:13 -04:00
commit 60e66dcf31
3 changed files with 144 additions and 29 deletions

58
pyfpdb/Configuration.py Executable file → Normal file
View File

@ -32,14 +32,30 @@ import shutil
import xml.dom.minidom import xml.dom.minidom
from xml.dom.minidom import Node from xml.dom.minidom import Node
class Layout: class Layout:
def __init__(self, max): def __init__(self, node):
self.max = int(max)
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 = [] self.location = []
self.location = map(lambda x: None, range(self.max+1)) # there must be a better way to do this? 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') != "":
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): 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 = " temp = temp + " Locations = "
for i in xrange(1, len(self.location)): for i in xrange(1, len(self.location)):
temp = temp + "(%d,%d)" % self.location[i] temp = temp + "(%d,%d)" % self.location[i]
@ -64,17 +80,17 @@ class Site:
self.font_size = node.getAttribute("font_size") self.font_size = node.getAttribute("font_size")
self.use_frames = node.getAttribute("use_frames") self.use_frames = node.getAttribute("use_frames")
self.layout = {} self.layout = {}
for layout_node in node.getElementsByTagName('layout'): for layout_node in node.getElementsByTagName('layout'):
max = int( layout_node.getAttribute('max') ) max = int( layout_node.getAttribute('max') )
lo = Layout(max) lo = Layout(max)
lo.fav_seat = int( layout_node.getAttribute('fav_seat') ) lo.fav_seat = int( layout_node.getAttribute('fav_seat') )
lo.width = int( layout_node.getAttribute('width') ) lo.width = int( layout_node.getAttribute('width') )
lo.height = int( layout_node.getAttribute('height') ) lo.height = int( layout_node.getAttribute('height') )
for location_node in layout_node.getElementsByTagName('location'): 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.location[int( location_node.getAttribute('seat') )] = (int( location_node.getAttribute('x') ), int( location_node.getAttribute('y')))
self.layout[lo.max] = lo self.layout[lo.max] = lo
def __str__(self): def __str__(self):
@ -158,21 +174,23 @@ class Aux_window:
def __init__(self, node): def __init__(self, node):
for (name, value) in node.attributes.items(): for (name, value) in node.attributes.items():
setattr(self, name, value) setattr(self, name, value)
# self.name = node.getAttribute("mw_name")
# self.cards = node.getAttribute("deck") self.layout = {}
# self.card_wd = node.getAttribute("card_wd") for layout_node in node.getElementsByTagName('layout'):
# self.card_ht = node.getAttribute("card_ht") lo = Layout(layout_node)
# self.rows = node.getAttribute("rows") self.layout[lo.max] = lo
# self.cols = node.getAttribute("cols")
# self.format = node.getAttribute("stud")
def __str__(self): def __str__(self):
temp = 'Aux = ' + self.name + "\n" temp = 'Aux = ' + self.name + "\n"
for key in dir(self): for key in dir(self):
if key.startswith('__'): continue if key.startswith('__'): continue
if key == 'layout': continue
value = getattr(self, key) value = getattr(self, key)
if callable(value): continue if callable(value): continue
temp = temp + ' ' + key + " = " + value + "\n" temp = temp + ' ' + key + " = " + value + "\n"
for layout in self.layout:
temp = temp + "%s" % self.layout[layout]
return temp return temp
class Popup: class Popup:
@ -493,6 +511,16 @@ class Config:
( 0, 280), (121, 280), ( 46, 30) ) ( 0, 280), (121, 280), ( 46, 30) )
return locations 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): def get_supported_sites(self):
"""Returns the list of supported sites.""" """Returns the list of supported sites."""
return self.supported_sites.keys() return self.supported_sites.keys()
@ -644,6 +672,8 @@ if __name__== "__main__":
print "locs = ", c.get_locations("PokerStars", 8) print "locs = ", c.get_locations("PokerStars", 8)
for mw in c.get_aux_windows(): for mw in c.get_aux_windows():
print c.get_aux_parameters(mw) print c.get_aux_parameters(mw)
print "mucked locations =", c.get_aux_locations('mucked', 9)
for site in c.supported_sites.keys(): for site in c.supported_sites.keys():
print "site = ", site, print "site = ", site,

View File

@ -52,6 +52,32 @@ class Aux_Window:
def destroy(self): def destroy(self):
self.container.destroy() 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): class Stud_mucked(Aux_Window):
def __init__(self, hud, config, params): def __init__(self, hud, config, params):
@ -273,9 +299,6 @@ class Stud_cards:
return self.parent.hud.stat_dict[k]['screen_name'] return self.parent.hud.stat_dict[k]['screen_name']
return "No Name" return "No Name"
def split_cards(self, card):
return (card[0], card[1].upper())
def clear(self): def clear(self):
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(" ")
@ -283,19 +306,80 @@ class Stud_cards:
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')]) self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')])
self.eb[(c, r)].set_tooltip_text('') self.eb[(c, r)].set_tooltip_text('')
def get_card_images(self): class Flop_Mucked(Aux_Window):
card_images = {} """Aux_Window class for displaying mucked cards for flop games."""
suits = ('S', 'H', 'D', 'C')
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B') def __init__(self, hud, config, params):
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck'])) 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): # make a scratch pixbuf 7 cards wide for creating our images
for i in range(0, 4): self.scratch = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, True, 8,
temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42) 7* int(self.params['card_wd']), int(self.params['card_ht']))
pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0)
card_images[(ranks[j], suits[i])] = temp_pb # create the stat windows
return(card_images) self.m_windows = {} # windows to put the card images
# cards are 30 wide x 42 high 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__": if __name__== "__main__":

View File

@ -22,6 +22,7 @@ import fpdb_save_to_db
#parses a holdem hand #parses a holdem hand
def mainParser(backend, db, cursor, site, category, hand): def mainParser(backend, db, cursor, site, category, hand):
category=fpdb_simple.recogniseCategory(hand[0])
if (category=="holdem" or category=="omahahi" or category=="omahahilo"): if (category=="holdem" or category=="omahahi" or category=="omahahilo"):
base="hold" base="hold"
else: else: