handle new hands in a thread, minimize stat windows on demand

This commit is contained in:
Ray 2008-10-17 21:28:33 -04:00
parent 1fde7655ea
commit fe2554ce35
2 changed files with 8 additions and 10 deletions

View File

@ -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):

View File

@ -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