From cd1d4df96d6fabde92faad5a18d2e67a17b7fc35 Mon Sep 17 00:00:00 2001 From: eblade Date: Wed, 14 Jan 2009 23:05:08 -0500 Subject: [PATCH 1/6] HUD_main: Add site name to list of windows being HUDed, fix weird call convention to the "del" operator, which is not a function. call clean_title() on hud titles being killed, so we actually kill (deep) tables and such HUD: Add function "kill_hud_menu", which is now called from the Kill This HUD menu option, to avoid a potential loop in kill_hud() Record the handle of the HUD's destroy signal, use it to un-register, before performing a kill, also avoiding potential loop there Do not allow kill_hud() to be called twice in the same HUD object, return doing nothing if deleted is already set on it (that should totally solve the loop problem) --- pyfpdb/HUD_main.py | 7 +++++-- pyfpdb/Hud.py | 12 +++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 2e89492d..50ec7068 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -65,7 +65,7 @@ def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_conn gtk.gdk.threads_enter() try: - newlabel = gtk.Label(table_name) + newlabel = gtk.Label(table.site + " - " + table_name) eb.add(newlabel) newlabel.show() @@ -98,9 +98,12 @@ def update_HUD(new_hand_id, table_name, config, stat_dict): def HUD_removed(tablename): global hud_dict, eb + tablename = Tables.clean_title(tablename) + # TODO: There's a potential problem here somewhere, that this hacks around .. the table_name as being passed to HUD_create is cleaned, + # but the table.name as being passed here is not cleaned. I don't know why. -eric if tablename in hud_dict and hud_dict[tablename].deleted: eb.remove(hud_dict[tablename].tablehudlabel) - del(hud_dict[tablename]) + del hud_dict[tablename] return False return True diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 9911a61b..612cd9de 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -76,7 +76,7 @@ class Hud: self.main_window = gtk.Window() self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC) self.main_window.set_title(table.name + " FPDBHUD") - self.main_window.connect("destroy", self.kill_hud) + self.main_window.destroyhandler = self.main_window.connect("destroy", self.kill_hud) self.main_window.set_decorated(False) self.main_window.set_opacity(self.colors["hudopacity"]) @@ -101,7 +101,7 @@ class Hud: self.menu = gtk.Menu() self.item1 = gtk.MenuItem('Kill this HUD') self.menu.append(self.item1) - self.item1.connect("activate", self.kill_hud) + self.item1.connect("activate", self.kill_hud_menu) self.item1.show() self.item2 = gtk.MenuItem('Save Layout') @@ -163,11 +163,17 @@ class Hud: return False def kill_hud(self, *args): + if self.deleted: + return # no killing self twice. for k in self.stat_windows: self.stat_windows[k].window.destroy() - self.main_window.destroy() self.deleted = True + self.main_window.disconnect(self.main_window.destroyhandler) # so we don't potentially infiniteloop in here, right + self.main_window.destroy() HUD_main.HUD_removed(self.table.name) + + def kill_hud_menu(self, *args): + self.main_window.destroy() def reposition_windows(self, *args): for w in self.stat_windows: From 9bf85513275d52e56eec5d64c0eeadab4fed584c Mon Sep 17 00:00:00 2001 From: eblade Date: Thu, 15 Jan 2009 11:09:30 -0500 Subject: [PATCH 2/6] update get_nt_exe() to elevate privileges before calling OpenProcess, bizarre. --- pyfpdb/Tables.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index ddd04fc0..6655b7a6 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -35,6 +35,7 @@ if os.name == 'nt': import win32process import win32api import win32con + import win32security # FreePokerTools modules import Configuration @@ -250,10 +251,23 @@ def discover_nt_tournament(c, tour_number, tab_number): def get_nt_exe(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 def decode_windows(c, title, hwnd): From 30cd5791315cf6c1c9dc613137a0718ab5d713f4 Mon Sep 17 00:00:00 2001 From: Worros Date: Thu, 22 Jan 2009 01:40:05 +0900 Subject: [PATCH 3/6] Session detection code. Possible use in showing sessions graphically on the plot --- pyfpdb/GuiGraphViewer.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 8026a2c7..834817fb 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -20,7 +20,7 @@ import pygtk pygtk.require('2.0') import gtk import os -from time import time +from time import * #import pokereval try: @@ -366,3 +366,31 @@ class GuiGraphViewer (threading.Thread): self.leftPanelBox.show() self.graphBox.show() + +################################# + + self.db.cursor.execute("""select UNIX_TIMESTAMP(handStart) as time, id from Hands ORDER BY time""") + THRESHOLD = 1800 + hands = self.db.cursor.fetchall() + + times = map(lambda x:long(x[0]), hands) + handids = map(lambda x:int(x[1]), hands) + print "DEBUG: len(times) %s" %(len(times)) + diffs = diff(times) + print "DEBUG: len(diffs) %s" %(len(diffs)) + index = nonzero(diff(times) > THRESHOLD) + print "DEBUG: len(index[0]) %s" %(len(index[0])) + print "DEBUG: index %s" %(index) + print "DEBUG: index[0][0] %s" %(index[0][0]) + + total = 0 + + last_idx = 0 + for i in range(len(index[0])): + print "Hands in session %4s: %4s Start: %s End: %s Total: %s" %(i, index[0][i] - last_idx, strftime("%d/%m/%Y %H:%M", localtime(times[last_idx])), strftime("%d/%m/%Y %H:%M", localtime(times[index[0][i]])), times[index[0][i]] - times[last_idx]) + total = total + (index[0][i] - last_idx) + last_idx = index[0][i] + 1 + + print "Total: ", total +################################# + From 37a643f0549617a2e625f2e902e27c97abbd280e Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 26 Jan 2009 14:31:08 -0500 Subject: [PATCH 4/6] Kill aux windows when killing the HUD. --- pyfpdb/Hud.py | 5 +++++ pyfpdb/Mucked.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 612cd9de..157e6c42 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -167,6 +167,11 @@ class Hud: return # no killing self twice. for k in self.stat_windows: self.stat_windows[k].window.destroy() +# also kill any aux windows + for m in self.aux_windows: + m.destroy() + self.aux_windows.remove(m) + self.deleted = True self.main_window.disconnect(self.main_window.destroyhandler) # so we don't potentially infiniteloop in here, right self.main_window.destroy() diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 5d4d8047..07021c7e 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -50,6 +50,9 @@ class Aux_Window: def update_gui(self): pass + def destroy(self): + self.container.destroy() + class Stud_mucked(Aux_Window): def __init__(self, container, hud, config, params): From 3261f285066c7edf2a74f8cf8f71ade1d344adbf Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 26 Jan 2009 18:31:04 -0500 Subject: [PATCH 5/6] Put a frame around each eb in the stat window-avoid tooltip annoyance. --- pyfpdb/Hud.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 157e6c42..b1794c5d 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -365,23 +365,29 @@ class Stat_Window: self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False) self.window.add(self.grid) + self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.e_box = [] self.frame = [] self.label = [] for r in range(self.game.rows): + self.frame.append([]) self.e_box.append([]) self.label.append([]) for c in range(self.game.cols): + self.frame[r].append( gtk.Frame() ) self.e_box[r].append( gtk.EventBox() ) self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor) Stats.do_tip(self.e_box[r][c], 'stuff') - self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) +# self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) + self.grid.attach(self.frame[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) + self.frame[r][c].add(self.e_box[r][c]) self.label[r].append( gtk.Label('xxx') ) + self.frame[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.label[r][c].modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) self.label[r][c].modify_fg(gtk.STATE_NORMAL, parent.foregroundcolor) From 64f1f17d7c25ef686c82fd0d4b5b7a6e2dc26054 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 26 Jan 2009 20:02:01 -0500 Subject: [PATCH 6/6] Make player stats rows not expand = prettier. --- pyfpdb/GuiPlayerStats.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 1f1967e9..b2eb0108 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -67,7 +67,7 @@ class GuiPlayerStats (threading.Thread): for t in titles: l = gtk.Label(titles[col]) l.show() - self.stats_table.attach(l, col, col+1, row, row+1) + self.stats_table.attach(l, col, col+1, row, row+1, yoptions=gtk.SHRINK) col +=1 for row in range(rows-1): @@ -87,7 +87,7 @@ class GuiPlayerStats (threading.Thread): else: l.set_alignment(xalign=1.0, yalign=0.5) eb.add(l) - self.stats_table.attach(eb, col, col+1, row+1, row+2) + self.stats_table.attach(eb, col, col+1, row+1, row+2, yoptions=gtk.SHRINK) l.show() eb.show() self.fdb.db.commit()