threaded the hudcache query, update to install in windows web page

This commit is contained in:
Ray 2008-10-14 10:33:32 -04:00
parent 52c651555d
commit 43cd552466
3 changed files with 71 additions and 59 deletions

View File

@ -36,7 +36,6 @@ Main for FreePokerTools HUD.
import sys import sys
import os import os
import thread import thread
import Queue
errorfile = open('HUD-error.txt', 'w', 0) errorfile = open('HUD-error.txt', 'w', 0)
sys.stderr = errorfile sys.stderr = errorfile
@ -61,54 +60,58 @@ config = 0;
def destroy(*args): # call back for terminating the main eventloop def destroy(*args): # call back for terminating the main eventloop
gtk.main_quit() gtk.main_quit()
def process_new_hand(new_hand_id, db_name): def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_connection, config, stat_dict):
# there is a new hand_id to be processed
# read the hand_id from stdin and strip whitespace
global hud_dict global hud_dict
def idle_func():
global hud_dict
gtk.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
gobject.idle_add(idle_func)
def update_HUD(new_hand_id, table_name, db_connection, config, stat_dict):
global hud_dict
def idle_func():
gtk.threads_enter()
try:
hud_dict[table_name].update(new_hand_id, db_connection, config, stat_dict)
return False
finally:
gtk.threads_leave
gobject.idle_add(idle_func)
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()
if new_hand_id == "": # blank line means quit
destroy()
# delete hud_dict entries for any HUD destroyed since last iteration
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])
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)
# 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):
hud_dict[table_name].update(new_hand_id, db_connection, config) update_HUD(new_hand_id, table_name, db_connection, config, stat_dict)
# otherwise create a new hud # otherwise create a new hud
else: else:
table_windows = Tables.discover(config) table_windows = Tables.discover(config)
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:
hud_dict[table_name] = Hud.Hud(table_windows[t], max, poker_game, config, db_name) create_HUD(new_hand_id, table_windows[t], db_name, table_name, max, poker_game, db_connection, config, stat_dict)
hud_dict[table_name].create(new_hand_id, config)
hud_dict[table_name].update(new_hand_id, db_connection, config)
break break
# print "table name \"%s\" not identified, no hud created" % (table_name)
db_connection.close_connection()
return(1)
def check_stdin(db_name):
try:
hand_no = dataQueue.get(block=False)
process_new_hand(hand_no, db_name)
except:
pass
return True
def read_stdin(source, condition, db_name):
new_hand_id = sys.stdin.readline()
if new_hand_id == "":
destroy()
process_new_hand(new_hand_id, db_name)
return True
def producer(): # This is the thread function
while True:
hand_no = sys.stdin.readline() # reads stdin
if new_hand_id == "":
destroy()
dataQueue.put(hand_no) # and puts result on the queue
if __name__== "__main__": if __name__== "__main__":
sys.stderr.write("HUD_main starting\n") sys.stderr.write("HUD_main starting\n")
@ -120,18 +123,9 @@ if __name__== "__main__":
sys.stderr.write("Using db name = %s\n" % (db_name)) sys.stderr.write("Using db name = %s\n" % (db_name))
config = Configuration.Config() config = Configuration.Config()
# db_connection = Database.Database(config, 'fpdb', 'holdem')
if os.name == 'posix':
s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, read_stdin, db_name)
elif os.name == 'nt':
dataQueue = Queue.Queue() # shared global. infinite size
gobject.threads_init() # this is required gobject.threads_init() # this is required
thread.start_new_thread(producer, ()) # starts the thread thread.start_new_thread(producer, ()) # starts the thread
gobject.timeout_add(1000, check_stdin, db_name)
else:
print "Sorry your operating system is not supported."
sys.exit()
main_window = gtk.Window() main_window = gtk.Window()
main_window.connect("destroy", destroy) main_window.connect("destroy", destroy)

View File

