Integrate new table handling.
This commit is contained in:
parent
d176da93d4
commit
2fc2cc9743
|
@ -109,6 +109,11 @@ class HUD_main(object):
|
||||||
|
|
||||||
# a main window
|
# a main window
|
||||||
self.main_window = gtk.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.main_window.connect("destroy", self.destroy)
|
||||||
self.vb = gtk.VBox()
|
self.vb = gtk.VBox()
|
||||||
self.label = gtk.Label(_('Closing this window will exit from the HUD.'))
|
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.add(self.vb)
|
||||||
self.main_window.set_title(_("HUD Main Window"))
|
self.main_window.set_title(_("HUD Main Window"))
|
||||||
self.main_window.show_all()
|
self.main_window.show_all()
|
||||||
|
gobject.timeout_add(100, self.check_tables)
|
||||||
except:
|
except:
|
||||||
log.error( "*** Exception in HUD_main.init() *** " )
|
log.error( "*** Exception in HUD_main.init() *** " )
|
||||||
for e in traceback.format_tb(sys.exc_info()[2]):
|
for e in traceback.format_tb(sys.exc_info()[2]):
|
||||||
log.error(e)
|
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
|
def destroy(self, *args): # call back for terminating the main eventloop
|
||||||
log.info(_("Terminating normally."))
|
log.info(_("Terminating normally."))
|
||||||
|
@ -135,6 +156,11 @@ class HUD_main(object):
|
||||||
del(self.hud_dict[table])
|
del(self.hud_dict[table])
|
||||||
self.main_window.resize(1,1)
|
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):
|
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"""
|
"""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
|
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)
|
,self.hero_ids[site_id], num_seats)
|
||||||
t3 = time.time()
|
t3 = time.time()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self.hud_dict[temp_key].stat_dict = stat_dict
|
self.hud_dict[temp_key].stat_dict = stat_dict
|
||||||
except KeyError: # HUD instance has been killed off, key is stale
|
except KeyError: # HUD instance has been killed off, key is stale
|
||||||
|
@ -299,10 +326,7 @@ class HUD_main(object):
|
||||||
cards['common'] = comm_cards['common']
|
cards['common'] = comm_cards['common']
|
||||||
|
|
||||||
table_kwargs = dict(table_name = table_name, tournament = tour_number, table_number = tab_number)
|
table_kwargs = dict(table_name = table_name, tournament = tour_number, table_number = tab_number)
|
||||||
search_string = getTableTitleRe(self.config, site_name, type, **table_kwargs)
|
tablewindow = Tables.Table(self.config, site_name, **table_kwargs)
|
||||||
# print "getTableTitleRe ", self.config, site_name, type, "=", search_string
|
|
||||||
tablewindow = Tables.Table(search_string, **table_kwargs)
|
|
||||||
|
|
||||||
if tablewindow is None:
|
if tablewindow is None:
|
||||||
# If no client window is found on the screen, complain and continue
|
# If no client window is found on the screen, complain and continue
|
||||||
if type == "tour":
|
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)")
|
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))
|
% (t6-t0,t1-t0,t2-t0,t3-t0,t4-t0,t5-t0,t6-t0))
|
||||||
self.db_connection.connection.rollback()
|
self.db_connection.connection.rollback()
|
||||||
|
if type == "tour":
|
||||||
|
tablewindow.check_table_no()
|
||||||
if __name__== "__main__":
|
if __name__== "__main__":
|
||||||
|
|
||||||
# start the HUD_main object
|
# start the HUD_main object
|
||||||
|
|
|
@ -135,6 +135,15 @@ class Table_Window(object):
|
||||||
self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs)
|
self.search_string = getTableTitleRe(self.config, self.site, self.type, **table_kwargs)
|
||||||
self.find_table_parameters()
|
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):
|
def __str__(self):
|
||||||
# __str__ method for testing
|
# __str__ method for testing
|
||||||
likely_attrs = ("number", "title", "site", "width", "height", "x", "y",
|
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
|
# by the "check" methods. Most of the get methods are in the
|
||||||
# subclass because they are specific to X, Windows, etc.
|
# subclass because they are specific to X, Windows, etc.
|
||||||
def get_game(self):
|
def get_game(self):
|
||||||
title = self.get_window_title()
|
# title = self.get_window_title()
|
||||||
if title is None:
|
# if title is None:
|
||||||
return False
|
# return False
|
||||||
|
title = self.title
|
||||||
|
|
||||||
# check for nl and pl games first, to avoid bad matches
|
# check for nl and pl games first, to avoid bad matches
|
||||||
for game, names in nlpl_game_names.iteritems():
|
for game, names in nlpl_game_names.iteritems():
|
||||||
|
@ -184,13 +194,13 @@ class Table_Window(object):
|
||||||
def check_table(self, hud):
|
def check_table(self, hud):
|
||||||
result = self.check_size()
|
result = self.check_size()
|
||||||
if result != False:
|
if result != False:
|
||||||
hud.main_window.emit(result, hud)
|
hud.parent.main_window.emit(result, hud)
|
||||||
if result == "client_destroyed":
|
if result == "client_destroyed":
|
||||||
return True
|
return True
|
||||||
|
|
||||||
result = self.check_loc()
|
result = self.check_loc()
|
||||||
if result != False:
|
if result != False:
|
||||||
hud.main_window.emit(result, hud)
|
hud.parent.main_window.emit(result, hud)
|
||||||
if result == "client_destroyed":
|
if result == "client_destroyed":
|
||||||
return True
|
return True
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -79,20 +79,9 @@ class Table(Table_Window):
|
||||||
log.error(_("self.window doesn't exist? why?"))
|
log.error(_("self.window doesn't exist? why?"))
|
||||||
return None
|
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.title = titles[hwnd]
|
||||||
self.site = ""
|
|
||||||
self.hud = None
|
self.hud = None
|
||||||
self.number = hwnd
|
self.number = hwnd
|
||||||
self.gdkhandle = gtk.gdk.window_foreign_new(long(self.window))
|
|
||||||
|
|
||||||
def get_geometry(self):
|
def get_geometry(self):
|
||||||
if not win32gui.IsWindow(self.number): # window closed
|
if not win32gui.IsWindow(self.number): # window closed
|
||||||
|
@ -104,8 +93,8 @@ class Table(Table_Window):
|
||||||
height = height - y
|
height = height - y
|
||||||
return {'x' : int(x) + b_width,
|
return {'x' : int(x) + b_width,
|
||||||
'y' : int(y) + tb_height,
|
'y' : int(y) + tb_height,
|
||||||
'width' : int(height) - b_width - tb_height,
|
'height' : int(height) - y,
|
||||||
'height' : int(width) - 2*b_width
|
'width' : int(width) - x
|
||||||
}
|
}
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
@ -113,26 +102,27 @@ class Table(Table_Window):
|
||||||
def get_window_title(self):
|
def get_window_title(self):
|
||||||
return win32gui.GetWindowText(self.window)
|
return win32gui.GetWindowText(self.window)
|
||||||
|
|
||||||
def get_nt_exe(self, hwnd):
|
# def get_nt_exe(self, hwnd):
|
||||||
"""Finds the name of the executable that the given window handle belongs to."""
|
# """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):
|
def topify(self, hud):
|
||||||
"""Set the specified gtk window to stayontop in MS Windows."""
|
"""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 = gtk.gdk.window_foreign_new(w[0])
|
||||||
hud.main_window.gdkhandle = hud.main_window.window
|
hud.main_window.gdkhandle = hud.main_window.window
|
||||||
hud.main_window.gdkhandle.set_transient_for(self.gdkhandle)
|
hud.main_window.gdkhandle.set_transient_for(self.gdkhandle)
|
||||||
rect = self.gdkhandle.get_frame_extents()
|
# rect = self.gdkhandle.get_frame_extents()
|
||||||
(innerx, innery) = self.gdkhandle.get_origin()
|
# (innerx, innery) = self.gdkhandle.get_origin()
|
||||||
b_width = rect.x - innerx
|
# b_width = rect.x - innerx
|
||||||
tb_height = rect.y - innery
|
# tb_height = rect.y - innery
|
||||||
#
|
#
|
||||||
# style = win32gui.GetWindowLong(self.number, win32con.GWL_EXSTYLE)
|
# style = win32gui.GetWindowLong(self.number, win32con.GWL_EXSTYLE)
|
||||||
# style |= win32con.WS_CLIPCHILDREN
|
# style |= win32con.WS_CLIPCHILDREN
|
||||||
|
|
|
@ -23,7 +23,6 @@
|
||||||
# Standard Library modules
|
# Standard Library modules
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import subprocess
|
|
||||||
|
|
||||||
# pyGTK modules
|
# pyGTK modules
|
||||||
import gtk
|
import gtk
|
||||||
|
@ -50,26 +49,15 @@ class Table(Table_Window):
|
||||||
if self.check_bad_words(title): continue
|
if self.check_bad_words(title): continue
|
||||||
self.number = int( mo.group(1), 0)
|
self.number = int( mo.group(1), 0)
|
||||||
self.title = title
|
self.title = title
|
||||||
self.exe = "" # not used?
|
|
||||||
self.hud = None # specified later
|
self.hud = None # specified later
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.number is None:
|
if self.number is None:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
self.window = self.get_window_from_xid(self.number)
|
self.window = self.get_window_from_xid(self.number)
|
||||||
self.parent = self.window.query_tree().parent
|
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):
|
def get_window_from_xid(self, id):
|
||||||
for outside in root.query_tree().children:
|
for outside in root.query_tree().children:
|
||||||
if outside.id == id:
|
if outside.id == id:
|
||||||
|
@ -92,13 +80,13 @@ class Table(Table_Window):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def get_window_title(self):
|
def get_window_title(self):
|
||||||
proc = subprocess.Popen("xwininfo -wm -id %d" % self.number, shell = True, stdout = subprocess.PIPE)
|
s = os.popen("xwininfo -wm -id %d" % self.number).read()
|
||||||
s = proc.stdout.read()
|
|
||||||
mo = re.search('"(.+)"', s)
|
mo = re.search('"(.+)"', s)
|
||||||
try:
|
try:
|
||||||
return mo.group(1)
|
return mo.group(1)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
def topify(self, hud):
|
def topify(self, hud):
|
||||||
hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(hud.main_window.window.xid)
|
hud.main_window.gdkhandle = gtk.gdk.window_foreign_new(hud.main_window.window.xid)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user