From 7d75e4af91cfba062df3e4edf9c56c6adbcc1e06 Mon Sep 17 00:00:00 2001 From: Ray Date: Mon, 8 Dec 2008 14:10:45 -0500 Subject: [PATCH 1/2] Add winner and pot to Mucked list list box + intfac imp. --- pyfpdb/Database.py | 11 ++++- pyfpdb/Hud.py | 3 +- pyfpdb/Mucked.py | 112 ++++++++++++++++----------------------------- pyfpdb/SQL.py | 8 ++++ pyfpdb/Tables.py | 4 +- 5 files changed, 62 insertions(+), 76 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 95abdd71..154edec5 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -151,7 +151,16 @@ class Database: act = row[1:] action[street].append(act) return action - + + def get_winners_from_hand(self, hand): + """Returns a hash of winners:amount won, given a hand number.""" + winners = {} + c = self.connection.cursor() + c.execute(self.sql.query['get_winners_from_hand'], (hand)) + for row in c.fetchall(): + winners[row[0]] = row[1] + return winners + def get_stats_from_hand(self, hand, aggregate = False): c = self.connection.cursor() diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index 80ec9a82..8dbb53a6 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.site = table.site self.colors = config.get_default_colors(self.table.site) self.stat_windows = {} @@ -212,7 +213,7 @@ class Hud: 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(), config, 'fpdb')" % (aux_params['module'], aux_params['class']))) + self.aux_windows.append(eval("%s.%s(gtk.Window(), self, config, 'fpdb')" % (aux_params['module'], aux_params['class']))) def update(self, hand, config, stat_dict): self.hand = hand # this is the last hand, so it is available later diff --git a/pyfpdb/Mucked.py b/pyfpdb/Mucked.py index e220bf32..aeb77103 100755 --- a/pyfpdb/Mucked.py +++ b/pyfpdb/Mucked.py @@ -22,14 +22,9 @@ Mucked cards display for FreePokerTools HUD. ######################################################################## # to do -# problem with hand 30586 # Standard Library modules import sys -import os -import string -import xml.dom.minidom -from xml.dom.minidom import Node # pyGTK modules import pygtk @@ -39,28 +34,30 @@ import gobject # FreePokerTools modules import Configuration import Database -import Tables -import Hud -import HandHistory class Aux_Window: - def __init__(self, parent, config, db_name): + def __init__(self, parent, hud, config, db_name): + self.config = hud self.config = config - self.parent = parent #this is the parent of the mucked cards widget + self.parent = parent self.db_name = db_name self.vbox = gtk.VBox() self.parent.add(self.vbox) - def update(self): + def update_data(self): + pass + + def update_gui(self): pass class Stud_mucked(Aux_Window): - def __init__(self, parent, config, db_name): + def __init__(self, parent, hud, config, db_name): - self.config = config - self.parent = parent #this is the parent of the mucked cards widget - self.db_name = db_name + self.hud = hud # hud object that this aux window supports + self.config = config # configuration object for this aux window to use + self.parent = parent # parent container for this aux window widget + self.db_name = db_name # database for this aux window to use self.vbox = gtk.VBox() self.parent.add(self.vbox) @@ -71,9 +68,11 @@ class Stud_mucked(Aux_Window): self.parent.show_all() def update_data(self, new_hand_id): + self.mucked_cards.update_data(new_hand_id) self.mucked_list.update_data(new_hand_id) def update_gui(self, new_hand_id): + self.mucked_cards.update_gui(new_hand_id) self.mucked_list.update_gui(new_hand_id) class Stud_list: @@ -89,16 +88,18 @@ class Stud_list: self.parent.add(self.scrolled_window) # create a ListStore to use as the model - self.liststore = gtk.ListStore(str, str, str) + self.liststore = gtk.ListStore(str, str, str, str) self.treeview = gtk.TreeView(self.liststore) self.tvcolumn0 = gtk.TreeViewColumn('HandID') self.tvcolumn1 = gtk.TreeViewColumn('Cards') self.tvcolumn2 = gtk.TreeViewColumn('Net') + self.tvcolumn3 = gtk.TreeViewColumn('Winner') # add tvcolumn to treeview self.treeview.append_column(self.tvcolumn0) self.treeview.append_column(self.tvcolumn1) self.treeview.append_column(self.tvcolumn2) + self.treeview.append_column(self.tvcolumn3) # create a CellRendererText to render the data self.cell = gtk.CellRendererText() @@ -107,11 +108,16 @@ class Stud_list: self.tvcolumn0.pack_start(self.cell, True) self.tvcolumn1.pack_start(self.cell, True) self.tvcolumn2.pack_start(self.cell, True) + self.tvcolumn3.pack_start(self.cell, True) self.tvcolumn0.add_attribute(self.cell, 'text', 0) self.tvcolumn1.add_attribute(self.cell, 'text', 1) self.tvcolumn2.add_attribute(self.cell, 'text', 2) + self.tvcolumn3.add_attribute(self.cell, 'text', 3) # resize the cols if nec self.tvcolumn0.set_resizable(True) + self.tvcolumn1.set_resizable(True) + self.tvcolumn2.set_resizable(True) + self.tvcolumn3.set_resizable(True) self.treeview.connect("row-activated", self.activated_event) self.scrolled_window.add_with_viewport(self.treeview) @@ -119,22 +125,25 @@ class Stud_list: def activated_event(self, path, column, data=None): sel = self.treeview.get_selection() (model, iter) = sel.get_selected() - self.mucked_cards.update(model.get_value(iter, 0)) - - def update(self, new_hand_id): -# info_row = self.db_connection.get_hand_info(new_hand_id) - info_row = ((new_hand_id, "xxxx", 0), ) - iter = self.liststore.append(info_row[0]) - sel = self.treeview.get_selection() - sel.select_iter(iter) - - vadj = self.scrolled_window.get_vadjustment() - vadj.set_value(vadj.upper) - self.mucked_cards.update(new_hand_id) + self.mucked_cards.update_data(model.get_value(iter, 0)) + self.mucked_cards.update_gui(model.get_value(iter, 0)) def update_data(self, new_hand_id): - self.info_row = ((new_hand_id, "xxxx", 0), ) - self.mucked_cards.update_data(new_hand_id) + """Updates the data needed for the list box.""" + + db_connection = Database.Database(self.config, 'fpdb', '') + self.winners = db_connection.get_winners_from_hand(new_hand_id) + db_connection.close_connection() + pot = 0 + winners = '' + for player in self.winners.keys(): + pot = pot + int(self.winners[player]) + if not winners == '': + winners = winners + ", " + winners = winners + player + pot_dec = "%.2f" % (float(pot)/100) + + self.info_row = ((new_hand_id, "xxxx", pot_dec, winners), ) def update_gui(self, new_hand_id): iter = self.liststore.append(self.info_row[0]) @@ -143,7 +152,6 @@ class Stud_list: vadj = self.scrolled_window.get_vadjustment() vadj.set_value(vadj.upper) - self.mucked_cards.update_gui(new_hand_id) class Stud_cards: def __init__(self, parent, config, db_name = 'fpdb'): @@ -204,46 +212,6 @@ class Stud_cards: old_cards[c][key] = ranks[old_cards[c][rank]] + old_cards[c][suit] return old_cards - def update(self, new_hand_id): - db_connection = Database.Database(self.config, 'fpdb', '') - cards = db_connection.get_cards(new_hand_id) - self.clear() - cards = self.translate_cards(cards) - for c in cards.keys(): - self.grid_contents[(1, cards[c]['seat_number'] - 1)].set_text(cards[c]['screen_name']) - for i in ((0, 'hole_card_1'), (1, 'hole_card_2'), (2, 'hole_card_3'), (3, 'hole_card_4'), - (4, 'hole_card_5'), (5, 'hole_card_6'), (6, 'hole_card_7')): - if not cards[c][i[1]] == "xx": - self.seen_cards[(i[0], cards[c]['seat_number'] - 1)]. \ - set_from_pixbuf(self.card_images[self.split_cards(cards[c][i[1]])]) - - tips = [] - action = db_connection.get_action_from_hand(new_hand_id) - for street in action: - temp = '' - for act in street: - temp = temp + act[0] + " " + act[1] + "s " - if act[2] > 0: - if act[2]%100 > 0: - temp = temp + "%4.2f\n" % (float(act[2])/100) - else: - temp = temp + "%d\n" % (act[2]/100) - else: - temp = temp + "\n" - tips.append(temp) - -## action in tool tips for 3rd street cards - for c in (0, 1, 2): - for r in range(0, self.rows): - self.eb[(c, r)].set_tooltip_text(tips[0]) - -# action in tools tips for later streets - round_to_col = (0, 3, 4, 5, 6) - for round in range(1, len(tips)): - for r in range(0, self.rows): - self.eb[(round_to_col[round], r)].set_tooltip_text(tips[round]) - db_connection.close_connection() - def update_data(self, new_hand_id): db_connection = Database.Database(self.config, 'fpdb', '') cards = db_connection.get_cards(new_hand_id) @@ -330,7 +298,7 @@ if __name__== "__main__": main_window.connect("destroy", destroy) aux_to_call = "Stud_mucked" - m = eval("%s(main_window, config, 'fpdb')" % aux_to_call) + m = eval("%s(main_window, None, config, 'fpdb')" % aux_to_call) main_window.show_all() s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand) diff --git a/pyfpdb/SQL.py b/pyfpdb/SQL.py index 45b0c60f..724ba8ed 100644 --- a/pyfpdb/SQL.py +++ b/pyfpdb/SQL.py @@ -320,6 +320,14 @@ class Sql: """ # WHERE handId = %s AND Players.id LIKE %s + self.query['get_winners_from_hand'] = """ + SELECT name, winnings + FROM HandsPlayers, Players + WHERE winnings > 0 + AND Players.id = HandsPlayers.playerId + AND handId = %s; + """ + self.query['get_table_name'] = """ select tableName, maxSeats, category from Hands,Gametypes diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index 9f5360e2..3e7bacc6 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -429,8 +429,8 @@ def discover_mac_by_name(c, tablename): if __name__=="__main__": c = Configuration.Config() - print discover_table_by_name(c, "Howard Lederer") - print discover_tournament_table(c, "118942908", "3") + print discover_table_by_name(c, "Daddy Nasty") +# print discover_tournament_table(c, "118942908", "3") tables = discover(c) for t in tables.keys(): From 95f5eab4480c719bd3ae32c7c03ff811378c672a Mon Sep 17 00:00:00 2001 From: Ray Date: Wed, 10 Dec 2008 13:45:56 -0500 Subject: [PATCH 2/2] merge with eric's drag changes --- pyfpdb/Hud.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/pyfpdb/Hud.py b/pyfpdb/Hud.py index e2147517..66655c9a 100644 --- a/pyfpdb/Hud.py +++ b/pyfpdb/Hud.py @@ -224,13 +224,9 @@ class Hud: game_params = config.get_game_parameters(self.poker_game) if not game_params['aux'] == "": aux_params = config.get_aux_parameters(game_params['aux']) -<<<<<<< HEAD:pyfpdb/Hud.py self.aux_windows.append(eval("%s.%s(gtk.Window(), self, config, 'fpdb')" % (aux_params['module'], aux_params['class']))) -======= - self.aux_windows.append(eval("%s.%s(gtk.Window(), config, 'fpdb')" % (aux_params['module'], aux_params['class']))) gobject.timeout_add(0.5, self.update_table_position) ->>>>>>> f607b3ff632a015de2cdbe2a92f706d90b116458:pyfpdb/Hud.py def update(self, hand, config, stat_dict): self.hand = hand # this is the last hand, so it is available later