Tables discovered via process name, then window name, only going through two nested loops, instead of two nested loops followed by another loop.

(can someone test to make sure this actually doesn't break stuff on *nix?)

Windows HUD Stats Windows no longer appear in Windows taskbar (now gtk transients for table hud window)
This commit is contained in:
unknown 2008-10-24 15:44:53 -04:00
parent 7833c0c5cd
commit 2bd4932a77
3 changed files with 176 additions and 24 deletions

View File

@ -77,14 +77,14 @@ def process_new_hand(new_hand_id, db_name):
hud_dict[table_name].update(new_hand_id, db_connection, config) hud_dict[table_name].update(new_hand_id, db_connection, config)
# otherwise create a new hud # otherwise create a new hud
else: else:
table_windows = Tables.discover(config) tablewindow = Tables.discover_table_by_name(config, table_name)
for t in table_windows.keys(): if tablewindow == None:
if table_windows[t].name == table_name: sys.stderr.write("table name "+table_name+" not found\n")
hud_dict[table_name] = Hud.Hud(table_windows[t], max, poker_game, config, db_name) else:
hud_dict[table_name] = Hud.Hud(tablewindow, max, poker_game, config, db_name)
hud_dict[table_name].create(new_hand_id, config) hud_dict[table_name].create(new_hand_id, config)
hud_dict[table_name].update(new_hand_id, db_connection, config) hud_dict[table_name].update(new_hand_id, db_connection, config)
break
# print "table name \"%s\" not identified, no hud created" % (table_name)
db_connection.close_connection() db_connection.close_connection()
return(1) return(1)

View File

@ -23,6 +23,7 @@ Create and manage the hud overlays.
######################################################################## ########################################################################
# Standard Library modules # Standard Library modules
import os import os
import sys
# pyGTK modules # pyGTK modules
import pygtk import pygtk
@ -61,9 +62,10 @@ class Hud:
self.main_window = gtk.Window() self.main_window = gtk.Window()
# self.window.set_decorated(0) # self.window.set_decorated(0)
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC) self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
self.main_window.set_keep_above(1) self.main_window.set_keep_above(True)
self.main_window.set_title(table.name) self.main_window.set_title(table.name + " FPDBHUD")
self.main_window.connect("destroy", self.kill_hud) self.main_window.connect("destroy", self.kill_hud)
#self.main_window.set_transient_for(parent.get_toplevel())
self.ebox = gtk.EventBox() self.ebox = gtk.EventBox()
self.label = gtk.Label("Close this window to\nkill the HUD for\n %s" % (table.name)) self.label = gtk.Label("Close this window to\nkill the HUD for\n %s" % (table.name))
@ -137,7 +139,56 @@ class Hud:
adj = self.adj_seats(hand, config) adj = self.adj_seats(hand, config)
# create the stat windows # create the stat windows
for i in range(1, self.max + 1): for i in range(1, self.max + 1):
# the below IF always appears to be passed as TRUE, I don't know why. If you have an 8-max game, but
# your config file doesn't understand 8 max, it's a crash. It was even a crash when I tried using the
# full-fledged exception handling blocks.
# - Eric
if self.max in config.supported_sites[self.table.site].layout:
(x, y) = config.supported_sites[self.table.site].layout[self.max].location[adj[i]] (x, y) = config.supported_sites[self.table.site].layout[self.max].location[adj[i]]
else:
if i == 1:
x = 684
y = 61
elif i == 2:
x = 689
y = 239
elif i == 3:
x = 692
y = 346
elif i == 4:
x = 586
y = 393
elif i == 5:
x = 421
y = 440
elif i == 6:
x = 267
y = 440
elif i == 7:
x = 0
y = 361
elif i == 8:
x = 0
y = 280
elif i == 9:
x = 121
y = 280
elif i == 10:
x = 46
y = 30
sys.stderr.write("at location "+str(x)+" "+str(y)+"\n")
sys.stderr.write("config:"+str(config)+"\n")
gameslist = config.supported_games
sys.stderr.write("supported games:"+str(gameslist)+"\n")
sys.stderr.write("desired game:"+str(self.poker_game)+"\n")
thisgame = gameslist['holdem']
sys.stderr.write("this game:"+str(thisgame)+"\n")
# the above code looks absolutely completely useless. The below line was freezing the interpreter, so I added the above lines to try and debug
# which piece of the below line was causing it to lock up. Adding the "thisgame = gameslist['holdem']" line fixed it, for some unknown reason.
# removing any one of the lines above causes the interpreter to freeze for me on the next statement.
# -eric
self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game], self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game],
parent = self, parent = self,
table = self.table, table = self.table,
@ -189,7 +240,15 @@ class Hud:
for w in tl_windows: for w in tl_windows:
if w[1] == unique_name: if w[1] == unique_name:
# win32gui.ShowWindow(w[0], win32con.SW_HIDE)
# style = win32gui.GetWindowLong(w[0], win32con.GWL_EXSTYLE)
# style |= win32con.WS_EX_TOOLWINDOW
# style &= ~win32con.WS_EX_APPWINDOW
# win32gui.SetWindowLong(w[0], win32con.GWL_EXSTYLE, style)
# win32gui.ShowWindow(w[0], win32con.SW_SHOW)
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE) win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
# notify_id = (w[0], # notify_id = (w[0],
# 0, # 0,
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP, # win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
@ -262,6 +321,7 @@ class Stat_Window:
self.window.set_keep_above(1) self.window.set_keep_above(1)
self.window.set_title("%s" % seat) self.window.set_title("%s" % seat)
self.window.set_property("skip-taskbar-hint", True) self.window.set_property("skip-taskbar-hint", True)
self.window.set_transient_for(parent.main_window)
self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False) self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False)
self.window.add(self.grid) self.window.add(self.grid)
@ -328,6 +388,7 @@ class Popup_window:
self.window.set_title("popup") self.window.set_title("popup")
self.window.set_property("skip-taskbar-hint", True) self.window.set_property("skip-taskbar-hint", True)
self.window.set_transient_for(parent.get_toplevel()) self.window.set_transient_for(parent.get_toplevel())
self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT) self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
self.ebox = gtk.EventBox() self.ebox = gtk.EventBox()
@ -440,7 +501,14 @@ class Popup_window:
for w in tl_windows: for w in tl_windows:
if w[1] == unique_name: if w[1] == unique_name:
# win32gui.ShowWindow(w[0], win32con.SW_HIDE)
# style = win32gui.GetWindowLong(w[0], win32con.GWL_EXSTYLE)
# style |= win32con.WS_EX_TOOLWINDOW
# style &= ~win32con.WS_EX_APPWINDOW
# win32gui.SetWindowLong(w[0], win32con.GWL_EXSTYLE, style)
# win32gui.ShowWindow(w[0], win32con.SW_SHOW)
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE) win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
# notify_id = (w[0], # notify_id = (w[0],
# 0, # 0,
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP, # win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
@ -459,11 +527,15 @@ if __name__== "__main__":
main_window.show_all() main_window.show_all()
c = Configuration.Config() c = Configuration.Config()
tables = Tables.discover(c) #tables = Tables.discover(c)
t = Tables.discover_table_by_name(c, "Southend")
if t is None:
print "Table not found."
db = Database.Database(c, 'fpdb', 'holdem') db = Database.Database(c, 'fpdb', 'holdem')
for t in tables: # for t in tables:
win = Hud(t, 8, c, db) win = Hud(t, 10, 'holdem', c, db)
win.create(1, c)
# t.get_details() # t.get_details()
win.update(8300, db, c) win.update(8300, db, c)

