2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/env python
|
2010-07-04 03:05:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-08-19 00:53:25 +02:00
|
|
|
"""Mucked.py
|
|
|
|
|
|
|
|
Mucked cards display for FreePokerTools HUD.
|
|
|
|
"""
|
2010-07-04 03:05:16 +02:00
|
|
|
# Copyright 2008-2010, Ray E. Barker
|
2008-08-19 00:53:25 +02:00
|
|
|
#
|
|
|
|
# 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
|
|
|
|
import sys
|
2009-03-21 00:32:02 +01:00
|
|
|
import pprint
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# pyGTK modules
|
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
# FreePokerTools modules
|
|
|
|
import Configuration
|
|
|
|
import Database
|
2009-06-17 20:24:16 +02:00
|
|
|
import Card
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-06-19 21:47:26 +02:00
|
|
|
class Aux_Window(object):
|
2009-03-05 02:04:23 +01:00
|
|
|
def __init__(self, hud, params, config):
|
2009-03-20 01:58:40 +01:00
|
|
|
self.hud = hud
|
2009-03-25 20:42:16 +01:00
|
|
|
self.params = params
|
2008-11-16 23:53:31 +01:00
|
|
|
self.config = config
|
|
|
|
|
2009-06-23 15:56:29 +02:00
|
|
|
# Override these methods as needed
|
|
|
|
def update_data(self, *args): pass
|
|
|
|
def update_gui(self, *args): pass
|
|
|
|
def create(self, *args): pass
|
|
|
|
def relocate(self, *args): pass
|
|
|
|
def save_layout(self, *args): pass
|
2009-01-26 20:31:08 +01:00
|
|
|
def destroy(self):
|
2009-03-21 17:54:51 +01:00
|
|
|
try:
|
|
|
|
self.container.destroy()
|
|
|
|
except:
|
|
|
|
pass
|
2009-01-26 20:31:08 +01:00
|
|
|
|
2009-03-08 02:44:10 +01:00
|
|
|
############################################################################
|
|
|
|
# Some utility routines useful for Aux_Windows
|
|
|
|
#
|
|
|
|
def get_card_images(self):
|
2009-06-17 20:24:16 +02:00
|
|
|
|
|
|
|
card_images = 53 * [0]
|
|
|
|
suits = ('s', 'h', 'd', 'c')
|
|
|
|
ranks = (14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2)
|
2009-10-22 07:44:45 +02:00
|
|
|
deckimg = self.params['deck']
|
|
|
|
try:
|
|
|
|
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(deckimg))
|
|
|
|
except:
|
|
|
|
stockpath = '/usr/share/python-fpdb/' + deckimg
|
|
|
|
pb = gtk.gdk.pixbuf_new_from_file(stockpath)
|
2009-03-08 02:44:10 +01:00
|
|
|
|
2009-06-17 20:24:16 +02:00
|
|
|
for j in range(0, 13):
|
2009-03-08 02:44:10 +01:00
|
|
|
for i in range(0, 4):
|
2009-06-18 20:11:53 +02:00
|
|
|
card_images[Card.cardFromValueSuit(ranks[j], suits[i])] = self.cropper(pb, i, j)
|
2009-06-17 20:24:16 +02:00
|
|
|
temp_pb = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, pb.get_has_alpha(), pb.get_bits_per_sample(), 30, 42)
|
|
|
|
# also pick out a card back and store in [0]
|
2009-06-18 20:11:53 +02:00
|
|
|
card_images[0] = self.cropper(pb, 2, 13)
|
2009-03-08 02:44:10 +01:00
|
|
|
return(card_images)
|
|
|
|
# cards are 30 wide x 42 high
|
|
|
|
|
2009-06-18 20:11:53 +02:00
|
|
|
def cropper(self, pb, i, j):
|
|
|
|
"""Crop out a card image given an FTP deck and the i, j position."""
|
|
|
|
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)
|
|
|
|
return temp_pb
|
|
|
|
|
2009-03-08 02:44:10 +01:00
|
|
|
def has_cards(self, cards):
|
2009-06-19 21:47:26 +02:00
|
|
|
"""Returns the number of cards in the list."""
|
|
|
|
n = 0
|
2009-03-08 02:44:10 +01:00
|
|
|
for c in cards:
|
2009-06-19 21:47:26 +02:00
|
|
|
if c != None and c > 0: n = n + 1
|
|
|
|
return n
|
2009-03-08 02:44:10 +01:00
|
|
|
|
2009-06-30 17:43:47 +02:00
|
|
|
def get_id_from_seat(self, seat):
|
|
|
|
"""Determine player id from seat number, given stat_dict."""
|
|
|
|
for id, dict in self.hud.stat_dict.iteritems():
|
|
|
|
if seat == dict['seat']:
|
|
|
|
return id
|
|
|
|
return None
|
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
class Stud_mucked(Aux_Window):
|
2009-03-05 02:04:23 +01:00
|
|
|
def __init__(self, hud, config, params):
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-12-08 20:10:45 +01:00
|
|
|
self.hud = hud # hud object that this aux window supports
|
|
|
|
self.config = config # configuration object for this aux window to use
|
2008-12-17 19:24:37 +01:00
|
|
|
self.params = params # hash aux params from config
|
|
|
|
|
|
|
|
try:
|
|
|
|
site_params = self.config.get_site_parameters(self.hud.site)
|
|
|
|
self.hero = site_params['screen_name']
|
|
|
|
except:
|
|
|
|
self.hero = ''
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-05 02:04:23 +01:00
|
|
|
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):
|
|
|
|
|
2009-06-17 20:24:16 +02:00
|
|
|
self.container = gtk.Window()
|
2008-08-19 00:53:25 +02:00
|
|
|
self.vbox = gtk.VBox()
|
2008-12-17 19:24:37 +01:00
|
|
|
self.container.add(self.vbox)
|
2009-06-17 20:24:16 +02:00
|
|
|
self.container.set_title(self.hud.table.name)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-05 02:04:23 +01:00
|
|
|
self.mucked_list.create(self.vbox)
|
|
|
|
self.mucked_cards.create(self.vbox)
|
2008-12-17 19:24:37 +01:00
|
|
|
self.container.show_all()
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
def update_data(self, new_hand_id, db_connection):
|
2010-01-28 20:37:45 +01:00
|
|
|
# uncomment next line when action is available in the db
|
|
|
|
# self.mucked_cards.update_data(new_hand_id, db_connection)
|
2008-12-17 19:24:37 +01:00
|
|
|
self.mucked_list.update_data(new_hand_id, db_connection)
|
2008-11-16 23:53:31 +01:00
|
|
|
|
|
|
|
def update_gui(self, new_hand_id):
|
2008-12-08 20:10:45 +01:00
|
|
|
self.mucked_cards.update_gui(new_hand_id)
|
2008-11-16 23:53:31 +01:00
|
|
|
self.mucked_list.update_gui(new_hand_id)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
class Stud_list:
|
2009-03-05 02:04:23 +01:00
|
|
|
def __init__(self, parent, params, config, hero):
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
self.parent = parent
|
|
|
|
self.params = params
|
2008-11-13 23:07:24 +01:00
|
|
|
self.config = config
|
2008-12-17 19:24:37 +01:00
|
|
|
self.hero = hero
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-05 02:04:23 +01:00
|
|
|
def create(self, container):
|
2008-08-19 00:53:25 +02:00
|
|
|
# set up a scrolled window to hold the listbox
|
2009-03-05 02:04:23 +01:00
|
|
|
self.container = container
|
2008-08-19 00:53:25 +02:00
|
|
|
self.scrolled_window = gtk.ScrolledWindow()
|
|
|
|
self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
|
2008-12-17 19:24:37 +01:00
|
|
|
self.container.add(self.scrolled_window)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# create a ListStore to use as the model
|
2008-12-08 20:10:45 +01:00
|
|
|
self.liststore = gtk.ListStore(str, str, str, str)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.treeview = gtk.TreeView(self.liststore)
|
|
|
|
self.tvcolumn0 = gtk.TreeViewColumn('HandID')
|
|
|
|
self.tvcolumn1 = gtk.TreeViewColumn('Cards')
|
|
|
|
self.tvcolumn2 = gtk.TreeViewColumn('Net')
|
2008-12-08 20:10:45 +01:00
|
|
|
self.tvcolumn3 = gtk.TreeViewColumn('Winner')
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# add tvcolumn to treeview
|
|
|
|
self.treeview.append_column(self.tvcolumn0)
|
|
|
|
self.treeview.append_column(self.tvcolumn1)
|
|
|
|
self.treeview.append_column(self.tvcolumn2)
|
2008-12-08 20:10:45 +01:00
|
|
|
self.treeview.append_column(self.tvcolumn3)
|
2008-08-19 00:53:25 +02:00
|
|
|
|
|
|
|
# create a CellRendererText to render the data
|
|
|
|
self.cell = gtk.CellRendererText()
|
|
|
|
|
|
|
|
# add the cell to the tvcolumn and allow it to expand
|
|
|
|
self.tvcolumn0.pack_start(self.cell, True)
|
|
|
|
self.tvcolumn1.pack_start(self.cell, True)
|
|
|
|
self.tvcolumn2.pack_start(self.cell, True)
|
2008-12-08 20:10:45 +01:00
|
|
|
self.tvcolumn3.pack_start(self.cell, True)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.tvcolumn0.add_attribute(self.cell, 'text', 0)
|
|
|
|
self.tvcolumn1.add_attribute(self.cell, 'text', 1)
|
|
|
|
self.tvcolumn2.add_attribute(self.cell, 'text', 2)
|
2008-12-08 20:10:45 +01:00
|
|
|
self.tvcolumn3.add_attribute(self.cell, 'text', 3)
|
2008-08-19 00:53:25 +02:00
|
|
|
# resize the cols if nec
|
|
|
|
self.tvcolumn0.set_resizable(True)
|
2008-12-08 20:10:45 +01:00
|
|
|
self.tvcolumn1.set_resizable(True)
|
|
|
|
self.tvcolumn2.set_resizable(True)
|
|
|
|
self.tvcolumn3.set_resizable(True)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.treeview.connect("row-activated", self.activated_event)
|
|
|
|
|
|
|
|
self.scrolled_window.add_with_viewport(self.treeview)
|
|
|
|
|
|
|
|
def activated_event(self, path, column, data=None):
|
2008-12-17 19:24:37 +01:00
|
|
|
pass
|
|
|
|
# sel = self.treeview.get_selection()
|
|
|
|
# (model, iter) = sel.get_selected()
|
|
|
|
# self.mucked_cards.update_data(model.get_value(iter, 0))
|
|
|
|
# self.mucked_cards.update_gui(model.get_value(iter, 0))
|
2008-11-16 23:53:31 +01:00
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
def update_data(self, new_hand_id, db_connection):
|
2008-12-08 20:10:45 +01:00
|
|
|
"""Updates the data needed for the list box."""
|
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
# db_connection = Database.Database(self.config, 'fpdb', '')
|
2008-12-08 20:10:45 +01:00
|
|
|
self.winners = db_connection.get_winners_from_hand(new_hand_id)
|
|
|
|
pot = 0
|
|
|
|
winners = ''
|
|
|
|
for player in self.winners.keys():
|
|
|
|
pot = pot + int(self.winners[player])
|
|
|
|
if not winners == '':
|
|
|
|
winners = winners + ", "
|
|
|
|
winners = winners + player
|
|
|
|
pot_dec = "%.2f" % (float(pot)/100)
|
|
|
|
|
2009-02-26 05:35:15 +01:00
|
|
|
hero_cards = self.get_hero_cards(self.parent.hero, self.parent.hud.cards)
|
2008-12-17 19:24:37 +01:00
|
|
|
self.info_row = ((new_hand_id, hero_cards, pot_dec, winners), )
|
|
|
|
|
|
|
|
def get_hero_cards(self, hero, cards):
|
|
|
|
"""Formats the hero cards for inclusion in the tree."""
|
|
|
|
trans = ('0', 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')
|
|
|
|
if hero == '':
|
|
|
|
return "xxxxxx"
|
|
|
|
else:
|
2009-02-26 05:35:15 +01:00
|
|
|
# find the hero's seat from the stat_dict
|
|
|
|
for stat in self.parent.hud.stat_dict.itervalues():
|
|
|
|
if stat['screen_name'] == hero:
|
2009-06-17 20:24:16 +02:00
|
|
|
return Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][0]) +\
|
|
|
|
Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][1]) +\
|
|
|
|
Card.valueSuitFromCard(self.parent.hud.cards[stat['seat']][2])
|
2008-12-17 19:24:37 +01:00
|
|
|
return "xxxxxx"
|
|
|
|
|
2008-11-16 23:53:31 +01:00
|
|
|
def update_gui(self, new_hand_id):
|
|
|
|
iter = self.liststore.append(self.info_row[0])
|
|
|
|
sel = self.treeview.get_selection()
|
|
|
|
sel.select_iter(iter)
|
|
|
|
|
|
|
|
vadj = self.scrolled_window.get_vadjustment()
|
|
|
|
vadj.set_value(vadj.upper)
|
|
|
|
|
|
|
|
class Stud_cards:
|
2009-03-05 02:04:23 +01:00
|
|
|
def __init__(self, parent, params, config):
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
self.parent = parent
|
|
|
|
self.params = params
|
2008-11-13 23:07:24 +01:00
|
|
|
self.config = config
|
2008-12-17 19:24:37 +01:00
|
|
|
# self.db_name = db_name
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-12 22:58:12 +01:00
|
|
|
self.card_images = self.parent.get_card_images()
|
2008-08-19 00:53:25 +02:00
|
|
|
self.seen_cards = {}
|
|
|
|
self.grid_contents = {}
|
|
|
|
self.eb = {}
|
|
|
|
|
|
|
|
self.rows = 8
|
|
|
|
self.cols = 7
|
2009-03-05 02:04:23 +01:00
|
|
|
|
|
|
|
def create(self, container):
|
|
|
|
self.container = container
|
2008-08-19 00:53:25 +02:00
|
|
|
self.grid = gtk.Table(self.rows, self.cols + 4, homogeneous = False)
|
|
|
|
|
|
|
|
for r in range(0, self.rows):
|
|
|
|
for c in range(0, self.cols):
|
2009-06-17 20:24:16 +02:00
|
|
|
self.seen_cards[(c, r)] = gtk.image_new_from_pixbuf(self.card_images[(0)])
|
2008-08-19 00:53:25 +02:00
|
|
|
self.eb[(c, r)]= gtk.EventBox()
|
|
|
|
|
|
|
|
# set up the contents for the cells
|
|
|
|
for r in range(0, self.rows):
|
|
|
|
self.grid_contents[( 0, r)] = gtk.Label("%d" % (r + 1))
|
|
|
|
self.grid_contents[( 1, r)] = gtk.Label("player %d" % (r + 1))
|
2008-12-05 18:51:19 +01:00
|
|
|
self.grid_contents[( 1, r)].set_property("width-chars", 12)
|
2008-08-19 00:53:25 +02:00
|
|
|
self.grid_contents[( 4, r)] = gtk.Label("-")
|
|
|
|
self.grid_contents[( 9, r)] = gtk.Label("-")
|
|
|
|
self.grid_contents[( 2, r)] = self.eb[( 0, r)]
|
|
|
|
self.grid_contents[( 3, r)] = self.eb[( 1, r)]
|
|
|
|
self.grid_contents[( 5, r)] = self.eb[( 2, r)]
|
|
|
|
self.grid_contents[( 6, r)] = self.eb[( 3, r)]
|
|
|
|
self.grid_contents[( 7, r)] = self.eb[( 4, r)]
|
|
|
|
self.grid_contents[( 8, r)] = self.eb[( 5, r)]
|
|
|
|
self.grid_contents[(10, r)] = self.eb[( 6, r)]
|
|
|
|
for c in range(0, self.cols):
|
|
|
|
self.eb[(c, r)].add(self.seen_cards[(c, r)])
|
|
|
|
|
|
|
|
# add the cell contents to the table
|
|
|
|
for c in range(0, self.cols + 4):
|
|
|
|
for r in range(0, self.rows):
|
|
|
|
self.grid.attach(self.grid_contents[(c, r)], c, c+1, r, r+1, xpadding = 1, ypadding = 1)
|
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
self.container.add(self.grid)
|
2008-09-15 22:31:55 +02:00
|
|
|
|
2008-12-17 19:24:37 +01:00
|
|
|
def update_data(self, new_hand_id, db_connection):
|
2008-11-16 23:53:31 +01:00
|
|
|
self.tips = []
|
|
|
|
action = db_connection.get_action_from_hand(new_hand_id)
|
|
|
|
for street in action:
|
|
|
|
temp = ''
|
|
|
|
for act in street:
|
|
|
|
temp = temp + act[0] + " " + act[1] + "s "
|
|
|
|
if act[2] > 0:
|
|
|
|
if act[2]%100 > 0:
|
|
|
|
temp = temp + "%4.2f\n" % (float(act[2])/100)
|
|
|
|
else:
|
|
|
|
temp = temp + "%d\n" % (act[2]/100)
|
|
|
|
else:
|
|
|
|
temp = temp + "\n"
|
|
|
|
self.tips.append(temp)
|
|
|
|
|
|
|
|
def update_gui(self, new_hand_id):
|
2008-12-17 19:24:37 +01:00
|
|
|
self.clear()
|
2009-02-26 05:35:15 +01:00
|
|
|
for c, cards in self.parent.hud.cards.iteritems():
|
2009-07-27 21:41:42 +02:00
|
|
|
if c == 'common': continue
|
2009-02-26 05:35:15 +01:00
|
|
|
self.grid_contents[(1, c - 1)].set_text(self.get_screen_name(c))
|
2009-06-17 20:24:16 +02:00
|
|
|
for i in ((0, cards[0]), (1, cards[1]), (2, cards[2]), (3, cards[3]),
|
|
|
|
(4, cards[4]), (5, cards[5]), (6, cards[6])):
|
|
|
|
if not i[1] == 0:
|
2009-02-26 05:35:15 +01:00
|
|
|
self.seen_cards[(i[0], c - 1)]. \
|
2009-06-17 20:24:16 +02:00
|
|
|
set_from_pixbuf(self.card_images[i[1]])
|
2008-11-16 23:53:31 +01:00
|
|
|
## action in tool tips for 3rd street cards
|
|
|
|
for c in (0, 1, 2):
|
|
|
|
for r in range(0, self.rows):
|
|
|
|
self.eb[(c, r)].set_tooltip_text(self.tips[0])
|
|
|
|
|
|
|
|
# action in tools tips for later streets
|
|
|
|
round_to_col = (0, 3, 4, 5, 6)
|
|
|
|
for round in range(1, len(self.tips)):
|
|
|
|
for r in range(0, self.rows):
|
|
|
|
self.eb[(round_to_col[round], r)].set_tooltip_text(self.tips[round])
|
|
|
|
|
2009-02-26 05:35:15 +01:00
|
|
|
def get_screen_name(self, seat_no):
|
|
|
|
"""Gets and returns the screen name from stat_dict, given seat number."""
|
|
|
|
for k in self.parent.hud.stat_dict.keys():
|
|
|
|
if self.parent.hud.stat_dict[k]['seat'] == seat_no:
|
|
|
|
return self.parent.hud.stat_dict[k]['screen_name']
|
2010-08-15 04:07:34 +02:00
|
|
|
return _("No Name")
|
2009-02-26 05:35:15 +01:00
|
|
|
|
2008-08-19 00:53:25 +02:00
|
|
|
def clear(self):
|
|
|
|
for r in range(0, self.rows):
|
2008-12-03 18:48:04 +01:00
|
|
|
self.grid_contents[(1, r)].set_text(" ")
|
2008-08-19 00:53:25 +02:00
|
|
|
for c in range(0, 7):
|
2009-06-17 20:24:16 +02:00
|
|
|
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[0])
|
2008-08-19 00:53:25 +02:00
|
|
|
self.eb[(c, r)].set_tooltip_text('')
|
2008-12-17 19:24:37 +01:00
|
|
|
|
2009-06-23 15:56:29 +02:00
|
|
|
class Seat_Window(gtk.Window):
|
|
|
|
"""Subclass gtk.Window for the seat windows."""
|
|
|
|
|
2009-06-19 21:47:26 +02:00
|
|
|
class Aux_Seats(Aux_Window):
|
|
|
|
"""A super class to display an aux_window at each seat."""
|
2009-03-08 02:44:10 +01:00
|
|
|
|
|
|
|
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
|
2009-03-15 20:27:47 +01:00
|
|
|
self.params = params # dict aux params from config
|
|
|
|
self.positions = {} # dict of window positions
|
2009-06-23 15:56:29 +02:00
|
|
|
self.displayed = False # the seat windows are displayed
|
|
|
|
self.uses_timer = False # the Aux_seats object uses a timer to control hiding
|
2009-03-21 00:28:57 +01:00
|
|
|
self.timer_on = False # bool = Ture if the timeout for removing the cards is on
|
2009-06-19 21:47:26 +02:00
|
|
|
|
2009-06-23 15:56:29 +02:00
|
|
|
# placeholders that should be overridden--so we don't throw errors
|
|
|
|
def create_contents(self): pass
|
2009-06-25 16:07:40 +02:00
|
|
|
def update_contents(self): pass
|
2009-03-08 02:44:10 +01:00
|
|
|
|
2009-08-15 09:44:04 +02:00
|
|
|
def update_card_positions(self):
|
|
|
|
# self.adj does not exist until .create() has been run
|
|
|
|
try:
|
|
|
|
adj = self.adj
|
|
|
|
except AttributeError:
|
|
|
|
return
|
|
|
|
loc = self.config.get_aux_locations(self.params['name'], int(self.hud.max))
|
2010-01-21 21:14:49 +01:00
|
|
|
width = self.hud.table.width
|
|
|
|
height = self.hud.table.height
|
|
|
|
|
2009-08-15 09:44:04 +02:00
|
|
|
for i in (range(1, self.hud.max + 1) + ['common']):
|
|
|
|
if i == 'common':
|
|
|
|
(x, y) = self.params['layout'][self.hud.max].common
|
|
|
|
else:
|
|
|
|
(x, y) = loc[adj[i]]
|
2010-01-21 21:14:49 +01:00
|
|
|
self.positions[i] = self.card_positions((x * width) / 1000, self.hud.table.x, (y * height) /1000, self.hud.table.y)
|
2009-08-15 09:44:04 +02:00
|
|
|
self.m_windows[i].move(self.positions[i][0], self.positions[i][1])
|
|
|
|
|
2009-03-08 02:44:10 +01:00
|
|
|
def create(self):
|
2009-06-19 21:47:26 +02:00
|
|
|
self.adj = self.hud.adj_seats(0, self.config) # move adj_seats to aux and get rid of it in Hud.py
|
2009-03-08 02:44:10 +01:00
|
|
|
loc = self.config.get_aux_locations(self.params['name'], int(self.hud.max))
|
2008-08-19 00:53:25 +02:00
|
|
|
|
2009-03-09 16:41:58 +01:00
|
|
|
self.m_windows = {} # windows to put the card images in
|
2010-01-21 21:14:49 +01:00
|
|
|
width = self.hud.table.width
|
|
|
|
height = self.hud.table.height
|
2009-03-09 16:41:58 +01:00
|
|
|
for i in (range(1, self.hud.max + 1) + ['common']):
|
|
|
|
if i == 'common':
|
|
|
|
(x, y) = self.params['layout'][self.hud.max].common
|
|
|
|
else:
|
2009-03-15 20:27:47 +01:00
|
|
|
(x, y) = loc[self.adj[i]]
|
2009-06-23 15:56:29 +02:00
|
|
|
self.m_windows[i] = Seat_Window()
|
2009-03-09 16:41:58 +01:00
|
|
|
self.m_windows[i].set_decorated(False)
|
2009-03-08 02:44:10 +01:00
|
|
|
self.m_windows[i].set_property("skip-taskbar-hint", True)
|
|
|
|
self.m_windows[i].set_transient_for(self.hud.main_window)
|
2009-03-09 16:41:58 +01:00
|
|
|
self.m_windows[i].set_focus_on_map(False)
|
2009-03-22 19:05:58 +01:00
|
|
|
self.m_windows[i].connect("configure_event", self.configure_event_cb, i)
|
2010-01-21 21:14:49 +01:00
|
|
|
self.positions[i] = self.card_positions((x * width) / 1000, self.hud.table.x, (y * height) /1000, self.hud.table.y)
|
2009-03-24 00:22:04 +01:00
|
|
|
self.m_windows[i].move(self.positions[i][0], self.positions[i][1])
|
2009-06-30 17:43:47 +02:00
|
|
|
if self.params.has_key('opacity'):
|
|
|
|
self.m_windows[i].set_opacity(float(self.params['opacity']))
|
2009-06-23 15:56:29 +02:00
|
|
|
|
|
|
|
# the create_contents method is supplied by the subclass
|
|
|
|
self.create_contents(self.m_windows[i], i)
|
|
|
|
|
2009-03-08 02:44:10 +01:00
|
|
|
self.m_windows[i].show_all()
|
2009-06-30 17:43:47 +02:00
|
|
|
if self.uses_timer:
|
|
|
|
self.m_windows[i].hide()
|
2009-03-08 02:44:10 +01:00
|
|
|
|
2009-08-15 09:44:04 +02:00
|
|
|
|
|
|
|
def card_positions(self, x, table_x, y, table_y):
|
|
|
|
_x = int(x) + int(table_x)
|
|
|
|
_y = int(y) + int(table_y)
|
|
|
|
return (_x, _y)
|
|
|
|
|
|
|
|
|
2009-06-25 16:07:40 +02:00
|
|
|
def update_gui(self, new_hand_id):
|
|
|
|
"""Update the gui, LDO."""
|
|
|
|
for i in self.m_windows.keys():
|
|
|
|
self.update_contents(self.m_windows[i], i)
|
|
|
|
|
2009-06-23 15:56:29 +02:00
|
|
|
# Methods likely to be of use for any Seat_Window implementation
|
|
|
|
def destroy(self):
|
|
|
|
"""Destroy all of the seat windows."""
|
|
|
|
for i in self.m_windows.keys():
|
|
|
|
self.m_windows[i].destroy()
|
|
|
|
del(self.m_windows[i])
|
|
|
|
|
|
|
|
# Methods likely to be useful for mucked card windows (or similar) only
|
|
|
|
def hide(self):
|
|
|
|
"""Hide the seat windows."""
|
|
|
|
for (i, w) in self.m_windows.iteritems():
|
|
|
|
w.hide()
|
|
|
|
self.displayed = False
|
|
|
|
|
2009-06-25 16:07:40 +02:00
|
|
|
def save_layout(self, *args):
|
|
|
|
"""Save new layout back to the aux element in the config file."""
|
|
|
|
new_locs = {}
|
|
|
|
# print "adj =", self.adj
|
2010-01-21 21:14:49 +01:00
|
|
|
witdh = self.hud.table.width
|
|
|
|
height = self.hud.table.height
|
2009-06-25 16:07:40 +02:00
|
|
|
for (i, pos) in self.positions.iteritems():
|
2010-01-21 21:14:49 +01:00
|
|
|
if i != 'common':
|
|
|
|
new_locs[self.adj[int(i)]] = ((pos[0] - self.hud.table.x) * 1000 / witdh, (pos[1] - self.hud.table.y) * 1000 / height)
|
|
|
|
else:
|
|
|
|
new_locs[i] = ((pos[0] - self.hud.table.x) * 1000 / witdh, (pos[1] - self.hud.table.y) * 1000 / height)
|
2009-06-25 16:07:40 +02:00
|
|
|
self.config.edit_aux_layout(self.params['name'], self.hud.max, locations = new_locs)
|
|
|
|
|
2009-06-30 17:43:47 +02:00
|
|
|
def configure_event_cb(self, widget, event, i, *args):
|
|
|
|
self.positions[i] = widget.get_position()
|
|
|
|
# self.rel_positions[i] = (self.positions[i][0] - self.hud.table.x, self.positions[i][1] - self.hud.table.y)
|
|
|
|
|
2009-06-23 15:56:29 +02:00
|
|
|
class Flop_Mucked(Aux_Seats):
|
|
|
|
"""Aux_Window class for displaying mucked cards for flop games."""
|
|
|
|
|
|
|
|
def __init__(self, hud, config, params):
|
|
|
|
super(Flop_Mucked, self).__init__(hud, config, params)
|
|
|
|
self.card_images = self.get_card_images()
|
|
|
|
self.uses_timer = True # this Aux_seats object uses a timer to control hiding
|
|
|
|
|
|
|
|
def create_contents(self, container, i):
|
2009-06-19 21:47:26 +02:00
|
|
|
"""Create the widgets for showing the contents of the Aux_seats window."""
|
2009-06-23 15:56:29 +02:00
|
|
|
container.eb = gtk.EventBox()
|
|
|
|
container.eb.connect("button_press_event", self.button_press_cb)
|
|
|
|
container.add(container.eb)
|
|
|
|
container.seen_cards = gtk.image_new_from_pixbuf(self.card_images[0])
|
|
|
|
container.eb.add(container.seen_cards)
|
2009-06-19 21:47:26 +02:00
|
|
|
|
2009-06-25 16:07:40 +02:00
|
|
|
def update_contents(self, container, i):
|
|
|
|
if not self.hud.cards.has_key(i): return
|
|
|
|
cards = self.hud.cards[i]
|
|
|
|
n_cards = self.has_cards(cards)
|
|
|
|
if n_cards > 1:
|
|
|
|
|
|
|
|
# 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'])*n_cards,
|
|
|
|
int(self.params['card_ht']))
|
|
|
|
x = 0 # x coord where the next card starts in scratch
|
|
|
|
for card in cards:
|
|
|
|
# concatenate each card image to scratch
|
|
|
|
if card == None or card ==0:
|
|
|
|
break
|
|
|
|
self.card_images[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'])
|
|
|
|
container.seen_cards.set_from_pixbuf(scratch)
|
|
|
|
container.resize(1,1)
|
|
|
|
container.show()
|
|
|
|
container.move(self.positions[i][0], self.positions[i][1]) # here is where I move back
|
|
|
|
self.displayed = True
|
|
|
|
if i != "common":
|
2009-07-01 14:29:37 +02:00
|
|
|
id = self.get_id_from_seat(i)
|
2009-08-17 22:51:13 +02:00
|
|
|
# sc: had KeyError here with new table so added id != None test as a guess:
|
2009-11-03 20:30:52 +01:00
|
|
|
if id is not None:
|
2009-08-17 22:51:13 +02:00
|
|
|
self.m_windows[i].eb.set_tooltip_text(self.hud.stat_dict[id]['screen_name'])
|
2009-06-25 16:07:40 +02:00
|
|
|
|
2009-03-08 02:44:10 +01:00
|
|
|
def update_gui(self, new_hand_id):
|
|
|
|
"""Prepare and show the mucked cards."""
|
2009-06-23 15:56:29 +02:00
|
|
|
if self.displayed: self.hide()
|
|
|
|
|
|
|
|
# See how many players showed a hand. Skip if only 1 shows (= hero)
|
|
|
|
n_sd = 0
|
|
|
|
for (i, cards) in self.hud.cards.iteritems():
|
|
|
|
n_cards = self.has_cards(cards)
|
2009-07-01 14:29:37 +02:00
|
|
|
if n_cards > 0 and i != 'common':
|
2009-06-23 15:56:29 +02:00
|
|
|
n_sd = n_sd + 1
|
2009-06-25 16:07:40 +02:00
|
|
|
if n_sd < 2:
|
|
|
|
return
|
2009-06-23 15:56:29 +02:00
|
|
|
|
2009-06-25 16:07:40 +02:00
|
|
|
super(Flop_Mucked, self).update_gui(new_hand_id)
|
2009-03-21 00:32:02 +01:00
|
|
|
|
2009-06-19 21:47:26 +02:00
|
|
|
if self.displayed and float(self.params['timeout']) > 0:
|
2009-03-21 00:28:57 +01:00
|
|
|
self.timer_on = True
|
|
|
|
gobject.timeout_add(int(1000*float(self.params['timeout'])), self.timed_out)
|
2009-03-08 02:44:10 +01:00
|
|
|
|
2009-03-21 00:28:57 +01:00
|
|
|
def timed_out(self):
|
|
|
|
# this is the callback from the timeout
|
|
|
|
|
|
|
|
# if timer_on is False the user has cancelled the timer with a click
|
|
|
|
# so just return False to cancel the timer
|
|
|
|
if not self.timer_on:
|
|
|
|
return False
|
|
|
|
else:
|
2009-06-23 15:56:29 +02:00
|
|
|
self.hide()
|
2009-03-21 00:28:57 +01:00
|
|
|
return False
|
|
|
|
|
2009-03-09 16:41:58 +01:00
|
|
|
def button_press_cb(self, widget, event, *args):
|
|
|
|
"""Handle button clicks in the event boxes."""
|
2009-03-21 00:28:57 +01:00
|
|
|
|
|
|
|
# shift-any button exposes all the windows and turns off the timer
|
|
|
|
if event.state & gtk.gdk.SHIFT_MASK:
|
|
|
|
self.timer_on = False
|
|
|
|
self.expose_all()
|
2009-03-21 17:54:51 +01:00
|
|
|
return
|
2009-03-21 00:28:57 +01:00
|
|
|
|
2009-03-09 16:41:58 +01:00
|
|
|
if event.button == 3: # right button event
|
|
|
|
pass
|
|
|
|
|
|
|
|
elif event.button == 2: # middle button event
|
2009-03-21 00:28:57 +01:00
|
|
|
if self.timer_on == True:
|
|
|
|
self.timer_on = False
|
|
|
|
else:
|
|
|
|
self.timer_on = False
|
2009-06-23 15:56:29 +02:00
|
|
|
self.hide()
|
2009-03-09 16:41:58 +01:00
|
|
|
|
|
|
|
elif event.button == 1: # left button event
|
|
|
|
window = widget.get_parent()
|
|
|
|
window.begin_move_drag(event.button, int(event.x_root), int(event.y_root), event.time)
|
|
|
|
|
2009-03-21 00:28:57 +01:00
|
|
|
def expose_all(self):
|
|
|
|
for (i, cards) in self.hud.cards.iteritems():
|
2009-03-23 22:13:32 +01:00
|
|
|
self.m_windows[i].show()
|
2009-03-21 00:28:57 +01:00
|
|
|
self.m_windows[i].move(self.positions[i][0], self.positions[i][1]) # here is where I move back
|
2009-06-19 21:47:26 +02:00
|
|
|
self.displayed = True
|