From 3e76033cd5ba2e18c4e155a201062b3a774ddd51 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sun, 29 Nov 2009 11:21:11 +0200 Subject: [PATCH 01/32] Do not minimize window when workspace changes When we have the systray icon enabled, any window visibility event seems to have WINDOW_STATE_ICONIFIED bit on. By checking both _ICONIFIED and _WITHDRAWN the behaviour appears nicer. --- pyfpdb/fpdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 80d3fb93..77f13ca7 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -669,8 +669,8 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") sys.stderr.write("fpdb starting ...") def window_state_event_cb(self, window, event): - print "window_state_event", event - if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: + print "window_state_event: %s, mask=%s" % (event, event.changed_mask) + if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED & gtk.gdk.WINDOW_STATE_WITHDRAWN: # -20 = GWL_EXSTYLE can't find it in the pywin32 libs #bits = win32api.GetWindowLong(self.window.window.handle, -20) #bits = bits ^ (win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_APPWINDOW) From 761d53f2f44b3dd50a1eac7ac17f70feb4539da1 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 2 Dec 2009 18:38:58 +0200 Subject: [PATCH 02/32] Revert "Use wider try-except block" This reverts commit 2f742e371be64964fe9499824901c71f0509601c. --- pyfpdb/HUD_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 4f7e8845..39096065 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -215,10 +215,10 @@ class HUD_main(object): # Update an existing HUD if temp_key in self.hud_dict: # get stats using hud's specific params and get cards - try: - self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] + self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] , self.hud_dict[temp_key].hud_params['h_hud_days']) - stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) + stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) + try: self.hud_dict[temp_key].stat_dict = stat_dict except KeyError: # HUD instance has been killed off, key is stale sys.stderr.write('hud_dict[%s] was not found\n' % temp_key) From 3e9353e3b9816aa36705c46c97b3f6a023e9cace Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 2 Dec 2009 18:39:06 +0200 Subject: [PATCH 03/32] Revert "Revert "Use wider try-except block"" This reverts commit 761d53f2f44b3dd50a1eac7ac17f70feb4539da1. --- pyfpdb/HUD_main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 39096065..4f7e8845 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -215,10 +215,10 @@ class HUD_main(object): # Update an existing HUD if temp_key in self.hud_dict: # get stats using hud's specific params and get cards - self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] - , self.hud_dict[temp_key].hud_params['h_hud_days']) - stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) try: + self.db_connection.init_hud_stat_vars( self.hud_dict[temp_key].hud_params['hud_days'] + , self.hud_dict[temp_key].hud_params['h_hud_days']) + stat_dict = self.db_connection.get_stats_from_hand(new_hand_id, type, self.hud_dict[temp_key].hud_params, self.hero_ids[site_id]) self.hud_dict[temp_key].stat_dict = stat_dict except KeyError: # HUD instance has been killed off, key is stale sys.stderr.write('hud_dict[%s] was not found\n' % temp_key) From 87a8d57669343ebcfd78bd722d3973793566281a Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Wed, 2 Dec 2009 18:39:58 +0200 Subject: [PATCH 04/32] Revert "Do not minimize window when workspace changes" This reverts commit 3e76033cd5ba2e18c4e155a201062b3a774ddd51. --- pyfpdb/fpdb.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/fpdb.py b/pyfpdb/fpdb.py index 77f13ca7..80d3fb93 100755 --- a/pyfpdb/fpdb.py +++ b/pyfpdb/fpdb.py @@ -669,8 +669,8 @@ This program is licensed under the AGPL3, see docs"""+os.sep+"agpl-3.0.txt") sys.stderr.write("fpdb starting ...") def window_state_event_cb(self, window, event): - print "window_state_event: %s, mask=%s" % (event, event.changed_mask) - if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED & gtk.gdk.WINDOW_STATE_WITHDRAWN: + print "window_state_event", event + if event.changed_mask & gtk.gdk.WINDOW_STATE_ICONIFIED: # -20 = GWL_EXSTYLE can't find it in the pywin32 libs #bits = win32api.GetWindowLong(self.window.window.handle, -20) #bits = bits ^ (win32con.WS_EX_TOOLWINDOW | win32con.WS_EX_APPWINDOW) From e62ae6c31ff2d35277f7c89ac90d9e1e8db8110b Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sun, 6 Dec 2009 14:08:27 +0200 Subject: [PATCH 05/32] Enclose dict key lookup in try-except block Some recent changes moved the dictionary access outside try-except block again. Widen the block enough again. --- pyfpdb/HUD_main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pyfpdb/HUD_main.py b/pyfpdb/HUD_main.py index 7e2d5fa6..108b89c7 100755 --- a/pyfpdb/HUD_main.py +++ b/pyfpdb/HUD_main.py @@ -159,10 +159,10 @@ class HUD_main(object): # function idle_func() to be run by the gui thread, at its leisure. def idle_func(): gtk.gdk.threads_enter() - self.hud_dict[table_name].update(new_hand_id, config) + try: + self.hud_dict[table_name].update(new_hand_id, config) # The HUD could get destroyed in the above call ^^, which leaves us with a KeyError here vv # if we ever get an error we need to expect ^^ then we need to handle it vv - Eric - try: [aw.update_gui(new_hand_id) for aw in self.hud_dict[table_name].aux_windows] except KeyError: pass From 3b1e67e78bcb0051fef3ade940466dfd403d8214 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 24 Dec 2009 09:52:47 +0200 Subject: [PATCH 06/32] Store names as UTF-8 The names should be always in UTF-8 encoding. At least for PostgreSQL the encdoding of the database comes from the time of running 'initdb' (which is different from 'createdb') and if the encoding was selected or set to something else at that time, the following error will occur: File ".../pyfpdb/Database.py", line 1630, in self.pcache = LambdaDict(lambda key:self.insertPlayer(key, siteid)) File ".../pyfpdb/Database.py", line 1661, in insertPlayer c.execute (q, (site_id, _name)) File "/usr/lib/python2.5/encodings/iso8859_15.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_table) UnicodeEncodeError: 'charmap' codec can't encode character u'\u2122' in position 10: character maps to This happens because 'name' is a regular string as opposed to a valid unicode object. By forcing the string to unicode and encoding it in UTF-8 the error goes away. In my case the database encoding was ISO-8859-15 (latin9) but any other "wrong" encoding would trigger the same problem. This is a relatively common problem in python. --- pyfpdb/Database.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index fcb0c066..fb70dbab 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -38,6 +38,7 @@ from decimal import Decimal import string import re import Queue +import codecs # pyGTK modules @@ -50,6 +51,7 @@ import Tourney from Exceptions import * log = Configuration.get_logger("logging.conf") +encoder = codecs.lookup('utf-8') class Database: @@ -1641,6 +1643,7 @@ class Database: def insertPlayer(self, name, site_id): result = None + (_name, _len) = encoder.encode(unicode(name)) c = self.get_cursor() q = "SELECT name, id FROM Players WHERE siteid=%s and name=%s" q = q.replace('%s', self.sql.query['placeholder']) @@ -1654,12 +1657,12 @@ class Database: #print "DEBUG: name: %s site: %s" %(name, site_id) - c.execute (q, (site_id, name)) + c.execute (q, (site_id, _name)) tmp = c.fetchone() if (tmp == None): #new player c.execute ("INSERT INTO Players (name, siteId) VALUES (%s, %s)".replace('%s',self.sql.query['placeholder']) - ,(name, site_id)) + ,(_name, site_id)) #Get last id might be faster here. #c.execute ("SELECT id FROM Players WHERE name=%s", (name,)) result = self.get_last_insert_id(c) From 012b5bc72c5ec08043237f619e10814d07c04f3c Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 12 Jan 2010 22:10:59 +0000 Subject: [PATCH 07/32] fix twostartcards to handle 22 and unknowns properly --- pyfpdb/Card.py | 35 ++++++++++++++++++++++++----------- pyfpdb/GuiPlayerStats.py | 4 ++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 287a0f6a..3eef58c5 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -20,23 +20,36 @@ def twoStartCards(value1, suit1, value2, suit2): """ Function to convert 2 value,suit pairs into a Holdem style starting hand e.g. AQo - Hand is stored as an int 13 * x + y where (x+2) represents rank of 1st card and + Incoming values should be ints 2-14 (2,3,...K,A), suits are 'd'/'h'/'c'/'s' + Hand is stored as an int 13 * x + y + 1 where (x+2) represents rank of 1st card and (y+2) represents rank of second card (2=2 .. 14=Ace) - If x > y then pair is suited, if x < y then unsuited""" - if value1 < 2 or value2 < 2: + If x > y then pair is suited, if x < y then unsuited + Examples: + 0 Unknown / Illegal cards + 1 22 + 2 32o + 3 42o + ... + 14 32s + 15 33 + 16 42o + ... + 170 AA + """ + if value1 is None or value1 < 2 or value1 > 14 or value2 is None or value2 < 2 or value2 > 14: ret = 0 - if value1 == value2: # pairs - ret = (13 * (value2-2) + (value2-2) ) + elif value1 == value2: # pairs + ret = (13 * (value2-2) + (value2-2) ) + 1 elif suit1 == suit2: if value1 > value2: - ret = 13 * (value1-2) + (value2-2) + ret = 13 * (value1-2) + (value2-2) + 1 else: - ret = 13 * (value2-2) + (value1-2) + ret = 13 * (value2-2) + (value1-2) + 1 else: if value1 > value2: - ret = 13 * (value2-2) + (value1-2) + ret = 13 * (value2-2) + (value1-2) + 1 else: - ret = 13 * (value1-2) + (value2-2) + ret = 13 * (value1-2) + (value2-2) + 1 # print "twoStartCards(", value1, suit1, value2, suit2, ")=", ret return ret @@ -47,8 +60,8 @@ def twoStartCardString(card): ret = 'xx' if card > 0: s = ('2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A') - x = card / 13 - y = card - 13 * x + x = (card-1) / 13 + y = (card-1) - 13 * x if x == y: ret = s[x] + s[y] elif x > y: ret = s[x] + s[y] + 's' else: ret = s[y] + s[x] + 'o' diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index d65b9ab6..889988c5 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -516,8 +516,8 @@ class GuiPlayerStats (threading.Thread): if holecards: # re-use level variables for hole card query query = query.replace("", "hp.startcards") query = query.replace("" - , ",case when floor(hp.startcards/13) >= mod(hp.startcards,13) then hp.startcards + 0.1 " - + " else 13*mod(hp.startcards,13) + floor(hp.startcards/13) " + , ",case when floor((hp.startcards-1)/13) >= mod((hp.startcards-1),13) then hp.startcards + 0.1 " + + " else 13*mod((hp.startcards-1),13) + floor((hp.startcards-1)/13) + 1 " + " end desc ") else: query = query.replace("", "") From cb172e15ae088a531f88d7a1701ae29c33ac2599 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Tue, 19 Jan 2010 19:25:36 +0200 Subject: [PATCH 08/32] Fix name display in HUD popup The names are stored in UTF-8, so simply converting the name from UTF-8 to Configuration.LOCALE_ENCODING before putting the string in tooltip is enough. Neat. --- pyfpdb/Stats.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 86caaea5..18913eed 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -62,9 +62,13 @@ import Database re_Places = re.compile("_[0-9]$") re_Percent = re.compile("%$") +# String manipulation +import codecs +encoder = codecs.lookup(Configuration.LOCALE_ENCODING) def do_tip(widget, tip): - widget.set_tooltip_text(tip) + (_tip, _len) = encoder.encode(tip) + widget.set_tooltip_text(_tip) def do_stat(stat_dict, player = 24, stat = 'vpip'): match = re_Places.search(stat) From 7ec58ad5c2789c69bcc97d113b7fb51378a0499c Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Tue, 19 Jan 2010 19:25:36 +0200 Subject: [PATCH 09/32] Fix name display in HUD popup The names are stored in UTF-8, so simply converting the name from UTF-8 to Configuration.LOCALE_ENCODING before putting the string in tooltip is enough. Neat. --- pyfpdb/Stats.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 86caaea5..18913eed 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -62,9 +62,13 @@ import Database re_Places = re.compile("_[0-9]$") re_Percent = re.compile("%$") +# String manipulation +import codecs +encoder = codecs.lookup(Configuration.LOCALE_ENCODING) def do_tip(widget, tip): - widget.set_tooltip_text(tip) + (_tip, _len) = encoder.encode(tip) + widget.set_tooltip_text(_tip) def do_stat(stat_dict, player = 24, stat = 'vpip'): match = re_Places.search(stat) From 41877097c999079b4c58221df13d301cfcee04a5 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 12 Jan 2010 22:10:59 +0000 Subject: [PATCH 10/32] fix twostartcards to handle 22 and unknowns properly --- pyfpdb/Card.py | 35 ++++++++++++++++++++++++----------- pyfpdb/GuiPlayerStats.py | 4 ++-- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 8639fd35..22eab979 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -39,23 +39,36 @@ def calcStartCards(hand, player): def twoStartCards(value1, suit1, value2, suit2): """ Function to convert 2 value,suit pairs into a Holdem style starting hand e.g. AQo - Hand is stored as an int 13 * x + y where (x+2) represents rank of 1st card and + Incoming values should be ints 2-14 (2,3,...K,A), suits are 'd'/'h'/'c'/'s' + Hand is stored as an int 13 * x + y + 1 where (x+2) represents rank of 1st card and (y+2) represents rank of second card (2=2 .. 14=Ace) - If x > y then pair is suited, if x < y then unsuited""" - if value1 < 2 or value2 < 2: + If x > y then pair is suited, if x < y then unsuited + Examples: + 0 Unknown / Illegal cards + 1 22 + 2 32o + 3 42o + ... + 14 32s + 15 33 + 16 42o + ... + 170 AA + """ + if value1 is None or value1 < 2 or value1 > 14 or value2 is None or value2 < 2 or value2 > 14: ret = 0 - if value1 == value2: # pairs - ret = (13 * (value2-2) + (value2-2) ) + elif value1 == value2: # pairs + ret = (13 * (value2-2) + (value2-2) ) + 1 elif suit1 == suit2: if value1 > value2: - ret = 13 * (value1-2) + (value2-2) + ret = 13 * (value1-2) + (value2-2) + 1 else: - ret = 13 * (value2-2) + (value1-2) + ret = 13 * (value2-2) + (value1-2) + 1 else: if value1 > value2: - ret = 13 * (value2-2) + (value1-2) + ret = 13 * (value2-2) + (value1-2) + 1 else: - ret = 13 * (value1-2) + (value2-2) + ret = 13 * (value1-2) + (value2-2) + 1 # print "twoStartCards(", value1, suit1, value2, suit2, ")=", ret return ret @@ -66,8 +79,8 @@ def twoStartCardString(card): ret = 'xx' if card > 0: s = ('2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A') - x = card / 13 - y = card - 13 * x + x = (card-1) / 13 + y = (card-1) - 13 * x if x == y: ret = s[x] + s[y] elif x > y: ret = s[x] + s[y] + 's' else: ret = s[y] + s[x] + 'o' diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index d65b9ab6..889988c5 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -516,8 +516,8 @@ class GuiPlayerStats (threading.Thread): if holecards: # re-use level variables for hole card query query = query.replace("", "hp.startcards") query = query.replace("" - , ",case when floor(hp.startcards/13) >= mod(hp.startcards,13) then hp.startcards + 0.1 " - + " else 13*mod(hp.startcards,13) + floor(hp.startcards/13) " + , ",case when floor((hp.startcards-1)/13) >= mod((hp.startcards-1),13) then hp.startcards + 0.1 " + + " else 13*mod((hp.startcards-1),13) + floor((hp.startcards-1)/13) + 1 " + " end desc ") else: query = query.replace("", "") From cd7177897562379fe799ac7238fb0e690bf4ccc4 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Tue, 19 Jan 2010 19:25:36 +0200 Subject: [PATCH 11/32] Fix name display in HUD popup The names are stored in UTF-8, so simply converting the name from UTF-8 to Configuration.LOCALE_ENCODING before putting the string in tooltip is enough. Neat. --- pyfpdb/Stats.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Stats.py b/pyfpdb/Stats.py index 86caaea5..18913eed 100755 --- a/pyfpdb/Stats.py +++ b/pyfpdb/Stats.py @@ -62,9 +62,13 @@ import Database re_Places = re.compile("_[0-9]$") re_Percent = re.compile("%$") +# String manipulation +import codecs +encoder = codecs.lookup(Configuration.LOCALE_ENCODING) def do_tip(widget, tip): - widget.set_tooltip_text(tip) + (_tip, _len) = encoder.encode(tip) + widget.set_tooltip_text(_tip) def do_stat(stat_dict, player = 24, stat = 'vpip'): match = re_Places.search(stat) From ef4f5289bb8ea8b8ce7fa301d2146d091b31b7e7 Mon Sep 17 00:00:00 2001 From: Gerko de Roo Date: Sun, 17 Jan 2010 19:54:40 +0100 Subject: [PATCH 12/32] Solved some merge issues --> Cards.py Issues Pokerstars when playing heads-up on ring games, being both on button and small blind now supported !!if not solved the winnings of the (button, small blind) is stored as rake!! Post both small and big blind when re-entering ring games solved --- pyfpdb/Card.py | 2 +- pyfpdb/PokerStarsToFpdb.py | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/pyfpdb/Card.py b/pyfpdb/Card.py index 22eab979..f33f08ed 100755 --- a/pyfpdb/Card.py +++ b/pyfpdb/Card.py @@ -61,7 +61,7 @@ def twoStartCards(value1, suit1, value2, suit2): ret = (13 * (value2-2) + (value2-2) ) + 1 elif suit1 == suit2: if value1 > value2: - ret = 13 * (value1-2) + (value2-2) + 1 + ret = 13 * (value1-2) + (value2-2) + 1 else: ret = 13 * (value2-2) + (value1-2) + 1 else: diff --git a/pyfpdb/PokerStarsToFpdb.py b/pyfpdb/PokerStarsToFpdb.py index 5e2f9c21..09bd0390 100755 --- a/pyfpdb/PokerStarsToFpdb.py +++ b/pyfpdb/PokerStarsToFpdb.py @@ -81,6 +81,7 @@ class PokerStars(HandHistoryConverter): re_Board = re.compile(r"\[(?P.+)\]") # self.re_setHandInfoRegex('.*#(?P[0-9]+): Table (?P[ a-zA-Z]+) - \$?(?P[.0-9]+)/\$?(?P[.0-9]+) - (?P.*) - (?P
[0-9]+):(?P[0-9]+) ET - (?P[0-9]+)/(?P[0-9]+)/(?P[0-9]+)Table (?P
[ a-zA-Z]+)\nSeat (?P