diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 0bfe7f40..88e87104 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -77,14 +77,14 @@ def process_new_hand(new_hand_id, db_name): hud_dict[table_name].update(new_hand_id, db_connection, config) # otherwise create a new hud else: - table_windows = Tables.discover(config) - for t in table_windows.keys(): - if table_windows[t].name == table_name: - hud_dict[table_name] = Hud.Hud(table_windows[t], max, poker_game, config, db_name) - hud_dict[table_name].create(new_hand_id, config) - hud_dict[table_name].update(new_hand_id, db_connection, config) - break -# print "table name \"%s\" not identified, no hud created" % (table_name) + tablewindow = Tables.discover_table_by_name(config, table_name) + if tablewindow == None: + sys.stderr.write("table name "+table_name+" not found\n") + 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].update(new_hand_id, db_connection, config) + db_connection.close_connection() return(1) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 003e0be1..6d3b1fef 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -23,6 +23,7 @@ Create and manage the hud overlays. ######################################################################## # Standard Library modules import os +import sys # pyGTK modules import pygtk @@ -61,9 +62,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) + #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" % (table.name)) @@ -136,8 +138,57 @@ 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]] + 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]] + 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, @@ -189,7 +240,15 @@ 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) +# 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, @@ -262,6 +321,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) @@ -328,6 +388,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() @@ -440,7 +501,14 @@ class Popup_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) +# 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, @@ -459,12 +527,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, "Southend") + 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() diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index cb6209c8..9cbcc384 100644 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -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,24 @@ 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 ox.name == 'mac': + elif os.name == 'mac': tables = discover_mac(c) - return 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 +104,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 @@ -120,6 +139,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 +170,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 +179,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 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): """ 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 +300,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():