diff --git a/pyfpdb/GuiAutoImport.py b/pyfpdb/GuiAutoImport.py index 2345f0f5..2ff70ca8 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,11 +228,11 @@ 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 - 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: diff --git a/pyfpdb/HUD_main.pyw b/pyfpdb/HUD_main.pyw index 6f1d7fe5..750b4bdb 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,10 +348,11 @@ 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() + tablewindow.check_table_no(None) + # Ray!! tablewindow::check_table_no expects a HUD as an argument! if __name__== "__main__": # start the HUD_main object diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 011b329c..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) @@ -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: @@ -542,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 @@ -555,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: diff --git a/pyfpdb/TableWindow.py b/pyfpdb/TableWindow.py index 0750ad75..f904fa15 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() @@ -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,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): 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,