Commit 448af2fc47afb96eafc7b8abd30874416da9e949

Authored by Paulo Henrique Junqueira Amorim
1 parent 6d99759d

ENH: Determines the encoding based in the operating system

invesalius/reader/dicom.py
@@ -21,7 +21,7 @@ import time @@ -21,7 +21,7 @@ import time
21 #import gdcm 21 #import gdcm
22 #import vtkgdcm 22 #import vtkgdcm
23 import sys 23 import sys
24 - 24 +import utils
25 25
26 # In DICOM file format, if multiple values are present for the 26 # In DICOM file format, if multiple values are present for the
27 # "Window Center" (Level) and "Window Width", both attributes 27 # "Window Center" (Level) and "Window Width", both attributes
@@ -1926,7 +1926,7 @@ class Image(object): @@ -1926,7 +1926,7 @@ class Image(object):
1926 self.number = parser.GetImageNumber() 1926 self.number = parser.GetImageNumber()
1927 self.spacing = spacing = parser.GetPixelSpacing() 1927 self.spacing = spacing = parser.GetPixelSpacing()
1928 self.orientation_label = parser.GetImageOrientationLabel() 1928 self.orientation_label = parser.GetImageOrientationLabel()
1929 - self.file = parser.filename.encode('utf-8') #Necessary original is unicode 1929 + self.file = parser.filename.encode(utils.get_system_encoding())
1930 self.time = parser.GetImageTime() 1930 self.time = parser.GetImageTime()
1931 self.type = parser.GetImageType() 1931 self.type = parser.GetImageType()
1932 self.size = (parser.GetDimensionX(), parser.GetDimensionY()) 1932 self.size = (parser.GetDimensionX(), parser.GetDimensionY())
invesalius/reader/dicom_reader.py
@@ -105,7 +105,7 @@ class LoadDicom(threading.Thread): @@ -105,7 +105,7 @@ class LoadDicom(threading.Thread):
105 break 105 break
106 106
107 reader = gdcm.Reader() 107 reader = gdcm.Reader()
108 - reader.SetFileName(filepath.encode('utf-8')) 108 + reader.SetFileName(filepath.encode(utils.get_system_encoding()))
109 109
110 if (reader.Read()): 110 if (reader.Read()):
111 file = reader.GetFile() 111 file = reader.GetFile()
@@ -211,7 +211,7 @@ class LoadDicom(threading.Thread): @@ -211,7 +211,7 @@ class LoadDicom(threading.Thread):
211 write_png.Write() 211 write_png.Write()
212 212
213 # ---------- Refactory -------------------------------------- 213 # ---------- Refactory --------------------------------------
214 - data_dict['invesalius'] = {'orientation_label' : GetImageOrientationLabel(filepath.encode('utf-8'))} 214 + data_dict['invesalius'] = {'orientation_label' : GetImageOrientationLabel(filepath.encode(utils.get_system_encoding()))}
215 215
216 # ------------------------------------------------------------- 216 # -------------------------------------------------------------
217 dict_file[filepath] = data_dict 217 dict_file[filepath] = data_dict
invesalius/utils.py
@@ -20,6 +20,7 @@ import platform @@ -20,6 +20,7 @@ import platform
20 import sigar 20 import sigar
21 import sys 21 import sys
22 import re 22 import re
  23 +import locale
23 24
24 def debug(error_str): 25 def debug(error_str):
25 """ 26 """
@@ -252,5 +253,5 @@ def get_physical_memory(): @@ -252,5 +253,5 @@ def get_physical_memory():
252 return int(mem.total()) 253 return int(mem.total())
253 254
254 255
255 -  
256 - 256 +def get_system_encoding():
  257 + return locale.getdefaultlocale()[1]