From fe2554ce358eed6a7f79d7d646dcb268c927b21a Mon Sep 17 00:00:00 2001 From: Ray Date: Fri, 17 Oct 2008 21:28:33 -0400 Subject: [PATCH] handle new hands in a thread, minimize stat windows on demand --- pyfpdb/Database.py | 2 -- pyfpdb/HUD_main.py | 16 ++++++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 09461a87..63de54b2 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -79,11 +79,9 @@ class Database: self.connection.close() def get_table_name(self, hand_id): - print "searching for ", hand_id c = self.connection.cursor() c.execute(self.sql.query['get_table_name'], (hand_id, )) row = c.fetchone() - print "found = ", row return row def get_last_hand(self): diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index faacc0bf..996a92ac 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -37,6 +37,7 @@ import sys import os import thread import time +import string errorfile = open('HUD-error.txt', 'w', 0) sys.stderr = errorfile @@ -65,14 +66,14 @@ def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_conn global hud_dict def idle_func(): global hud_dict - gtk.threads_enter() + gtk.gdk.threads_enter() try: hud_dict[table_name] = Hud.Hud(table, 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, stat_dict) return False finally: - gtk.threads_leave + gtk.gdk.threads_leave gobject.idle_add(idle_func) def update_HUD(new_hand_id, table_name, db_connection, config, stat_dict): @@ -88,11 +89,10 @@ def update_HUD(new_hand_id, table_name, db_connection, config, stat_dict): def producer(): # This is the thread function global hud_dict - db_connection = Database.Database(config, db_name, 'temp') while True: # wait for a new hand number on stdin new_hand_id = sys.stdin.readline() - print "hand = ", new_hand_id + new_hand_id = string.rstrip(new_hand_id) if new_hand_id == "": # blank line means quit destroy() @@ -100,10 +100,12 @@ def producer(): # This is the thread function for h in hud_dict.keys(): if hud_dict[h].deleted: del(hud_dict[h]) - print "getting table name" + +# connect to the db and get basic info about the new hand + db_connection = Database.Database(config, db_name, 'temp') (table_name, max, poker_game) = db_connection.get_table_name(new_hand_id) stat_dict = db_connection.get_stats_from_hand(new_hand_id) - print "table = %s, max = %s, game = %s" % (table_name, max, poker_game) + db_connection.close_connection() # if a hud for this table exists, just update it if hud_dict.has_key(table_name): @@ -111,10 +113,8 @@ def producer(): # This is the thread function # otherwise create a new hud else: table_windows = Tables.discover(config) - print "searching for %s" % (table_name) for t in table_windows.keys(): if table_windows[t].name == table_name: - print "found" create_HUD(new_hand_id, table_windows[t], db_name, table_name, max, poker_game, db_connection, config, stat_dict) break