From d32502d414591c2b0263683adab312c8686cbda9 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Mon, 5 Nov 2018 11:47:54 -0200 Subject: [PATCH] Arch/Draft: Fixed py3 bugs in text rendering --- src/Mod/Arch/ArchSpace.py | 8 +++++--- src/Mod/Draft/Draft.py | 29 ++++++++++++++++++----------- src/Mod/Draft/DraftTools.py | 4 +++- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/Mod/Arch/ArchSpace.py b/src/Mod/Arch/ArchSpace.py index 6c765be87b..9dbab6a20d 100644 --- a/src/Mod/Arch/ArchSpace.py +++ b/src/Mod/Arch/ArchSpace.py @@ -148,7 +148,7 @@ ConditioningTypes = [ "NaturallyVentedOnly" ] -import FreeCAD,ArchComponent,ArchCommands,math,Draft +import FreeCAD,ArchComponent,ArchCommands,math,Draft,sys if FreeCAD.GuiUp: import FreeCADGui from PySide import QtCore, QtGui @@ -609,10 +609,12 @@ class _ViewProviderSpace(ArchComponent.ViewProviderComponent): t = t.replace("$walls",vobj.Object.FinishWalls) if hasattr(vobj.Object,"FinishCeiling"): t = t.replace("$ceiling",vobj.Object.FinishCeiling) + if sys.version_info.major < 3: + t = t.encode("utf8") if first: - text1.append(t.encode("utf8")) + text1.append(t) else: - text2.append(t.encode("utf8")) + text2.append(t) first = False if text1: self.text1.string.setValues(text1) diff --git a/src/Mod/Draft/Draft.py b/src/Mod/Draft/Draft.py index 3bd190d003..05aa24969a 100644 --- a/src/Mod/Draft/Draft.py +++ b/src/Mod/Draft/Draft.py @@ -7368,8 +7368,12 @@ class ViewProviderDraftText: def updateData(self,obj,prop): if prop == "Text": if obj.Text: - self.text2d.string.setValues([l.encode("utf8") for l in obj.Text if l]) - self.text3d.string.setValues([l.encode("utf8") for l in obj.Text if l]) + if sys.version_info.major >= 3: + self.text2d.string.setValues([l for l in obj.Text if l]) + self.text3d.string.setValues([l for l in obj.Text if l]) + else: + self.text2d.string.setValues([l.encode("utf8") for l in obj.Text if l]) + self.text3d.string.setValues([l.encode("utf8") for l in obj.Text if l]) elif prop == "Placement": self.trans.translation.setValue(obj.Placement.Base) self.trans.rotation.setValue(obj.Placement.Rotation.Q) @@ -7388,15 +7392,18 @@ class ViewProviderDraftText: elif prop == "Justification": if "Justification" in vobj.PropertiesList: from pivy import coin - if vobj.Justification == "Left": - self.text2d.justification = coin.SoText2.LEFT - self.text3d.justification = coin.SoAsciiText.LEFT - elif vobj.Justification == "Right": - self.text2d.justification = coin.SoText2.RIGHT - self.text3d.justification = coin.SoAsciiText.RIGHT - else: - self.text2d.justification = coin.SoText2.CENTER - self.text3d.justification = coin.SoAsciiText.CENTER + try: + if vobj.Justification == "Left": + self.text2d.justification = coin.SoText2.LEFT + self.text3d.justification = coin.SoAsciiText.LEFT + elif vobj.Justification == "Right": + self.text2d.justification = coin.SoText2.RIGHT + self.text3d.justification = coin.SoAsciiText.RIGHT + else: + self.text2d.justification = coin.SoText2.CENTER + self.text3d.justification = coin.SoAsciiText.CENTER + except AssertionError: + pass # Race condition - Justification enum has not been set yet elif prop == "LineSpacing": if "LineSpacing" in vobj.PropertiesList: self.text2d.spacing = vobj.LineSpacing diff --git a/src/Mod/Draft/DraftTools.py b/src/Mod/Draft/DraftTools.py index 05d37faf91..edbb526d40 100644 --- a/src/Mod/Draft/DraftTools.py +++ b/src/Mod/Draft/DraftTools.py @@ -1822,7 +1822,9 @@ class Text(Creator): tx += ',' if sys.version_info.major < 3: l = unicode(l) - tx += '"'+str(l.encode("utf8"))+'"' #Python3 no more unicode + tx += '"'+str(l.encode("utf8"))+'"' + else: + tx += '"'+l+'"' #Python3 no more unicode tx += ']' FreeCADGui.addModule("Draft") self.commit(translate("draft","Create Text"),