@ -52,6 +52,7 @@ class Hud:
self.max = max self.max = max
self.db_name = db_name self.db_name = db_name
self.deleted = False self.deleted = False
self.stacked = True
self.stat_windows = {} self.stat_windows = {}
self.popup_windows = {} self.popup_windows = {}
@ -63,7 +64,10 @@ class Hud:
self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC) self.main_window.set_gravity(gtk.gdk.GRAVITY_STATIC)
self.main_window.set_keep_above(1) self.main_window.set_keep_above(1)
self.main_window.set_title(table.name) self.main_window.set_title(table.name)
self.main_window.connect("destroy", self.kill_hud) self.main_window.connect("destroy", self.kill_hud)
if self.stacked:
self.main_window.connect("window-state-event", self.on_window_event)
self.ebox = gtk.EventBox() self.ebox = gtk.EventBox()
self.label = gtk.Label("Close this window to\nkill the HUD for\n %s" % (table.name)) self.label = gtk.Label("Close this window to\nkill the HUD for\n %s" % (table.name))
@ -93,6 +97,15 @@ class Hud:
return True return True
return False return False
def on_window_event(self, widget, event):
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
for sw in self.stat_windows.keys():
self.stat_windows[sw].window.iconify()
else:
for sw in self.stat_windows:
self.stat_windows[sw].window.deiconify()
def kill_hud(self, args): def kill_hud(self, args):
for k in self.stat_windows.keys(): for k in self.stat_windows.keys():
self.stat_windows[k].window.destroy() self.stat_windows[k].window.destroy()
@ -160,9 +173,9 @@ class Hud:
# self.m = Mucked.Mucked(self.mucked_window, self.db_connection) # self.m = Mucked.Mucked(self.mucked_window, self.db_connection)
# self.mucked_window.show_all() # self.mucked_window.show_all()
def update(self, hand, db, config): def update(self, hand, db, config, stat_dict):
self.hand = hand # this is the last hand, so it is available later self.hand = hand # this is the last hand, so it is available later
stat_dict = db.get_stats_from_hand(hand) # stat_dict = db.get_stats_from_hand(hand)
for s in stat_dict.keys(): for s in stat_dict.keys():
self.stat_windows[stat_dict[s]['seat']].player_id = stat_dict[s]['player_id'] self.stat_windows[stat_dict[s]['seat']].player_id = stat_dict[s]['player_id']
for r in range(0, config.supported_games[self.poker_game].rows): for r in range(0, config.supported_games[self.poker_game].rows):

View File

@ -9,12 +9,17 @@ require 'sidebar.php';
<div id="main"> <div id="main">
<h1>Before You Begin</h1>
<p>Most people should install using the <a href="http://sourceforge.net/project/showfiles.php?group_id=226872">Installer</a>. These instructions have not been updated recently, but can serve as a guide to someone who knows what he is doing. Unless you have a special reason for installing manually, you really should be using the installer.</p>
<h1>Vista Users</h1>
<p>The installer does not install mysql properly on Microsoft Vista installations, due to the UAC. You should first install mysql using this <a href="http://port25.technet.com/videos/research/MySQL_Windows.pdf">how to (pdf)</a>. Then run the installer. The installer will detect the mysql installation and not reintstall.</p>
<h1>Installing in Windows</h1> <h1>Installing in Windows</h1>
<div class="winInst"> <div class="winInst">
<p>These instructions were made with Windows XP. They should also work with Windows NT / 2000 / 2003 / Vista and 2008. Please report any differences to gmic at users.sourceforge.net. <p>These instructions were made with Windows XP. They should also work with Windows NT / 2000 / 2003 and 2008. Please report any differences to gmic at users.sourceforge.net.
<p>If you're still using Win3/95/98/ME then you should switch to GNU/Linux, *BSD or WinXP.</p> <p>If you're still using Win3/95/98/ME then you should switch to GNU/Linux, *BSD or WinXP.</p>
<p>An Installer will be made at some point.</p>
<div class="screenshot"> <div class="screenshot">
<img src="img/00.mySqlWebsite1.jpg" alt="windows install guide screenshot" /> <img src="img/00.mySqlWebsite1.jpg" alt="windows install guide screenshot" />