From 2fc2cc9743451269b7b0276901591acf986ec17f Mon Sep 17 00:00:00 2001 From: Eratosthenes Date: Thu, 16 Sep 2010 20:29:58 -0400 Subject: [PATCH] Integrate new table handling. --- pyfpdb/HUD_main.pyw | 35 ++++++++++++++++++++---- pyfpdb/TableWindow.py | 20 ++++++++++---- pyfpdb/WinTables.py | 62 ++++++++++++++++++------------------------- pyfpdb/XTables.py | 18 +++---------- 4 files changed, 74 insertions(+), 61 deletions(-) diff --git a/pyfpdb/HUD_main.pyw b/pyfpdb/HUD_main.pyw index 590f9291..c3ac5d18 100755 --- a/pyfpdb/HUD_main.pyw +++ b/pyfpdb/HUD_main.pyw @@ -109,6 +109,11 @@ class HUD_main(object): # a main window self.main_window = gtk.Window() + self.main_window.connect("client_moved", self.client_moved) + self.main_window.connect("client_resized", self.client_resized) + self.main_window.connect("client_destroyed", self.client_destroyed) + self.main_window.connect("game_changed", self.game_changed) + self.main_window.connect("table_changed", self.table_changed) self.main_window.connect("destroy", self.destroy) self.vb = gtk.VBox() self.label = gtk.Label(_('Closing this window will exit from the HUD.')) @@ -116,11 +121,27 @@ class HUD_main(object): self.main_window.add(self.vb) self.main_window.set_title(_("HUD Main Window")) self.main_window.show_all() + gobject.timeout_add(100, self.check_tables) except: log.error( "*** Exception in HUD_main.init() *** " ) for e in traceback.format_tb(sys.exc_info()[2]): log.error(e) + def client_moved(self, widget, hud): + print hud, hud.table.name, "moved", hud.table.x, hud.table.y + + def client_resized(self, widget, hud): + print "Client resized" + + def client_destroyed(self, widget, hud): # call back for terminating the main eventloop + self.kill_hud(None, hud.table.name) + + def game_changed(self, widget, hud): + print "Game Changed." + + def table_changed(self, widget, hud): + print "Table Changed." + self.kill_hud(None, hud.table.name) def destroy(self, *args): # call back for terminating the main eventloop log.info(_("Terminating normally.")) @@ -135,6 +156,11 @@ class HUD_main(object): del(self.hud_dict[table]) self.main_window.resize(1,1) + def check_tables(self): + for hud in self.hud_dict.keys(): + self.hud_dict[hud].table.check_table(self.hud_dict[hud]) + return True + def create_HUD(self, new_hand_id, table, table_name, max, poker_game, type, stat_dict, cards): """type is "ring" or "tour" used to set hud_params""" @@ -269,6 +295,7 @@ class HUD_main(object): stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params ,self.hero_ids[site_id], num_seats) t3 = time.time() + try: self.hud_dict[temp_key].stat_dict = stat_dict except KeyError: # HUD instance has been killed off, key is stale @@ -299,10 +326,7 @@ class HUD_main(object): cards['common'] = comm_cards['common'] table_kwargs = dict(table_name = table_name, tournament = tour_number, table_number = tab_number) - search_string = getTableTitleRe(self.config, site_name, type, **table_kwargs) - # print "getTableTitleRe ", self.config, site_name, type, "=", search_string - tablewindow = Tables.Table(search_string, **table_kwargs) - + tablewindow = Tables.Table(self.config, site_name, **table_kwargs) if tablewindow is None: # If no client window is found on the screen, complain and continue if type == "tour": @@ -321,7 +345,8 @@ class HUD_main(object): log.info(_("HUD_main.read_stdin: hand read in %4.3f seconds (%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f)") % (t6-t0,t1-t0,t2-t0,t3-t0,t4-t0,t5-t0,t6-t0)) self.db_connection.connection.rollback() - + if type == "tour": + tablewindow.check_table_no() if __name__== "__main__": # start the HUD_main object diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index 55e1e549..0750ad75 100644 --- a/pyfpdb/TableWindow.py +++ b/pyfpdb/TableWindow.py @@ -135,6 +135,15 @@ class Table_Window(object): self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs) self.find_table_parameters() + 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'] + + self.game = self.get_game() + def __str__(self): # __str__ method for testing likely_attrs = ("number", "title", "site", "width", "height", "x", "y", @@ -152,9 +161,10 @@ class Table_Window(object): # by the "check" methods. Most of the get methods are in the # subclass because they are specific to X, Windows, etc. def get_game(self): - title = self.get_window_title() - if title is None: - return False +# title = self.get_window_title() +# if title is None: +# return False + title = self.title # check for nl and pl games first, to avoid bad matches for game, names in nlpl_game_names.iteritems(): @@ -184,13 +194,13 @@ class Table_Window(object): def check_table(self, hud): result = self.check_size() if result != False: - hud.main_window.emit(result, hud) + hud.parent.main_window.emit(result, hud) if result == "client_destroyed": return True result = self.check_loc() if result != False: - hud.main_window.emit(result, hud) + hud.parent.main_window.emit(result, hud) if result == "client_destroyed": return True return True diff --git a/pyfpdb/WinTables.py b/pyfpdb/WinTables.py index ab608ea2..2e1f493d 100644 --- a/pyfpdb/WinTables.py +++ b/pyfpdb/WinTables.py @@ -79,20 +79,9 @@ class Table(Table_Window): log.error(_("self.window doesn't exist? why?")) return None - (x, y, width, height) = win32gui.GetWindowRect(hwnd) - log.debug("x = %s y = %s width = %s height = %s" % (x, y, width, height)) - self.x = int(x) + b_width - self.y = int(y) + tb_height - self.width = width - x - self.height = height - y - log.debug("x = %s y = %s width = %s height = %s" % (self.x, self.y, self.width, self.height)) - - self.exe = self.get_nt_exe(hwnd) self.title = titles[hwnd] - self.site = "" self.hud = None self.number = hwnd - self.gdkhandle = gtk.gdk.window_foreign_new(long(self.window)) def get_geometry(self): if not win32gui.IsWindow(self.number): # window closed @@ -104,8 +93,8 @@ class Table(Table_Window): height = height - y return {'x' : int(x) + b_width, 'y' : int(y) + tb_height, - 'width' : int(height) - b_width - tb_height, - 'height' : int(width) - 2*b_width + 'height' : int(height) - y, + 'width' : int(width) - x } except: return None @@ -113,26 +102,27 @@ class Table(Table_Window): def get_window_title(self): return win32gui.GetWindowText(self.window) - def get_nt_exe(self, hwnd): - """Finds the name of the executable that the given window handle belongs to.""" +# def get_nt_exe(self, hwnd): +# """Finds the name of the executable that the given window handle belongs to.""" +# +# # Request privileges to enable "debug process", so we can later use PROCESS_VM_READ, retardedly required to GetModuleFileNameEx() +# priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY +# hToken = win32security.OpenProcessToken (win32api.GetCurrentProcess(), priv_flags) +# # enable "debug process" +# privilege_id = win32security.LookupPrivilegeValue (None, win32security.SE_DEBUG_NAME) +# old_privs = win32security.AdjustTokenPrivileges (hToken, 0, [(privilege_id, win32security.SE_PRIVILEGE_ENABLED)]) +# +# # Open the process, and query it's filename +# processid = win32process.GetWindowThreadProcessId(hwnd) +# pshandle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, processid[1]) +# exename = win32process.GetModuleFileNameEx(pshandle, 0) +# +# # clean up +# win32api.CloseHandle(pshandle) +# win32api.CloseHandle(hToken) +# +# return exename - # Request privileges to enable "debug process", so we can later use PROCESS_VM_READ, retardedly required to GetModuleFileNameEx() - priv_flags = win32security.TOKEN_ADJUST_PRIVILEGES | win32security.TOKEN_QUERY - hToken = win32security.OpenProcessToken (win32api.GetCurrentProcess(), priv_flags) - # enable "debug process" - privilege_id = win32security.LookupPrivilegeValue (None, win32security.SE_DEBUG_NAME) - old_privs = win32security.AdjustTokenPrivileges (hToken, 0, [(privilege_id, win32security.SE_PRIVILEGE_ENABLED)]) - - # Open the process, and query it's filename - processid = win32process.GetWindowThreadProcessId(hwnd) - pshandle = win32api.OpenProcess(win32con.PROCESS_QUERY_INFORMATION | win32con.PROCESS_VM_READ, False, processid[1]) - exename = win32process.GetModuleFileNameEx(pshandle, 0) - - # clean up - win32api.CloseHandle(pshandle) - win32api.CloseHandle(hToken) - - return exename def topify(self, hud): """Set the specified gtk window to stayontop in MS Windows.""" @@ -151,10 +141,10 @@ class Table(Table_Window): # hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(w[0]) hud.main_window.gdkhandle = hud.main_window.window hud.main_window.gdkhandle.set_transient_for(self.gdkhandle) - rect = self.gdkhandle.get_frame_extents() - (innerx, innery) = self.gdkhandle.get_origin() - b_width = rect.x - innerx - tb_height = rect.y - innery +# rect = self.gdkhandle.get_frame_extents() +# (innerx, innery) = self.gdkhandle.get_origin() +# b_width = rect.x - innerx +# tb_height = rect.y - innery # # style = win32gui.GetWindowLong(self.number, win32con.GWL_EXSTYLE) # style |= win32con.WS_CLIPCHILDREN diff --git a/pyfpdb/XTables.py b/pyfpdb/XTables.py index caf2251a..d8ca677f 100644 --- a/pyfpdb/XTables.py +++ b/pyfpdb/XTables.py @@ -23,7 +23,6 @@ # Standard Library modules import re import os -import subprocess # pyGTK modules import gtk @@ -50,26 +49,15 @@ class Table(Table_Window): if self.check_bad_words(title): continue self.number = int( mo.group(1), 0) self.title = title - self.exe = "" # not used? self.hud = None # specified later break - + if self.number is None: return None self.window = self.get_window_from_xid(self.number) self.parent = self.window.query_tree().parent - 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'] - - self.game = self.get_game() - self.gdk_handle = gtk.gdk.window_foreign_new(self.number) - def get_window_from_xid(self, id): for outside in root.query_tree().children: if outside.id == id: @@ -92,13 +80,13 @@ class Table(Table_Window): return None def get_window_title(self): - proc = subprocess.Popen("xwininfo -wm -id %d" % self.number, shell = True, stdout = subprocess.PIPE) - s = proc.stdout.read() + s = os.popen("xwininfo -wm -id %d" % self.number).read() mo = re.search('"(.+)"', s) try: return mo.group(1) except AttributeError: return None + def topify(self, hud): hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(hud.main_window.window.xid)