2010-07-08 20:01:03 +02:00
#!/usr/bin/env python
2009-08-09 22:26:24 +02:00
# -*- coding: utf-8 -*-
2008-08-19 00:53:25 +02:00
""" Hud.py
Create and manage the hud overlays .
"""
2010-07-04 03:05:16 +02:00
# Copyright 2008-2010 Ray E. Barker
2008-08-19 00:53:25 +02:00
2009-11-24 12:08:43 +01:00
#
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.
2009-11-24 12:08:43 +01:00
#
2008-08-19 00:53:25 +02:00
# 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.
2009-11-24 12:08:43 +01:00
#
2008-08-19 00:53:25 +02:00
# 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
########################################################################
2010-09-23 08:10:30 +02:00
import L10n
_ = L10n . get_translation ( )
2008-08-19 00:53:25 +02:00
# Standard Library modules
2008-09-15 22:31:55 +02:00
import os
2008-10-24 21:44:53 +02:00
import sys
2008-08-19 00:53:25 +02:00
2010-02-06 19:46:27 +01:00
import logging
# logging has been set up in fpdb.py or HUD_main.py, use their settings:
log = logging . getLogger ( " hud " )
2008-08-19 00:53:25 +02:00
# pyGTK modules
import pygtk
import gtk
import pango
import gobject
2008-09-15 22:31:55 +02:00
# win32 modules -- only imported on windows systems
if os . name == ' nt ' :
import win32gui
import win32con
2008-10-26 10:34:36 +01:00
import win32api
2008-09-15 22:31:55 +02:00
2008-08-19 00:53:25 +02:00
# FreePokerTools modules
import Configuration
import Stats
import Mucked
import Database
2009-06-15 05:14:53 +02:00
#import HUD_main
2008-08-19 00:53:25 +02:00
2010-09-27 11:08:34 +02:00
2009-03-05 02:04:23 +01:00
def importName ( module_name , name ) :
""" Import a named object ' name ' from module ' module_name ' . """
# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!!
2009-03-14 03:06:47 +01:00
2009-03-05 02:04:23 +01:00
try :
module = __import__ ( module_name , globals ( ) , locals ( ) , [ name ] )
except :
return None
return ( getattr ( module , name ) )
2009-11-24 12:08:43 +01:00
2010-09-27 11:08:34 +02:00
class Hud :
2009-02-22 00:19:49 +01:00
def __init__ ( self , parent , table , max , poker_game , config , db_connection ) :
2009-02-27 18:42:49 +01:00
# __init__ is (now) intended to be called from the stdin thread, so it
# cannot touch the gui
2010-09-27 11:08:34 +02:00
if parent is None : # running from cli ..
2009-08-06 05:57:26 +02:00
self . parent = self
2010-08-31 10:56:28 +02:00
else :
self . parent = parent
2008-08-19 00:53:25 +02:00
self . table = table
self . config = config
self . poker_game = poker_game
self . max = max
2008-12-17 19:24:37 +01:00
self . db_connection = db_connection
2008-09-15 22:31:55 +02:00
self . deleted = False
2008-10-22 03:46:30 +02:00
self . stacked = True
2008-12-08 20:10:45 +01:00
self . site = table . site
2009-02-27 18:42:49 +01:00
self . mw_created = False
2009-09-26 12:30:12 +02:00
self . hud_params = parent . hud_params
2009-11-24 12:08:43 +01:00
2009-02-27 18:42:49 +01:00
self . stat_windows = { }
2008-09-15 22:31:55 +02:00
self . popup_windows = { }
2009-02-27 18:42:49 +01:00
self . aux_windows = [ ]
2009-11-24 12:08:43 +01:00
2010-08-31 10:56:28 +02:00
# configure default font and colors from the configuration
2008-12-18 03:57:05 +01:00
( font , font_size ) = config . get_default_font ( self . table . site )
2009-02-27 18:42:49 +01:00
self . colors = config . get_default_colors ( self . table . site )
2009-10-03 20:05:41 +02:00
self . hud_ui = config . get_hud_ui_parameters ( )
2010-06-12 12:15:02 +02:00
self . site_params = config . get_site_parameters ( self . table . site )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
self . backgroundcolor = gtk . gdk . color_parse ( self . colors [ ' hudbgcolor ' ] )
self . foregroundcolor = gtk . gdk . color_parse ( self . colors [ ' hudfgcolor ' ] )
2009-03-24 10:19:20 +01:00
self . font = pango . FontDescription ( " %s %s " % ( font , font_size ) )
2008-12-21 12:49:34 +01:00
# do we need to add some sort of condition here for dealing with a request for a font that doesn't exist?
2008-10-29 15:35:47 +01:00
2009-03-05 02:04:23 +01:00
game_params = config . get_game_parameters ( self . poker_game )
2010-08-31 10:56:28 +02:00
# if there are AUX windows configured, set them up (Ray knows how this works, if anyone needs info)
2009-03-06 00:43:00 +01:00
if not game_params [ ' aux ' ] == [ " " ] :
2009-03-05 02:04:23 +01:00
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 ) )
2009-11-24 12:08:43 +01:00
2009-08-09 22:26:24 +02:00
self . creation_attrs = None
2009-03-05 02:04:23 +01:00
2009-02-27 18:42:49 +01:00
def create_mw ( self ) :
2008-10-29 15:35:47 +01:00
# Set up a main window for this this instance of the HUD
2009-09-03 16:35:59 +02:00
win = gtk . Window ( )
2010-09-27 11:08:34 +02:00
win . set_skip_taskbar_hint ( True ) # invisible to taskbar
2009-09-03 16:35:59 +02:00
win . set_gravity ( gtk . gdk . GRAVITY_STATIC )
2010-08-31 10:56:28 +02:00
win . set_title ( " %s FPDBHUD " % ( self . table . name ) ) # give it a title that we can easily filter out in the window list when Table search code is looking
2010-09-27 11:08:34 +02:00
win . set_decorated ( False ) # kill titlebars
win . set_opacity ( self . colors [ " hudopacity " ] ) # set it to configured hud opacity
2010-08-31 10:56:28 +02:00
win . set_focus ( None )
win . set_focus_on_map ( False )
win . set_accept_focus ( False )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
eventbox = gtk . EventBox ( )
2009-10-03 20:05:41 +02:00
label = gtk . Label ( self . hud_ui [ ' label ' ] )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
win . add ( eventbox )
eventbox . add ( label )
2009-11-24 12:08:43 +01:00
2010-08-31 10:56:28 +02:00
# set it to the desired color of the HUD for this site
2009-09-03 16:35:59 +02:00
label . modify_bg ( gtk . STATE_NORMAL , self . backgroundcolor )
label . modify_fg ( gtk . STATE_NORMAL , self . foregroundcolor )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
eventbox . modify_bg ( gtk . STATE_NORMAL , self . backgroundcolor )
eventbox . modify_fg ( gtk . STATE_NORMAL , self . foregroundcolor )
2008-10-27 11:29:39 +01:00
2009-09-03 16:35:59 +02:00
self . main_window = win
2010-08-31 10:56:28 +02:00
# move it to the table window's X/Y position (0,0 on the table window usually)
2008-09-15 22:31:55 +02:00
self . main_window . move ( self . table . x , self . table . y )
2009-01-06 02:26:39 +01:00
# A popup menu for the main window
2010-08-31 10:56:28 +02:00
# This menu code has become extremely long - is there a better way to do this?
2009-09-03 16:35:59 +02:00
menu = gtk . Menu ( )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
killitem = gtk . MenuItem ( _ ( ' Kill This HUD ' ) )
2009-09-03 16:35:59 +02:00
menu . append ( killitem )
2009-11-03 20:30:52 +01:00
if self . parent is not None :
2009-09-03 16:35:59 +02:00
killitem . connect ( " activate " , self . parent . kill_hud , self . table_name )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
saveitem = gtk . MenuItem ( _ ( ' Save HUD Layout ' ) )
2009-09-03 16:35:59 +02:00
menu . append ( saveitem )
saveitem . connect ( " activate " , self . save_layout )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
repositem = gtk . MenuItem ( _ ( ' Reposition StatWindows ' ) )
2009-09-03 16:35:59 +02:00
menu . append ( repositem )
repositem . connect ( " activate " , self . reposition_windows )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
aggitem = gtk . MenuItem ( _ ( ' Show Player Stats ' ) )
2009-09-27 22:23:00 +02:00
menu . append ( aggitem )
2009-09-29 00:59:17 +02:00
self . aggMenu = gtk . Menu ( )
aggitem . set_submenu ( self . aggMenu )
2009-09-27 22:23:00 +02:00
# set agg_bb_mult to 1 to stop aggregation
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' For This Blind Level Only ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2010-09-27 11:08:34 +02:00
item . connect ( " activate " , self . set_aggregation , ( ' P ' , 1 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_aggBBmultItem1 ' , item )
2010-09-27 11:08:34 +02:00
2010-08-17 19:53:08 +02:00
item = gtk . MenuItem ( _ ( ' For Multiple Blind Levels: ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.5 to 2.0 x Current Blinds ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_aggregation , ( ' P ' , 2 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_aggBBmultItem2 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.33 to 3.0 x Current Blinds ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_aggregation , ( ' P ' , 3 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_aggBBmultItem3 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.1 to 10 x Current Blinds ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_aggregation , ( ' P ' , 10 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_aggBBmultItem10 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' All Levels ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_aggregation , ( ' P ' , 10000 ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' h_aggBBmultItem10000 ' , item )
2010-08-17 19:53:08 +02:00
2010-08-17 20:05:12 +02:00
item = gtk . MenuItem ( _ ( ' For #Seats: ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Any Number ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' P ' , ' A ' ) )
setattr ( self , ' h_seatsStyleOptionA ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Custom ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' P ' , ' C ' ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' h_seatsStyleOptionC ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Exact ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' P ' , ' E ' ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' h_seatsStyleOptionE ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . MenuItem ( _ ( ' Since: ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' All Time ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_hud_style , ( ' P ' , ' A ' ) )
setattr ( self , ' h_hudStyleOptionA ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Session ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_hud_style , ( ' P ' , ' S ' ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_hudStyleOptionS ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' %s Days ' ) % ( self . hud_params [ ' h_hud_days ' ] ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_hud_style , ( ' P ' , ' T ' ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' h_hudStyleOptionT ' , item )
2010-08-17 19:53:08 +02:00
aggitem = gtk . MenuItem ( _ ( ' Show Opponent Stats ' ) )
2009-10-04 13:26:37 +02:00
menu . append ( aggitem )
self . aggMenu = gtk . Menu ( )
aggitem . set_submenu ( self . aggMenu )
# set agg_bb_mult to 1 to stop aggregation
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' For This Blind Level Only ' ) )
2009-10-04 13:26:37 +02:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_aggregation , ( ' O ' , 1 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' aggBBmultItem1 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . MenuItem ( _ ( ' For Multiple Blind Levels: ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.5 to 2.0 x Current Blinds ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_aggregation , ( ' O ' , 2 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' aggBBmultItem2 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.33 to 3.0 x Current Blinds ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_aggregation , ( ' O ' , 3 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' aggBBmultItem3 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' 0.1 to 10 x Current Blinds ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_aggregation , ( ' O ' , 10 ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' aggBBmultItem10 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' All Levels ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_aggregation , ( ' O ' , 10000 ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' aggBBmultItem10000 ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . MenuItem ( _ ( ' For #Seats: ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Any Number ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' O ' , ' A ' ) )
setattr ( self , ' seatsStyleOptionA ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Custom ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' O ' , ' C ' ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' seatsStyleOptionC ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Exact ' ) )
2009-11-26 23:24:24 +01:00
self . aggMenu . append ( item )
item . connect ( " activate " , self . set_seats_style , ( ' O ' , ' E ' ) )
2009-12-03 13:24:12 +01:00
setattr ( self , ' seatsStyleOptionE ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . MenuItem ( _ ( ' Since: ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' All Time ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_hud_style , ( ' O ' , ' A ' ) )
setattr ( self , ' hudStyleOptionA ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' Session ' ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_hud_style , ( ' O ' , ' S ' ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' hudStyleOptionS ' , item )
2010-08-17 19:53:08 +02:00
item = gtk . CheckMenuItem ( _ ( ' %s Days ' ) % ( self . hud_params [ ' h_hud_days ' ] ) )
2009-09-29 00:59:17 +02:00
self . aggMenu . append ( item )
2009-10-04 13:26:37 +02:00
item . connect ( " activate " , self . set_hud_style , ( ' O ' , ' T ' ) )
2009-11-24 12:08:43 +01:00
setattr ( self , ' hudStyleOptionT ' , item )
2009-10-01 22:40:14 +02:00
# set active on current options:
2009-10-04 13:26:37 +02:00
if self . hud_params [ ' h_agg_bb_mult ' ] == 1 :
getattr ( self , ' h_aggBBmultItem1 ' ) . set_active ( True )
elif self . hud_params [ ' h_agg_bb_mult ' ] == 2 :
getattr ( self , ' h_aggBBmultItem2 ' ) . set_active ( True )
elif self . hud_params [ ' h_agg_bb_mult ' ] == 3 :
getattr ( self , ' h_aggBBmultItem3 ' ) . set_active ( True )
elif self . hud_params [ ' h_agg_bb_mult ' ] == 10 :
getattr ( self , ' h_aggBBmultItem10 ' ) . set_active ( True )
elif self . hud_params [ ' h_agg_bb_mult ' ] > 9000 :
2009-10-08 00:45:59 +02:00
getattr ( self , ' h_aggBBmultItem10000 ' ) . set_active ( True )
2010-08-17 19:53:08 +02:00
2009-10-01 22:40:14 +02:00
if self . hud_params [ ' agg_bb_mult ' ] == 1 :
getattr ( self , ' aggBBmultItem1 ' ) . set_active ( True )
elif self . hud_params [ ' agg_bb_mult ' ] == 2 :
getattr ( self , ' aggBBmultItem2 ' ) . set_active ( True )
elif self . hud_params [ ' agg_bb_mult ' ] == 3 :
getattr ( self , ' aggBBmultItem3 ' ) . set_active ( True )
elif self . hud_params [ ' agg_bb_mult ' ] == 10 :
getattr ( self , ' aggBBmultItem10 ' ) . set_active ( True )
elif self . hud_params [ ' agg_bb_mult ' ] > 9000 :
2009-10-08 00:45:59 +02:00
getattr ( self , ' aggBBmultItem10000 ' ) . set_active ( True )
2010-08-17 19:53:08 +02:00
2009-11-26 23:24:24 +01:00
if self . hud_params [ ' h_seats_style ' ] == ' A ' :
getattr ( self , ' h_seatsStyleOptionA ' ) . set_active ( True )
elif self . hud_params [ ' h_seats_style ' ] == ' C ' :
getattr ( self , ' h_seatsStyleOptionC ' ) . set_active ( True )
elif self . hud_params [ ' h_seats_style ' ] == ' E ' :
getattr ( self , ' h_seatsStyleOptionE ' ) . set_active ( True )
2010-08-17 19:53:08 +02:00
2009-11-26 23:24:24 +01:00
if self . hud_params [ ' seats_style ' ] == ' A ' :
getattr ( self , ' seatsStyleOptionA ' ) . set_active ( True )
elif self . hud_params [ ' seats_style ' ] == ' C ' :
getattr ( self , ' seatsStyleOptionC ' ) . set_active ( True )
elif self . hud_params [ ' seats_style ' ] == ' E ' :
getattr ( self , ' seatsStyleOptionE ' ) . set_active ( True )
2010-08-17 19:53:08 +02:00
2009-09-30 00:34:52 +02:00
if self . hud_params [ ' h_hud_style ' ] == ' A ' :
2009-10-04 13:26:37 +02:00
getattr ( self , ' h_hudStyleOptionA ' ) . set_active ( True )
2009-10-01 22:40:14 +02:00
elif self . hud_params [ ' h_hud_style ' ] == ' S ' :
2009-10-04 13:26:37 +02:00
getattr ( self , ' h_hudStyleOptionS ' ) . set_active ( True )
2009-10-01 22:40:14 +02:00
elif self . hud_params [ ' h_hud_style ' ] == ' T ' :
2009-10-04 13:26:37 +02:00
getattr ( self , ' h_hudStyleOptionT ' ) . set_active ( True )
2010-08-17 19:53:08 +02:00
2009-10-04 13:26:37 +02:00
if self . hud_params [ ' hud_style ' ] == ' A ' :
getattr ( self , ' hudStyleOptionA ' ) . set_active ( True )
elif self . hud_params [ ' hud_style ' ] == ' S ' :
getattr ( self , ' hudStyleOptionS ' ) . set_active ( True )
elif self . hud_params [ ' hud_style ' ] == ' T ' :
getattr ( self , ' hudStyleOptionT ' ) . set_active ( True )
2009-11-24 12:08:43 +01:00
2009-09-27 22:23:00 +02:00
eventbox . connect_object ( " button-press-event " , self . on_button_press , menu )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
debugitem = gtk . MenuItem ( _ ( ' Debug StatWindows ' ) )
2009-09-03 16:35:59 +02:00
menu . append ( debugitem )
debugitem . connect ( " activate " , self . debug_stat_windows )
2009-11-24 12:08:43 +01:00
2010-08-17 19:53:08 +02:00
item5 = gtk . MenuItem ( _ ( ' Set max seats ' ) )
2009-09-03 16:35:59 +02:00
menu . append ( item5 )
maxSeatsMenu = gtk . Menu ( )
item5 . set_submenu ( maxSeatsMenu )
2009-08-09 22:26:24 +02:00
for i in range ( 2 , 11 , 1 ) :
item = gtk . MenuItem ( ' %d -max ' % i )
item . ms = i
2009-09-03 16:35:59 +02:00
maxSeatsMenu . append ( item )
2009-08-09 22:26:24 +02:00
item . connect ( " activate " , self . change_max_seats )
2010-09-27 11:08:34 +02:00
setattr ( self , ' maxSeatsMenuItem %d ' % ( i - 1 ) , item )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
eventbox . connect_object ( " button-press-event " , self . on_button_press , menu )
2008-09-15 22:31:55 +02:00
2009-02-27 18:42:49 +01:00
self . mw_created = True
2009-09-03 16:35:59 +02:00
self . label = label
menu . show_all ( )
self . main_window . show_all ( )
2011-03-03 13:39:04 +01:00
# self.topify_window(self.main_window)
2009-11-24 12:08:43 +01:00
2009-08-09 22:26:24 +02:00
def change_max_seats ( self , widget ) :
if self . max != widget . ms :
2009-12-03 13:24:12 +01:00
#print 'change_max_seats', widget.ms
2009-08-09 22:26:24 +02:00
self . max = widget . ms
try :
self . kill ( )
self . create ( * self . creation_attrs )
self . update ( self . hand , self . config )
except Exception , e :
2010-02-06 19:46:27 +01:00
log . error ( " Exception: " , str ( e ) )
2009-08-09 22:26:24 +02:00
pass
2009-09-27 22:23:00 +02:00
2009-10-02 00:16:20 +02:00
def set_aggregation ( self , widget , val ) :
2009-10-04 13:26:37 +02:00
( player_opp , num ) = val
if player_opp == ' P ' :
# set these true all the time, set the multiplier to 1 to turn agg off:
self . hud_params [ ' h_aggregate_ring ' ] = True
self . hud_params [ ' h_aggregate_tour ' ] = True
if self . hud_params [ ' h_agg_bb_mult ' ] != num \
and getattr ( self , ' h_aggBBmultItem ' + str ( num ) ) . get_active ( ) :
2010-10-12 05:42:05 +02:00
log . debug ( ' set_player_aggregation %d ' , num )
2009-10-04 13:26:37 +02:00
self . hud_params [ ' h_agg_bb_mult ' ] = num
for mult in ( ' 1 ' , ' 2 ' , ' 3 ' , ' 10 ' , ' 10000 ' ) :
if mult != str ( num ) :
getattr ( self , ' h_aggBBmultItem ' + mult ) . set_active ( False )
else :
self . hud_params [ ' aggregate_ring ' ] = True
self . hud_params [ ' aggregate_tour ' ] = True
2009-09-27 22:23:00 +02:00
2009-10-04 13:26:37 +02:00
if self . hud_params [ ' agg_bb_mult ' ] != num \
and getattr ( self , ' aggBBmultItem ' + str ( num ) ) . get_active ( ) :
2010-10-12 04:23:06 +02:00
log . debug ( ' set_opponent_aggregation %d ' , num )
2009-10-04 13:26:37 +02:00
self . hud_params [ ' agg_bb_mult ' ] = num
for mult in ( ' 1 ' , ' 2 ' , ' 3 ' , ' 10 ' , ' 10000 ' ) :
if mult != str ( num ) :
getattr ( self , ' aggBBmultItem ' + mult ) . set_active ( False )
2009-09-27 22:23:00 +02:00
2009-11-26 23:24:24 +01:00
def set_seats_style ( self , widget , val ) :
( player_opp , style ) = val
if player_opp == ' P ' :
param = ' h_seats_style '
prefix = ' h_ '
else :
param = ' seats_style '
prefix = ' '
2009-12-03 13:24:12 +01:00
2009-11-26 23:24:24 +01:00
if style == ' A ' and getattr ( self , prefix + ' seatsStyleOptionA ' ) . get_active ( ) :
self . hud_params [ param ] = ' A '
getattr ( self , prefix + ' seatsStyleOptionC ' ) . set_active ( False )
getattr ( self , prefix + ' seatsStyleOptionE ' ) . set_active ( False )
elif style == ' C ' and getattr ( self , prefix + ' seatsStyleOptionC ' ) . get_active ( ) :
self . hud_params [ param ] = ' C '
getattr ( self , prefix + ' seatsStyleOptionA ' ) . set_active ( False )
getattr ( self , prefix + ' seatsStyleOptionE ' ) . set_active ( False )
elif style == ' E ' and getattr ( self , prefix + ' seatsStyleOptionE ' ) . get_active ( ) :
self . hud_params [ param ] = ' E '
getattr ( self , prefix + ' seatsStyleOptionA ' ) . set_active ( False )
getattr ( self , prefix + ' seatsStyleOptionC ' ) . set_active ( False )
2010-02-06 19:46:27 +01:00
log . debug ( " setting self.hud_params[ %s ] = %s " % ( param , style ) )
2009-11-26 23:24:24 +01:00
2009-09-30 00:34:52 +02:00
def set_hud_style ( self , widget , val ) :
2009-10-04 13:26:37 +02:00
( player_opp , style ) = val
if player_opp == ' P ' :
2009-09-29 00:59:17 +02:00
param = ' h_hud_style '
2009-10-04 13:26:37 +02:00
prefix = ' h_ '
2009-09-29 00:59:17 +02:00
else :
param = ' hud_style '
2009-10-04 13:26:37 +02:00
prefix = ' '
2009-11-24 12:08:43 +01:00
2009-10-04 13:26:37 +02:00
if style == ' A ' and getattr ( self , prefix + ' hudStyleOptionA ' ) . get_active ( ) :
2009-09-30 00:34:52 +02:00
self . hud_params [ param ] = ' A '
2009-10-04 13:26:37 +02:00
getattr ( self , prefix + ' hudStyleOptionS ' ) . set_active ( False )
getattr ( self , prefix + ' hudStyleOptionT ' ) . set_active ( False )
elif style == ' S ' and getattr ( self , prefix + ' hudStyleOptionS ' ) . get_active ( ) :
2009-09-30 00:34:52 +02:00
self . hud_params [ param ] = ' S '
2009-10-04 13:26:37 +02:00
getattr ( self , prefix + ' hudStyleOptionA ' ) . set_active ( False )
getattr ( self , prefix + ' hudStyleOptionT ' ) . set_active ( False )
elif style == ' T ' and getattr ( self , prefix + ' hudStyleOptionT ' ) . get_active ( ) :
2009-09-30 00:34:52 +02:00
self . hud_params [ param ] = ' T '
2009-10-04 13:26:37 +02:00
getattr ( self , prefix + ' hudStyleOptionA ' ) . set_active ( False )
getattr ( self , prefix + ' hudStyleOptionS ' ) . set_active ( False )
2010-02-06 19:46:27 +01:00
log . debug ( " setting self.hud_params[ %s ] = %s " % ( param , style ) )
2009-09-29 00:59:17 +02:00
2008-12-09 13:51:41 +01:00
def update_table_position ( self ) :
2010-08-31 10:56:28 +02:00
# get table's X/Y position on the desktop, and relocate all of our child windows to accomodate
# In Windows, we can verify the existence of a Window, with win32gui.IsWindow(). In Linux, there doesn't seem to be a
# way to verify the existence of a Window, without trying to access it, which if it doesn't exist anymore, results in a
# big giant X trap and crash.
# People tell me this is a bad idea, because theoretically, IsWindow() could return true now, but not be true when we actually
# use it, but accessing a dead window doesn't result in a complete windowing system shutdown in Windows, whereas it does
# in X. - Eric
2008-12-15 08:04:35 +01:00
if os . name == ' nt ' :
if not win32gui . IsWindow ( self . table . number ) :
2009-03-01 00:46:54 +01:00
self . parent . kill_hud ( self , self . table . name )
2010-03-17 22:38:40 +01:00
self . parent . kill_hud ( self , self . table . name . split ( " " ) [ 0 ] )
#table.name is only a valid handle for ring games ! we are not killing tourney tables here.
2008-12-15 08:04:35 +01:00
return False
2008-12-21 12:49:34 +01:00
# anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window?
2009-09-03 16:35:59 +02:00
if self . table . gdkhandle is not None :
2010-09-27 10:04:56 +02:00
( oldx , oldy ) = self . table . gdkhandle . get_origin ( ) # In Windows, this call returns (0,0) if it's an invalid window. In X, the X server is immediately killed.
#(x, y, width, height) = self.table.get_geometry()
#print "self.table.get_geometry=",x,y,width,height
if self . table . oldx != oldx or self . table . oldy != oldy : # If the current position does not equal the stored position, save the new position, and then move all the sub windows.
self . table . oldx = oldx
self . table . oldy = oldy
self . main_window . move ( oldx + self . site_params [ ' xshift ' ] , oldy + self . site_params [ ' yshift ' ] )
2009-09-03 16:35:59 +02:00
adj = self . adj_seats ( self . hand , self . config )
loc = self . config . get_locations ( self . table . site , self . max )
# TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason?
for i , w in enumerate ( self . stat_windows . itervalues ( ) ) :
2010-09-27 10:04:56 +02:00
( oldx , oldy ) = loc [ adj [ i + 1 ] ]
w . relocate ( oldx , oldy )
2009-08-15 09:44:04 +02:00
2009-11-06 22:46:50 +01:00
# While we're at it, fix the positions of mucked cards too
for aux in self . aux_windows :
aux . update_card_positions ( )
2010-08-01 09:05:35 +02:00
self . reposition_windows ( )
# call reposition_windows, which apparently moves even hidden windows, where this function does not, even though they do the same thing, afaict
2009-08-15 09:44:04 +02:00
2008-12-10 19:35:15 +01:00
return True
2008-10-26 10:34:36 +01:00
2010-11-18 05:36:59 +01:00
def up_update_table_position ( self ) :
# callback for table moved
# move the stat windows
adj = self . adj_seats ( self . hand , self . config )
loc = self . config . get_locations ( self . table . site , self . max )
for i , w in enumerate ( self . stat_windows . itervalues ( ) ) :
( x , y ) = loc [ adj [ i + 1 ] ]
w . relocate ( x , y )
# move the main window
self . main_window . move ( self . table . x + self . site_params [ ' xshift ' ] , self . table . y + self . site_params [ ' yshift ' ] )
# and move any auxs
for aux in self . aux_windows :
aux . update_card_positions ( )
return True
2008-09-15 22:31:55 +02:00
def on_button_press ( self , widget , event ) :
2010-08-31 10:56:28 +02:00
if event . button == 1 : # if primary button, start movement
2008-11-11 10:36:44 +01:00
self . main_window . begin_move_drag ( event . button , int ( event . x_root ) , int ( event . y_root ) , event . time )
return True
2010-08-31 10:56:28 +02:00
if event . button == 3 : # if secondary button, popup our main popup window
2008-09-15 22:31:55 +02:00
widget . popup ( None , None , None , event . button , event . time )
return True
return False
2009-02-28 01:47:52 +01:00
def kill ( self , * args ) :
# kill all stat_windows, popups and aux_windows in this HUD
# heap dead, burnt bodies, blood 'n guts, veins between my teeth
for s in self . stat_windows . itervalues ( ) :
2009-03-06 03:27:12 +01:00
s . kill_popups ( )
2009-09-26 12:30:12 +02:00
try :
# throws "invalid window handle" in WinXP (sometimes?)
s . window . destroy ( )
2009-11-29 18:25:02 +01:00
except : # TODO: what exception?
2009-09-26 12:30:12 +02:00
pass
2009-03-08 21:28:09 +01:00
self . stat_windows = { }
2009-01-26 20:31:08 +01:00
# also kill any aux windows
2009-03-30 17:59:07 +02:00
for aux in self . aux_windows :
aux . destroy ( )
2009-02-28 01:47:52 +01:00
self . aux_windows = [ ]
2008-09-15 22:31:55 +02:00
2010-12-01 07:54:42 +01:00
def resize_windows ( self , * args ) :
for w in self . stat_windows . itervalues ( ) :
if type ( w ) == int :
continue
rel_x = ( w . x - self . table . x ) * self . table . width / self . table . oldwidth
rel_y = ( w . y - self . table . y ) * self . table . height / self . table . oldheight
w . x = self . table . x + rel_x
w . y = self . table . y + rel_y
w . window . move ( w . x , w . y )
2008-11-10 11:58:55 +01:00
def reposition_windows ( self , * args ) :
2009-08-15 13:27:20 +02:00
self . update_table_position ( )
2009-03-30 17:49:20 +02:00
for w in self . stat_windows . itervalues ( ) :
2009-03-30 21:53:10 +02:00
if type ( w ) == int :
2009-04-06 17:03:51 +02:00
# print "in reposition, w =", w
2009-03-30 21:53:10 +02:00
continue
2009-04-06 17:03:51 +02:00
# print "in reposition, w =", w, w.x, w.y
2009-03-30 17:49:20 +02:00
w . window . move ( w . x , w . y )
2008-12-10 19:35:15 +01:00
return True
2008-12-03 09:25:49 +01:00
def debug_stat_windows ( self , * args ) :
2009-04-06 17:03:51 +02:00
# print self.table, "\n", self.main_window.window.get_transient_for()
2008-12-03 09:25:49 +01:00
for w in self . stat_windows :
2010-08-19 23:17:58 +02:00
try :
print self . stat_windows [ w ] . window . window . get_transient_for ( )
except AttributeError :
print " this window doesnt have get_transient_for "
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
def save_layout ( self , * args ) :
2008-11-12 16:28:48 +01:00
new_layout = [ ( 0 , 0 ) ] * self . max
2008-09-15 22:31:55 +02:00
for sw in self . stat_windows :
loc = self . stat_windows [ sw ] . window . get_position ( )
new_loc = ( loc [ 0 ] - self . table . x , loc [ 1 ] - self . table . y )
2008-11-12 16:28:48 +01:00
new_layout [ self . stat_windows [ sw ] . adj - 1 ] = new_loc
2010-09-27 11:08:34 +02:00
self . config . edit_layout ( self . table . site , self . max , locations = new_layout )
2009-03-15 20:27:47 +01:00
# ask each aux to save its layout back to the config object
2009-11-06 21:47:31 +01:00
[ aux . save_layout ( ) for aux in self . aux_windows ]
2009-03-15 20:27:47 +01:00
# save the config object back to the file
2010-08-17 19:53:08 +02:00
print _ ( " Updating config file " )
2008-09-15 22:31:55 +02:00
self . config . save ( )
2008-10-10 02:50:12 +02:00
def adj_seats ( self , hand , config ) :
2010-08-31 10:56:28 +02:00
# determine how to adjust seating arrangements, if a "preferred seat" is set in the hud layout configuration
2009-11-24 12:08:43 +01:00
# Need range here, not xrange -> need the actual list
2009-03-12 22:51:29 +01:00
adj = range ( 0 , self . max + 1 ) # default seat adjustments = no adjustment
2008-10-10 02:50:12 +02:00
# does the user have a fav_seat?
2009-11-01 06:23:07 +01:00
if self . max not in config . supported_sites [ self . table . site ] . layout :
2010-09-27 11:08:34 +02:00
sys . stderr . write ( _ ( " No layout found for %d -max games for site %s \n " ) % ( self . max , self . table . site ) )
2009-11-01 06:23:07 +01:00
return adj
2009-08-06 05:57:26 +02:00
if self . table . site != None and int ( config . supported_sites [ self . table . site ] . layout [ self . max ] . fav_seat ) > 0 :
2009-03-24 10:55:07 +01:00
try :
2008-10-10 02:50:12 +02:00
fav_seat = config . supported_sites [ self . table . site ] . layout [ self . max ] . fav_seat
2009-02-24 03:33:23 +01:00
actual_seat = self . get_actual_seat ( config . supported_sites [ self . table . site ] . screen_name )
2009-03-08 20:39:55 +01:00
for i in xrange ( 0 , self . max + 1 ) :
2008-10-10 02:50:12 +02:00
j = actual_seat + i
2009-03-24 10:55:07 +01:00
if j > self . max :
j = j - self . max
2008-10-10 02:50:12 +02:00
adj [ j ] = fav_seat + i
2009-03-24 10:55:07 +01:00
if adj [ j ] > self . max :
adj [ j ] = adj [ j ] - self . max
except Exception , inst :
2010-08-17 19:53:08 +02:00
sys . stderr . write ( _ ( " exception in Hud.adj_seats \n \n " ) )
sys . stderr . write ( _ ( " error is %s " ) % inst ) # __str__ allows args to printed directly
2008-10-10 02:50:12 +02:00
return adj
2009-02-24 03:33:23 +01:00
def get_actual_seat ( self , name ) :
2009-03-08 21:28:09 +01:00
for key in self . stat_dict :
2009-02-24 03:33:23 +01:00
if self . stat_dict [ key ] [ ' screen_name ' ] == name :
return self . stat_dict [ key ] [ ' seat ' ]
2010-08-17 19:53:08 +02:00
sys . stderr . write ( _ ( " Error finding actual seat. \n " ) )
2009-02-24 03:33:23 +01:00
2009-02-26 05:35:15 +01:00
def create ( self , hand , config , stat_dict , cards ) :
2008-08-19 00:53:25 +02:00
# update this hud, to the stats and players as of "hand"
# hand is the hand id of the most recent hand played at this table
#
# this method also manages the creating and destruction of stat
# windows via calls to the Stat_Window class
2009-11-24 12:08:43 +01:00
self . creation_attrs = hand , config , stat_dict , cards
2009-08-09 22:26:24 +02:00
2009-11-24 12:08:43 +01:00
self . hand = hand
2009-02-27 18:42:49 +01:00
if not self . mw_created :
self . create_mw ( )
2009-11-24 12:08:43 +01:00
2009-02-24 03:33:23 +01:00
self . stat_dict = stat_dict
2009-02-26 05:35:15 +01:00
self . cards = cards
2010-08-29 21:55:40 +02:00
log . info ( _ ( ' Creating hud from hand ' ) + str ( hand ) )
2008-10-10 02:50:12 +02:00
adj = self . adj_seats ( hand , config )
2008-10-30 03:37:05 +01:00
loc = self . config . get_locations ( self . table . site , self . max )
2009-11-01 06:23:07 +01:00
if loc is None and self . max != 10 :
loc = self . config . get_locations ( self . table . site , 10 )
if loc is None and self . max != 9 :
loc = self . config . get_locations ( self . table . site , 9 )
2008-10-30 03:37:05 +01:00
2008-10-10 02:50:12 +02:00
# create the stat windows
2009-11-24 12:08:43 +01:00
for i in xrange ( 1 , self . max + 1 ) :
2008-10-30 03:37:05 +01:00
( x , y ) = loc [ adj [ i ] ]
2009-01-06 11:18:45 +01:00
if i in self . stat_windows :
2008-11-04 11:02:41 +01:00
self . stat_windows [ i ] . relocate ( x , y )
else :
self . stat_windows [ i ] = Stat_Window ( game = config . supported_games [ self . poker_game ] ,
2008-09-15 22:31:55 +02:00
parent = self ,
2009-11-24 12:08:43 +01:00
table = self . table ,
2008-08-19 00:53:25 +02:00
x = x ,
y = y ,
seat = i ,
2009-11-24 12:08:43 +01:00
adj = adj [ i ] ,
2008-08-19 00:53:25 +02:00
player_id = ' fake ' ,
font = self . font )
2011-03-03 13:39:04 +01:00
self . topify_window ( self . main_window )
for i in xrange ( 1 , self . max + 1 ) :
self . topify_window ( self . stat_windows [ i ] . window , self . main_window )
2008-08-20 21:29:08 +02:00
self . stats = [ ]
2009-03-24 10:19:20 +01:00
game = config . supported_games [ self . poker_game ]
2009-11-24 12:08:43 +01:00
2009-03-24 10:19:20 +01:00
for i in xrange ( 0 , game . rows + 1 ) :
row_list = [ ' ' ] * game . cols
2008-08-20 21:29:08 +02:00
self . stats . append ( row_list )
2009-03-24 10:19:20 +01:00
for stat in game . stats :
2008-08-19 00:53:25 +02:00
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
2009-11-24 12:08:43 +01:00
2010-11-12 21:08:04 +01:00
# if os.name == "nt": # we call update_table_position() regularly in Windows to see if we're moving around. See comments on that function for why this isn't done in X.
# gobject.timeout_add(500, self.update_table_position)
2009-11-24 12:08:43 +01:00
2009-02-26 05:35:15 +01:00
def update ( self , hand , config ) :
2008-09-15 22:31:55 +02:00
self . hand = hand # this is the last hand, so it is available later
2009-02-28 01:47:52 +01:00
if os . name == ' nt ' :
2009-11-24 12:08:43 +01:00
if self . update_table_position ( ) == False : # we got killed by finding our table was gone
return
2009-01-07 18:46:19 +01:00
2010-01-01 23:57:25 +01:00
self . label . modify_fg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( self . colors [ ' hudfgcolor ' ] ) )
2009-02-26 05:35:15 +01:00
for s in self . stat_dict :
2009-09-16 04:25:26 +02:00
try :
statd = self . stat_dict [ s ]
except KeyError :
2010-08-17 19:53:08 +02:00
log . error ( _ ( " KeyError at the start of the for loop in update in hud_main. How this can possibly happen is totally beyond my comprehension. Your HUD may be about to get really weird. -Eric " ) )
log . error ( _ ( " (btw, the key was %s and statd is %s " ) % ( s , statd ) )
2009-09-16 04:25:26 +02:00
continue
2008-11-04 11:02:41 +01:00
try :
2009-09-07 06:07:40 +02:00
self . stat_windows [ statd [ ' seat ' ] ] . player_id = statd [ ' player_id ' ]
#self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id']
2009-09-16 04:25:26 +02:00
except KeyError : # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here
2008-11-04 11:02:41 +01:00
self . max = 10
2009-02-26 05:35:15 +01:00
self . create ( hand , config , self . stat_dict , self . cards )
2009-03-24 10:55:07 +01:00
self . stat_windows [ statd [ ' seat ' ] ] . player_id = statd [ ' player_id ' ]
2009-11-24 12:08:43 +01:00
2009-03-08 20:39:55 +01:00
for r in xrange ( 0 , config . supported_games [ self . poker_game ] . rows ) :
for c in xrange ( 0 , config . supported_games [ self . poker_game ] . cols ) :
2008-10-31 19:34:41 +01:00
this_stat = config . supported_games [ self . poker_game ] . stats [ self . stats [ r ] [ c ] ]
2009-03-24 10:55:07 +01:00
number = Stats . do_stat ( self . stat_dict , player = statd [ ' player_id ' ] , stat = self . stats [ r ] [ c ] )
2009-03-24 10:19:20 +01:00
statstring = " %s %s %s " % ( this_stat . hudprefix , str ( number [ 1 ] ) , this_stat . hudsuffix )
2009-03-24 10:55:07 +01:00
window = self . stat_windows [ statd [ ' seat ' ] ]
2009-11-24 12:08:43 +01:00
2008-11-25 12:47:58 +01:00
if this_stat . hudcolor != " " :
2009-03-24 10:55:07 +01:00
window . label [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( this_stat . hudcolor ) )
2009-12-23 21:44:55 +01:00
else :
2010-08-31 10:56:28 +02:00
window . label [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( self . colors [ ' hudfgcolor ' ] ) )
2009-12-23 21:15:55 +01:00
if this_stat . stat_loth != " " :
2009-12-28 03:21:31 +01:00
if number [ 0 ] < ( float ( this_stat . stat_loth ) / 100 ) :
window . label [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( this_stat . stat_locolor ) )
2009-12-23 21:15:55 +01:00
if this_stat . stat_hith != " " :
2009-12-28 03:21:31 +01:00
if number [ 0 ] > ( float ( this_stat . stat_hith ) / 100 ) :
window . label [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , gtk . gdk . color_parse ( this_stat . stat_hicolor ) )
2009-12-23 21:15:55 +01:00
2009-03-24 10:55:07 +01:00
window . label [ r ] [ c ] . set_text ( statstring )
2008-12-21 23:14:57 +01:00
if statstring != " xxx " : # is there a way to tell if this particular stat window is visible already, or no?
2010-08-31 10:56:28 +02:00
unhidewindow = True
2009-03-24 10:55:07 +01:00
tip = " %s \n %s \n %s , %s " % ( statd [ ' screen_name ' ] , number [ 5 ] , number [ 3 ] , number [ 4 ] )
Stats . do_tip ( window . e_box [ r ] [ c ] , tip )
2010-08-31 10:56:28 +02:00
if unhidewindow : #and not window.window.visible: # there is no "visible" attribute in gtk.Window, although the docs seem to indicate there should be
window . window . show_all ( )
unhidewindow = False
2008-09-15 22:31:55 +02:00
2011-03-03 13:39:04 +01:00
def topify_window ( self , window , parentwindow = None ) :
2009-09-03 16:35:59 +02:00
window . set_focus_on_map ( False )
window . set_accept_focus ( False )
2011-03-03 13:39:04 +01:00
# print "topify_window", window, parentwindow
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
if not self . table . gdkhandle :
self . table . gdkhandle = gtk . gdk . window_foreign_new ( int ( self . table . number ) ) # gtk handle to poker window
2011-03-03 13:39:04 +01:00
if parentwindow is not None :
window . window . set_transient_for ( parentwindow . window )
else :
window . window . set_transient_for ( self . table . gdkhandle )
window . set_destroy_with_parent ( True )
2008-09-15 22:31:55 +02:00
2008-08-19 00:53:25 +02:00
class Stat_Window :
def button_press_cb ( self , widget , event , * args ) :
2009-11-24 12:08:43 +01:00
# This handles all callbacks from button presses on the event boxes in
2008-08-19 00:53:25 +02:00
# the stat windows. There is a bit of an ugly kludge to separate single-
# and double-clicks.
2010-08-31 10:56:28 +02:00
self . window . show ( ) #_all()
2008-11-10 11:58:55 +01:00
if event . button == 3 : # right button event
2009-08-27 14:41:43 +02:00
newpopup = Popup_window ( self . window , self )
#print "added popup", newpopup
# TODO: how should we go about making sure it doesn't open a dozen popups if you click?
self . popups . append ( newpopup )
2009-08-19 12:59:44 +02:00
return True
2008-08-19 00:53:25 +02:00
if event . button == 2 : # middle button event
2008-11-25 14:52:59 +01:00
self . window . hide ( )
2009-08-19 12:59:44 +02:00
return True
2008-11-10 11:58:55 +01:00
if event . button == 1 : # left button event
2010-01-23 07:38:53 +01:00
# close on double click for a stat window
# for those that don't have a mouse with middle button
if event . type == gtk . gdk . _2BUTTON_PRESS :
self . window . hide ( )
return True
2008-12-09 07:43:13 +01:00
# TODO: make position saving save sizes as well?
2008-11-10 11:58:55 +01:00
if event . state & gtk . gdk . SHIFT_MASK :
self . window . begin_resize_drag ( gtk . gdk . WINDOW_EDGE_SOUTH_EAST , event . button , int ( event . x_root ) , int ( event . y_root ) , event . time )
else :
self . window . begin_move_drag ( event . button , int ( event . x_root ) , int ( event . y_root ) , event . time )
2009-08-19 12:59:44 +02:00
return True
return False
2009-11-24 12:08:43 +01:00
2009-08-27 11:28:59 +02:00
def noop ( self , arga = None , argb = None ) : # i'm going to try to connect the focus-in and focus-out events here, to see if that fixes any of the focus problems.
2009-08-19 12:59:44 +02:00
return True
2009-11-24 12:08:43 +01:00
2009-02-28 01:47:52 +01:00
def kill_popup ( self , popup ) :
2009-12-03 13:24:12 +01:00
#print "remove popup", popup
2009-11-24 12:08:43 +01:00
self . popups . remove ( popup )
2009-02-28 01:47:52 +01:00
popup . window . destroy ( )
2009-11-24 12:08:43 +01:00
2009-03-06 03:27:12 +01:00
def kill_popups ( self ) :
2009-03-08 21:28:09 +01:00
map ( lambda x : x . window . destroy ( ) , self . popups )
2009-03-06 03:27:12 +01:00
self . popups = { }
2009-02-28 01:47:52 +01:00
2008-11-04 11:02:41 +01:00
def relocate ( self , x , y ) :
self . x = x + self . table . x
self . y = y + self . table . y
self . window . move ( self . x , self . y )
2008-08-19 00:53:25 +02:00
2008-11-12 16:28:48 +01:00
def __init__ ( self , parent , game , table , seat , adj , x , y , player_id , font ) :
2008-09-15 22:31:55 +02:00
self . parent = parent # Hud object that this stat window belongs to
self . game = game # Configuration object for the curren
self . table = table # Table object where this is going
2008-11-12 16:28:48 +01:00
self . seat = seat # seat number of his player
self . adj = adj # the adjusted seat number for this player
2008-09-15 22:31:55 +02:00
self . x = x + table . x # table.x and y are the location of the table
self . y = y + table . y # x and y are the location relative to table.x & y
self . player_id = player_id # looks like this isn't used ;)
self . sb_click = 0 # used to figure out button clicks
2009-02-28 01:47:52 +01:00
self . popups = [ ] # list of open popups for this stat window
2009-02-25 21:25:58 +01:00
self . useframes = parent . config . get_frames ( parent . site )
2008-08-19 00:53:25 +02:00
self . window = gtk . Window ( )
self . window . set_decorated ( 0 )
2010-08-31 10:56:28 +02:00
self . window . set_property ( " skip-taskbar-hint " , True )
2008-08-19 00:53:25 +02:00
self . window . set_gravity ( gtk . gdk . GRAVITY_STATIC )
2008-10-28 12:30:22 +01:00
2008-08-19 00:53:25 +02:00
self . window . set_title ( " %s " % seat )
2010-08-31 10:56:28 +02:00
self . window . set_focus ( None ) # set gtk default focus widget for this window to None
2009-03-24 11:04:00 +01:00
self . window . set_focus_on_map ( False )
2010-08-31 10:56:28 +02:00
self . window . set_accept_focus ( False )
2008-08-19 00:53:25 +02:00
2011-03-03 13:39:04 +01:00
self . window . set_type_hint ( gtk . gdk . WINDOW_TYPE_HINT_UTILITY )
2009-03-26 00:33:01 +01:00
grid = gtk . Table ( rows = game . rows , columns = game . cols , homogeneous = False )
2009-11-24 12:08:43 +01:00
self . grid = grid
2009-03-26 00:33:01 +01:00
self . window . add ( grid )
2009-01-27 00:31:04 +01:00
self . window . modify_bg ( gtk . STATE_NORMAL , parent . backgroundcolor )
2009-11-24 12:08:43 +01:00
2008-08-19 00:53:25 +02:00
self . e_box = [ ]
self . frame = [ ]
self . label = [ ]
2009-03-08 21:28:09 +01:00
usegtkframes = self . useframes
e_box = self . e_box
label = self . label
2009-03-24 10:19:20 +01:00
for r in xrange ( game . rows ) :
2009-03-08 21:28:09 +01:00
if usegtkframes :
2009-02-25 21:25:58 +01:00
self . frame . append ( [ ] )
2009-03-08 21:28:09 +01:00
e_box . append ( [ ] )
label . append ( [ ] )
2009-03-24 10:19:20 +01:00
for c in xrange ( game . cols ) :
2009-03-08 21:28:09 +01:00
if usegtkframes :
2009-02-25 21:25:58 +01:00
self . frame [ r ] . append ( gtk . Frame ( ) )
2009-03-08 21:28:09 +01:00
e_box [ r ] . append ( gtk . EventBox ( ) )
2009-11-24 12:08:43 +01:00
2009-03-08 21:28:09 +01:00
e_box [ r ] [ c ] . modify_bg ( gtk . STATE_NORMAL , parent . backgroundcolor )
e_box [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , parent . foregroundcolor )
2009-11-24 12:08:43 +01:00
2009-03-08 21:28:09 +01:00
Stats . do_tip ( e_box [ r ] [ c ] , ' stuff ' )
if usegtkframes :
2009-06-20 16:01:52 +02:00
grid . attach ( self . frame [ r ] [ c ] , c , c + 1 , r , r + 1 , xpadding = game . xpad , ypadding = game . ypad )
2009-03-08 21:28:09 +01:00
self . frame [ r ] [ c ] . add ( e_box [ r ] [ c ] )
2009-02-25 21:25:58 +01:00
else :
2009-06-20 16:01:52 +02:00
grid . attach ( e_box [ r ] [ c ] , c , c + 1 , r , r + 1 , xpadding = game . xpad , ypadding = game . ypad )
2009-03-08 21:28:09 +01:00
label [ r ] . append ( gtk . Label ( ' xxx ' ) )
2009-11-24 12:08:43 +01:00
2009-03-08 21:28:09 +01:00
if usegtkframes :
2009-02-25 21:25:58 +01:00
self . frame [ r ] [ c ] . modify_bg ( gtk . STATE_NORMAL , parent . backgroundcolor )
2009-03-08 21:28:09 +01:00
label [ r ] [ c ] . modify_bg ( gtk . STATE_NORMAL , parent . backgroundcolor )
label [ r ] [ c ] . modify_fg ( gtk . STATE_NORMAL , parent . foregroundcolor )
2008-10-27 11:29:39 +01:00
2009-03-08 21:28:09 +01:00
e_box [ r ] [ c ] . add ( self . label [ r ] [ c ] )
e_box [ r ] [ c ] . connect ( " button_press_event " , self . button_press_cb )
2009-08-19 12:59:44 +02:00
e_box [ r ] [ c ] . connect ( " focus-in-event " , self . noop )
e_box [ r ] [ c ] . connect ( " focus " , self . noop )
e_box [ r ] [ c ] . connect ( " focus-out-event " , self . noop )
2009-03-08 21:28:09 +01:00
label [ r ] [ c ] . modify_font ( font )
2008-10-31 19:34:41 +01:00
2008-11-10 11:58:55 +01:00
self . window . set_opacity ( parent . colors [ ' hudopacity ' ] )
2009-08-19 12:59:44 +02:00
self . window . connect ( " focus " , self . noop )
self . window . connect ( " focus-in-event " , self . noop )
self . window . connect ( " focus-out-event " , self . noop )
self . window . connect ( " button_press_event " , self . button_press_cb )
2009-09-03 16:35:59 +02:00
self . window . set_focus_on_map ( False )
self . window . set_accept_focus ( False )
2009-11-24 12:08:43 +01:00
2008-08-19 00:53:25 +02:00
self . window . move ( self . x , self . y )
2008-11-25 13:03:33 +01:00
self . window . hide ( )
2011-03-03 13:39:04 +01:00
self . window . realize ( ) # window must be realized before it has a gdkwindow so we can attach it to the table window..
# self.topify_window(self.window)
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
2008-08-19 00:53:25 +02:00
def destroy ( * args ) : # call back for terminating the main eventloop
gtk . main_quit ( )
2008-09-15 22:31:55 +02:00
class Popup_window :
def __init__ ( self , parent , stat_window ) :
self . sb_click = 0
2009-02-28 01:47:52 +01:00
self . stat_window = stat_window
2009-05-30 18:02:31 +02:00
self . parent = parent
2008-09-15 22:31:55 +02:00
# create the popup window
self . window = gtk . Window ( )
self . window . set_decorated ( 0 )
self . window . set_gravity ( gtk . gdk . GRAVITY_STATIC )
self . window . set_title ( " popup " )
self . window . set_property ( " skip-taskbar-hint " , True )
2009-09-03 16:35:59 +02:00
self . window . set_focus_on_map ( False )
2009-11-24 12:08:43 +01:00
self . window . set_accept_focus ( False )
2008-09-15 22:31:55 +02:00
self . window . set_transient_for ( parent . get_toplevel ( ) )
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
self . window . set_position ( gtk . WIN_POS_CENTER_ON_PARENT )
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
self . ebox = gtk . EventBox ( )
self . ebox . connect ( " button_press_event " , self . button_press_cb )
self . lab = gtk . Label ( " stuff \n stuff \n stuff " )
# need an event box so we can respond to clicks
self . window . add ( self . ebox )
self . ebox . add ( self . lab )
2009-11-24 12:08:43 +01:00
2008-12-21 12:49:34 +01:00
self . ebox . modify_bg ( gtk . STATE_NORMAL , stat_window . parent . backgroundcolor )
self . ebox . modify_fg ( gtk . STATE_NORMAL , stat_window . parent . foregroundcolor )
self . window . modify_bg ( gtk . STATE_NORMAL , stat_window . parent . backgroundcolor )
self . window . modify_fg ( gtk . STATE_NORMAL , stat_window . parent . foregroundcolor )
self . lab . modify_bg ( gtk . STATE_NORMAL , stat_window . parent . backgroundcolor )
self . lab . modify_fg ( gtk . STATE_NORMAL , stat_window . parent . foregroundcolor )
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
# figure out the row, col address of the click that activated the popup
row = 0
col = 0
2009-03-08 20:39:55 +01:00
for r in xrange ( 0 , stat_window . game . rows ) :
for c in xrange ( 0 , stat_window . game . cols ) :
2008-09-15 22:31:55 +02:00
if stat_window . e_box [ r ] [ c ] == parent :
row = r
col = c
break
# figure out what popup format we're using
popup_format = " default "
2009-01-06 11:18:45 +01:00
for stat in stat_window . game . stats :
2008-09-15 22:31:55 +02:00
if stat_window . game . stats [ stat ] . row == row and stat_window . game . stats [ stat ] . col == col :
popup_format = stat_window . game . stats [ stat ] . popup
break
# get the list of stats to be presented from the config
stat_list = [ ]
2009-01-06 11:18:45 +01:00
for w in stat_window . parent . config . popup_windows :
2008-09-15 22:31:55 +02:00
if w == popup_format :
stat_list = stat_window . parent . config . popup_windows [ w ] . pu_stats
break
# get a database connection
2008-12-17 19:24:37 +01:00
# db_connection = Database.Database(stat_window.parent.config, stat_window.parent.db_name, 'temp')
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
# calculate the stat_dict and then create the text for the pu
# stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand, stat_window.player_id)
2009-01-06 02:26:39 +01:00
# stat_dict = self.db_connection.get_stats_from_hand(stat_window.parent.hand)
2008-12-17 19:24:37 +01:00
# db_connection.close_connection()
2009-01-06 02:26:39 +01:00
stat_dict = stat_window . parent . stat_dict
2008-09-15 22:31:55 +02:00
pu_text = " "
2009-04-02 11:02:24 +02:00
mo_text = " "
2008-09-15 22:31:55 +02:00
for s in stat_list :
number = Stats . do_stat ( stat_dict , player = int ( stat_window . player_id ) , stat = s )
2009-04-02 11:02:24 +02:00
mo_text + = number [ 5 ] + " " + number [ 4 ] + " \n "
2008-09-15 22:31:55 +02:00
pu_text + = number [ 3 ] + " \n "
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
2009-04-02 11:02:24 +02:00
self . lab . set_text ( pu_text )
Stats . do_tip ( self . lab , mo_text )
2008-09-15 22:31:55 +02:00
self . window . show_all ( )
2009-11-24 12:08:43 +01:00
2008-11-10 11:58:55 +01:00
self . window . set_transient_for ( stat_window . window )
2008-11-06 12:58:28 +01:00
2008-09-15 22:31:55 +02:00
def button_press_cb ( self , widget , event , * args ) :
2009-11-24 12:08:43 +01:00
# This handles all callbacks from button presses on the event boxes in
2008-09-15 22:31:55 +02:00
# the popup windows. There is a bit of an ugly kludge to separate single-
# and double-clicks. This is the same code as in the Stat_window class
if event . button == 1 : # left button event
2009-01-06 02:26:39 +01:00
pass
2008-09-15 22:31:55 +02:00
if event . button == 2 : # middle button event
pass
if event . button == 3 : # right button event
2009-02-28 01:47:52 +01:00
self . stat_window . kill_popup ( self )
2009-08-19 12:59:44 +02:00
return True
2009-02-28 01:47:52 +01:00
# self.window.destroy()
2009-08-19 12:59:44 +02:00
return False
2008-09-15 22:31:55 +02:00
def toggle_decorated ( self , widget ) :
top = widget . get_toplevel ( )
( x , y ) = top . get_position ( )
2009-11-24 12:08:43 +01:00
2008-09-15 22:31:55 +02:00
if top . get_decorated ( ) :
top . set_decorated ( 0 )
top . move ( x , y )
else :
top . set_decorated ( 1 )
top . move ( x , y )
def topify_window ( self , window ) :
2009-09-03 16:35:59 +02:00
window . set_focus_on_map ( False )
window . set_accept_focus ( False )
2009-11-24 12:08:43 +01:00
2009-09-03 16:35:59 +02:00
if not self . table . gdkhandle :
self . table . gdkhandle = gtk . gdk . window_foreign_new ( int ( self . table . number ) ) # gtk handle to poker window
# window.window.reparent(self.table.gdkhandle, 0, 0)
window . window . set_transient_for ( self . table . gdkhandle )
# window.present()
2009-09-26 12:30:12 +02:00
2008-09-15 22:31:55 +02:00