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 +################################# + 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() 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..b1794c5d 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,22 @@ 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() +# 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() 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: @@ -354,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) 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): 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):