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

This commit is contained in:
Worros 2009-03-08 14:18:20 +09:00
commit b679fddfd2
6 changed files with 306 additions and 66 deletions

View File

@ -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
@ -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):
@ -105,7 +118,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'):
@ -156,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:
@ -509,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()
@ -660,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,

View File

@ -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
@ -99,7 +99,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()
@ -108,6 +108,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):

101
pyfpdb/Hello.py Normal file
View File

@ -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))

View File

@ -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)

View File

@ -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,53 @@ 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()
############################################################################
# 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, 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 +91,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 +114,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 +208,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 +222,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):
@ -267,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(" ")
@ -277,20 +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']))
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)
class Flop_Mucked(Aux_Window):
"""Aux_Window class for displaying mucked cards for flop games."""
# cards are 30 wide x 42 high
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))
# 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__":

View File

@ -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: