Merge branch 'master' of git://git.assembla.com/fpdb-eric

This commit is contained in:
Worros 2008-10-26 18:49:03 +09:00
commit 40af286fd6
3 changed files with 195 additions and 46 deletions

11
pyfpdb/HUD_main.py Executable file → Normal file
View File

@ -112,11 +112,11 @@ def read_stdin(): # This is the thread function
update_HUD(new_hand_id, table_name, config, stat_dict)
# otherwise create a new hud
else:
table_windows = Tables.discover(config)
for t in table_windows.keys():
if table_windows[t].name == table_name:
create_HUD(new_hand_id, table_windows[t], db_name, table_name, max, poker_game, db_connection, config, stat_dict)
break
tablewindow = Tables.discover_table_by_name(config, table_name)
if tablewindow == None:
sys.stderr.write("table name "+table_name+" not found\n")
else:
create_HUD(new_hand_id, tablewindow, db_name, table_name, max, poker_game, db_connection, config, stat_dict)
if __name__== "__main__":
sys.stderr.write("HUD_main starting\n")
@ -142,3 +142,4 @@ if __name__== "__main__":
main_window.show_all()
gtk.main()

View File

@ -23,6 +23,7 @@ Create and manage the hud overlays.
########################################################################
# Standard Library modules
import os
import sys
# pyGTK modules
import pygtk
@ -34,6 +35,7 @@ import gobject
if os.name == 'nt':
import win32gui
import win32con
import win32api
# FreePokerTools modules
import Tables # needed for testing only
@ -62,12 +64,10 @@ class Hud:
self.main_window = gtk.Window()
# self.window.set_decorated(0)
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
self.main_window.set_keep_above(1)
self.main_window.set_title(table.name)
self.main_window.set_keep_above(True)
self.main_window.set_title(table.name + " FPDBHUD")
self.main_window.connect("destroy", self.kill_hud)
if self.stacked:
self.main_window.connect("window-state-event", self.on_window_event)
#self.main_window.set_transient_for(parent.get_toplevel())
self.ebox = gtk.EventBox()
self.label = gtk.Label("Close this window to\nkill the HUD for\n %s\nMinimizing it hides stats." %
@ -90,7 +90,8 @@ class Hud:
self.main_window.show_all()
# set_keep_above(1) for windows
if os.name == 'nt': self.topify_window(self.main_window)
if os.name == 'nt':
self.topify_window(self.main_window)
def on_button_press(self, widget, event):
if event.button == 3:
@ -98,16 +99,6 @@ class Hud:
return True
return False
def on_window_event(self, widget, event):
if self.stacked:
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
for sw in self.stat_windows.keys():
self.stat_windows[sw].window.iconify()
else:
for sw in self.stat_windows:
self.stat_windows[sw].window.deiconify()
def kill_hud(self, args):
for k in self.stat_windows.keys():
self.stat_windows[k].window.destroy()
@ -152,7 +143,56 @@ class Hud:
adj = self.adj_seats(hand, config)
# create the stat windows
for i in range(1, self.max + 1):
(x, y) = config.supported_sites[self.table.site].layout[self.max].location[adj[i]]
# 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]]
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],
parent = self,
table = self.table,
@ -203,7 +243,21 @@ class Hud:
for w in tl_windows:
if w[1] == unique_name:
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
#win32gui.ShowWindow(w[0], win32con.SW_HIDE)
window.parentgdkhandle = gtk.gdk.window_foreign_new(long(self.table.number))
self.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0])
self.main_window.gdkhandle.set_transient_for(window.parentgdkhandle)
#win32gui.ShowWindow(w[0], win32con.SW_SHOW)
style = win32gui.GetWindowLong(self.table.number, win32con.GWL_EXSTYLE)
#style |= win32con.WS_EX_TOOLWINDOW
#style &= ~win32con.WS_EX_APPWINDOW
style |= win32con.WS_CLIPCHILDREN
win32gui.SetWindowLong(self.table.number, win32con.GWL_EXSTYLE, style)
#win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
# notify_id = (w[0],
# 0,
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
@ -276,6 +330,7 @@ class Stat_Window:
self.window.set_keep_above(1)
self.window.set_title("%s" % seat)
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.window.add(self.grid)
@ -316,16 +371,15 @@ class Stat_Window:
for w in tl_windows:
if w[1] == unique_name:
win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
# notify_id = (w[0],
# 0,
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
# win32con.WM_USER+20,
# 0,
# '')
# win32gui.Shell_NotifyIcon(win32gui.NIM_DELETE, notify_id)
#
window.set_title(real_name)
#win32gui.SetWindowPos(w[0], win32con.HWND_TOPMOST, 0, 0, 0, 0, win32con.SWP_NOMOVE|win32con.SWP_NOSIZE)
# 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)
window.set_title(real_name)
def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit()
@ -342,6 +396,7 @@ class Popup_window:
self.window.set_title("popup")
self.window.set_property("skip-taskbar-hint", True)
self.window.set_transient_for(parent.get_toplevel())
self.window.set_position(gtk.WIN_POS_CENTER_ON_PARENT)
self.ebox = gtk.EventBox()
@ -454,7 +509,14 @@ class Popup_window:
for w in tl_windows:
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)
# notify_id = (w[0],
# 0,
# win32gui.NIF_ICON | win32gui.NIF_MESSAGE | win32gui.NIF_TIP,
@ -473,12 +535,16 @@ if __name__== "__main__":
main_window.show_all()
c = Configuration.Config()
tables = Tables.discover(c)
#tables = Tables.discover(c)
t = Tables.discover_table_by_name(c, "Corona")
if t is None:
print "Table not found."
db = Database.Database(c, 'fpdb', 'holdem')
for t in tables:
win = Hud(t, 8, c, db)
# for t in tables:
win = Hud(t, 10, 'holdem', c, db)
win.create(1, c)
# t.get_details()
win.update(8300, db, c)
win.update(8300, db, c)
gtk.main()

View File

@ -33,6 +33,9 @@ import re
if os.name == 'nt':
import win32gui
import win32process
import win32api
import win32con
# FreePokerTools modules
import Configuration
@ -57,17 +60,26 @@ class Table_Window:
def discover(c):
if os.name == 'posix':
tables = discover_posix(c)
return tables
elif os.name == 'nt':
tables = discover_nt(c)
return tables
elif os.name == 'mac':
tables = discover_mac(c)
return tables
else: tables = {}
else:
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):
""" Poker client table window finder for posix/Linux = XWindows."""
tables = {}
@ -94,8 +106,17 @@ def discover_posix(c):
# use this eval thingie to call the title bar decoder specified in the config file
eval("%s(tw)" % c.supported_sites[s].decoder)
tables[tw.name] = tw
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
# currently displayed on the screen. The discover_posix should give you
@ -121,6 +142,7 @@ def discover_posix(c):
def win_enum_handler(hwnd, titles):
titles[hwnd] = win32gui.GetWindowText(hwnd)
def child_enum_handler(hwnd, children):
print hwnd, win32.GetWindowRect(hwnd)
@ -150,7 +172,7 @@ def discover_nt(c):
tw.y = int( y ) + tb_height
if re.search('Logged In as', titles[hwnd]):
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"
else:
tw.site = "Unknown"
@ -159,14 +181,73 @@ def discover_nt(c):
eval("%s(tw)" % c.supported_sites[tw.site].decoder)
else:
tw.name = "Unknown"
tables[tw.name] = tw
tables[len(tables)] = tw
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 c.supported_sites[tw.site].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):
""" Poker client table window finder for Macintosh."""
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):
# 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
@ -221,6 +302,7 @@ def fulltilt_decode_table(tw):
if __name__=="__main__":
c = Configuration.Config()
print discover_table_by_name(c, "Catacaos")
tables = discover(c)
for t in tables.keys():