From 070a1537578077ba1fcab5b0bcd2c6af2a8f96bb Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 26 Feb 2019 19:26:00 +0100 Subject: [PATCH] fixes 0003865: non-ASCII characters incorrectly displayed in material cards The combination Py2+Qt5 already worked, this change now fixes the combinations Py2+Qt4 and Py3+Qt5 --- src/Mod/Material/importFCMat.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Mod/Material/importFCMat.py b/src/Mod/Material/importFCMat.py index c41c93ad50..d4cb62354b 100644 --- a/src/Mod/Material/importFCMat.py +++ b/src/Mod/Material/importFCMat.py @@ -103,17 +103,26 @@ def read(filename): filename = filename.encode(sys.getfilesystemencoding()) # print(filename) card_name_file = os.path.splitext(os.path.basename(filename))[0] - f = pythonopen(filename) + if sys.version_info.major >= 3: + f = pythonopen(filename, encoding="utf8") + else: + f = pythonopen(filename) d = {} d["CardName"] = card_name_file # CardName is the MatCard file name ln = 0 for line in f: if ln == 0: - card_name_content = line.split(";")[1].strip() # Line 1 + v = line.split(";")[1].strip() # Line 1 + if hasattr(v, "decode"): + v = v.decode('utf-8') + card_name_content = v if card_name_content != d["CardName"]: FreeCAD.Console.PrintError("File CardName (" + card_name_file + ") is not content CardName (" + card_name_content + ")\n") elif ln == 1: - d["AuthorAndLicense"] = line.split(";")[1].strip() # Line 2 + v = line.split(";")[1].strip() # Line 2 + if hasattr(v, "decode"): + v = v.decode('utf-8') + d["AuthorAndLicense"] = v else: # ; is a Commend # # might be a comment too ?