- Timestamp:
- 03/25/06 22:18:03 (19 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykoticon/trunk/bin/pykoticon
r111 r112 112 112 for (k, v) in varvalues.items() : 113 113 values[k] = v.data 114 wx.CallAfter(self.frame.askDatas, [ v.datafor v in labels ], \114 wx.CallAfter(self.frame.askDatas, [ self.frame.UTF8ToUserCharset(v.data) for v in labels ], \ 115 115 varnames, \ 116 values)116 [ self.frame.UTF8ToUserCharset(v.data) for v in values]) 117 117 # ugly, isn't it ? 118 118 while self.frame.dialogAnswer is None : … … 121 121 for (k, v) in retcode.items() : 122 122 if k != "isValid" : 123 retcode[k] = xmlrpclib.Binary( v)123 retcode[k] = xmlrpclib.Binary(self.frame.userCharsetToUTF8(v)) 124 124 self.frame.dialogAnswer = None # prepare for next call, just in case 125 125 return retcode … … 127 127 def export_showDialog(self, message, yesno) : 128 128 """Opens a notification or confirmation dialog.""" 129 wx.CallAfter(self.frame.showDialog, message.data, yesno)129 wx.CallAfter(self.frame.showDialog, self.frame.UTF8ToUserCharset(message.data), yesno) 130 130 # ugly, isn't it ? 131 131 while self.frame.dialogAnswer is None : … … 333 333 pass 334 334 335 def postInit(self, printserver, localport) :335 def postInit(self, charset, printserver, localport) : 336 336 """Starts the XML-RPC server.""" 337 337 self.quitEvent = threading.Event() 338 self.charset = charset 338 339 self.port = localport 339 340 self.server = MyXMLRPCServer(self, printserver, localport) 340 341 342 def UTF8ToUserCharset(self, text) : 343 """Converts from UTF-8 to user's charset.""" 344 if text is not None : 345 try : 346 return unicode(text, "UTF-8").encode(self.charset) 347 except UnicodeError : 348 try : 349 # Incorrect locale settings ? 350 return unicode(text, "UTF-8").encode("ISO-8859-15") 351 except UnicodeError : 352 pass 353 return text 354 355 def userCharsetToUTF8(self, text) : 356 """Converts from user's charset to UTF-8.""" 357 if text is not None : 358 try : 359 return unicode(text, self.charset).encode("UTF-8") 360 except UnicodeError : 361 try : 362 # Incorrect locale settings ? 363 return unicode(text, "ISO-8859-15").encode("UTF-8") 364 except UnicodeError : 365 pass 366 return text 341 367 342 368 class PyKotIconApp(wx.App): … … 347 373 return True 348 374 349 def postInit(self, printserver, localport) :375 def postInit(self, charset, printserver, localport) : 350 376 """Continues processing.""" 351 self.frame.postInit( printserver, localport)377 self.frame.postInit(charset, printserver, localport) 352 378 353 379 def main(printserver, localport): … … 361 387 except : 362 388 gettext.NullTranslations().install() 389 390 localecharset = None 391 try : 392 try : 393 localecharset = locale.nl_langinfo(locale.CODESET) 394 except AttributeError : 395 try : 396 localecharset = locale.getpreferredencoding() 397 except AttributeError : 398 try : 399 localecharset = locale.getlocale()[1] 400 localecharset = localecharset or locale.getdefaultlocale()[1] 401 except ValueError : 402 pass # Unknown locale, strange... 403 except locale.Error : 404 pass 405 charset = os.environ.get("CHARSET") or localecharset or "ISO-8859-15" 406 363 407 app = PyKotIconApp() 364 408 try : … … 366 410 except (TypeError, ValueError) : 367 411 raise ValueError, "Invalid TCP port parameter %s\n" % localport 368 app.postInit( printserver, localport)412 app.postInit(charset, printserver, localport) 369 413 app.MainLoop() 370 414