I modified the rows: filepath = chooser.get_filename() chooser.destroy() return filepath
to: filepath = chooser.get_filename() chooser.destroy() return unicode(filepath) if filepath != None else None But now I get error when opening E:\SOFTWARE\Кириллица.ctb : Traceback (most recent call last): File "test.py", line 35, in <module> print filepath File "C:\Python27\lib\encodings\cp850.py", line 12, in encode return codecs.charmap_encode(input,errors,encoding_map) UnicodeEncodeError: 'charmap' codec can't encode characters in position 12-20: character maps to <undefined> Premere un tasto per continuare . . . I really don't know what to do :( On Thu, Jan 24, 2013 at 12:38 PM, Timo <timomli...@gmail.com> wrote: > Op 23-01-13 18:52, Giuseppe Penone schreef: > >> Hi, >> >> while I have a file named *E:\SOFTWARE\Кириллица.ctb* on my pc, selecting >> it with a gtk.FileChooserDialog >> and printing to terminal returns weird characters >> *E:\SOFTWARE\ÐsиÑ?иллиÑ┼**а.ctb*. >> > Ah the joy of encodings on Windows. This is the piece of code I use > (trimmed): > > class _FileChooser(gtk.FileChooser): > def get_filename(self): > filename = gtk.FileChooser.get_filename(**self) > if filename is not None: > return unicode(filename) > > def get_current_folder(self): > return unicode(gtk.FileChooser.get_**current_folder(self)) > > > And then subclass the above when creating a FileChooserDialog or > FileChooserButton, like so: > > class MyFileChooserDialog(gtk.**FileChooserDialog, _FileChooser): > def __init__(self): > super(MyFileChooserDialog, self).__init__() > > class MyFileChooserButton(gtk.**FileChooserButton, _FileChooser): > def __init__(self): > super(MyFileChooserButton, self).__init__("") > > > You can do fun things this way, but the most important thing is the > unicode conversion ofcourse. > > Timo > > >> Does anybody have a clue of the reason? >> PS I have all my files starting with *# -*- coding: UTF-8 -*-* >> >> >> Regards, >> Giuseppe. >> >> >> ______________________________**_________________ >> pygtk mailing list pygtk@daa.com.au >> http://www.daa.com.au/mailman/**listinfo/pygtk<http://www.daa.com.au/mailman/listinfo/pygtk> >> Read the PyGTK FAQ: http://faq.pygtk.org/ >> > > ______________________________**_________________ > pygtk mailing list pygtk@daa.com.au > http://www.daa.com.au/mailman/**listinfo/pygtk<http://www.daa.com.au/mailman/listinfo/pygtk> > Read the PyGTK FAQ: http://faq.pygtk.org/ >
_______________________________________________ pygtk mailing list pygtk@daa.com.au http://www.daa.com.au/mailman/listinfo/pygtk Read the PyGTK FAQ: http://faq.pygtk.org/