Use debian 2.7 only
[fpbd-bostik.git] / pyfpdb / Aux_Hud.py
blobe1b98eed4f3ade050e3d8b66d4607c7baab2f42e
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 """Aux_Hud.py
5 Aux Hud stats display for FreePokerTools HUD.
6 """
7 # Copyright 2008-2011, Ray E. Barker
8 #
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ########################################################################
25 # to do
27 # Standard Library modules
29 # pyGTK modules
30 import gtk
31 import gobject
32 import logging
34 # FreePokerTools modules
35 import Mucked
36 import Stats
38 log = logging.getLogger("hud")
40 class Stat_Window(Mucked.Seat_Window):
41 """Simple window class for stat windows."""
43 def create_contents(self, i):
44 self.grid = gtk.Table(rows = self.aw.nrows, columns = self.aw.ncols, homogeneous = False)
45 self.add(self.grid)
46 log.debug("Stat_Window rows: "+str(self.aw.rows)+", cols:"+str(self.aw.cols))
47 self.stat_box = [ [None]*self.aw.ncols for i in range(self.aw.nrows) ]
48 for r in xrange(self.aw.nrows):
49 for c in xrange(self.aw.ncols):
50 self.stat_box[r][c] = Simple_stat(self.aw.stats[r*self.aw.ncols+c])
51 self.grid.attach(self.stat_box[r][c].widget, c, c+1, r, r+1, xpadding = self.aw.xpad, ypadding = self.aw.ypad)
53 def update_contents(self, i):
54 if i == "common": return
55 player_id = self.aw.get_id_from_seat(i)
56 if player_id is None: return
57 for r in xrange(self.aw.nrows):
58 for c in xrange(self.aw.ncols):
59 self.stat_box[r][c].update(player_id, self.aw.hud.stat_dict)
61 class Simple_HUD(Mucked.Aux_Seats):
62 """A simple HUD class based on the Aux_Window interface."""
64 def __init__(self, hud, config, params):
65 super(Simple_HUD, self).__init__(hud, config, params)
66 # Save everything you need to know about the hud as attrs.
67 # That way a subclass doesn't have to grab them.
68 self.poker_game = self.hud.poker_game
69 self.game_params = self.hud.config.get_game_parameters(self.hud.poker_game)
70 self.game = self.hud.config.supported_games[self.hud.poker_game]
71 self.max = self.hud.max
72 self.nrows = self.game_params['rows']
73 self.ncols = self.game_params['cols']
74 self.xpad = self.game_params['xpad']
75 self.ypad = self.game_params['ypad']
76 self.xshift = self.game_params['xshift']
77 self.yshift = self.game_params['yshift']
79 self.aw_window_type = Stat_Window
81 # layout is handled by superclass!
82 log.debug("SimpleHUD rows: "+str(self.nrows)+", cols:"+str(self.ncols))
83 self.stats = [None for i in range(self.nrows*self.cols) ]
84 for stat in self.game.stats:
85 log.debug("Simple_HUD stat: "+str(self.config.supported_games[self.poker_game].stats[stat].stat_name))
86 self.stats[self.config.supported_games[self.poker_game].stats[stat].row*self.ncols + \
87 self.config.supported_games[self.poker_game].stats[stat].col] = \
88 self.config.supported_games[self.poker_game].stats[stat].stat_name
90 def create_contents(self, container, i):
91 container.create_contents(i)
93 def update_contents(self, container, i):
94 container.update_contents(i)
96 class Simple_stat(object):
97 """A simple class for displaying a single stat."""
98 def __init__(self, stat):
99 self.stat = stat
100 self.eb = Simple_eb();
101 if self.stat is not None:
102 self.lab = Simple_label(self.stat)
103 else:
104 self.lab = gtk.Label()
105 self.eb.add(self.lab)
106 self.widget = self.eb
108 def update(self, player_id, stat_dict):
109 if self.stat is None:
110 self.lab.set_text( str(" ") )
111 else:
112 self.lab.set_text( str(Stats.do_stat(stat_dict, player_id, self.stat)[1]) )
115 # Override thise methods to customize your eb or label
116 class Simple_eb(gtk.EventBox): pass
117 class Simple_label(gtk.Label): pass