Commit 448af2fc47afb96eafc7b8abd30874416da9e949
1 parent
6d99759d
Exists in
master
and in
67 other branches
ENH: Determines the encoding based in the operating system
Showing
3 changed files
with
7 additions
and
6 deletions
Show diff stats
invesalius/reader/dicom.py
... | ... | @@ -21,7 +21,7 @@ import time |
21 | 21 | #import gdcm |
22 | 22 | #import vtkgdcm |
23 | 23 | import sys |
24 | - | |
24 | +import utils | |
25 | 25 | |
26 | 26 | # In DICOM file format, if multiple values are present for the |
27 | 27 | # "Window Center" (Level) and "Window Width", both attributes |
... | ... | @@ -1926,7 +1926,7 @@ class Image(object): |
1926 | 1926 | self.number = parser.GetImageNumber() |
1927 | 1927 | self.spacing = spacing = parser.GetPixelSpacing() |
1928 | 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 | 1930 | self.time = parser.GetImageTime() |
1931 | 1931 | self.type = parser.GetImageType() |
1932 | 1932 | self.size = (parser.GetDimensionX(), parser.GetDimensionY()) | ... | ... |
invesalius/reader/dicom_reader.py
... | ... | @@ -105,7 +105,7 @@ class LoadDicom(threading.Thread): |
105 | 105 | break |
106 | 106 | |
107 | 107 | reader = gdcm.Reader() |
108 | - reader.SetFileName(filepath.encode('utf-8')) | |
108 | + reader.SetFileName(filepath.encode(utils.get_system_encoding())) | |
109 | 109 | |
110 | 110 | if (reader.Read()): |
111 | 111 | file = reader.GetFile() |
... | ... | @@ -211,7 +211,7 @@ class LoadDicom(threading.Thread): |
211 | 211 | write_png.Write() |
212 | 212 | |
213 | 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 | 217 | dict_file[filepath] = data_dict | ... | ... |
invesalius/utils.py
... | ... | @@ -20,6 +20,7 @@ import platform |
20 | 20 | import sigar |
21 | 21 | import sys |
22 | 22 | import re |
23 | +import locale | |
23 | 24 | |
24 | 25 | def debug(error_str): |
25 | 26 | """ |
... | ... | @@ -252,5 +253,5 @@ def get_physical_memory(): |
252 | 253 | return int(mem.total()) |
253 | 254 | |
254 | 255 | |
255 | - | |
256 | - | |
256 | +def get_system_encoding(): | |
257 | + return locale.getdefaultlocale()[1] | ... | ... |