From f26baac94cc2bc00b844e91a7784c8e0206551d3 Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 29 Oct 2008 22:37:05 -0400 Subject: [PATCH] added some configuration accessors for Hud.py and some cleanup --- pyfpdb/Configuration.py | 53 ++++++++++++++++++++---------- pyfpdb/Hud.py | 72 ++++++++--------------------------------- 2 files changed, 49 insertions(+), 76 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index 4690a84c..6e38d50f 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -53,19 +53,9 @@ class Site: self.site_path = node.getAttribute("site_path") self.HH_path = node.getAttribute("HH_path") self.decoder = node.getAttribute("decoder") - self.hudopacity = node.getAttribute("hudopacity") - if self.hudopacity == "": - self.hudopacity = 0.90 - else: - self.hudopacity = float(self.hudopacity) - self.hudbgcolor = node.getAttribute("bgcolor") - if self.hudbgcolor == "": - self.hudbgcolor = "#FFFFFF" self.hudfgcolor = node.getAttribute("fgcolor") - if self.hudfgcolor == "": - self.hudfgcolor = "#000000" self.layout = {} @@ -88,7 +78,7 @@ class Site: if key == 'layout': continue value = getattr(self, key) if callable(value): continue - temp = temp + ' ' + key + " = " + value + "\n" + temp = temp + ' ' + key + " = " + str(value) + "\n" for layout in self.layout: temp = temp + "%s" % self.layout[layout] @@ -372,6 +362,33 @@ class Config: paths['bulkImport-defaultPath'] = "default" return paths + def get_default_colors(self, site = "PokerStars"): + colors = {} + try: + colors['hudopacity'] = float(self.supported_sites[site].hudopacity) + except: + colors['hudopacity'] = 0.90 + try: + colors['hudbgcolor'] = float(self.supported_sites[site].hudbgcolor) + except: + colors['hudbgcolor'] = "#FFFFFF" + try: + colors['hudfgcolor'] = float(self.supported_sites[site].hudbgcolor) + except: + colors['hudfgcolor'] = "#000000" + return colors + + def get_locations(self, site = "PokerStars", max = "8"): + + try: + locations = self.supported_sites[site].layout[max].location + except: + locations = ( ( 0, 0), (684, 61), (689, 239), (692, 346), + (586, 393), (421, 440), (267, 440), ( 0, 361), + ( 0, 280), (121, 280), ( 46, 30) ) + return locations + + if __name__== "__main__": c = Config() @@ -403,17 +420,19 @@ if __name__== "__main__": print "----------- END MUCKED WINDOW FORMATS -----------" print "\n----------- IMPORT -----------" - print c.imp +# print c.imp print "----------- END IMPORT -----------" print "\n----------- TABLE VIEW -----------" - print c.tv +# print c.tv print "----------- END TABLE VIEW -----------" c.edit_layout("PokerStars", 6, locations=( (1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6) )) c.save(file="testout.xml") - print "db = ", c.get_db_parameters() - print "tv = ", c.get_tv_parameters() - print "imp = ", c.get_import_parameters() - print "paths = ", c.get_default_paths("PokerStars") + print "db = ", c.get_db_parameters() +# print "tv = ", c.get_tv_parameters() +# print "imp = ", c.get_import_parameters() + print "paths = ", c.get_default_paths("PokerStars") + print "colors = ", c.get_default_colors("PokerStars") + print "locs = ", c.get_locations("PokerStars", 8) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index dc4ab242..0cb4062b 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -55,6 +55,7 @@ class Hud: self.db_name = db_name self.deleted = False self.stacked = True + self.colors = config.get_default_colors(self.table.site) self.stat_windows = {} self.popup_windows = {} @@ -73,13 +74,13 @@ class Hud: self.ebox = gtk.EventBox() self.label = gtk.Label("Right click to close HUD for %s\nor Save Stat Positions." % (table.name)) - self.label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(config.supported_sites[self.table.site].hudbgcolor)) - self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(config.supported_sites[self.table.site].hudfgcolor)) + self.label.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudbgcolor'])) + self.label.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor'])) self.main_window.add(self.ebox) self.ebox.add(self.label) - self.ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(config.supported_sites[self.table.site].hudbgcolor)) - self.ebox.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(config.supported_sites[self.table.site].hudfgcolor)) + self.ebox.modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudbgcolor'])) + self.ebox.modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(self.colors['hudfgcolor'])) self.main_window.move(self.table.x, self.table.y) @@ -153,58 +154,11 @@ class Hud: # windows via calls to the Stat_Window class adj = self.adj_seats(hand, config) + loc = self.config.get_locations(self.table.site, self.max) + # create the stat windows for i in range(1, self.max + 1): - # the below IF always appears to be passed as TRUE, I don't know why. If you have an 8-max game, but - # your config file doesn't understand 8 max, it's a crash. It was even a crash when I tried using the - # full-fledged exception handling blocks. - # - Eric - - if self.max in config.supported_sites[self.table.site].layout: - (x, y) = config.supported_sites[self.table.site].layout[self.max].location[adj[i]] - else: - if i == 1: - x = 684 - y = 61 - elif i == 2: - x = 689 - y = 239 - elif i == 3: - x = 692 - y = 346 - elif i == 4: - x = 586 - y = 393 - elif i == 5: - x = 421 - y = 440 - elif i == 6: - x = 267 - y = 440 - elif i == 7: - x = 0 - y = 361 - elif i == 8: - x = 0 - y = 280 - elif i == 9: - x = 121 - y = 280 - elif i == 10: - x = 46 - y = 30 - - sys.stderr.write("at location "+str(x)+" "+str(y)+"\n") - sys.stderr.write("config:"+str(config)+"\n") - gameslist = config.supported_games - sys.stderr.write("supported games:"+str(gameslist)+"\n") - sys.stderr.write("desired game:"+str(self.poker_game)+"\n") - thisgame = gameslist['holdem'] - sys.stderr.write("this game:"+str(thisgame)+"\n") - # the above code looks absolutely completely useless. The below line was freezing the interpreter, so I added the above lines to try and debug - # which piece of the below line was causing it to lock up. Adding the "thisgame = gameslist['holdem']" line fixed it, for some unknown reason. - # removing any one of the lines above causes the interpreter to freeze for me on the next statement. - # -eric + (x, y) = loc[adj[i]] self.stat_windows[i] = Stat_Window(game = config.supported_games[self.poker_game], parent = self, table = self.table, @@ -338,7 +292,7 @@ class Stat_Window: self.window = gtk.Window() self.window.set_decorated(0) - self.window.set_opacity(parent.config.supported_sites[self.table.site].hudopacity) + self.window.set_opacity(parent.colors['hudopacity']) self.window.set_gravity(gtk.gdk.GRAVITY_STATIC) # self.window.set_keep_above(1) @@ -358,15 +312,15 @@ class Stat_Window: for c in range(self.game.cols): self.e_box[r].append( gtk.EventBox() ) - self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.config.supported_sites[self.table.site].hudbgcolor)) - self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.config.supported_sites[self.table.site].hudfgcolor)) + self.e_box[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudbgcolor'])) + self.e_box[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudfgcolor'])) Stats.do_tip(self.e_box[r][c], 'farts') self.grid.attach(self.e_box[r][c], c, c+1, r, r+1, xpadding = 0, ypadding = 0) self.label[r].append( gtk.Label('xxx') ) - self.label[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.config.supported_sites[self.table.site].hudbgcolor)) - self.label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.config.supported_sites[self.table.site].hudfgcolor)) + self.label[r][c].modify_bg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudbgcolor'])) + self.label[r][c].modify_fg(gtk.STATE_NORMAL, gtk.gdk.color_parse(parent.colors['hudfgcolor'])) self.e_box[r][c].add(self.label[r][c]) self.e_box[r][c].connect("button_press_event", self.button_press_cb)