2010-07-08 20:01:03 +02:00
|
|
|
#!/usr/bin/env python
|
2010-07-04 03:05:16 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2010-09-07 15:50:29 +02:00
|
|
|
"""Base class for interacting with poker client windows.
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
There are currently subclasses for X and Windows.
|
|
|
|
|
|
|
|
The class queries the poker client window for data of interest, such as
|
|
|
|
size and location. It also controls the signals to alert the HUD when the
|
|
|
|
client has been resized, destroyed, etc.
|
2009-05-21 17:13:39 +02:00
|
|
|
"""
|
2010-09-07 15:50:29 +02:00
|
|
|
# Copyright 2008 - 2010, Ray E. Barker
|
2009-05-21 17:13:39 +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.
|
2010-02-04 22:33:21 +01:00
|
|
|
#
|
2009-05-21 17:13:39 +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.
|
2010-02-04 22:33:21 +01:00
|
|
|
#
|
2009-05-21 17:13:39 +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
|
|
|
|
|
|
|
|
########################################################################
|
|
|
|
|
|
|
|
# Standard Library modules
|
2010-09-07 15:50:29 +02:00
|
|
|
import re
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
# pyGTK modules
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
# FreePokerTools modules
|
2010-09-07 15:50:29 +02:00
|
|
|
from HandHistoryConverter import getTableTitleRe
|
|
|
|
from HandHistoryConverter import getTableNoRe
|
|
|
|
|
|
|
|
# Global used for figuring out the current game being played from the title.
|
|
|
|
# The dict key is a tuple of (limit type, category) for the game.
|
2009-05-21 17:13:39 +02:00
|
|
|
# The list is the names for those games used by the supported poker sites
|
2010-09-07 15:50:29 +02:00
|
|
|
# This is currently only used for mixed games, so it only needs to support those
|
2009-05-21 17:13:39 +02:00
|
|
|
# games on PokerStars and Full Tilt.
|
2010-09-07 15:50:29 +02:00
|
|
|
nlpl_game_names = { #fpdb name Stars Name FTP Name (if different)
|
|
|
|
("nl", "holdem" ) : ("No Limit Hold\'em" , ),
|
|
|
|
("pl", "holdem" ) : ("Pot Limit Hold\'em" , ),
|
|
|
|
("pl", "omahahi" ) : ("Pot Limit Omaha" ,"Pot Limit Omaha Hi" ),
|
|
|
|
}
|
|
|
|
limit_game_names = { #fpdb name Stars Name FTP Name
|
|
|
|
("fl", "holdem" ) : ("Limit Hold\'em" , ),
|
|
|
|
("fl", "omahahilo" ) : ("Limit Omaha H/L" , ),
|
|
|
|
("fl", "studhilo" ) : ("Limit Stud H/L" , ),
|
|
|
|
("fl", "razz" ) : ("Limit Razz" , ),
|
|
|
|
("fl", "studhi" ) : ("Limit Stud" , "Stud Hi"),
|
|
|
|
("fl", "27_3draw" ) : ("Limit Triple Draw 2-7 Lowball", )
|
2009-05-21 17:13:39 +02:00
|
|
|
}
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
# A window title might have our table name + one of these words/
|
2009-05-21 17:13:39 +02:00
|
|
|
# phrases. If it has this word in the title, it is not a table.
|
2010-09-09 02:35:59 +02:00
|
|
|
bad_words = ('History for table:', 'HUD:', 'Chat:', 'FPDBHUD')
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
# Here are the custom signals we define for allowing the 'client watcher'
|
|
|
|
# thread to communicate with the gui thread. Any time a poker client is
|
2010-02-04 22:33:21 +01:00
|
|
|
# is moved, resized, or closed on of these signals is emitted to the
|
2009-05-21 17:13:39 +02:00
|
|
|
# HUD main window.
|
|
|
|
gobject.signal_new("client_moved", gtk.Window,
|
|
|
|
gobject.SIGNAL_RUN_LAST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_PYOBJECT,))
|
|
|
|
|
|
|
|
gobject.signal_new("client_resized", gtk.Window,
|
|
|
|
gobject.SIGNAL_RUN_LAST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_PYOBJECT,))
|
|
|
|
|
|
|
|
gobject.signal_new("client_destroyed", gtk.Window,
|
|
|
|
gobject.SIGNAL_RUN_LAST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_PYOBJECT,))
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
gobject.signal_new("game_changed", gtk.Window,
|
|
|
|
gobject.SIGNAL_RUN_LAST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_PYOBJECT,))
|
|
|
|
|
|
|
|
gobject.signal_new("table_changed", gtk.Window,
|
|
|
|
gobject.SIGNAL_RUN_LAST,
|
|
|
|
gobject.TYPE_NONE,
|
|
|
|
(gobject.TYPE_PYOBJECT,))
|
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
# Each TableWindow object must have the following attributes correctly populated:
|
|
|
|
# tw.name = the table name from the title bar, which must to match the table name
|
2010-09-07 15:50:29 +02:00
|
|
|
# from the corresponding hand record in the db.
|
2010-02-04 22:33:21 +01:00
|
|
|
# tw.number = This is the system id number for the client table window in the
|
2009-05-21 17:13:39 +02:00
|
|
|
# format that the system presents it. This is Xid in Xwindows and
|
|
|
|
# hwnd in Microsoft Windows.
|
|
|
|
# tw.title = The full title from the window title bar.
|
2010-02-04 22:33:21 +01:00
|
|
|
# tw.width, tw.height = The width and height of the window in pixels. This is
|
|
|
|
# the internal width and height, not including the title bar and
|
2009-05-21 17:13:39 +02:00
|
|
|
# window borders.
|
2010-02-04 22:33:21 +01:00
|
|
|
# tw.x, tw.y = The x, y (horizontal, vertical) location of the window relative
|
2009-05-21 17:13:39 +02:00
|
|
|
# to the top left of the display screen. This also does not include the
|
2010-02-04 22:33:21 +01:00
|
|
|
# title bar and window borders. To put it another way, this is the
|
2009-05-21 17:13:39 +02:00
|
|
|
# screen location of (0, 0) in the working window.
|
2010-09-07 15:50:29 +02:00
|
|
|
# tournament = Tournament number for a tournament or None for a cash game.
|
|
|
|
# table = Table number for a tournament.
|
|
|
|
# gdkhandle =
|
|
|
|
# window =
|
|
|
|
# parent =
|
|
|
|
# game =
|
|
|
|
# search_string =
|
2009-05-21 17:13:39 +02:00
|
|
|
|
|
|
|
class Table_Window(object):
|
2010-09-07 15:50:29 +02:00
|
|
|
def __init__(self, config, site, table_name = None, tournament = None, table_number = None):
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
self.config = config
|
|
|
|
self.site = site
|
2010-11-22 22:37:37 +01:00
|
|
|
self.hud = None # fill in later
|
2009-11-07 18:30:47 +01:00
|
|
|
if tournament is not None and table_number is not None:
|
2009-05-21 17:13:39 +02:00
|
|
|
self.tournament = int(tournament)
|
|
|
|
self.table = int(table_number)
|
|
|
|
self.name = "%s - %s" % (self.tournament, self.table)
|
2010-09-07 15:50:29 +02:00
|
|
|
self.type = "tour"
|
|
|
|
table_kwargs = dict(tournament = self.tournament, table_number = self.table)
|
|
|
|
self.tableno_re = getTableNoRe(self.config, self.site, tournament = self.tournament)
|
2010-11-22 22:37:37 +01:00
|
|
|
self.key = tournament # used as key for the hud_dict in HUD_main
|
2009-11-07 18:30:47 +01:00
|
|
|
elif table_name is not None:
|
|
|
|
self.name = table_name
|
2010-09-07 15:50:29 +02:00
|
|
|
self.type = "cash"
|
2009-11-07 18:30:47 +01:00
|
|
|
self.tournament = None
|
2010-09-07 15:50:29 +02:00
|
|
|
table_kwargs = dict(table_name = table_name)
|
2010-11-22 22:37:37 +01:00
|
|
|
self.key = table_name
|
2010-09-07 15:50:29 +02:00
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs)
|
|
|
|
self.find_table_parameters()
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-11-27 00:51:25 +01:00
|
|
|
try:
|
|
|
|
self.gdkhandle = gtk.gdk.window_foreign_new(self.number)
|
|
|
|
except AttributeError: # self.number does not exist, table was closed
|
|
|
|
return None
|
2010-09-17 02:29:58 +02:00
|
|
|
geo = self.get_geometry()
|
|
|
|
if geo is None: return None
|
|
|
|
self.width = geo['width']
|
|
|
|
self.height = geo['height']
|
|
|
|
self.x = geo['x']
|
|
|
|
self.y = geo['y']
|
2010-09-27 10:04:56 +02:00
|
|
|
self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position()
|
|
|
|
self.oldy = self.y
|
2010-09-17 02:29:58 +02:00
|
|
|
|
|
|
|
self.game = self.get_game()
|
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
def __str__(self):
|
|
|
|
# __str__ method for testing
|
2010-09-07 15:50:29 +02:00
|
|
|
likely_attrs = ("number", "title", "site", "width", "height", "x", "y",
|
|
|
|
"tournament", "table", "gdkhandle", "window", "parent",
|
2010-11-22 22:37:37 +01:00
|
|
|
"key", "hud", "game", "search_string", "tableno_re")
|
2009-05-21 17:13:39 +02:00
|
|
|
temp = 'TableWindow object\n'
|
2009-11-06 23:34:42 +01:00
|
|
|
for a in likely_attrs:
|
|
|
|
if getattr(self, a, 0):
|
|
|
|
temp += " %s = %s\n" % (a, getattr(self, a))
|
2009-05-21 17:13:39 +02:00
|
|
|
return temp
|
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
####################################################################
|
|
|
|
# "get" methods. These query the table and return the info to get.
|
|
|
|
# They don't change the data in the table and are generally used
|
|
|
|
# by the "check" methods. Most of the get methods are in the
|
|
|
|
# subclass because they are specific to X, Windows, etc.
|
2009-05-21 17:13:39 +02:00
|
|
|
def get_game(self):
|
2010-09-17 02:29:58 +02:00
|
|
|
# title = self.get_window_title()
|
|
|
|
# if title is None:
|
|
|
|
# return False
|
|
|
|
title = self.title
|
2010-09-07 15:50:29 +02:00
|
|
|
|
|
|
|
# check for nl and pl games first, to avoid bad matches
|
|
|
|
for game, names in nlpl_game_names.iteritems():
|
2009-05-21 17:13:39 +02:00
|
|
|
for name in names:
|
|
|
|
if name in title:
|
2010-02-04 22:33:21 +01:00
|
|
|
return game
|
2010-09-07 15:50:29 +02:00
|
|
|
for game, names in limit_game_names.iteritems():
|
|
|
|
for name in names:
|
|
|
|
if name in title:
|
|
|
|
return game
|
|
|
|
return False
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
def get_table_no(self):
|
|
|
|
new_title = self.get_window_title()
|
|
|
|
if new_title is None:
|
|
|
|
return False
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-10-12 08:23:56 +02:00
|
|
|
try:
|
2010-11-22 22:37:37 +01:00
|
|
|
mo = re.search(self.tableno_re, new_title)
|
2010-10-12 08:23:56 +02:00
|
|
|
except AttributeError: #'Table' object has no attribute 'tableno_re'
|
2010-11-22 22:37:37 +01:00
|
|
|
return False
|
2010-10-12 08:23:56 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
if mo is not None:
|
2010-10-12 04:23:06 +02:00
|
|
|
#print "get_table_no: mo=",mo.groups()
|
2010-11-22 22:37:37 +01:00
|
|
|
return int(mo.group(1))
|
2010-09-07 15:50:29 +02:00
|
|
|
return False
|
2010-09-28 05:41:03 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
####################################################################
|
|
|
|
# check_table() is meant to be called by the hud periodically to
|
|
|
|
# determine if the client has been moved or resized. check_table()
|
|
|
|
# also checks and signals if the client has been closed.
|
|
|
|
def check_table(self, hud):
|
|
|
|
result = self.check_size()
|
|
|
|
if result != False:
|
2010-09-17 02:29:58 +02:00
|
|
|
hud.parent.main_window.emit(result, hud)
|
2010-09-07 15:50:29 +02:00
|
|
|
if result == "client_destroyed":
|
|
|
|
return True
|
|
|
|
|
|
|
|
result = self.check_loc()
|
|
|
|
if result != False:
|
2010-09-17 02:29:58 +02:00
|
|
|
hud.parent.main_window.emit(result, hud)
|
2010-09-07 15:50:29 +02:00
|
|
|
if result == "client_destroyed":
|
|
|
|
return True
|
|
|
|
return True
|
|
|
|
|
|
|
|
####################################################################
|
|
|
|
# "check" methods. They use the corresponding get method, update the
|
|
|
|
# table object and return the name of the signal to be emitted or
|
|
|
|
# False if unchanged. These do not signal for destroyed
|
|
|
|
# clients to prevent a race condition.
|
|
|
|
|
|
|
|
# These might be called by a Window.timeout, so they must not
|
|
|
|
# return False, or the timeout will be cancelled.
|
|
|
|
def check_game(self, hud):
|
|
|
|
new_game = self.get_game()
|
|
|
|
if new_game is not None and self.game != new_game:
|
|
|
|
self.game = new_game
|
|
|
|
hud.main_window.emit("game_changed", hud)
|
|
|
|
return "game_changed"
|
|
|
|
return True
|
|
|
|
|
|
|
|
def check_size(self):
|
|
|
|
new_geo = self.get_geometry()
|
2009-11-03 20:30:52 +01:00
|
|
|
if new_geo is None: # window destroyed
|
2009-05-21 17:13:39 +02:00
|
|
|
return "client_destroyed"
|
|
|
|
|
|
|
|
elif self.width != new_geo['width'] or self.height != new_geo['height']: # window resized
|
|
|
|
self.width = new_geo['width']
|
|
|
|
self.height = new_geo['height']
|
|
|
|
return "client_resized"
|
2010-09-07 15:50:29 +02:00
|
|
|
return False # no change
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
def check_loc(self):
|
|
|
|
new_geo = self.get_geometry()
|
|
|
|
if new_geo is None: # window destroyed
|
|
|
|
return "client_destroyed"
|
2009-05-21 17:13:39 +02:00
|
|
|
|
2010-09-07 15:50:29 +02:00
|
|
|
if self.x != new_geo['x'] or self.y != new_geo['y']: # window moved
|
2010-11-18 05:36:59 +01:00
|
|
|
# print self.x, self.y, new_geo['x'], new_geo['y']
|
2010-09-07 15:50:29 +02:00
|
|
|
self.x = new_geo['x']
|
|
|
|
self.y = new_geo['y']
|
|
|
|
return "client_moved"
|
|
|
|
return False # no change
|
|
|
|
|
|
|
|
def check_table_no(self, hud):
|
|
|
|
result = self.get_table_no()
|
|
|
|
if result != False and result != self.table:
|
|
|
|
self.table = result
|
2010-09-27 13:34:25 +02:00
|
|
|
if hud is not None:
|
2010-11-22 22:37:37 +01:00
|
|
|
hud.parent.main_window.emit("table_changed", hud)
|
2010-09-07 15:50:29 +02:00
|
|
|
return True
|
2010-09-28 05:41:03 +02:00
|
|
|
|
2009-05-21 17:13:39 +02:00
|
|
|
def check_bad_words(self, title):
|
|
|
|
for word in bad_words:
|
|
|
|
if word in title: return True
|
2009-11-07 18:30:47 +01:00
|
|
|
return False
|