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

This commit is contained in:
eblade 2009-03-05 00:04:03 -05:00
commit 98e0a096d2
5 changed files with 160 additions and 32 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
@ -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'):

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
@ -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
@ -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,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__":