From c042bea1817a99a6639c4ecbd66be20d54e76d28 Mon Sep 17 00:00:00 2001 From: grindi Date: Sun, 9 Aug 2009 16:24:31 +0400 Subject: [PATCH] Improved table-by-name recognition for non-latin window titles What i mean: u'1464739' in 'Speed #1464739 - \xc1\xcb \xd5\xee\xeb\xe4\xe5\xec' -> Exception u'1464739' in 'Speed #1464739 - \xc1\xcb \xd5\xee\xeb\xe4\xe5\xec'.decode('cp1251') -> True --- pyfpdb/Tables.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pyfpdb/Tables.py b/pyfpdb/Tables.py index 97a897ca..9fdc8630 100755 --- a/pyfpdb/Tables.py +++ b/pyfpdb/Tables.py @@ -230,11 +230,20 @@ def discover_nt_by_name(c, tablename): """Finds poker client window with the given table name.""" titles = {} win32gui.EnumWindows(win_enum_handler, titles) + + def getDefaultEncoding(): + # FIXME: if somebody know better place fot this function - move it + # FIXME: it's better to use GetCPInfo for windows http://msdn.microsoft.com/en-us/library/dd318078(VS.85).aspx + # but i have no idea, how to call it + import locale + return locale.getpreferredencoding() + for hwnd in titles: #print "Tables.py: tablename =", tablename, "title =", titles[hwnd] try: + # maybe it's better to make global titles[hwnd] decoding? # this can blow up in XP on some windows, eg firefox displaying http://docs.python.org/tutorial/classes.html - if not tablename.lower() in titles[hwnd].lower(): continue + if not tablename.lower() in titles[hwnd].decode(getDefaultEncoding()).lower(): continue except: continue if 'History for table:' in titles[hwnd]: continue # Everleaf Network HH viewer window