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

View File

@ -99,12 +99,13 @@ class Hud:
def on_window_event(self, widget, event): def on_window_event(self, widget, event):
if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED: if self.stacked:
for sw in self.stat_windows.keys(): if event.new_window_state & gtk.gdk.WINDOW_STATE_ICONIFIED:
self.stat_windows[sw].window.iconify() for sw in self.stat_windows.keys():
else: self.stat_windows[sw].window.iconify()
for sw in self.stat_windows: else:
self.stat_windows[sw].window.deiconify() 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():
@ -173,9 +174,8 @@ 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, stat_dict): def update(self, hand, 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)
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):