Cleanup of HUD_main prior to integrating newTables code.

This commit is contained in:
Eratosthenes 2009-11-03 21:52:40 -05:00
parent 0a563cad53
commit 3265766c77

View File

@ -109,7 +109,7 @@ class HUD_main(object):
self.main_window.set_title("HUD Main Window") self.main_window.set_title("HUD Main Window")
self.main_window.show_all() self.main_window.show_all()
def destroy(*args): # call back for terminating the main eventloop def destroy(self, *args): # call back for terminating the main eventloop
gtk.main_quit() gtk.main_quit()
def kill_hud(self, event, table): def kill_hud(self, event, table):
@ -190,7 +190,6 @@ class HUD_main(object):
# need their own access to the database, but should open their own # need their own access to the database, but should open their own
# if it is required. # if it is required.
self.db_connection = Database.Database(self.config) self.db_connection = Database.Database(self.config)
tourny_finder = re.compile('(\d+) (\d+)')
# get hero's screen names and player ids # get hero's screen names and player ids
self.hero, self.hero_ids = {}, {} self.hero, self.hero_ids = {}, {}
@ -207,65 +206,47 @@ class HUD_main(object):
if new_hand_id == "": # blank line means quit if new_hand_id == "": # blank line means quit
self.destroy() self.destroy()
break # this thread is not always killed immediately with gtk.main_quit() break # this thread is not always killed immediately with gtk.main_quit()
# get basic info about the new hand from the db # get basic info about the new hand from the db
# if there is a db error, complain, skip hand, and proceed # if there is a db error, complain, skip hand, and proceed
try: try:
(table_name, max, poker_game, type, site_id) = self.db_connection.get_table_name(new_hand_id) (table_name, max, poker_game, type, site_id, tour_number, tab_number) = \
self.db_connection.get_table_info(new_hand_id)
cards = self.db_connection.get_cards(new_hand_id)
comm_cards = self.db_connection.get_common_cards(new_hand_id)
if comm_cards != {}: # stud!
cards['common'] = comm_cards['common']
except Exception, err: except Exception, err:
err = traceback.extract_tb(sys.exc_info()[2])[-1] print "db error: skipping %s" % new_hand_id
print "db error: skipping "+str(new_hand_id)+" "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) sys.stderr.write("Database error: could not find hand %s.\n" % new_hand_id)
if new_hand_id: # new_hand_id is none if we had an error prior to the store
sys.stderr.write("Database error %s in hand %d. Skipping.\n" % (err, int(new_hand_id)))
continue continue
if type == "tour": # hand is from a tournament if type == "tour": # hand is from a tournament
mat_obj = tourny_finder.search(table_name)
if mat_obj:
(tour_number, tab_number) = mat_obj.group(1, 2)
temp_key = tour_number temp_key = tour_number
else: # tourney, but can't get number and table
print "could not find tournament: skipping "
#sys.stderr.write("Could not find tournament %d in hand %d. Skipping.\n" % (int(tour_number), int(new_hand_id)))
continue
else: else:
temp_key = table_name temp_key = table_name
# Update an existing HUD # Update an existing HUD
if temp_key in self.hud_dict: if temp_key in self.hud_dict:
try: # get stats using hud's specific params and get cards
# get stats using hud's specific params
self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days']
, self.hud_dict[temp_key].hud_params['h_hud_days']) , self.hud_dict[temp_key].hud_params['h_hud_days'])
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id])
except:
err = traceback.extract_tb(sys.exc_info()[2])[-1]
print "db get_stats error: skipping "+str(new_hand_id)+" "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1])
if new_hand_id: # new_hand_id is none if we had an error prior to the store
sys.stderr.write("Database get_stats error %s in hand %d. Skipping.\n" % (err, int(new_hand_id)))
continue
self.hud_dict[temp_key].stat_dict = stat_dict self.hud_dict[temp_key].stat_dict = stat_dict
cards = self.db_connection.get_cards(new_hand_id)
comm_cards = self.db_connection.get_common_cards(new_hand_id)
if comm_cards != {}: # stud!
cards['common'] = comm_cards['common']
self.hud_dict[temp_key].cards = cards self.hud_dict[temp_key].cards = cards
[aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows] [aw.update_data(new_hand_id, self.db_connection) for aw in self.hud_dict[temp_key].aux_windows]
self.update_HUD(new_hand_id, temp_key, self.config) self.update_HUD(new_hand_id, temp_key, self.config)
# Or create a new HUD # Or create a new HUD
else: else:
try: # get stats using default params--also get cards
# get stats using default params
self.db_connection.init_hud_stat_vars( self.hud_params['hud_days'], self.hud_params['h_hud_days'] ) self.db_connection.init_hud_stat_vars( self.hud_params['hud_days'], self.hud_params['h_hud_days'] )
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params, self.hero_ids[site_id]) stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params, self.hero_ids[site_id])
except: cards = self.db_connection.get_cards(new_hand_id)
err = traceback.extract_tb(sys.exc_info()[2])[-1] comm_cards = self.db_connection.get_common_cards(new_hand_id)
print "db get_stats error: skipping "+str(new_hand_id)+" "+err[2]+"("+str(err[1])+"): "+str(sys.exc_info()[1]) if comm_cards != {}: # stud!
if new_hand_id: # new_hand_id is none if we had an error prior to the store cards['common'] = comm_cards['common']
sys.stderr.write("Database get_stats error %s in hand %d. Skipping.\n" % (err, int(new_hand_id)))
continue
if type == "tour": if type == "tour":
tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number) tablewindow = Tables.discover_tournament_table(self.config, tour_number, tab_number)
else: else: