cleanup of threads in HUD_main.py

This commit is contained in:
Ray 2008-10-18 11:48:24 -04:00
parent edf22d8cf3
commit 93a167b64d
2 changed files with 14 additions and 14 deletions

View File

@ -70,24 +70,24 @@ def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_conn
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)
hud_dict[table_name].update(new_hand_id, config, stat_dict)
return False
finally:
gtk.gdk.threads_leave
gobject.idle_add(idle_func)
def update_HUD(new_hand_id, table_name, db_connection, config, stat_dict):
def update_HUD(new_hand_id, 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)
hud_dict[table_name].update(new_hand_id, config, stat_dict)
return False
finally:
gtk.threads_leave
gobject.idle_add(idle_func)
def producer(): # This is the thread function
def read_stdin(): # This is the thread function
global hud_dict
while True: # wait for a new hand number on stdin
@ -109,7 +109,7 @@ def producer(): # This is the thread function
# if a hud for this table exists, just update it
if hud_dict.has_key(table_name):
update_HUD(new_hand_id, table_name, db_connection, config, stat_dict)
update_HUD(new_hand_id, config, stat_dict)
# otherwise create a new hud
else:
table_windows = Tables.discover(config)
@ -130,7 +130,7 @@ if __name__== "__main__":
config = Configuration.Config()
gobject.threads_init() # this is required
thread.start_new_thread(producer, ()) # starts the thread
thread.start_new_thread(read_stdin, ()) # starts the thread
main_window = gtk.Window()
main_window.connect("destroy", destroy)

View File

@ -99,6 +99,7 @@ class Hud:
def on_window_event(self, widget, event):
if self.stacked:
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
for sw in self.stat_windows.keys():
self.stat_windows[sw].window.iconify()
@ -173,9 +174,8 @@ class Hud:
# self.m = Mucked.Mucked(self.mucked_window, self.db_connection)
# self.mucked_window.show_all()
def update(self, hand, db, config, stat_dict):
def update(self, hand, config, stat_dict):
self.hand = hand # this is the last hand, so it is available later
# stat_dict = db.get_stats_from_hand(hand)
for s in stat_dict.keys():
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):