View File

@ -33,6 +33,9 @@ import re
if os.name == 'nt': if os.name == 'nt':
import win32gui import win32gui
import win32process
import win32api
import win32con
# FreePokerTools modules # FreePokerTools modules
import Configuration import Configuration
@ -57,17 +60,24 @@ class Table_Window:
def discover(c): def discover(c):
if os.name == 'posix': if os.name == 'posix':
tables = discover_posix(c) tables = discover_posix(c)
return tables
elif os.name == 'nt': elif os.name == 'nt':
tables = discover_nt(c) tables = discover_nt(c)
return tables elif os.name == 'mac':
elif ox.name == 'mac':
tables = discover_mac(c) tables = discover_mac(c)
return tables
else: tables = {} else: tables = {}
return(tables) return(tables)
def discover_table_by_name(c, tablename):
if os.name == 'posix':
table = discover_posix_by_name(c, tablename)
elif os.name == 'nt':
table = discover_nt_by_name(c, tablename)
elif os.name == 'mac':
table = discover_mac_by_name(c, tablename)
else: table = None
return(table)
def discover_posix(c): def discover_posix(c):
""" Poker client table window finder for posix/Linux = XWindows.""" """ Poker client table window finder for posix/Linux = XWindows."""
tables = {} tables = {}
@ -94,8 +104,17 @@ def discover_posix(c):
# use this eval thingie to call the title bar decoder specified in the config file # use this eval thingie to call the title bar decoder specified in the config file
eval("%s(tw)" % c.supported_sites[s].decoder) eval("%s(tw)" % c.supported_sites[s].decoder)
tables[tw.name] = tw tables[tw.name] = tw
return tables return tables
def discover_posix_by_name(c, tablename):
tables = discover_posix(c)
for t in tables:
if t.name.find(tablename) > -1:
return t
return None
# #
# The discover_xx functions query the system and report on the poker clients # The discover_xx functions query the system and report on the poker clients
# currently displayed on the screen. The discover_posix should give you # currently displayed on the screen. The discover_posix should give you
@ -121,6 +140,7 @@ def discover_posix(c):
def win_enum_handler(hwnd, titles): def win_enum_handler(hwnd, titles):
titles[hwnd] = win32gui.GetWindowText(hwnd) titles[hwnd] = win32gui.GetWindowText(hwnd)
def child_enum_handler(hwnd, children): def child_enum_handler(hwnd, children):
print hwnd, win32.GetWindowRect(hwnd) print hwnd, win32.GetWindowRect(hwnd)
@ -150,7 +170,7 @@ def discover_nt(c):
tw.y = int( y ) + tb_height tw.y = int( y ) + tb_height
if re.search('Logged In as', titles[hwnd]): if re.search('Logged In as', titles[hwnd]):
tw.site = "PokerStars" tw.site = "PokerStars"
elif re.search('Logged In As', titles[hwnd]): elif re.search('Logged In As', titles[hwnd]): #wait, what??!
tw.site = "Full Tilt" tw.site = "Full Tilt"
else: else:
tw.site = "Unknown" tw.site = "Unknown"
@ -159,14 +179,73 @@ def discover_nt(c):
eval("%s(tw)" % c.supported_sites[tw.site].decoder) eval("%s(tw)" % c.supported_sites[tw.site].decoder)
else: else:
tw.name = "Unknown" tw.name = "Unknown"
tables[tw.name] = tw tables[len(tables)] = tw
return tables return tables
def discover_nt_by_name(c, tablename):
# this is pretty much identical to the 'search all windows for all poker sites' code, but made to dig just for a specific table name
# it could be implemented a bunch better - and we need to not assume the width/height thing that (steffen?) assumed above, we should
# be able to dig up the window's titlebar handle and get it's information, and such .. but.. for now, i guess this will work.
# - eric
b_width = 3
tb_height = 29
titles = {}
# tables = discover_nt(c)
win32gui.EnumWindows(win_enum_handler, titles)
for s in c.supported_sites.keys():
for hwnd in titles.keys():
processid = win32process.GetWindowThreadProcessId(hwnd)
pshandle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, processid[1])
exe = win32process.GetModuleFileNameEx(pshandle, 0)
if exe.find(c.supported_sites[s].table_finder) == -1:
continue
if titles[hwnd].find(tablename) > -1:
if titles[hwnd].find("History for table:") > -1 or titles[hwnd].find("FPDBHUD") > -1:
continue
tw = Table_Window()
tw.number = hwnd
(x, y, width, height) = win32gui.GetWindowRect(hwnd)
tw.title = titles[hwnd]
tw.width = int(width) - 2 * b_width
tw.height = int(height) - b_width - tb_height
tw.x = int(x) + b_width
tw.y = int(y) + tb_height
tw.site = c.supported_sites[s].site_name
if not tw.site == "Unknown" and not tw.decoder == "Unknown":
eval("%s(tw)" % c.supported_sites[tw.site].decoder)
else:
tw.name = tablename
return tw
# if we don't find anything by process name, let's search one more time, and call it Unknown ?
for hwnd in titles.keys():
if titles[hwnd].find(tablename) > -1:
if titles[hwnd].find("History for table:") > -1 or titles[hwnd].find("FPDBHUD") > -1:
continue
tw = Table_Window()
tw.number = hwnd
(x, y, width, height) = win32gui.GetWindowRect(hwnd)
tw.title = titles[hwnd]
tw.width = int(width) - 2 * b_width
tw.height = int(height) - b_width - tb_height
tw.x = int(x) + b_width
tw.y = int(y) + tb_height
tw.site = "Unknown"
tw.name = tablename
return tw
return None
def discover_mac(c): def discover_mac(c):
""" Poker client table window finder for Macintosh.""" """ Poker client table window finder for Macintosh."""
tables = {} tables = {}
return tables return tables
def discover_mac_by_name(c, tablename):
# again, i have no mac to test this on, sorry -eric
return discover_mac(c)
def pokerstars_decode_table(tw): def pokerstars_decode_table(tw):
# extract the table name OR the tournament number and table name from the title # extract the table name OR the tournament number and table name from the title
# other info in title is redundant with data in the database # other info in title is redundant with data in the database
@ -221,6 +300,7 @@ def fulltilt_decode_table(tw):
if __name__=="__main__": if __name__=="__main__":
c = Configuration.Config() c = Configuration.Config()
print discover_table_by_name(c, "Catacaos")
tables = discover(c) tables = discover(c)
for t in tables.keys(): for t in tables.keys():