slight formatting changes to agree with PEP8 moar closely

This commit is contained in:
Eric Blade 2010-09-27 05:08:34 -04:00
parent 4b3fe3dfa2
commit bfec231b5d
2 changed files with 34 additions and 32 deletions

View File

@ -61,17 +61,19 @@ elif os.name == 'nt':
import Hud import Hud
import locale import locale
lang=locale.getdefaultlocale()[0][0:2] lang = locale.getdefaultlocale()[0][0:2]
print "lang:", lang print "lang:", lang
if lang=="en": if lang == "en":
def _(string): return string def _(string):
return string
else: else:
import gettext import gettext
try: try:
trans = gettext.translation("fpdb", localedir="locale", languages=[lang]) trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
trans.install() trans.install()
except IOError: except IOError:
def _(string): return string def _(string):
return string
# get config and set up logger # get config and set up logger
c = Configuration.Config(file=options.config, dbname=options.dbname) c = Configuration.Config(file=options.config, dbname=options.dbname)
@ -82,7 +84,7 @@ class HUD_main(object):
"""A main() object to own both the read_stdin thread and the gui.""" """A main() object to own both the read_stdin thread and the gui."""
# This class mainly provides state for controlling the multiple HUDs. # This class mainly provides state for controlling the multiple HUDs.
def __init__(self, db_name = 'fpdb'): def __init__(self, db_name='fpdb'):
print _("\nHUD_main: starting ...") print _("\nHUD_main: starting ...")
self.db_name = db_name self.db_name = db_name
self.config = c self.config = c
@ -92,9 +94,9 @@ class HUD_main(object):
try: try:
if not options.errorsToConsole: if not options.errorsToConsole:
fileName = os.path.join(self.config.dir_log, 'HUD-errors.txt') fileName = os.path.join(self.config.dir_log, 'HUD-errors.txt')
print _("Note: error output is being diverted to:\n")+fileName \ print _("Note: error output is being diverted to:\n") + fileName \
+ _("\nAny major error will be reported there _only_.\n") + _("\nAny major error will be reported there _only_.\n")
log.info(_("Note: error output is being diverted to:")+fileName) log.info(_("Note: error output is being diverted to:") + fileName)
log.info(_("Any major error will be reported there _only_.")) log.info(_("Any major error will be reported there _only_."))
errorFile = open(fileName, 'w', 0) errorFile = open(fileName, 'w', 0)
sys.stderr = errorFile sys.stderr = errorFile
@ -123,7 +125,7 @@ class HUD_main(object):
self.main_window.show_all() self.main_window.show_all()
gobject.timeout_add(100, self.check_tables) gobject.timeout_add(100, self.check_tables)
except: except:
log.error( "*** Exception in HUD_main.init() *** " ) log.error("*** Exception in HUD_main.init() *** ")
for e in traceback.format_tb(sys.exc_info()[2]): for e in traceback.format_tb(sys.exc_info()[2]):
log.error(e) log.error(e)
@ -157,7 +159,7 @@ class HUD_main(object):
self.hud_dict[table].main_window.destroy() self.hud_dict[table].main_window.destroy()
self.vb.remove(self.hud_dict[table].tablehudlabel) self.vb.remove(self.hud_dict[table].tablehudlabel)
del(self.hud_dict[table]) del(self.hud_dict[table])
self.main_window.resize(1,1) self.main_window.resize(1, 1)
def check_tables(self): def check_tables(self):
for hud in self.hud_dict.keys(): for hud in self.hud_dict.keys():
@ -185,7 +187,7 @@ class HUD_main(object):
self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].update(new_hand_id, self.config)
self.hud_dict[table_name].reposition_windows() self.hud_dict[table_name].reposition_windows()
except: except:
log.error( "*** Exception in HUD_main::idle_func() *** " + str(sys.exc_info()) ) log.error("*** Exception in HUD_main::idle_func() *** " + str(sys.exc_info()))
for e in traceback.format_tb(sys.exc_info()[2]): for e in traceback.format_tb(sys.exc_info()[2]):
log.error(e) log.error(e)
finally: finally:
@ -295,8 +297,8 @@ class HUD_main(object):
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'])
t2 = time.time() t2 = time.time()
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params 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], num_seats) self.hero_ids[site_id], num_seats)
t3 = time.time() t3 = time.time()
try: try:
@ -321,14 +323,14 @@ class HUD_main(object):
else: else:
# get stats using default params--also get cards # get stats using default params--also get cards
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 stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params,
,self.hero_ids[site_id], num_seats) self.hero_ids[site_id], num_seats)
cards = self.db_connection.get_cards(new_hand_id) cards = self.db_connection.get_cards(new_hand_id)
comm_cards = self.db_connection.get_common_cards(new_hand_id) comm_cards = self.db_connection.get_common_cards(new_hand_id)
if comm_cards != {}: # stud! if comm_cards != {}: # stud!
cards['common'] = comm_cards['common'] cards['common'] = comm_cards['common']
table_kwargs = dict(table_name = table_name, tournament = tour_number, table_number = tab_number) table_kwargs = dict(table_name=table_name, tournament=tour_number, table_number=tab_number)
tablewindow = Tables.Table(self.config, site_name, **table_kwargs) tablewindow = Tables.Table(self.config, site_name, **table_kwargs)
if tablewindow is None: if tablewindow is None:
# If no client window is found on the screen, complain and continue # If no client window is found on the screen, complain and continue
@ -346,7 +348,7 @@ class HUD_main(object):
t6 = time.time() t6 = time.time()
log.info(_("HUD_main.read_stdin: hand read in %4.3f seconds (%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f)") log.info(_("HUD_main.read_stdin: hand read in %4.3f seconds (%4.3f,%4.3f,%4.3f,%4.3f,%4.3f,%4.3f)")
% (t6-t0,t1-t0,t2-t0,t3-t0,t4-t0,t5-t0,t6-t0)) % (t6 - t0,t1 - t0,t2 - t0,t3 - t0,t4 - t0,t5 - t0,t6 - t0))
self.db_connection.connection.rollback() self.db_connection.connection.rollback()
if type == "tour": if type == "tour":
tablewindow.check_table_no() tablewindow.check_table_no()

