Merge branch 'eric'

trivial conflict
This commit is contained in:
steffen123 2010-09-27 22:14:37 +02:00
commit 2ecee26d99
5 changed files with 64 additions and 47 deletions

View File

@ -40,6 +40,10 @@ from optparse import OptionParser
import Configuration import Configuration
import string import string
if os.name == "nt":
import win32console
class GuiAutoImport (threading.Thread): class GuiAutoImport (threading.Thread):
def __init__(self, settings, config, sql, parent): def __init__(self, settings, config, sql, parent):
self.importtimer = 0 self.importtimer = 0
@ -211,8 +215,10 @@ class GuiAutoImport (threading.Thread):
bs = 0 bs = 0
elif os.name == 'nt': elif os.name == 'nt':
path = sys.path[0].replace('\\','\\\\') path = sys.path[0].replace('\\','\\\\')
command = 'pythonw "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options'] if win32console.GetConsoleWindow() == 0:
#command = 'python "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options'] command = 'pythonw "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options']
else:
command = 'python "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options']
# uncomment above line if you want hud_main stdout to work ... and make sure you are running fpdb.py using python.exe not pythonw.exe # uncomment above line if you want hud_main stdout to work ... and make sure you are running fpdb.py using python.exe not pythonw.exe
bs = 0 bs = 0
else: else:
@ -222,11 +228,11 @@ class GuiAutoImport (threading.Thread):
try: try:
print _("opening pipe to HUD") print _("opening pipe to HUD")
if Configuration.FROZEN: if Configuration.FROZEN or (os.name == "nt" and win32console.GetConsoleWindow()) == 0:
self.pipe_to_hud = subprocess.Popen(command, bufsize=bs, self.pipe_to_hud = subprocess.Popen(command, bufsize=bs,
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, # only needed for py2exe stdout=subprocess.PIPE, # needed for pythonw / py2exe
stderr=subprocess.PIPE, # only needed for py2exe stderr=subprocess.PIPE, # needed for pythonw / py2exe
universal_newlines=True universal_newlines=True
) )
else: else:

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
@ -104,8 +106,8 @@ class HUD_main(object):
self.hud_params = self.config.get_hud_ui_parameters() self.hud_params = self.config.get_hud_ui_parameters()
# a thread to read stdin # a thread to read stdin
gobject.threads_init() # this is required gobject.threads_init() # this is required
thread.start_new_thread(self.read_stdin, ()) # starts the thread thread.start_new_thread(self.read_stdin, ()) # starts the thread
# a main window # a main window
self.main_window = gtk.Window() self.main_window = gtk.Window()
@ -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)
@ -135,7 +137,7 @@ class HUD_main(object):
print _("hud_main: Client resized") print _("hud_main: Client resized")
print hud, hud.table.name, hud.table.x, hud.table.y print hud, hud.table.name, hud.table.x, hud.table.y
def client_destroyed(self, widget, hud): # call back for terminating the main eventloop def client_destroyed(self, widget, hud): # call back for terminating the main eventloop
print _("hud_main: Client destroyed") print _("hud_main: Client destroyed")
self.kill_hud(None, hud.table.name) self.kill_hud(None, hud.table.name)
@ -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:
@ -251,7 +253,7 @@ class HUD_main(object):
self.hero, self.hero_ids = {}, {} self.hero, self.hero_ids = {}, {}
found = False found = False
while 1: # wait for a new hand number on stdin while 1: # wait for a new hand number on stdin
new_hand_id = sys.stdin.readline() new_hand_id = sys.stdin.readline()
t0 = time.time() t0 = time.time()
t1 = t2 = t3 = t4 = t5 = t6 = t0 t1 = t2 = t3 = t4 = t5 = t6 = t0
@ -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:
@ -307,7 +309,7 @@ class HUD_main(object):
# Unlocks table, copied from end of function # Unlocks table, copied from end of function
self.db_connection.connection.rollback() self.db_connection.connection.rollback()
return return
cards = self.db_connection.get_cards(new_hand_id) cards = self.db_connection.get_cards(new_hand_id)
t4 = time.time() t4 = time.time()
comm_cards = self.db_connection.get_common_cards(new_hand_id) comm_cards = self.db_connection.get_common_cards(new_hand_id)
t5 = time.time() t5 = time.time()
@ -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,10 +348,11 @@ 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(None)
# Ray!! tablewindow::check_table_no expects a HUD as an argument!
if __name__== "__main__": if __name__== "__main__":
# start the HUD_main object # start the HUD_main object

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,12 +64,12 @@ 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
if parent is None: # running from cli .. if parent is None: # running from cli ..
self.parent = self self.parent = self
else: else:
self.parent = parent self.parent = parent
@ -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 = []
@ -115,11 +115,11 @@ class Hud:
def create_mw(self): def create_mw(self):
# Set up a main window for this this instance of the HUD # Set up a main window for this this instance of the HUD
win = gtk.Window() win = gtk.Window()
win.set_skip_taskbar_hint(True) # invisible to taskbar win.set_skip_taskbar_hint(True) # invisible to taskbar
win.set_gravity(gtk.gdk.GRAVITY_STATIC) win.set_gravity(gtk.gdk.GRAVITY_STATIC)
win.set_title("%s FPDBHUD" % (self.table.name)) # give it a title that we can easily filter out in the window list when Table search code is looking win.set_title("%s FPDBHUD" % (self.table.name)) # give it a title that we can easily filter out in the window list when Table search code is looking
win.set_decorated(False) # kill titlebars win.set_decorated(False) # kill titlebars
win.set_opacity(self.colors["hudopacity"]) # set it to configured hud opacity win.set_opacity(self.colors["hudopacity"]) # set it to configured hud opacity
win.set_focus(None) win.set_focus(None)
win.set_focus_on_map(False) win.set_focus_on_map(False)
win.set_accept_focus(False) win.set_accept_focus(False)
@ -165,9 +165,9 @@ 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:'))
self.aggMenu.append(item) self.aggMenu.append(item)
@ -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)
@ -472,17 +472,19 @@ class Hud:
return False return False
# anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window? # anyone know how to do this in unix, or better yet, trap the X11 error that is triggered when executing the get_origin() for a closed window?
if self.table.gdkhandle is not None: if self.table.gdkhandle is not None:
(x, y) = self.table.gdkhandle.get_origin() # In Windows, this call returns (0,0) if it's an invalid window. In X, the X server is immediately killed. (oldx, oldy) = self.table.gdkhandle.get_origin() # In Windows, this call returns (0,0) if it's an invalid window. In X, the X server is immediately killed.
if self.table.x != x or self.table.y != y: # If the current position does not equal the stored position, save the new position, and then move all the sub windows. #(x, y, width, height) = self.table.get_geometry()
self.table.x = x #print "self.table.get_geometry=",x,y,width,height
self.table.y = y if self.table.oldx != oldx or self.table.oldy != oldy: # If the current position does not equal the stored position, save the new position, and then move all the sub windows.
self.main_window.move(x + self.site_params['xshift'], y + self.site_params['yshift']) self.table.oldx = oldx
self.table.oldy = oldy
self.main_window.move(oldx + self.site_params['xshift'], oldy + self.site_params['yshift'])
adj = self.adj_seats(self.hand, self.config) adj = self.adj_seats(self.hand, self.config)
loc = self.config.get_locations(self.table.site, self.max) loc = self.config.get_locations(self.table.site, self.max)
# TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason? # TODO: is stat_windows getting converted somewhere from a list to a dict, for no good reason?
for i, w in enumerate(self.stat_windows.itervalues()): for i, w in enumerate(self.stat_windows.itervalues()):
(x, y) = loc[adj[i+1]] (oldx, oldy) = loc[adj[i+1]]
w.relocate(x, y) w.relocate(oldx, oldy)
# While we're at it, fix the positions of mucked cards too # While we're at it, fix the positions of mucked cards too
for aux in self.aux_windows: for aux in self.aux_windows:
@ -542,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
@ -555,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:

