Merge branch 'master' of git://git.assembla.com/fpdb

Conflicts:
	pyfpdb/Hud.py
This commit is contained in:
Worros 2010-09-28 11:43:42 +08:00
commit d299a19abc
5 changed files with 78 additions and 63 deletions

View File

@ -40,6 +40,10 @@ from optparse import OptionParser
import Configuration
import string
if os.name == "nt":
import win32console
class GuiAutoImport (threading.Thread):
def __init__(self, settings, config, sql, parent):
self.importtimer = 0
@ -205,13 +209,17 @@ class GuiAutoImport (threading.Thread):
self.doAutoImportBool = True
widget.set_label(_(u' _Stop Auto Import '))
if self.pipe_to_hud is None:
if Configuration.FROZEN:
if Configuration.FROZEN: # if py2exe, run hud_main.exe
path = Configuration.EXEC_PATH
command = "HUD_main.exe"
bs = 0
elif os.name == 'nt':
path = sys.path[0].replace('\\','\\\\')
if win32console.GetConsoleWindow() == 0:
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
bs = 0
else:
command = os.path.join(sys.path[0], 'HUD_main.pyw')
@ -220,12 +228,15 @@ class GuiAutoImport (threading.Thread):
try:
print _("opening pipe to HUD")
if Configuration.FROZEN or (os.name == "nt" and win32console.GetConsoleWindow()) == 0:
self.pipe_to_hud = subprocess.Popen(command, bufsize=bs,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE, # only needed for py2exe
stderr=subprocess.PIPE, # only needed for py2exe
stdout=subprocess.PIPE, # needed for pythonw / py2exe
stderr=subprocess.PIPE, # needed for pythonw / py2exe
universal_newlines=True
)
else:
self.pipe_to_hud = subprocess.Popen(command, bufsize=bs, stdin=subprocess.PIPE, universal_newlines=True)
#self.pipe_to_hud.stdout.close()
#self.pipe_to_hud.stderr.close()
except:

View File

@ -64,14 +64,16 @@ import locale
lang = locale.getdefaultlocale()[0][0:2]
print "lang:", lang
if lang == "en":
def _(string): return string
def _(string):
return string
else:
import gettext
try:
trans = gettext.translation("fpdb", localedir="locale", languages=[lang])
trans.install()
except IOError:
def _(string): return string
def _(string):
return string
# get config and set up logger
c = Configuration.Config(file=options.config, dbname=options.dbname)
@ -128,19 +130,22 @@ class HUD_main(object):
log.error(e)
def client_moved(self, widget, hud):
print "hud_main: client moved"
print hud, hud.table.name, "moved", hud.table.x, hud.table.y
def client_resized(self, widget, hud):
print "Client resized"
print _("hud_main: Client resized")
print hud, hud.table.name, hud.table.x, hud.table.y
def client_destroyed(self, widget, hud): # call back for terminating the main eventloop
print _("hud_main: Client destroyed")
self.kill_hud(None, hud.table.name)
def game_changed(self, widget, hud):
print "Game Changed."
print _("hud_main: Game changed.")
def table_changed(self, widget, hud):
print "Table Changed."
print _("hud_main: Table changed.")
self.kill_hud(None, hud.table.name)
def destroy(self, *args): # call back for terminating the main eventloop
@ -292,8 +297,8 @@ class HUD_main(object):
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'])
t2 = time.time()
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)
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)
t3 = time.time()
try:
@ -318,8 +323,8 @@ class HUD_main(object):
else:
# 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'] )
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params
,self.hero_ids[site_id], num_seats)
stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_params,
self.hero_ids[site_id], num_seats)
cards = self.db_connection.get_cards(new_hand_id)
comm_cards = self.db_connection.get_common_cards(new_hand_id)
if comm_cards != {}: # stud!
@ -346,7 +351,8 @@ class HUD_main(object):
% (t6 - t0,t1 - t0,t2 - t0,t3 - t0,t4 - t0,t5 - t0,t6 - t0))
self.db_connection.connection.rollback()
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__":
# start the HUD_main object

View File

@ -53,6 +53,7 @@ import Mucked
import Database
#import HUD_main
def importName(module_name, name):
"""Import a named object 'name' from module 'module_name'."""
# Recipe 16.3 in the Python Cookbook, 2nd ed. Thanks!!!!
@ -63,8 +64,8 @@ def importName(module_name, name):
return None
return(getattr(module, name))
class Hud:
class Hud:
def __init__(self, parent, table, max, poker_game, config, db_connection):
# __init__ is (now) intended to be called from the stdin thread, so it
# cannot touch the gui
@ -83,7 +84,6 @@ class Hud:
self.mw_created = False
self.hud_params = parent.hud_params
self.stat_windows = {}
self.popup_windows = {}
self.aux_windows = []
@ -472,27 +472,19 @@ class Hud:
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?
if self.table.gdkhandle is not None:
updateFlag = False
actual_seat = self.get_actual_seat(self.config.supported_sites[self.table.site].screen_name)
if self.table.hud != actual_seat:
self.table.hud = actual_seat
updateFlag = True
# dont know what the intention of table.hud was, so misusing the variable here
# to auto detect table change during tourney's
(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.
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.
self.table.x = x
self.table.y = y
self.main_window.move(x + self.site_params['xshift'], y + self.site_params['yshift'])
updateFlag = True
if updateFlag:
(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.
#(x, y, width, height) = self.table.get_geometry()
#print "self.table.get_geometry=",x,y,width,height
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.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)
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?
for i, w in enumerate(self.stat_windows.itervalues()):
(x, y) = loc[adj[i+1]]
w.relocate(x, y)
(oldx, oldy) = loc[adj[i+1]]
w.relocate(oldx, oldy)
# While we're at it, fix the positions of mucked cards too
for aux in self.aux_windows:

View File

@ -141,6 +141,8 @@ class Table_Window(object):
self.height = geo['height']
self.x = geo['x']
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()
@ -184,7 +186,8 @@ class Table_Window(object):
mo = re.search(self.tableno_re, new_title)
if mo is not None:
return mo[1]
print "get_table_no: mo=",mo.groups()
return mo.group(1)
return False
####################################################################
@ -238,6 +241,7 @@ class Table_Window(object):
return "client_destroyed"
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.y = new_geo['y']
return "client_moved"
@ -247,6 +251,7 @@ class Table_Window(object):
result = self.get_table_no()
if result != False and result != self.table:
self.table = result
if hud is not None:
hud.main_window.emit("table_changed", hud)
return True

View File

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