View File

@ -53,6 +53,7 @@ import Mucked
import Database import Database
#import HUD_main #import HUD_main
def importName(module_name, name): def importName(module_name, name):
"""Import a named object 'name' from module 'module_name'.""" """Import a named object 'name' from module 'module_name'."""
# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!! # Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!!
@ -63,8 +64,8 @@ def importName(module_name, name):
return None return None
return(getattr(module, name)) return(getattr(module, name))
class Hud:
class Hud:
def __init__(self, parent, table, max, poker_game, config, db_connection): def __init__(self, parent, table, max, poker_game, config, db_connection):
# __init__ is (now) intended to be called from the stdin thread, so it # __init__ is (now) intended to be called from the stdin thread, so it
# cannot touch the gui # cannot touch the gui
@ -83,7 +84,6 @@ class Hud:
self.mw_created = False self.mw_created = False
self.hud_params = parent.hud_params self.hud_params = parent.hud_params
self.stat_windows = {} self.stat_windows = {}
self.popup_windows = {} self.popup_windows = {}
self.aux_windows = [] self.aux_windows = []
@ -165,7 +165,7 @@ class Hud:
# set agg_bb_mult to 1 to stop aggregation # set agg_bb_mult to 1 to stop aggregation
item = gtk.CheckMenuItem(_('For This Blind Level Only')) item = gtk.CheckMenuItem(_('For This Blind Level Only'))
self.aggMenu.append(item) self.aggMenu.append(item)
item.connect("activate", self.set_aggregation, ('P',1)) item.connect("activate", self.set_aggregation, ('P', 1))
setattr(self, 'h_aggBBmultItem1', item) setattr(self, 'h_aggBBmultItem1', item)
item = gtk.MenuItem(_('For Multiple Blind Levels:')) item = gtk.MenuItem(_('For Multiple Blind Levels:'))
@ -362,7 +362,7 @@ class Hud:
item.ms = i item.ms = i
maxSeatsMenu.append(item) maxSeatsMenu.append(item)
item.connect("activate", self.change_max_seats) item.connect("activate", self.change_max_seats)
setattr(self, 'maxSeatsMenuItem%d' % (i-1), item) setattr(self, 'maxSeatsMenuItem%d' % (i - 1), item)
eventbox.connect_object("button-press-event", self.on_button_press, menu) eventbox.connect_object("button-press-event", self.on_button_press, menu)
@ -544,7 +544,7 @@ class Hud:
loc = self.stat_windows[sw].window.get_position() loc = self.stat_windows[sw].window.get_position()
new_loc = (loc[0] - self.table.x, loc[1] - self.table.y) new_loc = (loc[0] - self.table.x, loc[1] - self.table.y)
new_layout[self.stat_windows[sw].adj - 1] = new_loc new_layout[self.stat_windows[sw].adj - 1] = new_loc
self.config.edit_layout(self.table.site, self.max, locations = new_layout) self.config.edit_layout(self.table.site, self.max, locations=new_layout)
# ask each aux to save its layout back to the config object # ask each aux to save its layout back to the config object
[aux.save_layout() for aux in self.aux_windows] [aux.save_layout() for aux in self.aux_windows]
# save the config object back to the file # save the config object back to the file
@ -557,7 +557,7 @@ class Hud:
adj = range(0, self.max + 1) # default seat adjustments = no adjustment adj = range(0, self.max + 1) # default seat adjustments = no adjustment
# does the user have a fav_seat? # does the user have a fav_seat?
if self.max not in config.supported_sites[self.table.site].layout: if self.max not in config.supported_sites[self.table.site].layout:
sys.stderr.write(_("No layout found for %d-max games for site %s\n") % (self.max, self.table.site) ) sys.stderr.write(_("No layout found for %d-max games for site %s\n") % (self.max, self.table.site))
return adj return adj
if self.table.site != None and int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0: if self.table.site != None and int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0:
try: try: