New file Aux_Hud. Minor mods to Mucked.

Aux_Hud is the prototype of the new HUD that uses the AW interface.
This version works as a minimal HUD, but the default HUD from 
Hud.py is also displayed.
This commit is contained in:
Eratosthenes 2011-01-29 23:41:37 -05:00
parent 59c7985410
commit d01951089b
2 changed files with 111 additions and 2 deletions

104
pyfpdb/Aux_Hud.py Normal file
View File

@ -0,0 +1,104 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Mucked.py
Mucked cards display for FreePokerTools HUD.
"""
# Copyright 2008-2010, 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
# Standard Library modules
# pyGTK modules
import gtk
import gobject
# FreePokerTools modules
import Mucked
import Stats
class Stat_Window(Mucked.Seat_Window):
"""Simple window class for stat windows."""
def create_contents(self, i):
self.grid = gtk.Table(rows = self.aw.nrows, columns = self.aw.ncols, homogeneous = False)
self.add(self.grid)
self.stat_box = [ [None]*self.aw.ncols for i in range(self.aw.nrows) ]
for r in xrange(self.aw.nrows):
for c in xrange(self.aw.ncols):
self.stat_box[r][c] = Simple_stat(self.aw.stats[r][c])
self.grid.attach(self.stat_box[r][c].widget, c, c+1, r, r+1, xpadding = self.aw.xpad, ypadding = self.aw.ypad)
def update_contents(self, i):
if i == "common": return
player_id = self.aw.get_id_from_seat(i)
if player_id is None: return
for r in xrange(self.aw.nrows):
for c in xrange(self.aw.ncols):
self.stat_box[r][c].update(player_id, self.aw.hud.stat_dict)
class Simple_HUD(Mucked.Aux_Seats):
"""A simple HUD class based on the Aux_Window interface."""
def __init__(self, hud, config, params):
super(Simple_HUD, self).__init__(hud, config, params)
# Save everything you need to know about the hud as attrs.
# That way a subclass doesn't have to grab them.
self.poker_game = self.hud.poker_game
self.game_params = self.hud.config.get_game_parameters(self.hud.poker_game)
self.game = self.hud.config.supported_games[self.hud.poker_game]
self.max = self.hud.max
self.nrows = self.game_params['rows']
self.ncols = self.game_params['cols']
self.xpad = self.game_params['xpad']
self.ypad = self.game_params['ypad']
self.xshift = self.game_params['xshift']
self.yshift = self.game_params['yshift']
self.aw_window_type = Stat_Window
# layout is handled by superclass!
self.stats = [ [None]*self.ncols for i in range(self.nrows) ]
for stat in self.game.stats:
self.stats[self.config.supported_games[self.poker_game].stats[stat].row] \
[self.config.supported_games[self.poker_game].stats[stat].col] = \
self.config.supported_games[self.poker_game].stats[stat].stat_name
def create_contents(self, container, i):
container.create_contents(i)
def update_contents(self, container, i):
container.update_contents(i)
class Simple_stat(object):
"""A simple class for displaying a single stat."""
def __init__(self, stat):
self.stat = stat
self.eb = Simple_eb();
self.lab = Simple_label(self.stat)
self.eb.add(self.lab)
self.widget = self.eb
def update(self, player_id, stat_dict):
self.lab.set_text( str(Stats.do_stat(stat_dict, player_id, self.stat)[1]) )
# Override thise methods to customize your eb or label
class Simple_eb(gtk.EventBox): pass
class Simple_label(gtk.Label): pass

View File

@ -335,6 +335,9 @@ class Stud_cards:
class Seat_Window(gtk.Window): class Seat_Window(gtk.Window):
"""Subclass gtk.Window for the seat windows.""" """Subclass gtk.Window for the seat windows."""
def __init__(self, aw = None):
super(Seat_Window, self).__init__()
self.aw = aw
class Aux_Seats(Aux_Window): class Aux_Seats(Aux_Window):
"""A super class to display an aux_window at each seat.""" """A super class to display an aux_window at each seat."""
@ -348,6 +351,8 @@ class Aux_Seats(Aux_Window):
self.uses_timer = False # the Aux_seats object uses a timer to control hiding self.uses_timer = False # the Aux_seats object uses a timer to control hiding
self.timer_on = False # bool = Ture if the timeout for removing the cards is on self.timer_on = False # bool = Ture if the timeout for removing the cards is on
self.aw_window_type = Seat_Window
# placeholders that should be overridden--so we don't throw errors # placeholders that should be overridden--so we don't throw errors
def create_contents(self): pass def create_contents(self): pass
def update_contents(self): pass def update_contents(self): pass
@ -382,10 +387,10 @@ class Aux_Seats(Aux_Window):
(x, y) = self.params['layout'][self.hud.max].common (x, y) = self.params['layout'][self.hud.max].common
else: else:
(x, y) = loc[self.adj[i]] (x, y) = loc[self.adj[i]]
self.m_windows[i] = Seat_Window() self.m_windows[i] = self.aw_window_type(self)
self.m_windows[i].set_decorated(False) self.m_windows[i].set_decorated(False)
self.m_windows[i].set_property("skip-taskbar-hint", True) self.m_windows[i].set_property("skip-taskbar-hint", True)
self.m_windows[i].set_transient_for(self.hud.main_window) self.m_windows[i].set_transient_for(self.hud.main_window) # FIXME: shouldn't this be the table window??
self.m_windows[i].set_focus_on_map(False) self.m_windows[i].set_focus_on_map(False)
self.m_windows[i].connect("configure_event", self.configure_event_cb, i) self.m_windows[i].connect("configure_event", self.configure_event_cb, i)
self.positions[i] = self.card_positions((x * width) / 1000, self.hud.table.x, (y * height) /1000, self.hud.table.y) self.positions[i] = self.card_positions((x * width) / 1000, self.hud.table.x, (y * height) /1000, self.hud.table.y)