From: Peter L. <pet...@te...> - 2010-02-23 09:41:10
|
Den Monday 22 February 2010 20.52.03 skrev Josip: > On 22.02.2010 18:05, Peter Landgren wrote: > > Hi > > > > I have a silly string conversion question: > > > > When I, in Windows, drag and drop an image to the Media View or to a > > gallery I get a file reference like: > > "C:\Documents%20and%20Settings\P%C3%A4r\Mina dokument\Mina > > bilder\IMG_1662.JPG" (%20 is only replaced in Gramps mediaview.py now.) > > > > The file reference string is of type 'unicode' and the sequence %C3%A4 > > represents the letter "ä". The directory name is "Pär", which in a Python > > 'str' is represented by 'P\xc3\xa4r' and in a Python unicode is > > represented by u'P\xe4r'. > > > > I can covert the original string to a 'str' so that I only need to > > replace % by \x and then convert back to unicode before using it as a > > path. > > > > So, my silly question how do I get the '%' to '\x'? > > Or is there a another way to handle this situation? > > It looks like URL so: > urllib.url2pathname(UPATH.encode(sys.getfilesystemencoding())) Thanks for the hint Josip. Yes, indeed it's URL like. So from \C:\Documents%20and%20Settings\P%C3%A4r\Mina%20dokument\Mina%20bilder\NissesBild.jpg it is now C:\Documents and Settings\Pär\Mina dokument\Mina bilder\NissesBild.jpg in Windows. I had to do convert the path to unicode to get it to work with non ASCII characters in the path name. I cant' test it in Linux as I can't drag an drop into the Media View there. I can drag and drop into Gallery tabs in the editors though. However I see a similar problem with url escape sequences like %20 in Linux where I can drag and drop. /Peter |