2010-07-05 06:17:08 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*- coding: utf-8 -*-
|
2009-05-21 17:13:39 +02:00
|
|
|
"""Discover_TableWindow.py
|
|
|
|
|
|
|
|
Inspects the currently open windows and finds those of interest to us--that is
|
|
|
|
poker table windows from supported sites. Returns a list
|
|
|
|
of Table_Window objects representing the windows found.
|
|
|
|
"""
|
2010-07-05 06:17:08 +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
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
# pyGTK modules
|
|
|
|
import pygtk
|
|
|
|
import gtk
|
|
|
|
import gobject
|
|
|
|
|
|
|
|
# FreePokerTools modules
|
|
|
|
import Configuration
|
|
|
|
#if os.name == "posix":
|
|
|
|
# import XTables
|
|
|
|
#elif os.name == "nt":
|
|
|
|
# import WinTables
|
|
|
|
|
|
|
|
# Global used for figuring out the current game being played from the title
|
|
|
|
# The dict key is the fpdb name for the game
|
|
|
|
# The list is the names for those games used by the supported poker sites
|
|
|
|
# This is currently only used for HORSE, so it only needs to support those
|
|
|
|
# games on PokerStars and Full Tilt.
|
|
|
|
game_names = { #fpdb name Stars Name FTP Name
|
|
|
|
"holdem" : ("Hold\'em" , ),
|
|
|
|
"omahahilo" : ("Omaha H/L" , ),
|
|
|
|
"studhilo" : ("Stud H/L" , ),
|
|
|
|
"razz" : ("Razz" , ),
|
|
|
|
"studhi" : ("Stud" , "Stud Hi")
|
|
|
|
}
|
|
|
|
|
|
|
|
# A window title might have our table name + one of theses words/
|
|
|
|
# phrases. If it has this word in the title, it is not a table.
|
|
|
|
bad_words = ('History for table:', 'HUD:', 'Chat:')
|
|
|
|
|
|
|
|
# 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,))
|
|
|
|
|
|
|
|
# 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
|
|
|
|
# from the corresponding hand history.
|
|
|
|
# tw.site = the site name, e.g. PokerStars, FullTilt. This must match the site
|
|
|
|
# name specified in the config file.
|
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.
|
|
|
|
|
|
|
|
class Table_Window(object):
|
2009-11-07 18:30:47 +01:00
|
|
|
def __init__(self, search_string, table_name = None, tournament = None, table_number = None):
|
2009-05-21 17:13:39 +02:00
|
|
|
|
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
|
|
|
print "tournament %s, table %s" % (tournament, table_number)
|
|
|
|
self.tournament = int(tournament)
|
|
|
|
self.table = int(table_number)
|
|
|
|
self.name = "%s - %s" % (self.tournament, self.table)
|
2009-11-07 18:30:47 +01:00
|
|
|
elif table_name is not None:
|
2010-02-04 22:33:21 +01:00
|
|
|
# search_string = table_name
|
2009-11-07 18:30:47 +01:00
|
|
|
self.name = table_name
|
|
|
|
self.tournament = None
|
2009-05-21 17:13:39 +02:00
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
|
|
|
self.find_table_parameters(search_string)
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
# __str__ method for testing
|
2010-02-04 22:33:21 +01:00
|
|
|
likely_attrs = ("site", "number", "title", "width", "height", "x", "y",
|
2009-11-06 23:34:42 +01:00
|
|
|
"tournament", "table", "gdkhandle")
|
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
|
|
|
|
|
|
|
|
def get_game(self):
|
|
|
|
title = self.get_window_title()
|
|
|
|
print title
|
|
|
|
for game, names in game_names.iteritems():
|
|
|
|
for name in names:
|
|
|
|
if name in title:
|
2010-02-04 22:33:21 +01:00
|
|
|
return game
|
2009-05-21 17:13:39 +02:00
|
|
|
return None
|
|
|
|
|
|
|
|
def check_geometry(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.x != new_geo['x'] or self.y != new_geo['y']: # window moved
|
|
|
|
self.x = new_geo['x']
|
|
|
|
self.y = new_geo['y']
|
|
|
|
return "client_moved"
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
else: return False # window not changed
|
|
|
|
|
|
|
|
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
|