handle new hands in a thread, minimize stat windows on demand
This commit is contained in:
parent
1fde7655ea
commit
fe2554ce35
|
@ -79,11 +79,9 @@ class Database:
|
||||||
self.connection.close()
|
self.connection.close()
|
||||||
|
|
||||||
def get_table_name(self, hand_id):
|
def get_table_name(self, hand_id):
|
||||||
print "searching for ", hand_id
|
|
||||||
c = self.connection.cursor()
|
c = self.connection.cursor()
|
||||||
c.execute(self.sql.query['get_table_name'], (hand_id, ))
|
c.execute(self.sql.query['get_table_name'], (hand_id, ))
|
||||||
row = c.fetchone()
|
row = c.fetchone()
|
||||||
print "found = ", row
|
|
||||||
return row
|
return row
|
||||||
|
|
||||||
def get_last_hand(self):
|
def get_last_hand(self):
|
||||||
|
|
|
@ -37,6 +37,7 @@ import sys
|
||||||
import os
|
import os
|
||||||
import thread
|
import thread
|
||||||
import time
|
import time
|
||||||
|
import string
|
||||||
|
|
||||||
errorfile = open('HUD-error.txt', 'w', 0)
|
errorfile = open('HUD-error.txt', 'w', 0)
|
||||||
sys.stderr = errorfile
|
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
|
global hud_dict
|
||||||
def idle_func():
|
def idle_func():
|
||||||
global hud_dict
|
global hud_dict
|
||||||
gtk.threads_enter()
|
gtk.gdk.threads_enter()
|
||||||
try:
|
try:
|
||||||
hud_dict[table_name] = Hud.Hud(table, max, poker_game, config, db_name)
|
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].create(new_hand_id, config)
|
||||||
hud_dict[table_name].update(new_hand_id, db_connection, config, stat_dict)
|
hud_dict[table_name].update(new_hand_id, db_connection, config, stat_dict)
|
||||||
return False
|
return False
|
||||||
finally:
|
finally:
|
||||||
gtk.threads_leave
|
gtk.gdk.threads_leave
|
||||||
gobject.idle_add(idle_func)
|
gobject.idle_add(idle_func)
|
||||||
|
|
||||||
def update_HUD(new_hand_id, table_name, db_connection, config, stat_dict):
|
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
|
def producer(): # This is the thread function
|
||||||
global hud_dict
|
global hud_dict
|
||||||
db_connection = Database.Database(config, db_name, 'temp')
|
|
||||||
|
|
||||||
while True: # wait for a new hand number on stdin
|
while True: # wait for a new hand number on stdin
|
||||||
new_hand_id = sys.stdin.readline()
|
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
|
if new_hand_id == "": # blank line means quit
|
||||||
destroy()
|
destroy()
|
||||||
|
|
||||||
|
@ -100,10 +100,12 @@ def producer(): # This is the thread function
|
||||||
for h in hud_dict.keys():
|
for h in hud_dict.keys():
|
||||||
if hud_dict[h].deleted:
|
if hud_dict[h].deleted:
|
||||||
del(hud_dict[h])
|
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)
|
(table_name, max, poker_game) = db_connection.get_table_name(new_hand_id)
|
||||||
stat_dict = db_connection.get_stats_from_hand(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 a hud for this table exists, just update it
|
||||||
if hud_dict.has_key(table_name):
|
if hud_dict.has_key(table_name):
|
||||||
|
@ -111,10 +113,8 @@ def producer(): # This is the thread function
|
||||||
# otherwise create a new hud
|
# otherwise create a new hud
|
||||||
else:
|
else:
|
||||||
table_windows = Tables.discover(config)
|
table_windows = Tables.discover(config)
|
||||||
print "searching for %s" % (table_name)
|
|
||||||
for t in table_windows.keys():
|
for t in table_windows.keys():
|
||||||
if table_windows[t].name == table_name:
|
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)
|
create_HUD(new_hand_id, table_windows[t], db_name, table_name, max, poker_game, db_connection, config, stat_dict)
|
||||||
break
|
break
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user