From 3e76033cd5ba2e18c4e155a201062b3a774ddd51 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Sun, 29 Nov 2009 11:21:11 +0200 Subject: [PATCH 01/18] 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/18] 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/18] 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/18] 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/18] 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/18] 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 659443127711355cd47dc5a133bb456ddaae8a03 Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 12 Jan 2010 22:10:59 +0000 Subject: [PATCH 07/18] 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 012b5bc72c5ec08043237f619e10814d07c04f3c Mon Sep 17 00:00:00 2001 From: sqlcoder Date: Tue, 12 Jan 2010 22:10:59 +0000 Subject: [PATCH 08/18] 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 09/18] 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 10/18] 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 34bf2bd8e9e41a7dd4cb04ed73c67c12aa0a40ba Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 18:12:45 +0200 Subject: [PATCH 11/18] Use better function name --- pyfpdb/Charset.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 pyfpdb/Charset.py diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py new file mode 100644 index 00000000..2c6f78c3 --- /dev/null +++ b/pyfpdb/Charset.py @@ -0,0 +1,34 @@ +#!/usr/bin/python + +#Copyright 2010 Mika Bostrom +#This program is free software: you can redistribute it and/or modify +#it under the terms of the GNU Affero General Public License as published by +#the Free Software Foundation, version 3 of the License. +# +#This program is distributed in the hope that it will be useful, +#but WITHOUT ANY WARRANTY; without even the implied warranty of +#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +#GNU General Public License for more details. +# +#You should have received a copy of the GNU Affero General Public License +#along with this program. If not, see . +#In the "official" distribution you can find the license in +#agpl-3.0.txt in the docs folder of the package. + +# String manipulation +import codecs + +# Settings +import Configuration + +encoder_to_utf = codecs.lookup('utf-8') +encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) + +def to_utf8(s): + (_out, _len) = encoder_to_utf.encode(s) + return _out + +def to_gui(s): + (_out, _len) = encoder_to_sys.encode(s) + return _out + From e915b0b62cb5abb920580f2cd379c9ca6b29d27d Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 21:23:13 +0200 Subject: [PATCH 12/18] Allow to bypass codec If the system (display) locale is UTF-8, there is no need to encode to either direction. In fact, running the .encode() routine appears to mangle a valid UTF-8 string to a worse condition, effectively breaking it. --- pyfpdb/Charset.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index 2c6f78c3..85cbd69a 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -24,11 +24,18 @@ import Configuration encoder_to_utf = codecs.lookup('utf-8') encoder_to_sys = codecs.lookup(Configuration.LOCALE_ENCODING) +# I'm saving a few cycles with this one +not_needed = False +if Configuration.LOCALE_ENCODING == 'utf-8': + not_needed = True + def to_utf8(s): + if not_needed: return s (_out, _len) = encoder_to_utf.encode(s) return _out def to_gui(s): + if not_needed: return s (_out, _len) = encoder_to_sys.encode(s) return _out From a8416034600525aa3179c15c9835aaac08f5cb47 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 21:24:55 +0200 Subject: [PATCH 13/18] Some character set improvements The strings (names) as stored in database should always be UTF-8; whatever the display locale is, we then need to convert from the storage encoding to session encoding. When making database queries with players names in them, the names must be reconverted to UTF-8. --- pyfpdb/Database.py | 7 +++++-- pyfpdb/Filters.py | 15 +++++++++++---- pyfpdb/GuiGraphViewer.py | 3 ++- pyfpdb/GuiPlayerStats.py | 3 ++- pyfpdb/GuiSessionViewer.py | 6 +++++- pyfpdb/GuiTableViewer.py | 3 ++- 6 files changed, 27 insertions(+), 10 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index 72b41336..bf071782 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -48,6 +48,7 @@ import Configuration import SQL import Card import Tourney +import Charset from Exceptions import * log = Configuration.get_logger("logging.conf") @@ -602,7 +603,8 @@ class Database: def get_player_id(self, config, site, player_name): c = self.connection.cursor() - c.execute(self.sql.query['get_player_id'], (player_name, site)) + p_name = Charset.to_utf8(player_name) + c.execute(self.sql.query['get_player_id'], (p_name, site)) row = c.fetchone() if row: return row[0] @@ -615,7 +617,8 @@ class Database: if site_id is None: site_id = -1 c = self.get_cursor() - c.execute(self.sql.query['get_player_names'], (like_player_name, site_id, site_id)) + p_name = Charset.to_utf8(like_player_name) + c.execute(self.sql.query['get_player_names'], (p_name, site_id, site_id)) rows = c.fetchall() return rows diff --git a/pyfpdb/Filters.py b/pyfpdb/Filters.py index dc2e4859..3a25c1f1 100644 --- a/pyfpdb/Filters.py +++ b/pyfpdb/Filters.py @@ -29,6 +29,7 @@ import gobject import Configuration import fpdb_db import FpdbSQLQueries +import Charset class Filters(threading.Thread): def __init__(self, db, config, qdict, display = {}, debug=True): @@ -238,6 +239,7 @@ class Filters(threading.Thread): print "DEBUG: %s was toggled %s" % (data, ("OFF", "ON")[widget.get_active()]) def createPlayerLine(self, hbox, site, player): + print 'DEBUG :: add:"%s"' % player label = gtk.Label(site +" id:") hbox.pack_start(label, False, False, 0) @@ -254,13 +256,17 @@ class Filters(threading.Thread): completion.set_model(liststore) completion.set_text_column(0) names = self.db.get_player_names(self.conf) # (config=self.conf, site_id=None, like_player_name="%") - for n in names: - liststore.append(n) + for n in names: # list of single-element "tuples" + _n = Charset.to_gui(n[0]) + _nt = (_n, ) + liststore.append(_nt) self.__set_hero_name(pname, site) def __set_hero_name(self, w, site): - self.heroes[site] = w.get_text() + _name = w.get_text() + _guiname = Charset.to_gui(_name) + self.heroes[site] = _guiname # print "DEBUG: setting heroes[%s]: %s"%(site, self.heroes[site]) def __set_num_hands(self, w, val): @@ -417,7 +423,8 @@ class Filters(threading.Thread): vbox.pack_start(hBox, False, True, 0) player = self.conf.supported_sites[site].screen_name - self.createPlayerLine(hBox, site, player) + _pname = Charset.to_gui(player) + self.createPlayerLine(hBox, site, _pname) if "GroupsAll" in display and display["GroupsAll"] == True: hbox = gtk.HBox(False, 0) diff --git a/pyfpdb/GuiGraphViewer.py b/pyfpdb/GuiGraphViewer.py index 9daa940f..4534920a 100644 --- a/pyfpdb/GuiGraphViewer.py +++ b/pyfpdb/GuiGraphViewer.py @@ -145,7 +145,8 @@ class GuiGraphViewer (threading.Thread): if sites[site] == True: sitenos.append(siteids[site]) c = self.db.get_cursor() - c.execute(self.sql.query['getPlayerId'], (heroes[site],)) + _hname = Charset.to_utf8(heroes[site]) + c.execute(self.sql.query['getPlayerId'], (_hname,)) result = c.fetchall() if len(result) == 1: playerids.append( int(result[0][0]) ) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 889988c5..140ed30b 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -189,7 +189,8 @@ class GuiPlayerStats (threading.Thread): sitenos.append(siteids[site]) # Nasty hack to deal with multiple sites + same player name -Eric que = self.sql.query['getPlayerId'] + " AND siteId=%d" % siteids[site] - self.cursor.execute(que, (heroes[site],)) + _hname = Charset.to_utf8(heroes[site]) + self.cursor.execute(que, (_hname,)) result = self.db.cursor.fetchall() if len(result) == 1: playerids.append(result[0][0]) diff --git a/pyfpdb/GuiSessionViewer.py b/pyfpdb/GuiSessionViewer.py index d8cd7042..b5ca0867 100755 --- a/pyfpdb/GuiSessionViewer.py +++ b/pyfpdb/GuiSessionViewer.py @@ -47,6 +47,7 @@ import fpdb_import import Database import Filters import FpdbSQLQueries +import Charset class GuiSessionViewer (threading.Thread): def __init__(self, config, querylist, mainwin, debug=True): @@ -181,7 +182,10 @@ class GuiSessionViewer (threading.Thread): for site in sites: if sites[site] == True: sitenos.append(siteids[site]) - self.cursor.execute(self.sql.query['getPlayerId'], (heroes[site],)) + _q = self.sql.query['getPlayerId'] + _name = Charset.to_utf8(heroes[site]) + print 'DEBUG(_name) :: %s' % _name + self.cursor.execute(_q, (_name,)) # arg = tuple result = self.db.cursor.fetchall() if len(result) == 1: playerids.append(result[0][0]) diff --git a/pyfpdb/GuiTableViewer.py b/pyfpdb/GuiTableViewer.py index c730f962..c5b843f1 100644 --- a/pyfpdb/GuiTableViewer.py +++ b/pyfpdb/GuiTableViewer.py @@ -80,7 +80,8 @@ class GuiTableViewer (threading.Thread): #then the data rows for player in range(len(self.player_names)): tmp=[] - tmp.append(self.player_names[player][0]) + p_name = Charset.to_gui(self.player_names[player][0]) + tmp.append(p_name) seatCount=len(self.player_names) if seatCount>=8: From dda00b6b10ff4dcc32b22b24853e9e973f5e38cc Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 21:31:19 +0200 Subject: [PATCH 14/18] Catch character encoding errors --- pyfpdb/Charset.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index 85cbd69a..69511cdd 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -31,11 +31,21 @@ if Configuration.LOCALE_ENCODING == 'utf-8': def to_utf8(s): if not_needed: return s - (_out, _len) = encoder_to_utf.encode(s) - return _out + + try: + (_out, _len) = encoder_to_utf.encode(s) + return _out + except UnicodeDecodeError: + print 'Could not convert: "%s"' % s + raise def to_gui(s): if not_needed: return s - (_out, _len) = encoder_to_sys.encode(s) - return _out + + try: + (_out, _len) = encoder_to_sys.encode(s) + return _out + except UnicodeDecodeError: + print 'Could not convert: "%s"' % s + raise From 04c345ae1f213c26ae50d56bdda11f372fa191be Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 21:46:14 +0200 Subject: [PATCH 15/18] Use a different "unicoder" for db strings It seems that running encoder.encode() on a latin1/latin9 string results in, yes a bloody UnicodeDecodeError. Decode error on .encode()... Really. This way the modification from non-unicode string to real unicode appears to work better. --- pyfpdb/Charset.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Charset.py b/pyfpdb/Charset.py index 69511cdd..f8043876 100644 --- a/pyfpdb/Charset.py +++ b/pyfpdb/Charset.py @@ -33,7 +33,8 @@ def to_utf8(s): if not_needed: return s try: - (_out, _len) = encoder_to_utf.encode(s) + #(_out, _len) = encoder_to_utf.encode(s) + _out = unicode(s, Configuration.LOCALE_ENCODING).encode('utf-8') return _out except UnicodeDecodeError: print 'Could not convert: "%s"' % s From 29d5204bee45b8f1a5ee9093943d6c29d2af5395 Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 21:52:22 +0200 Subject: [PATCH 16/18] Add missing import GuiPlayerStats.py didn't import the new Charset module but tried to use the functions. --- pyfpdb/GuiPlayerStats.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyfpdb/GuiPlayerStats.py b/pyfpdb/GuiPlayerStats.py index 140ed30b..a528e784 100644 --- a/pyfpdb/GuiPlayerStats.py +++ b/pyfpdb/GuiPlayerStats.py @@ -29,6 +29,7 @@ import fpdb_import import Database import fpdb_db import Filters +import Charset colalias,colshow,colheading,colxalign,colformat,coltype = 0,1,2,3,4,5 ranks = {'x':0, '2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14} From 91cd2d25998516249259b67d75a3e8c8416fa5fd Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Thu, 21 Jan 2010 22:05:24 +0200 Subject: [PATCH 17/18] Remove erroneous encoding This string should not be encoded, it seems. --- pyfpdb/Database.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pyfpdb/Database.py b/pyfpdb/Database.py index d5eadf7a..3bcb99a3 100644 --- a/pyfpdb/Database.py +++ b/pyfpdb/Database.py @@ -605,8 +605,7 @@ class Database: def get_player_id(self, config, site, player_name): c = self.connection.cursor() - p_name = Charset.to_utf8(player_name) - c.execute(self.sql.query['get_player_id'], (p_name, site)) + c.execute(self.sql.query['get_player_id'], (player_name, site)) row = c.fetchone() if row: return row[0] From 8b012a3af324c0df98442e8dc76c15143d9bbead Mon Sep 17 00:00:00 2001 From: Mika Bostrom Date: Fri, 22 Jan 2010 09:27:09 +0200 Subject: [PATCH 18/18] Update debian/changelog for snapshot --- packaging/debian/changelog | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/debian/changelog b/packaging/debian/changelog index ec66f4a7..4bacf635 100644 --- a/packaging/debian/changelog +++ b/packaging/debian/changelog @@ -1,8 +1,8 @@ -free-poker-tools (0.12-1) unstable; urgency=low +free-poker-tools (0.12~git20100122) unstable; urgency=low - * New release + * New snapshot release with reworked import code - -- Mika Bostrom Mon, 26 Oct 2009 17:49:07 +0200 + -- Mika Bostrom Fri, 22 Jan 2010 09:25:27 +0200 free-poker-tools (0.11.3+git20091023) unstable; urgency=low