pyqt  

Re: [PyQt] Accented characters

alteo_gange
Fri, 02 May 2008 04:31:43 -0700

Le vendredi 02 mai 2008, Christoph Burgmer a écrit :
> If I'm not wrong this "trick" will only work for people who use utf8 as
> default encoding.
>
> You may want to read about Python's way of dealing with encodings and
> Unicode, but that's off topic here.
>
> Little hint:
>
> _, system_encoding = locale.getdefaultlocale()
>
> print unicode(your_string).encode(system_encoding)
>

Thank you Christoph. That settles me an another crack:

I was problems with both "print" and "unicode":

The next script works when it starts with or without terminal (that is file 
navigator):

-------------------------------------------
#!/usr/bin/python
# -*- coding: Utf-8 -*-

import sys, locale
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Widget(QWidget):
        def __init__(self,parent=None):
                QWidget.__init__(self)
                
                # File selection (the file's name is accented: ex. animé.txt)
                file = QFileDialog.getOpenFileName(self, 
"Open",QDir.homePath(),"All files 
(*.*)")
                system_encoding = locale.getdefaultlocale()
                print unicode(file).encode(system_encoding[1]) #####
                QMessageBox.information(self, "title", "Print Success!")
                
if __name__ == "__main__":
        app = QApplication(sys.argv)
        main = Widget()
        #main.show()
        sys.exit(app.exec_())
-------------------------------------------

The next script works only when it starts with terminal:

-------------------------------------------
#!/usr/bin/python
# -*- coding: Utf-8 -*-

import sys, locale
from PyQt4.QtCore import *
from PyQt4.QtGui import *

class Widget(QWidget):
        def __init__(self,parent=None):
                QWidget.__init__(self)
                
                # File selection (the file's name is accented: ex. animé.txt)
                file = QFileDialog.getOpenFileName(self, 
"Open",QDir.homePath(),"All files 
(*.*)")
                print unicode(file) #####
                QMessageBox.information(self, "title", "Print Success!")
                
if __name__ == "__main__":
        app = QApplication(sys.argv)
        main = Widget()
        #main.show()
        sys.exit(app.exec_())
-------------------------------------------

Both "print" and "unicode" are very dangerous.

-- 
alteo_gange


_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt