Clean up db connection in aux window. Hole cards to stud mucked list.
This commit is contained in:
parent
5afc411cad
commit
e0105c5ed1
|
@ -22,14 +22,11 @@ Main for FreePokerTools HUD.
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
|
|
||||||
# to do kill window on my seat
|
|
||||||
# to do adjust for preferred seat
|
|
||||||
# to do allow window resizing
|
# to do allow window resizing
|
||||||
# to do hud to echo, but ignore non numbers
|
# to do hud to echo, but ignore non numbers
|
||||||
# to do no hud window for hero
|
# to do no stat window for hero
|
||||||
# to do things to add to config.xml
|
# to do things to add to config.xml
|
||||||
# to do font and size
|
# to do font and size
|
||||||
# to do opacity
|
|
||||||
|
|
||||||
# Standard Library modules
|
# Standard Library modules
|
||||||
import sys
|
import sys
|
||||||
|
@ -68,8 +65,11 @@ def create_HUD(new_hand_id, table, db_name, table_name, max, poker_game, db_conn
|
||||||
global hud_dict
|
global hud_dict
|
||||||
gtk.gdk.threads_enter()
|
gtk.gdk.threads_enter()
|
||||||
try:
|
try:
|
||||||
hud_dict[table_name] = Hud.Hud(table, max, poker_game, config, db_name)
|
hud_dict[table_name] = Hud.Hud(table, max, poker_game, config, db_connection)
|
||||||
hud_dict[table_name].create(new_hand_id, config)
|
hud_dict[table_name].create(new_hand_id, config)
|
||||||
|
for m in hud_dict[table_name].aux_windows:
|
||||||
|
m.update_data(new_hand_id, db_connection)
|
||||||
|
m.update_gui(new_hand_id)
|
||||||
hud_dict[table_name].update(new_hand_id, config, stat_dict)
|
hud_dict[table_name].update(new_hand_id, config, stat_dict)
|
||||||
hud_dict[table_name].reposition_windows()
|
hud_dict[table_name].reposition_windows()
|
||||||
return False
|
return False
|
||||||
|
@ -114,7 +114,6 @@ def read_stdin(): # This is the thread function
|
||||||
is_tournament = False
|
is_tournament = False
|
||||||
(tour_number, tab_number) = (0, 0)
|
(tour_number, tab_number) = (0, 0)
|
||||||
mat_obj = tourny_finder.search(table_name)
|
mat_obj = tourny_finder.search(table_name)
|
||||||
# if len(mat_obj.groups) == 2:
|
|
||||||
if mat_obj:
|
if mat_obj:
|
||||||
is_tournament = True
|
is_tournament = True
|
||||||
(tour_number, tab_number) = mat_obj.group(1, 2)
|
(tour_number, tab_number) = mat_obj.group(1, 2)
|
||||||
|
@ -125,11 +124,13 @@ def read_stdin(): # This is the thread function
|
||||||
if hud_dict.has_key(table_name):
|
if hud_dict.has_key(table_name):
|
||||||
# update the data for the aux_windows
|
# update the data for the aux_windows
|
||||||
for aw in hud_dict[table_name].aux_windows:
|
for aw in hud_dict[table_name].aux_windows:
|
||||||
aw.update_data(new_hand_id)
|
aw.update_data(new_hand_id, db_connection)
|
||||||
update_HUD(new_hand_id, table_name, config, stat_dict)
|
update_HUD(new_hand_id, table_name, config, stat_dict)
|
||||||
|
|
||||||
# if a hud for this TOURNAMENT table exists, just update it
|
# if a hud for this TOURNAMENT table exists, just update it
|
||||||
elif hud_dict.has_key(tour_number):
|
elif hud_dict.has_key(tour_number):
|
||||||
update_HUD(new_hand_id, tour_number, config, stat_dict)
|
update_HUD(new_hand_id, tour_number, config, stat_dict)
|
||||||
|
|
||||||
# otherwise create a new hud
|
# otherwise create a new hud
|
||||||
else:
|
else:
|
||||||
if is_tournament:
|
if is_tournament:
|
||||||
|
|
|
@ -47,12 +47,12 @@ import HUD_main
|
||||||
|
|
||||||
class Hud:
|
class Hud:
|
||||||
|
|
||||||
def __init__(self, table, max, poker_game, config, db_name):
|
def __init__(self, table, max, poker_game, config, db_connection):
|
||||||
self.table = table
|
self.table = table
|
||||||
self.config = config
|
self.config = config
|
||||||
self.poker_game = poker_game
|
self.poker_game = poker_game
|
||||||
self.max = max
|
self.max = max
|
||||||
self.db_name = db_name
|
self.db_connection = db_connection
|
||||||
self.deleted = False
|
self.deleted = False
|
||||||
self.stacked = True
|
self.stacked = True
|
||||||
self.site = table.site
|
self.site = table.site
|
||||||
|
@ -134,7 +134,6 @@ class Hud:
|
||||||
(x, y) = loc[adj[i]]
|
(x, y) = loc[adj[i]]
|
||||||
if self.stat_windows.has_key(i):
|
if self.stat_windows.has_key(i):
|
||||||
self.stat_windows[i].relocate(x, y)
|
self.stat_windows[i].relocate(x, y)
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def on_button_press(self, widget, event):
|
def on_button_press(self, widget, event):
|
||||||
|
@ -177,9 +176,9 @@ class Hud:
|
||||||
try:
|
try:
|
||||||
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:
|
||||||
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
|
fav_seat = config.supported_sites[self.table.site].layout[self.max].fav_seat
|
||||||
db_connection = Database.Database(config, self.db_name, 'temp')
|
# db_connection = Database.Database(config, self.db_name, 'temp')
|
||||||
actual_seat = db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
|
actual_seat = self.db_connection.get_actual_seat(hand, config.supported_sites[self.table.site].screen_name)
|
||||||
db_connection.close_connection()
|
# db_connection.close_connection()
|
||||||
for i in range(0, self.max + 1):
|
for i in range(0, self.max + 1):
|
||||||
j = actual_seat + i
|
j = actual_seat + i
|
||||||
if j > self.max: j = j - self.max
|
if j > self.max: j = j - self.max
|
||||||
|
@ -227,7 +226,7 @@ class Hud:
|
||||||
game_params = config.get_game_parameters(self.poker_game)
|
game_params = config.get_game_parameters(self.poker_game)
|
||||||
if not game_params['aux'] == "":
|
if not game_params['aux'] == "":
|
||||||
aux_params = config.get_aux_parameters(game_params['aux'])
|
aux_params = config.get_aux_parameters(game_params['aux'])
|
||||||
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(), self, config, aux_params)" % (aux_params['module'], aux_params['class'])))
|
||||||
|
|
||||||
# gobject.timeout_add(500, self.update_table_position)
|
# gobject.timeout_add(500, self.update_table_position)
|
||||||
|
|
||||||
|
@ -471,12 +470,12 @@ class Popup_window:
|
||||||
break
|
break
|
||||||
|
|
||||||
# get a database connection
|
# get a database connection
|
||||||
db_connection = Database.Database(stat_window.parent.config, stat_window.parent.db_name, 'temp')
|
# db_connection = Database.Database(stat_window.parent.config, stat_window.parent.db_name, 'temp')
|
||||||
|
|
||||||
# calculate the stat_dict and then create the text for the pu
|
# calculate the stat_dict and then create the text for the pu
|
||||||
# stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand, stat_window.player_id)
|
# stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand, stat_window.player_id)
|
||||||
stat_dict = db_connection.get_stats_from_hand(stat_window.parent.hand)
|
stat_dict = self.db_connection.get_stats_from_hand(stat_window.parent.hand)
|
||||||
db_connection.close_connection()
|
# db_connection.close_connection()
|
||||||
|
|
||||||
pu_text = ""
|
pu_text = ""
|
||||||
for s in stat_list:
|
for s in stat_list:
|
||||||
|
|
106
pyfpdb/Mucked.py
106
pyfpdb/Mucked.py
|
@ -36,14 +36,13 @@ import Configuration
|
||||||
import Database
|
import Database
|
||||||
|
|
||||||
class Aux_Window:
|
class Aux_Window:
|
||||||
def __init__(self, parent, hud, config, db_name):
|
def __init__(self, container, hud, params, config):
|
||||||
self.config = hud
|
self.config = hud
|
||||||
self.config = config
|
self.config = config
|
||||||
self.parent = parent
|
self.container = container
|
||||||
self.db_name = db_name
|
|
||||||
|
|
||||||
self.vbox = gtk.VBox()
|
self.vbox = gtk.VBox()
|
||||||
self.parent.add(self.vbox)
|
self.container.add(self.vbox)
|
||||||
|
|
||||||
def update_data(self):
|
def update_data(self):
|
||||||
pass
|
pass
|
||||||
|
@ -52,40 +51,49 @@ class Aux_Window:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Stud_mucked(Aux_Window):
|
class Stud_mucked(Aux_Window):
|
||||||
def __init__(self, parent, hud, config, db_name):
|
def __init__(self, container, hud, config, params):
|
||||||
|
|
||||||
self.hud = hud # hud object that this aux window supports
|
self.hud = hud # hud object that this aux window supports
|
||||||
self.config = config # configuration object for this aux window to use
|
self.config = config # configuration object for this aux window to use
|
||||||
self.parent = parent # parent container for this aux window widget
|
self.container = container # parent container for this aux window widget
|
||||||
self.db_name = db_name # database for this aux window to use
|
self.params = params # hash aux params from config
|
||||||
|
|
||||||
|
try:
|
||||||
|
site_params = self.config.get_site_parameters(self.hud.site)
|
||||||
|
self.hero = site_params['screen_name']
|
||||||
|
except:
|
||||||
|
self.hero = ''
|
||||||
|
|
||||||
self.vbox = gtk.VBox()
|
self.vbox = gtk.VBox()
|
||||||
self.parent.add(self.vbox)
|
self.container.add(self.vbox)
|
||||||
|
|
||||||
self.mucked_list = Stud_list(self.vbox, config, db_name)
|
self.mucked_list = Stud_list(self.vbox, self, params, config, self.hero)
|
||||||
self.mucked_cards = Stud_cards(self.vbox, config, db_name)
|
self.mucked_cards = Stud_cards(self.vbox, self, params, config)
|
||||||
self.mucked_list.mucked_cards = self.mucked_cards
|
self.mucked_list.mucked_cards = self.mucked_cards
|
||||||
self.parent.show_all()
|
self.container.show_all()
|
||||||
|
|
||||||
def update_data(self, new_hand_id):
|
def update_data(self, new_hand_id, db_connection):
|
||||||
self.mucked_cards.update_data(new_hand_id)
|
self.mucked_cards.update_data(new_hand_id, db_connection)
|
||||||
self.mucked_list.update_data(new_hand_id)
|
self.mucked_list.update_data(new_hand_id, db_connection)
|
||||||
|
|
||||||
def update_gui(self, new_hand_id):
|
def update_gui(self, new_hand_id):
|
||||||
self.mucked_cards.update_gui(new_hand_id)
|
self.mucked_cards.update_gui(new_hand_id)
|
||||||
self.mucked_list.update_gui(new_hand_id)
|
self.mucked_list.update_gui(new_hand_id)
|
||||||
|
|
||||||
class Stud_list:
|
class Stud_list:
|
||||||
def __init__(self, parent, config, db_name):
|
def __init__(self, container, parent, params, config, hero):
|
||||||
|
|
||||||
|
self.container = container
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.params = params
|
||||||
self.config = config
|
self.config = config
|
||||||
self.db_name = db_name
|
self.hero = hero
|
||||||
|
# self.db_name = db_name
|
||||||
|
|
||||||
# set up a scrolled window to hold the listbox
|
# set up a scrolled window to hold the listbox
|
||||||
self.scrolled_window = gtk.ScrolledWindow()
|
self.scrolled_window = gtk.ScrolledWindow()
|
||||||
self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
|
self.scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_ALWAYS)
|
||||||
self.parent.add(self.scrolled_window)
|
self.container.add(self.scrolled_window)
|
||||||
|
|
||||||
# create a ListStore to use as the model
|
# create a ListStore to use as the model
|
||||||
self.liststore = gtk.ListStore(str, str, str, str)
|
self.liststore = gtk.ListStore(str, str, str, str)
|
||||||
|
@ -123,17 +131,17 @@ class Stud_list:
|
||||||
self.scrolled_window.add_with_viewport(self.treeview)
|
self.scrolled_window.add_with_viewport(self.treeview)
|
||||||
|
|
||||||
def activated_event(self, path, column, data=None):
|
def activated_event(self, path, column, data=None):
|
||||||
sel = self.treeview.get_selection()
|
pass
|
||||||
(model, iter) = sel.get_selected()
|
# sel = self.treeview.get_selection()
|
||||||
self.mucked_cards.update_data(model.get_value(iter, 0))
|
# (model, iter) = sel.get_selected()
|
||||||
self.mucked_cards.update_gui(model.get_value(iter, 0))
|
# 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):
|
def update_data(self, new_hand_id, db_connection):
|
||||||
"""Updates the data needed for the list box."""
|
"""Updates the data needed for the list box."""
|
||||||
|
|
||||||
db_connection = Database.Database(self.config, 'fpdb', '')
|
# db_connection = Database.Database(self.config, 'fpdb', '')
|
||||||
self.winners = db_connection.get_winners_from_hand(new_hand_id)
|
self.winners = db_connection.get_winners_from_hand(new_hand_id)
|
||||||
db_connection.close_connection()
|
|
||||||
pot = 0
|
pot = 0
|
||||||
winners = ''
|
winners = ''
|
||||||
for player in self.winners.keys():
|
for player in self.winners.keys():
|
||||||
|
@ -143,7 +151,21 @@ class Stud_list:
|
||||||
winners = winners + player
|
winners = winners + player
|
||||||
pot_dec = "%.2f" % (float(pot)/100)
|
pot_dec = "%.2f" % (float(pot)/100)
|
||||||
|
|
||||||
self.info_row = ((new_hand_id, "xxxx", pot_dec, winners), )
|
hero_cards = self.get_hero_cards(self.parent.hero, self.parent.mucked_cards.cards)
|
||||||
|
self.info_row = ((new_hand_id, hero_cards, pot_dec, winners), )
|
||||||
|
|
||||||
|
def get_hero_cards(self, hero, cards):
|
||||||
|
"""Formats the hero cards for inclusion in the tree."""
|
||||||
|
trans = ('0', 'A', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')
|
||||||
|
if hero == '':
|
||||||
|
return "xxxxxx"
|
||||||
|
else:
|
||||||
|
for k in cards.keys():
|
||||||
|
if cards[k]['screen_name'] == hero:
|
||||||
|
return trans[cards[k]['card1Value']] + cards[k]['card1Suit'] \
|
||||||
|
+ trans[cards[k]['card2Value']] + cards[k]['card2Suit'] \
|
||||||
|
+ trans[cards[k]['card3Value']] + cards[k]['card3Suit']
|
||||||
|
return "xxxxxx"
|
||||||
|
|
||||||
def update_gui(self, new_hand_id):
|
def update_gui(self, new_hand_id):
|
||||||
iter = self.liststore.append(self.info_row[0])
|
iter = self.liststore.append(self.info_row[0])
|
||||||
|
@ -154,11 +176,13 @@ class Stud_list:
|
||||||
vadj.set_value(vadj.upper)
|
vadj.set_value(vadj.upper)
|
||||||
|
|
||||||
class Stud_cards:
|
class Stud_cards:
|
||||||
def __init__(self, parent, config, db_name = 'fpdb'):
|
def __init__(self, container, parent, params, config):
|
||||||
|
|
||||||
self.parent = parent #this is the parent of the mucked cards widget
|
self.container = container #this is the parent container of the mucked cards widget
|
||||||
|
self.parent = parent
|
||||||
|
self.params = params
|
||||||
self.config = config
|
self.config = config
|
||||||
self.db_name = db_name
|
# self.db_name = db_name
|
||||||
|
|
||||||
self.card_images = self.get_card_images()
|
self.card_images = self.get_card_images()
|
||||||
self.seen_cards = {}
|
self.seen_cards = {}
|
||||||
|
@ -196,7 +220,7 @@ class Stud_cards:
|
||||||
for r in range(0, self.rows):
|
for r in range(0, self.rows):
|
||||||
self.grid.attach(self.grid_contents[(c, r)], c, c+1, r, r+1, xpadding = 1, ypadding = 1)
|
self.grid.attach(self.grid_contents[(c, r)], c, c+1, r, r+1, xpadding = 1, ypadding = 1)
|
||||||
|
|
||||||
self.parent.add(self.grid)
|
self.container.add(self.grid)
|
||||||
|
|
||||||
def translate_cards(self, old_cards):
|
def translate_cards(self, old_cards):
|
||||||
ranks = ('', '', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')
|
ranks = ('', '', '2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')
|
||||||
|
@ -212,10 +236,9 @@ class Stud_cards:
|
||||||
old_cards[c][key] = ranks[old_cards[c][rank]] + old_cards[c][suit]
|
old_cards[c][key] = ranks[old_cards[c][rank]] + old_cards[c][suit]
|
||||||
return old_cards
|
return old_cards
|
||||||
|
|
||||||
def update_data(self, new_hand_id):
|
def update_data(self, new_hand_id, db_connection):
|
||||||
db_connection = Database.Database(self.config, 'fpdb', '')
|
# db_connection = Database.Database(self.config, 'fpdb', '')
|
||||||
cards = db_connection.get_cards(new_hand_id)
|
cards = db_connection.get_cards(new_hand_id)
|
||||||
self.clear()
|
|
||||||
self.cards = self.translate_cards(cards)
|
self.cards = self.translate_cards(cards)
|
||||||
|
|
||||||
self.tips = []
|
self.tips = []
|
||||||
|
@ -232,9 +255,9 @@ class Stud_cards:
|
||||||
else:
|
else:
|
||||||
temp = temp + "\n"
|
temp = temp + "\n"
|
||||||
self.tips.append(temp)
|
self.tips.append(temp)
|
||||||
db_connection.close_connection()
|
|
||||||
|
|
||||||
def update_gui(self, new_hand_id):
|
def update_gui(self, new_hand_id):
|
||||||
|
self.clear()
|
||||||
for c in self.cards.keys():
|
for c in self.cards.keys():
|
||||||
self.grid_contents[(1, self.cards[c]['seat_number'] - 1)].set_text(self.cards[c]['screen_name'])
|
self.grid_contents[(1, self.cards[c]['seat_number'] - 1)].set_text(self.cards[c]['screen_name'])
|
||||||
for i in ((0, 'hole_card_1'), (1, 'hole_card_2'), (2, 'hole_card_3'), (3, 'hole_card_4'),
|
for i in ((0, 'hole_card_1'), (1, 'hole_card_2'), (2, 'hole_card_3'), (3, 'hole_card_4'),
|
||||||
|
@ -262,11 +285,12 @@ class Stud_cards:
|
||||||
for c in range(0, 7):
|
for c in range(0, 7):
|
||||||
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')])
|
self.seen_cards[(c, r)].set_from_pixbuf(self.card_images[('B', 'S')])
|
||||||
self.eb[(c, r)].set_tooltip_text('')
|
self.eb[(c, r)].set_tooltip_text('')
|
||||||
|
|
||||||
def get_card_images(self):
|
def get_card_images(self):
|
||||||
card_images = {}
|
card_images = {}
|
||||||
suits = ('S', 'H', 'D', 'C')
|
suits = ('S', 'H', 'D', 'C')
|
||||||
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B')
|
ranks = ('A', 'K', 'Q', 'J', 'T', '9', '8', '7', '6', '5', '4', '3', '2', 'B')
|
||||||
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path("54PFozzycards0.png"))
|
pb = gtk.gdk.pixbuf_new_from_file(self.config.execution_path(self.params['deck']))
|
||||||
|
|
||||||
for j in range(0, 14):
|
for j in range(0, 14):
|
||||||
for i in range(0, 4):
|
for i in range(0, 4):
|
||||||
|
@ -282,24 +306,24 @@ if __name__== "__main__":
|
||||||
def destroy(*args): # call back for terminating the main eventloop
|
def destroy(*args): # call back for terminating the main eventloop
|
||||||
gtk.main_quit() # used only for testing
|
gtk.main_quit() # used only for testing
|
||||||
|
|
||||||
def process_new_hand(source, condition): #callback from stdin watch -- testing only
|
def process_new_hand(source, condition, db_connection): #callback from stdin watch -- testing only
|
||||||
# there is a new hand_id to be processed
|
# there is a new hand_id to be processed
|
||||||
# just read it and pass it to update
|
# just read it and pass it to update
|
||||||
new_hand_id = sys.stdin.readline()
|
new_hand_id = sys.stdin.readline()
|
||||||
new_hand_id = new_hand_id.rstrip() # remove trailing whitespace
|
new_hand_id = new_hand_id.rstrip() # remove trailing whitespace
|
||||||
m.update_data(new_hand_id)
|
m.update_data(new_hand_id, db_connection)
|
||||||
m.update_gui(new_hand_id)
|
m.update_gui(new_hand_id)
|
||||||
return(True)
|
return(True)
|
||||||
|
|
||||||
config = Configuration.Config()
|
config = Configuration.Config()
|
||||||
# db_connection = Database.Database(config, 'fpdb', '')
|
db_connection = Database.Database(config, 'fpdb', '')
|
||||||
main_window = gtk.Window()
|
main_window = gtk.Window()
|
||||||
main_window.set_keep_above(True)
|
main_window.set_keep_above(True)
|
||||||
main_window.connect("destroy", destroy)
|
main_window.connect("destroy", destroy)
|
||||||
|
|
||||||
aux_to_call = "Stud_mucked"
|
aux_to_call = "stud_mucked"
|
||||||
m = eval("%s(main_window, None, config, 'fpdb')" % aux_to_call)
|
aux_params = config.get_aux_parameters(aux_to_call)
|
||||||
main_window.show_all()
|
m = eval("%s(main_window, None, config, aux_params)" % aux_params['class'])
|
||||||
|
|
||||||
s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand)
|
s_id = gobject.io_add_watch(sys.stdin, gobject.IO_IN, process_new_hand, db_connection)
|
||||||
gtk.main()
|
gtk.main()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user