Unicode fixes for Python3
This commit is contained in:
@@ -21,7 +21,9 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import FreeCAD,Draft,math,DraftVecUtils,ArchCommands,sys
|
||||
import six
|
||||
|
||||
import FreeCAD,Draft,math,DraftVecUtils,ArchCommands
|
||||
from FreeCAD import Vector
|
||||
if FreeCAD.GuiUp:
|
||||
import FreeCADGui
|
||||
@@ -544,7 +546,7 @@ class _ViewProviderAxis:
|
||||
tx = coin.SoAsciiText()
|
||||
tx.justification = coin.SoText2.LEFT
|
||||
t = vobj.Object.Labels[i]
|
||||
if sys.version_info.major < 3 and isinstance(t,unicode):
|
||||
if six.PY2 and isinstance(t,six.text_type):
|
||||
t = t.encode("utf8")
|
||||
tx.string.setValue(t)
|
||||
if hasattr(vobj,"FontSize"):
|
||||
@@ -577,7 +579,7 @@ class _ViewProviderAxis:
|
||||
('C',100),('XC',90),('L',50),('XL',40),
|
||||
('X',10),('IX',9),('V',5),('IV',4),('I',1))
|
||||
if hasattr(vobj.Object,"CustomNumber") and vobj.Object.CustomNumber:
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
return vobj.Object.CustomNumber.encode("utf8")
|
||||
else:
|
||||
return vobj.Object.CustomNumber
|
||||
|
||||
@@ -27,6 +27,8 @@ __title__ = "FreeCAD IFC importer - Enhanced ifcopenshell-only version"
|
||||
__author__ = "Yorik van Havre","Jonathan Wiedemann"
|
||||
__url__ = "http://www.freecadweb.org"
|
||||
|
||||
import six
|
||||
|
||||
import os,time,tempfile,uuid,FreeCAD,Part,Draft,Arch,math,DraftVecUtils,sys
|
||||
from DraftGeomUtils import vec
|
||||
|
||||
@@ -121,12 +123,9 @@ def decode(filename,utf=False):
|
||||
|
||||
"turns unicodes into strings"
|
||||
|
||||
if (sys.version_info.major < 3) and isinstance(filename,unicode):
|
||||
if six.PY2 and isinstance(filename,six.text_type):
|
||||
# workaround since ifcopenshell currently can't handle unicode filenames
|
||||
if utf:
|
||||
encoding = "utf8"
|
||||
else:
|
||||
encoding = sys.getfilesystemencoding()
|
||||
encoding = "utf8" if utf else sys.getfilesystemencoding()
|
||||
filename = filename.encode(encoding)
|
||||
return filename
|
||||
|
||||
@@ -321,7 +320,7 @@ def explore(filename=None):
|
||||
t = "Entity #" + str(argvalue.id()) + ": " + str(argvalue.is_a())
|
||||
elif isinstance(argvalue,list):
|
||||
t = ""
|
||||
elif (sys.version_info.major < 3) and (isinstance(argvalue,str) or isinstance(argvalue,unicode)):
|
||||
elif six.PY2 and isinstance(argvalue,six.string_types):
|
||||
t = argvalue.encode("latin1")
|
||||
else:
|
||||
t = str(argvalue)
|
||||
@@ -573,7 +572,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
name = str(ptype[3:])
|
||||
if product.Name:
|
||||
name = product.Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
if PREFIX_NUMBERS: name = "ID" + str(pid) + " " + name
|
||||
obj = None
|
||||
@@ -942,7 +941,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
if l.is_a("IfcPropertySingleValue"):
|
||||
if DEBUG:
|
||||
print("property name",l.Name,type(l.Name))
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
catname = catname.encode("utf8")
|
||||
lname = lname.encode("utf8")
|
||||
ifc_spreadsheet.set(str('A'+str(n)), catname)
|
||||
@@ -954,7 +953,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
#print("l.NominalValue.Unit",l.NominalValue.Unit,type(l.NominalValue.Unit))
|
||||
ifc_spreadsheet.set(str('C'+str(n)), l.NominalValue.is_a())
|
||||
if l.NominalValue.is_a() in ['IfcLabel','IfcText','IfcIdentifier','IfcDescriptiveMeasure']:
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
ifc_spreadsheet.set(str('D'+str(n)), "'" + str(l.NominalValue.wrappedValue.encode("utf8")))
|
||||
else:
|
||||
ifc_spreadsheet.set(str('D'+str(n)), "'" + str(l.NominalValue.wrappedValue))
|
||||
@@ -972,18 +971,18 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
d = obj.IfcProperties
|
||||
for pset in properties[pid].keys():
|
||||
psetname = ifcfile[pset].Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
psetname = psetname.encode("utf8")
|
||||
for prop in properties[pid][pset]:
|
||||
e = ifcfile[prop]
|
||||
pname = e.Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
pname = pname.encode("utf8")
|
||||
if e.is_a("IfcPropertySingleValue"):
|
||||
ptype = e.NominalValue.is_a()
|
||||
if ptype in ['IfcLabel','IfcText','IfcIdentifier','IfcDescriptiveMeasure']:
|
||||
pvalue = e.NominalValue.wrappedValue
|
||||
if sys.version_info.major < 3:
|
||||
if six.py2:
|
||||
pvalue = pvalue.encode("utf8")
|
||||
else:
|
||||
pvalue = str(e.NominalValue.wrappedValue)
|
||||
@@ -1125,7 +1124,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
else:
|
||||
if DEBUG: print("no group name specified for entity: #", ifcfile[host].id(), ", entity type is used!")
|
||||
grp_name = ifcfile[host].is_a() + "_" + str(ifcfile[host].id())
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
grp_name = grp_name.encode("utf8")
|
||||
grp = FreeCAD.ActiveDocument.addObject("App::DocumentObjectGroup",grp_name)
|
||||
grp.Label = grp_name
|
||||
@@ -1266,7 +1265,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
name = "Grid"
|
||||
if annotation.Name:
|
||||
name = annotation.Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
if PREFIX_NUMBERS:
|
||||
name = "ID" + str(aid) + " " + name
|
||||
@@ -1276,7 +1275,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
name = "Annotation"
|
||||
if annotation.Name:
|
||||
name = annotation.Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
if "annotation" not in name.lower():
|
||||
name = "Annotation " + name
|
||||
@@ -1323,7 +1322,7 @@ def insert(filename,docname,skip=[],only=[],root=None):
|
||||
name = "Material"
|
||||
if material.Name:
|
||||
name = material.Name
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
if MERGE_MATERIALS and (name in fcmats.keys()):
|
||||
mat = fcmats[name]
|
||||
@@ -1589,7 +1588,7 @@ def export(exportList,filename):
|
||||
template = template.replace("IfcOpenShell","IfcOpenShell "+ifcopenshell.version)
|
||||
templatefilehandle,templatefile = tempfile.mkstemp(suffix=".ifc")
|
||||
of = pyopen(templatefile,"w")
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
template = template.encode("utf8")
|
||||
of.write(template)
|
||||
of.close()
|
||||
@@ -1656,10 +1655,10 @@ def export(exportList,filename):
|
||||
# getting generic data
|
||||
|
||||
name = obj.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
description = obj.Description if hasattr(obj,"Description") else ""
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
description = description.encode("utf8")
|
||||
|
||||
# getting uid
|
||||
@@ -1841,7 +1840,7 @@ def export(exportList,filename):
|
||||
r2,p2,c2 = getRepresentation(ifcfile,context,o)
|
||||
if DEBUG: print(" adding ",c2," : ",o.Label)
|
||||
l = o.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
l = l.encode("utf8")
|
||||
prod2 = ifcfile.createIfcBuildingElementProxy(ifcopenshell.guid.compress(uuid.uuid1().hex),history,l,None,None,p2,r2,None,"ELEMENT")
|
||||
subproducts[o.Name] = prod2
|
||||
@@ -1861,7 +1860,7 @@ def export(exportList,filename):
|
||||
r2,p2,c2 = getRepresentation(ifcfile,context,o,subtraction=True)
|
||||
if DEBUG: print(" subtracting ",c2," : ",o.Label)
|
||||
l = o.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
l = l.encode("utf8")
|
||||
prod2 = ifcfile.createIfcOpeningElement(ifcopenshell.guid.compress(uuid.uuid1().hex),history,l,None,None,p2,r2,None)
|
||||
subproducts[o.Name] = prod2
|
||||
@@ -1900,7 +1899,7 @@ def export(exportList,filename):
|
||||
|
||||
#if DEBUG: print(" property ",key," : ",pvalue.encode("utf8"), " (", str(ptype), ") in ",pset)
|
||||
if ptype in ["IfcLabel","IfcText","IfcIdentifier",'IfcDescriptiveMeasure']:
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
pvalue = pvalue.encode("utf8")
|
||||
elif ptype == "IfcBoolean":
|
||||
if pvalue == ".T.":
|
||||
@@ -1916,7 +1915,7 @@ def export(exportList,filename):
|
||||
try:
|
||||
pvalue = FreeCAD.Units.Quantity(pvalue).Value
|
||||
except:
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
pvalue = pvalue.encode("utf8")
|
||||
if DEBUG:print(" warning: unable to export property as numeric value:",key,pvalue)
|
||||
p = ifcbin.createIfcPropertySingleValue(str(key),str(ptype),pvalue)
|
||||
@@ -1943,11 +1942,11 @@ def export(exportList,filename):
|
||||
val = sheet.get('D'+str(n))
|
||||
else:
|
||||
val = ''
|
||||
if sys.version_info.major < 3 and isinstance(key, unicode):
|
||||
if six.py2 and isinstance(key, six.text_type):
|
||||
key = key.encode("utf8")
|
||||
else:
|
||||
key = str(key)
|
||||
if sys.version_info.major < 3 and isinstance(tp, unicode):
|
||||
if six.PY2 and isinstance(tp, six.text_type):
|
||||
tp = tp.encode("utf8")
|
||||
else:
|
||||
tp = str(tp)
|
||||
@@ -2010,7 +2009,7 @@ def export(exportList,filename):
|
||||
val = val.strip('"')
|
||||
#if DEBUG: print(" property ",key," : ",val.encode("utf8"), " (", str(tp), ")")
|
||||
if tp in ["IfcLabel","IfcText","IfcIdentifier",'IfcDescriptiveMeasure']:
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
val = val.encode("utf8")
|
||||
elif tp == "IfcBoolean":
|
||||
if val == ".T.":
|
||||
@@ -2244,7 +2243,7 @@ def export(exportList,filename):
|
||||
relobjs.append(subproducts[o.Name])
|
||||
if relobjs:
|
||||
l = m.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
l = l.encode("utf8")
|
||||
mat = ifcfile.createIfcMaterial(l)
|
||||
materials[m.Label] = mat
|
||||
@@ -2299,7 +2298,7 @@ def export(exportList,filename):
|
||||
pos = ifcbin.createIfcCartesianPoint((l.x,l.y,l.z))
|
||||
tpl = ifcbin.createIfcAxis2Placement3D(pos,None,None)
|
||||
s = ";".join(anno.LabelText)
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
s = s.encode("utf8")
|
||||
txt = ifcfile.createIfcTextLiteral(s,tpl,"LEFT")
|
||||
reps = [txt]
|
||||
@@ -2308,7 +2307,7 @@ def export(exportList,filename):
|
||||
pos = ifcbin.createIfcCartesianPoint((l.x,l.y,l.z))
|
||||
tpl = ifcbin.createIfcAxis2Placement3D(pos,None,None)
|
||||
s = ";".join(anno.Text)
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
s = s.encode("utf8")
|
||||
txt = ifcfile.createIfcTextLiteral(s,tpl,"LEFT")
|
||||
reps = [txt]
|
||||
@@ -2334,7 +2333,7 @@ def export(exportList,filename):
|
||||
shp = ifcfile.createIfcShapeRepresentation(context,'Annotation','Annotation2D',reps)
|
||||
rep = ifcfile.createIfcProductDefinitionShape(None,None,[shp])
|
||||
l = anno.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
l = l.encode("utf8")
|
||||
ann = ifcfile.createIfcAnnotation(ifcopenshell.guid.compress(uuid.uuid1().hex),history,l,'',None,gpl,rep)
|
||||
annos[anno.Name] = ann
|
||||
@@ -2370,7 +2369,7 @@ def export(exportList,filename):
|
||||
swallowed.append(annos[o])
|
||||
if children:
|
||||
name = FreeCAD.ActiveDocument.getObject(g[0]).Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
name = name.encode("utf8")
|
||||
grp = ifcfile.createIfcGroup(ifcopenshell.guid.compress(uuid.uuid1().hex),history,name,'',None)
|
||||
products[g[0]] = grp
|
||||
@@ -2426,7 +2425,7 @@ def buildAddress(obj,ifcfile):
|
||||
t = obj.City or None
|
||||
r = obj.Region or None
|
||||
c = obj.Country or None
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
if a:
|
||||
a = a.encode("utf8")
|
||||
if p:
|
||||
@@ -2969,7 +2968,7 @@ def getRepresentation(ifcfile,context,obj,forcebrep=False,subtraction=False,tess
|
||||
if hasattr(obj,"Material"):
|
||||
if obj.Material:
|
||||
m = obj.Material.Label
|
||||
if sys.version_info.major < 3:
|
||||
if six.PY2:
|
||||
m = m.encode("utf8")
|
||||
psa = ifcbin.createIfcPresentationStyleAssignment(m,rgb[0],rgb[1],rgb[2])
|
||||
surfstyles[key] = psa
|
||||
|
||||
@@ -39,6 +39,8 @@ This is the GUI part of the Draft module.
|
||||
Report to Draft.py for info
|
||||
'''
|
||||
|
||||
import six
|
||||
|
||||
import FreeCAD, FreeCADGui, os, Draft, sys, DraftVecUtils, math
|
||||
|
||||
try:
|
||||
@@ -47,10 +49,7 @@ except ImportError:
|
||||
FreeCAD.Console.PrintMessage("Error: Python-pyside package must be installed on your system to use the Draft module.")
|
||||
|
||||
try:
|
||||
if sys.version_info.major >= 3:
|
||||
_encoding = None
|
||||
else:
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8
|
||||
_encoding = QtGui.QApplication.UnicodeUTF8 if six.PY2 else None
|
||||
def translate(context, text, utf8_decode=True):
|
||||
"""convenience function for Qt translator
|
||||
context: str
|
||||
@@ -61,7 +60,7 @@ try:
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version_info.major >= 3:
|
||||
if six.PY3:
|
||||
return QtGui.QApplication.translate(context, text, None)
|
||||
elif utf8_decode:
|
||||
return QtGui.QApplication.translate(context, text, None, _encoding)
|
||||
@@ -79,7 +78,7 @@ except AttributeError:
|
||||
if set to true utf8 encoded unicode will be returned. This option does not have influence
|
||||
on python3 as for python3 we are returning utf-8 encoded unicode by default!
|
||||
"""
|
||||
if sys.version_info.major >= 3:
|
||||
if six.PY3:
|
||||
return QtGui.QApplication.translate(context, text, None)
|
||||
elif QtCore.qVersion() > "4":
|
||||
if utf8_decode:
|
||||
@@ -153,12 +152,12 @@ class todo:
|
||||
wrn = "[Draft.todo.tasks] Unexpected error:", sys.exc_info()[0], "in ", f, "(", arg, ")"
|
||||
FreeCAD.Console.PrintWarning (wrn)
|
||||
except ReferenceError:
|
||||
print ("Debug: DraftGui.todo.doTasks: queue contains a deleted object, skipping")
|
||||
print("Debug: DraftGui.todo.doTasks: queue contains a deleted object, skipping")
|
||||
todo.itinerary = []
|
||||
if todo.commitlist:
|
||||
for name,func in todo.commitlist:
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(name,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(name,six.text_type):
|
||||
name = name.encode("utf8")
|
||||
#print("debug: committing ",str(name))
|
||||
try:
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
import FreeCAD, math, sys, os, DraftVecUtils, WorkingPlane
|
||||
import six
|
||||
|
||||
import FreeCAD, math, os, DraftVecUtils, WorkingPlane
|
||||
import Part, DraftGeomUtils
|
||||
from FreeCAD import Vector
|
||||
from Draft import getType, getrgb, svgpatterns, gui
|
||||
@@ -390,7 +392,7 @@ def getSVG(obj,scale=1,linewidth=0.35,fontsize=12,fillstyle="shape color",direct
|
||||
svg = ""
|
||||
for i in range(len(text)):
|
||||
t = text[i]
|
||||
if sys.version_info.major < 3 and (not isinstance(t,unicode)):
|
||||
if six.PY2 and not isinstance(t, six.text_type):
|
||||
t = t.decode("utf8")
|
||||
# possible workaround if UTF8 is unsupported
|
||||
# import unicodedata
|
||||
|
||||
@@ -33,6 +33,8 @@
|
||||
# Converter application to convert to/from DXF. Then the real work is done by
|
||||
# importDXF
|
||||
|
||||
import six
|
||||
|
||||
if open.__module__ == '__builtin__':
|
||||
pythonopen = open # to distinguish python built-in open function from the one declared here
|
||||
|
||||
@@ -101,8 +103,8 @@ def convertToDxf(dwgfilename):
|
||||
basename = os.path.basename(dwgfilename)
|
||||
cmdline = '"%s" "%s" "%s" "ACAD2000" "DXF" "0" "1" "%s"' % (teigha, indir, outdir, basename)
|
||||
print("Converting: " + cmdline)
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(cmdline,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(cmdline,six.text_type):
|
||||
encoding = sys.getfilesystemencoding()
|
||||
cmdline = cmdline.encode(encoding)
|
||||
subprocess.call(cmdline, shell=True) #os.system(cmdline)
|
||||
|
||||
@@ -48,6 +48,8 @@ texts, colors,layers (from groups)
|
||||
TEXTSCALING = 1.35 # scaling factor between autocad font sizes and coin font sizes
|
||||
CURRENTDXFLIB = 1.40 # the minimal version of the dxfLibrary needed to run
|
||||
|
||||
import six
|
||||
|
||||
import sys, FreeCAD, os, Part, math, re, string, Mesh, Draft, DraftVecUtils, DraftGeomUtils
|
||||
from Draft import _Dimension, _ViewProviderDimension
|
||||
from FreeCAD import Vector
|
||||
@@ -128,8 +130,8 @@ Please either enable FreeCAD to download these libraries:
|
||||
Or download these libraries manually, as explained on
|
||||
https://github.com/yorikvanhavre/Draft-dxf-importer
|
||||
To enabled FreeCAD to download these libraries, answer Yes.""")
|
||||
if sys.version_info.major < 3:
|
||||
if not isinstance(message,unicode):
|
||||
if six.PY2:
|
||||
if not isinstance(message,six.text_type):
|
||||
message = message.decode('utf8')
|
||||
reply = QtGui.QMessageBox.question(None,"",message,
|
||||
QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
|
||||
@@ -206,7 +208,7 @@ def deformat(text):
|
||||
#print(ss, type(ss))
|
||||
if ss.startswith("U+"):
|
||||
ucode = "0x"+ss[2:]
|
||||
ns += unichr(eval(ucode)) #Python3 - unichr doesn't exist anymore
|
||||
ns += six.unichr(eval(ucode)) # Python3 - unichr doesn't exist anymore
|
||||
else:
|
||||
try:
|
||||
ns += ss.decode("utf8")
|
||||
@@ -1566,14 +1568,13 @@ def warn(dxfobject,num=None):
|
||||
|
||||
def open(filename):
|
||||
"called when freecad opens a file."
|
||||
import sys
|
||||
readPreferences()
|
||||
if dxfUseLegacyImporter:
|
||||
getDXFlibs()
|
||||
if dxfReader:
|
||||
docname = os.path.splitext(os.path.basename(filename))[0]
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(docname,unicode):
|
||||
if six.py2:
|
||||
if isinstance(docname,six.text_type):
|
||||
#workaround since newDocument currently can't handle unicode filenames
|
||||
docname = docname.encode(sys.getfilesystemencoding())
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
@@ -1584,8 +1585,8 @@ def open(filename):
|
||||
errorDXFLib(gui)
|
||||
else:
|
||||
docname = os.path.splitext(os.path.basename(filename))[0]
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(docname,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(docname,six.text_type):
|
||||
#workaround since newDocument currently can't handle unicode filenames
|
||||
docname = docname.encode(sys.getfilesystemencoding())
|
||||
doc = FreeCAD.newDocument(docname)
|
||||
@@ -1606,8 +1607,8 @@ def insert(filename,docname):
|
||||
getDXFlibs()
|
||||
if dxfReader:
|
||||
groupname = os.path.splitext(os.path.basename(filename))[0]
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(groupname,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(groupname,six.text_type):
|
||||
#workaround since newDocument currently can't handle unicode filenames
|
||||
groupname = groupname.encode(sys.getfilesystemencoding())
|
||||
importgroup = doc.addObject("App::DocumentObjectGroup",groupname)
|
||||
@@ -1922,8 +1923,8 @@ def writePanelCut(ob,dxf,nospline,lwPoly,parent=None):
|
||||
def getStrGroup(ob):
|
||||
"gets a string version of the group name"
|
||||
l = getGroup(ob)
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(l,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(l,six.text_type):
|
||||
# dxf R12 files are rather over-sensitive with utf8...
|
||||
try:
|
||||
import unicodedata
|
||||
@@ -2134,8 +2135,8 @@ def export(objectslist,filename,nospline=False,lwPoly=False):
|
||||
dxf.append(dxfLibrary.Dimension(pbase,p1,p2,color=getACI(ob),
|
||||
layer=getStrGroup(ob)))
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
if isinstance(filename,unicode):
|
||||
if six.PY2:
|
||||
if isinstance(filename,six.text_type):
|
||||
filename = filename.encode("utf8")
|
||||
dxf.saveas(filename)
|
||||
|
||||
|
||||
@@ -11,9 +11,11 @@
|
||||
# OCC7 doesn't support non-ASCII characters at the moment
|
||||
# https://forum.freecadweb.org/viewtopic.php?t=20815
|
||||
|
||||
import six
|
||||
|
||||
import FreeCAD,FreeCADGui
|
||||
import shutil
|
||||
import sys, os, re
|
||||
import os, re
|
||||
import ImportGui
|
||||
import PySide
|
||||
from PySide import QtGui, QtCore
|
||||
@@ -22,39 +24,37 @@ import tempfile
|
||||
___stpZversion___ = "1.3.2"
|
||||
|
||||
|
||||
if (sys.version_info > (3, 0)): #py3
|
||||
import builtins as builtin #py3
|
||||
if six.PY3:
|
||||
import gzip as gz
|
||||
else: #py2
|
||||
import __builtin__ as builtin #py2
|
||||
else: # six.PY2
|
||||
import gzip_utf8 as gz
|
||||
|
||||
# import stepZ; reload(stepZ); import gzip_utf8; reload(gzip_utf8)
|
||||
|
||||
def mkz_string(input):
|
||||
if (sys.version_info > (3, 0)): #py3
|
||||
if isinstance(input, str):
|
||||
if six.PY3:
|
||||
if not isinstance(input, str):
|
||||
return input
|
||||
else:
|
||||
input = input.encode('utf-8')
|
||||
input = input.encode('utf-8')
|
||||
return input
|
||||
else: #py2
|
||||
if type(input) == unicode:
|
||||
input = input.encode('utf-8')
|
||||
else: # six.PY2
|
||||
if isinstance(input, six.text_type):
|
||||
input = input.encode('utf-8')
|
||||
return input
|
||||
else:
|
||||
return input
|
||||
####
|
||||
def mkz_unicode(input):
|
||||
if (sys.version_info > (3, 0)): #py3
|
||||
if six.PY3:
|
||||
if isinstance(input, str):
|
||||
return input
|
||||
else:
|
||||
input = input.decode('utf-8')
|
||||
input = input.decode('utf-8')
|
||||
return input
|
||||
else: #py2
|
||||
if type(input) != unicode:
|
||||
input = input.decode('utf-8')
|
||||
else: # six.PY2
|
||||
if isinstance(input, six.text_type):
|
||||
input = input.decode('utf-8')
|
||||
return input
|
||||
else:
|
||||
return input
|
||||
@@ -85,7 +85,7 @@ def open(filename):
|
||||
tempdir = tempfile.gettempdir() # get the current temporary directory
|
||||
tempfilepath = os.path.join(tempdir,fname + u'.stp')
|
||||
|
||||
with builtin.open(tempfilepath, 'wb') as f: #py3
|
||||
with six.builtins.open(tempfilepath, 'wb') as f: #py3
|
||||
f.write(file_content)
|
||||
#ImportGui.insert(filepath)
|
||||
ImportGui.open(tempfilepath)
|
||||
@@ -110,7 +110,7 @@ def insert(filename,doc):
|
||||
tempdir = tempfile.gettempdir() # get the current temporary directory
|
||||
tempfilepath = os.path.join(tempdir,fname + u'.stp')
|
||||
|
||||
with builtin.open(tempfilepath, 'wb') as f: #py3
|
||||
with six.builtins.open(tempfilepath, 'wb') as f: #py3
|
||||
f.write(file_content)
|
||||
ImportGui.insert(tempfilepath, doc)
|
||||
#ImportGui.open(tempfilepath)
|
||||
@@ -154,7 +154,7 @@ def export(objs,filename):
|
||||
QtGui.QApplication.restoreOverrideCursor()
|
||||
reply = QtGui.QMessageBox.information(None,"info", "File cannot be compressed because\na file with the same name exists\n'"+ namefpath+ "'")
|
||||
else:
|
||||
with builtin.open(outfpath_stp, 'rb') as f_in:
|
||||
with six.builtins.open(outfpath_stp, 'rb') as f_in:
|
||||
file_content = f_in.read()
|
||||
new_f_content = file_content
|
||||
f_in.close()
|
||||
|
||||
@@ -32,6 +32,8 @@ So if you add to this file and think about importing anything from PathScripts
|
||||
other than PathLog, then it probably doesn't belong here.
|
||||
'''
|
||||
|
||||
import six
|
||||
|
||||
import PathScripts.PathLog as PathLog
|
||||
import sys
|
||||
|
||||
@@ -107,20 +109,12 @@ Use this function to remove all expressions before deletion.'''
|
||||
|
||||
def toUnicode(string):
|
||||
'''toUnicode(string) ... returns a unicode version of string regardless of the python version.'''
|
||||
if sys.version_info.major < 3:
|
||||
return unicode(string)
|
||||
return string
|
||||
return six.text_type(string)
|
||||
|
||||
def isString(string):
|
||||
'''isString(string) ... return True if string is a string, regardless of string type and python version.'''
|
||||
if type(string) == str:
|
||||
return True
|
||||
if sys.version_info.major < 3 and type(string) == unicode:
|
||||
return True
|
||||
return False
|
||||
return isinstance(string, six.text_type)
|
||||
|
||||
def keyValueIter(dictionary):
|
||||
'''keyValueIter(dict) ... return iterable object over dictionary's (key,value) tuples.'''
|
||||
if sys.version_info.major < 3:
|
||||
return dictionary.items()
|
||||
return dictionary.items()
|
||||
return six.iteritems(dictionary)
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import six
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
|
||||
@@ -454,8 +456,8 @@ class TaskPanel:
|
||||
if loc in ['left', 'right']:
|
||||
spine.set_position(('outward', form.yOffset.value()))
|
||||
# Now we can restore axes labels
|
||||
Plot.xlabel(unicode(x))
|
||||
Plot.ylabel(unicode(y))
|
||||
Plot.xlabel(six.text_type(x))
|
||||
Plot.ylabel(six.text_type(y))
|
||||
plt.update()
|
||||
|
||||
def onScales(self):
|
||||
|
||||
@@ -21,6 +21,8 @@
|
||||
#* *
|
||||
#***************************************************************************
|
||||
|
||||
import six
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
|
||||
@@ -221,9 +223,9 @@ class TaskPanel:
|
||||
form.xLabel = self.widget(QtGui.QLineEdit, "titleX")
|
||||
form.yLabel = self.widget(QtGui.QLineEdit, "titleY")
|
||||
|
||||
Plot.title(unicode(form.title.text()))
|
||||
Plot.xlabel(unicode(form.xLabel.text()))
|
||||
Plot.ylabel(unicode(form.yLabel.text()))
|
||||
Plot.title(six.text_type(form.title.text()))
|
||||
Plot.xlabel(six.text_type(form.xLabel.text()))
|
||||
Plot.ylabel(six.text_type(form.yLabel.text()))
|
||||
plt.update()
|
||||
|
||||
def onFontSizes(self, value):
|
||||
|
||||
@@ -23,6 +23,8 @@
|
||||
|
||||
import os
|
||||
|
||||
import six
|
||||
|
||||
import FreeCAD as App
|
||||
import FreeCADGui as Gui
|
||||
|
||||
@@ -51,7 +53,7 @@ class TaskPanel:
|
||||
form.sizeX = self.widget(QtGui.QDoubleSpinBox, "sizeX")
|
||||
form.sizeY = self.widget(QtGui.QDoubleSpinBox, "sizeY")
|
||||
form.dpi = self.widget(QtGui.QSpinBox, "dpi")
|
||||
path = unicode(form.path.text())
|
||||
path = six.text_type(form.path.text())
|
||||
size = (form.sizeX.value(), form.sizeY.value())
|
||||
dpi = form.dpi.value()
|
||||
Plot.save(path, size, dpi)
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
# This is the start page template. It builds a HTML global variable that contains
|
||||
# the html code of the start page. It is built only once per FreeCAD session for now...
|
||||
|
||||
import six
|
||||
|
||||
import sys,os,FreeCAD,FreeCADGui,tempfile,time,zipfile,urllib,re
|
||||
from . import TranslationTexts
|
||||
from PySide import QtCore,QtGui
|
||||
@@ -41,8 +43,8 @@ def encode(text):
|
||||
|
||||
"make sure we are always working with unicode in python2"
|
||||
|
||||
if sys.version_info.major < 3:
|
||||
if not isinstance(text,unicode):
|
||||
if six.PY2:
|
||||
if not isinstance(text,six.text_type):
|
||||
return text.decode("utf8")
|
||||
return text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user