From a6d70e6e13f89747f11f57cc41e7e3972bc99d7e Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 4 Mar 2009 20:04:23 -0500 Subject: [PATCH] More tuning of the aux_window interface. --- pyfpdb/Configuration.py | 9 +++++++-- pyfpdb/HUD_main.py | 12 ++++++++---- pyfpdb/Hud.py | 27 +++++++++++++++++++------- pyfpdb/Mucked.py | 43 +++++++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 32 deletions(-) diff --git a/pyfpdb/Configuration.py b/pyfpdb/Configuration.py index fb182f4b..7c6b9895 100755 --- a/pyfpdb/Configuration.py +++ b/pyfpdb/Configuration.py @@ -3,7 +3,7 @@ Handles HUD configuration files. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # This program is free software; you can redistribute it and/or modify @@ -105,7 +105,12 @@ class Game: self.db = node.getAttribute("db") self.rows = int( node.getAttribute("rows") ) self.cols = int( node.getAttribute("cols") ) - self.aux = node.getAttribute("aux") + + aux_text = node.getAttribute("aux") + aux_list = aux_text.split(',') + for i in range(0, len(aux_list)): + aux_list[i] = aux_list[i].strip() + self.aux = aux_list self.stats = {} for stat_node in node.getElementsByTagName('stat'): diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 7418cfc8..cb1f5ded 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -4,7 +4,7 @@ Main for FreePokerTools HUD. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -31,8 +31,8 @@ Main for FreePokerTools HUD. import sys # redirect the stderr -errorfile = open('HUD-error.txt', 'w', 0) -sys.stderr = errorfile +#errorfile = open('HUD-error.txt', 'w', 0) +#sys.stderr = errorfile import os import thread @@ -97,7 +97,7 @@ class HUD_main(object): self.hud_dict[table_name].tablehudlabel = newlabel self.hud_dict[table_name].create(new_hand_id, self.config, stat_dict, cards) for m in self.hud_dict[table_name].aux_windows: - m.update_data(new_hand_id, self.db_connection) + m.create() m.update_gui(new_hand_id) self.hud_dict[table_name].update(new_hand_id, self.config) self.hud_dict[table_name].reposition_windows() @@ -106,6 +106,10 @@ class HUD_main(object): gtk.gdk.threads_leave() self.hud_dict[table_name] = Hud.Hud(self, table, max, poker_game, self.config, self.db_connection) + self.hud_dict[table_name].stat_dict = stat_dict + self.hud_dict[table_name].cards = cards + for aw in self.hud_dict[table_name].aux_windows: + aw.update_data(new_hand_id, self.db_connection) gobject.idle_add(idle_func) def update_HUD(self, new_hand_id, table_name, config): diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index ed43bea2..34d1b0cf 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -3,7 +3,7 @@ Create and manage the hud overlays. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009 Ray E. Barker # # This program is free software; you can redistribute it and/or modify @@ -45,6 +45,15 @@ 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!!!! + try: + module = __import__(module_name, globals(), locals(), [name]) + except: + return None + return(getattr(module, name)) + class Hud: def __init__(self, parent, table, max, poker_game, config, db_connection): @@ -75,6 +84,15 @@ class Hud: self.font = pango.FontDescription(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) + if not game_params['aux'] == "": + for aux in game_params['aux']: + aux_params = config.get_aux_parameters(aux) + my_import = importName(aux_params['module'], aux_params['class']) + if my_import == None: + continue + self.aux_windows.append(my_import(self, config, aux_params)) + def create_mw(self): # Set up a main window for this this instance of the HUD @@ -135,7 +153,7 @@ class Hud: if os.name == 'nt': self.topify_window(self.main_window) else: - self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(self.table.number) # gets a gdk handle for poker client + self.main_window.parentgdkhandle = gtk.gdk.window_foreign_new(int(self.table.number)) # gets a gdk handle for poker client self.main_window.gdkhandle = gtk.gdk.window_foreign_new(self.main_window.window.xid) # gets a gdk handle for the hud table window self.main_window.gdkhandle.set_transient_for(self.main_window.parentgdkhandle) # @@ -269,11 +287,6 @@ class Hud: 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 - - game_params = config.get_game_parameters(self.poker_game) - if not game_params['aux'] == "": - aux_params = config.get_aux_parameters(game_params['aux']) - self.aux_windows.append(eval("%s.%s(gtk.Window(), self, config, aux_params)" % (aux_params['module'], aux_params['class']))) if os.name == "nt": gobject.timeout_add(500, self.update_table_position) diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index 1e550edc..0b605e2f 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -3,7 +3,7 @@ Mucked cards display for FreePokerTools HUD. """ -# Copyright 2008, Ray E. Barker +# Copyright 2008, 2009, Ray E. Barker # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -36,29 +36,27 @@ import Configuration import Database class Aux_Window: - def __init__(self, container, hud, params, config): + def __init__(self, hud, params, config): self.config = hud self.config = config - self.container = container - self.vbox = gtk.VBox() - self.container.add(self.vbox) - - def update_data(self): + def update_data(self, *parms): pass - def update_gui(self): + def update_gui(self, *parms): + pass + + def create(self, *parms): pass def destroy(self): self.container.destroy() class Stud_mucked(Aux_Window): - def __init__(self, container, hud, config, params): + def __init__(self, hud, config, params): self.hud = hud # hud object that this aux window supports self.config = config # configuration object for this aux window to use - self.container = container # parent container for this aux window widget self.params = params # hash aux params from config try: @@ -67,12 +65,18 @@ class Stud_mucked(Aux_Window): except: self.hero = '' + self.mucked_list = Stud_list(self, params, config, self.hero) + self.mucked_cards = Stud_cards(self, params, config) + self.mucked_list.mucked_cards = self.mucked_cards + + def create(self): + + self.container =gtk.Window() self.vbox = gtk.VBox() self.container.add(self.vbox) - self.mucked_list = Stud_list(self.vbox, self, params, config, self.hero) - self.mucked_cards = Stud_cards(self.vbox, self, params, config) - self.mucked_list.mucked_cards = self.mucked_cards + self.mucked_list.create(self.vbox) + self.mucked_cards.create(self.vbox) self.container.show_all() def update_data(self, new_hand_id, db_connection): @@ -84,16 +88,16 @@ class Stud_mucked(Aux_Window): self.mucked_list.update_gui(new_hand_id) class Stud_list: - def __init__(self, container, parent, params, config, hero): + def __init__(self, parent, params, config, hero): - self.container = container self.parent = parent self.params = params self.config = config self.hero = hero -# self.db_name = db_name + def create(self, container): # set up a scrolled window to hold the listbox + self.container = container self.scrolled_window = gtk.ScrolledWindow() self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS) self.container.add(self.scrolled_window) @@ -178,9 +182,8 @@ class Stud_list: vadj.set_value(vadj.upper) class Stud_cards: - def __init__(self, container, parent, params, config): + def __init__(self, parent, params, config): - self.container = container #this is the parent container of the mucked cards widget self.parent = parent self.params = params self.config = config @@ -193,6 +196,9 @@ class Stud_cards: self.rows = 8 self.cols = 7 + + def create(self, container): + self.container = container self.grid = gtk.Table(self.rows, self.cols + 4, homogeneous = False) for r in range(0, self.rows): @@ -289,7 +295,6 @@ class Stud_cards: pb.copy_area(30*j, 42*i, 30, 42, temp_pb, 0, 0) card_images[(ranks[j], suits[i])] = temp_pb return(card_images) - # cards are 30 wide x 42 high if __name__== "__main__":