View File

@ -141,6 +141,8 @@ class Table_Window(object):
self.height = geo['height'] self.height = geo['height']
self.x = geo['x'] self.x = geo['x']
self.y = geo['y'] self.y = geo['y']
self.oldx = self.x # attn ray: remove these two lines and update Hud.py::update_table_position()
self.oldy = self.y
self.game = self.get_game() self.game = self.get_game()
@ -184,7 +186,8 @@ class Table_Window(object):
mo = re.search(self.tableno_re, new_title) mo = re.search(self.tableno_re, new_title)
if mo is not None: if mo is not None:
return mo[1] print "get_table_no: mo=",mo.groups()
return mo.group(1)
return False return False
#################################################################### ####################################################################
@ -238,6 +241,7 @@ class Table_Window(object):
return "client_destroyed" return "client_destroyed"
if self.x != new_geo['x'] or self.y != new_geo['y']: # window moved if self.x != new_geo['x'] or self.y != new_geo['y']: # window moved
print self.x, self.y, new_geo['x'], new_geo['y']
self.x = new_geo['x'] self.x = new_geo['x']
self.y = new_geo['y'] self.y = new_geo['y']
return "client_moved" return "client_moved"
@ -247,7 +251,8 @@ class Table_Window(object):
result = self.get_table_no() result = self.get_table_no()
if result != False and result != self.table: if result != False and result != self.table:
self.table = result self.table = result
hud.main_window.emit("table_changed", hud) if hud is not None:
hud.main_window.emit("table_changed", hud)
return True return True
def check_bad_words(self, title): def check_bad_words(self, title):

View File

@ -80,6 +80,7 @@ class Table(Table_Window):
try: try:
(x, y, width, height) = win32gui.GetWindowRect(self.number) (x, y, width, height) = win32gui.GetWindowRect(self.number)
#print "x=",x,"y=",y,"width=",width,"height=",height
width = width - x width = width - x
height = height - y height = height - y
return {'x' : int(x) + b_width, return {'x' : int(x) + b_width,