From 4b3fe3dfa2fb35d3f2194d611b3385390fc43c6f Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 04:04:56 -0400 Subject: [PATCH 1/7] fix conflicts between ray's new window move code and my old window move code Ray: when you finish implementing yours, please adapt and/or disable Hud::update_table_position --- pyfpdb/Hud.py | 16 +++++++++------- pyfpdb/TableWindow.py | 3 +++ pyfpdb/WinTables.py | 1 + 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 011b329c..6b4737e5 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -472,17 +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: - (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']) + (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: diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index 0750ad75..761be73b 100644 --- a/pyfpdb/TableWindow.py +++ b/pyfpdb/TableWindow.py @@ -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() @@ -238,6 +240,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" diff --git a/pyfpdb/WinTables.py b/pyfpdb/WinTables.py index 331714bb..442aeaa2 100644 --- a/pyfpdb/WinTables.py +++ b/pyfpdb/WinTables.py @@ -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, From bfec231b5d42d0e3523ceeb0f2263d4482a2b75e Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 05:08:34 -0400 Subject: [PATCH 2/7] slight formatting changes to agree with PEP8 moar closely --- pyfpdb/HUD_main.pyw | 44 +++++++++++++++++++++++--------------------- pyfpdb/Hud.py | 22 +++++++++++----------- 2 files changed, 34 insertions(+), 32 deletions(-) diff --git a/pyfpdb/HUD_main.pyw b/pyfpdb/HUD_main.pyw index dc80543e..b38fc664 100755 --- a/pyfpdb/HUD_main.pyw +++ b/pyfpdb/HUD_main.pyw @@ -61,17 +61,19 @@ elif os.name == 'nt': import Hud import locale -lang=locale.getdefaultlocale()[0][0:2] +lang = locale.getdefaultlocale()[0][0:2] print "lang:", lang -if lang=="en": - def _(string): return string +if lang == "en": + 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) @@ -82,7 +84,7 @@ class HUD_main(object): """A main() object to own both the read_stdin thread and the gui.""" # 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 ...") self.db_name = db_name self.config = c @@ -92,9 +94,9 @@ class HUD_main(object): try: if not options.errorsToConsole: 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") - 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_.")) errorFile = open(fileName, 'w', 0) sys.stderr = errorFile @@ -104,8 +106,8 @@ class HUD_main(object): self.hud_params = self.config.get_hud_ui_parameters() # a thread to read stdin - gobject.threads_init() # this is required - thread.start_new_thread(self.read_stdin, ()) # starts the thread + gobject.threads_init() # this is required + thread.start_new_thread(self.read_stdin, ()) # starts the thread # a main window self.main_window = gtk.Window() @@ -123,7 +125,7 @@ class HUD_main(object): self.main_window.show_all() gobject.timeout_add(100, self.check_tables) 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]): log.error(e) @@ -135,7 +137,7 @@ class HUD_main(object): 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 + 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) @@ -157,7 +159,7 @@ class HUD_main(object): self.hud_dict[table].main_window.destroy() self.vb.remove(self.hud_dict[table].tablehudlabel) del(self.hud_dict[table]) - self.main_window.resize(1,1) + self.main_window.resize(1, 1) def check_tables(self): 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].reposition_windows() 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]): log.error(e) finally: @@ -251,7 +253,7 @@ class HUD_main(object): self.hero, self.hero_ids = {}, {} 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() t0 = time.time() 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.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: @@ -307,7 +309,7 @@ class HUD_main(object): # Unlocks table, copied from end of function self.db_connection.connection.rollback() return - cards = self.db_connection.get_cards(new_hand_id) + cards = self.db_connection.get_cards(new_hand_id) t4 = time.time() comm_cards = self.db_connection.get_common_cards(new_hand_id) t5 = time.time() @@ -321,14 +323,14 @@ 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! 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) if tablewindow is None: # If no client window is found on the screen, complain and continue @@ -346,7 +348,7 @@ class HUD_main(object): 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)") - % (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() if type == "tour": tablewindow.check_table_no() diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 6b4737e5..15a9e6de 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -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,12 +64,12 @@ 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 - if parent is None: # running from cli .. + if parent is None: # running from cli .. self.parent = self else: self.parent = parent @@ -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 = [] @@ -115,11 +115,11 @@ class Hud: def create_mw(self): # Set up a main window for this this instance of the HUD 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_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_opacity(self.colors["hudopacity"]) # set it to configured hud opacity + win.set_decorated(False) # kill titlebars + win.set_opacity(self.colors["hudopacity"]) # set it to configured hud opacity win.set_focus(None) win.set_focus_on_map(False) win.set_accept_focus(False) @@ -165,9 +165,9 @@ class Hud: # set agg_bb_mult to 1 to stop aggregation item = gtk.CheckMenuItem(_('For This Blind Level Only')) 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) - + item = gtk.MenuItem(_('For Multiple Blind Levels:')) self.aggMenu.append(item) @@ -362,7 +362,7 @@ class Hud: item.ms = i maxSeatsMenu.append(item) 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) @@ -544,7 +544,7 @@ class Hud: loc = self.stat_windows[sw].window.get_position() new_loc = (loc[0] - self.table.x, loc[1] - self.table.y) 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 [aux.save_layout() for aux in self.aux_windows] # 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 # does the user have a fav_seat? 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 if self.table.site != None and int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0: try: From baf47d476e2c6dcbe42b040c1180979bffffd944 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 05:56:52 -0400 Subject: [PATCH 3/7] fix for call to check_table_no now needing an argument --- pyfpdb/HUD_main.pyw | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/HUD_main.pyw b/pyfpdb/HUD_main.pyw index b38fc664..f52b8ee4 100755 --- a/pyfpdb/HUD_main.pyw +++ b/pyfpdb/HUD_main.pyw @@ -351,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 From b0056be03ceb757255c38918fb7c1b6cf12ca59e Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 07:10:13 -0400 Subject: [PATCH 4/7] further fixes to get stdout working in windows again --- pyfpdb/GuiAutoImport.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 2345f0f5..52410f79 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -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 @@ -211,8 +215,10 @@ class GuiAutoImport (threading.Thread): bs = 0 elif os.name == 'nt': path = sys.path[0].replace('\\','\\\\') - command = 'pythonw "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options'] - #command = 'python "'+path+'\\HUD_main.pyw" ' + self.settings['cl_options'] + 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: @@ -222,7 +228,7 @@ class GuiAutoImport (threading.Thread): try: 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, stdin=subprocess.PIPE, stdout=subprocess.PIPE, # only needed for py2exe From ca967992b54e23633a1006c09457e9f3b852c333 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 07:11:16 -0400 Subject: [PATCH 5/7] fix a comment --- pyfpdb/GuiAutoImport.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 52410f79..2ff70ca8 100755 --- a/pyfpdb/GuiAutoImport.py +++ b/pyfpdb/GuiAutoImport.py @@ -231,8 +231,8 @@ class GuiAutoImport (threading.Thread): 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: From df1cd4a15d815ab4da9af12b849e7c1d1de30eb5 Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 07:29:34 -0400 Subject: [PATCH 6/7] fix syntactical issue in get_table_no --- pyfpdb/TableWindow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index 761be73b..0e59a87b 100644 --- a/pyfpdb/TableWindow.py +++ b/pyfpdb/TableWindow.py @@ -186,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 #################################################################### From c325daf7f6bcd739fc19083709b9db2eb43ac36e Mon Sep 17 00:00:00 2001 From: Eric Blade Date: Mon, 27 Sep 2010 07:34:25 -0400 Subject: [PATCH 7/7] check_table_no deals with "None" passed to it --- pyfpdb/TableWindow.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index 0e59a87b..f904fa15 100644 --- a/pyfpdb/TableWindow.py +++ b/pyfpdb/TableWindow.py @@ -251,7 +251,8 @@ class Table_Window(object): result = self.get_table_no() if result != False and result != self.table: self.table = result - hud.main_window.emit("table_changed", hud) + if hud is not None: + hud.main_window.emit("table_changed", hud) return True def check_bad_words(self, title):