From d4165a51094ed0830f3abb1162bb5f432b749bf9 Mon Sep 17 00:00:00 2001 From: eblade Date: Tue, 24 Mar 2009 05:19:20 -0400 Subject: [PATCH 1/3] ongoing effort to squeeze a couple more cpu cycles out of the hud creation process --- pyfpdb/Hud.py | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 20750b96..e3e008cd 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -82,7 +82,7 @@ class Hud: font = "Sans" if font_size == None: font_size = "8" - self.font = pango.FontDescription(font + " " + font_size) + self.font = pango.FontDescription("%s %s" % (font, font_size)) # do we need to add some sort of condition here for dealing with a request for a font that doesn't exist? game_params = config.get_game_parameters(self.poker_game) @@ -173,10 +173,11 @@ class Hud: self.main_window.move(x, y) adj = self.adj_seats(self.hand, self.config) loc = self.config.get_locations(self.table.site, self.max) - for i in xrange(1, self.max + 1): - (x, y) = loc[adj[i]] - if i in self.stat_windows: - self.stat_windows[i].relocate(x, y) + for i, w in enumerate(self.stat_windows): + if not type(w) == int: # how do we get pure ints in this list?? + (x, y) = loc[adj[i]] + w.relocate(x, y) + return True def on_button_press(self, widget, event): @@ -286,10 +287,12 @@ class Hud: font = self.font) self.stats = [] - for i in xrange(0, config.supported_games[self.poker_game].rows + 1): - row_list = [''] * config.supported_games[self.poker_game].cols + game = config.supported_games[self.poker_game] + + for i in xrange(0, game.rows + 1): + row_list = [''] * game.cols self.stats.append(row_list) - for stat in config.supported_games[self.poker_game].stats: + for stat in game.stats: self.stats[config.supported_games[self.poker_game].stats[stat].row] \ [config.supported_games[self.poker_game].stats[stat].col] = \ config.supported_games[self.poker_game].stats[stat].stat_name @@ -314,7 +317,7 @@ class Hud: for c in xrange(0, config.supported_games[self.poker_game].cols): this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]] number = Stats.do_stat(self.stat_dict, player = self.stat_dict[s]['player_id'], stat = self.stats[r][c]) - statstring = this_stat.hudprefix + str(number[1]) + this_stat.hudsuffix + statstring = "%s%s%s" % (this_stat.hudprefix, str(number[1]), this_stat.hudsuffix) if this_stat.hudcolor != "": self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor'])) @@ -324,8 +327,7 @@ class Hud: if statstring != "xxx": # is there a way to tell if this particular stat window is visible already, or no? self.stat_windows[self.stat_dict[s]['seat']].window.show_all() # self.reposition_windows() - tip = self.stat_dict[s]['screen_name'] + "\n" + number[5] + "\n" + \ - number[3] + ", " + number[4] + tip = "%s\n%s\n%s, %s" % (self.stat_dict[s]['screen_name'], number[5], number[3], number[4]) Stats.do_tip(self.stat_windows[self.stat_dict[s]['seat']].e_box[r][c], tip) def topify_window(self, window): @@ -408,7 +410,7 @@ class Stat_Window: self.window.set_property("skip-taskbar-hint", True) self.window.set_transient_for(parent.main_window) - self.grid = gtk.Table(rows = self.game.rows, columns = self.game.cols, homogeneous = False) + self.grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False) self.window.add(self.grid) self.window.modify_bg(gtk.STATE_NORMAL, parent.backgroundcolor) @@ -418,12 +420,12 @@ class Stat_Window: usegtkframes = self.useframes e_box = self.e_box label = self.label - for r in xrange(self.game.rows): + for r in xrange(game.rows): if usegtkframes: self.frame.append([]) e_box.append([]) label.append([]) - for c in xrange(self.game.cols): + for c in xrange(game.cols): if usegtkframes: self.frame[r].append( gtk.Frame() ) e_box[r].append( gtk.EventBox() ) From d168618b4b06b90787b48cc112631232c942e29e Mon Sep 17 00:00:00 2001 From: eblade Date: Tue, 24 Mar 2009 05:55:07 -0400 Subject: [PATCH 2/3] try to squeeze a few more cycles out .. seems to not be locking up anymore, though i could be running good on that right now --- pyfpdb/Hud.py | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index e3e008cd..95c6c18e 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -197,12 +197,12 @@ class Hud: s.window.destroy() self.stat_windows = {} # also kill any aux windows - [aux.destroy() for aux in self.aux_windows] + (aux.destroy() for aux in self.aux_windows) self.aux_windows = [] def reposition_windows(self, *args): if self.stat_windows != {} and len(self.stat_windows) > 0: - map(lambda x: x.window.move(x.x, x.y), self.stat_windows.itervalues()) + (x.window.move(x.x, x.y) for x in self.stat_windows.itervalues() if type(x) != int) return True def debug_stat_windows(self, *args): @@ -218,7 +218,7 @@ class Hud: new_layout[self.stat_windows[sw].adj - 1] = new_loc 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] + (aux.save_layout() for aux in self.aux_windows) # save the config object back to the file print "saving new xml file" self.config.save() @@ -228,9 +228,9 @@ class Hud: # Need range here, not xrange -> need the actual list adj = range(0, self.max + 1) # default seat adjustments = no adjustment # does the user have a fav_seat? - try: - sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat)) - if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0: + if int(config.supported_sites[self.table.site].layout[self.max].fav_seat) > 0: + try: + sys.stderr.write("site = %s, max = %d, fav seat = %d\n" % (self.table.site, self.max, config.supported_sites[self.table.site].layout[self.max].fav_seat)) fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat sys.stderr.write("found fav seat = %d\n" % fav_seat) # actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name) @@ -238,12 +238,14 @@ class Hud: sys.stderr.write("found actual seat = %d\n" % actual_seat) for i in xrange(0, self.max + 1): j = actual_seat + i - if j > self.max: j = j - self.max + if j > self.max: + j = j - self.max adj[j] = fav_seat + i - if adj[j] > self.max: adj[j] = adj[j] - self.max - except Exception, inst: - sys.stderr.write("exception in adj!!!\n\n") - sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly + if adj[j] > self.max: + adj[j] = adj[j] - self.max + except Exception, inst: + sys.stderr.write("exception in adj!!!\n\n") + sys.stderr.write("error is %s" % inst) # __str__ allows args to printed directly return adj def get_actual_seat(self, name): @@ -306,29 +308,30 @@ class Hud: self.update_table_position() for s in self.stat_dict: + statd = self.stat_dict[s] try: self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] except: # omg, we have more seats than stat windows .. damn poker sites with incorrect max seating info .. let's force 10 here self.max = 10 self.create(hand, config, self.stat_dict, self.cards) - self.stat_windows[self.stat_dict[s]['seat']].player_id = self.stat_dict[s]['player_id'] + self.stat_windows[statd['seat']].player_id = statd['player_id'] for r in xrange(0, config.supported_games[self.poker_game].rows): for c in xrange(0, config.supported_games[self.poker_game].cols): this_stat = config.supported_games[self.poker_game].stats[self.stats[r][c]] - number = Stats.do_stat(self.stat_dict, player = self.stat_dict[s]['player_id'], stat = self.stats[r][c]) + number = Stats.do_stat(self.stat_dict, player = statd['player_id'], stat = self.stats[r][c]) statstring = "%s%s%s" % (this_stat.hudprefix, str(number[1]), this_stat.hudsuffix) + window = self.stat_windows[statd['seat']] if this_stat.hudcolor != "": self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor'])) - self.stat_windows[self.stat_dict[s]['seat']].label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor)) - - self.stat_windows[self.stat_dict[s]['seat']].label[r][c].set_text(statstring) + window.label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(this_stat.hudcolor)) + + window.label[r][c].set_text(statstring) if statstring != "xxx": # is there a way to tell if this particular stat window is visible already, or no? - self.stat_windows[self.stat_dict[s]['seat']].window.show_all() -# self.reposition_windows() - tip = "%s\n%s\n%s, %s" % (self.stat_dict[s]['screen_name'], number[5], number[3], number[4]) - Stats.do_tip(self.stat_windows[self.stat_dict[s]['seat']].e_box[r][c], tip) + window.window.show_all() + tip = "%s\n%s\n%s, %s" % (statd['screen_name'], number[5], number[3], number[4]) + Stats.do_tip(window.e_box[r][c], tip) def topify_window(self, window): """Set the specified gtk window to stayontop in MS Windows.""" From 42f2cb049da892787628090c4212e2c711d497f6 Mon Sep 17 00:00:00 2001 From: eblade Date: Tue, 24 Mar 2009 06:04:00 -0400 Subject: [PATCH 3/3] add set_focus_on_map calls to hud window creation, doesn't seem to do much, but feels correct --- pyfpdb/Hud.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 95c6c18e..3fa677b6 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -102,6 +102,7 @@ class Hud: self.main_window.set_title("%s FPDBHUD" % (self.table.name)) self.main_window.set_decorated(False) self.main_window.set_opacity(self.colors["hudopacity"]) + self.main_window.set_focus_on_map(False) self.ebox = gtk.EventBox() self.label = gtk.Label("FPDB Menu (Right Click)\nLeft-drag to move") @@ -412,6 +413,7 @@ class Stat_Window: self.window.set_title("%s" % seat) self.window.set_property("skip-taskbar-hint", True) self.window.set_transient_for(parent.main_window) + self.window.set_focus_on_map(False) self.grid = gtk.Table(rows = game.rows, columns = game.cols, homogeneous = False) self.window.add(self.grid)