Fix run time errors with python3.12 and pyside6 (#13337)

* Change pyopen=open expression to from builtins import open as pyopen

---------

Co-authored-by: Adrián Insaurralde Avalos <36372335+adrianinsaval@users.noreply.github.com>
This commit is contained in:
Dov Grobgeld
2024-04-30 06:28:01 +02:00
committed by GitHub
parent b9aaf131fb
commit e66e90b512
56 changed files with 161 additions and 213 deletions

View File

@@ -46,6 +46,7 @@ from DraftGeomUtils import vec
from importIFCHelper import dd2dms
from draftutils import params
from draftutils.messages import _msg, _err
from builtins import open as pyopen
if FreeCAD.GuiUp:
import FreeCADGui
@@ -54,10 +55,6 @@ __title__ = "FreeCAD IFC export"
__author__ = ("Yorik van Havre", "Jonathan Wiedemann", "Bernd Hahnebach")
__url__ = "https://www.freecad.org"
# Save the Python open function because it will be redefined
if open.__module__ in ['__builtin__', 'io']:
pyopen = open
# Templates and other definitions ****
# Specific FreeCAD <-> IFC slang translations
translationtable = {

View File

@@ -25,6 +25,7 @@ __url__ = "https://www.freecad.org"
import FreeCAD
import Draft
from builtins import open as pyopen
if FreeCAD.GuiUp:
from draftutils.translate import translate

View File

@@ -44,6 +44,7 @@ import importIFCmulticore
from draftutils import params
from draftutils.messages import _msg, _err
from builtins import open as pyopen
if FreeCAD.GuiUp:
import FreeCADGui as Gui
@@ -55,10 +56,6 @@ __url__ = "https://www.freecad.org"
DEBUG = False # Set to True to see debug messages. Otherwise, totally silent
ZOOMOUT = True # Set to False to not zoom extents after import
# Save the Python open function because it will be redefined
if open.__module__ in ['__builtin__', 'io']:
pyopen = open
# Templates and other definitions ****
# which IFC type must create which FreeCAD type

View File

@@ -29,6 +29,7 @@
import FreeCAD, Arch, Draft, os, sys, time, Part, DraftVecUtils, uuid, math, re
from draftutils import params
from draftutils.translate import translate
from builtins import open as pyopen
__title__="FreeCAD IFC importer"
__author__ = "Yorik van Havre"
@@ -54,8 +55,7 @@ supportedIfcTypes = ["IfcSite", "IfcBuilding", "IfcBuildingStorey", "IfcBeam", "
"IfcPile", "IfcFooting", "IfcReinforcingBar", "IfcTendon"]
# TODO : shading device not supported?
if open.__module__ in ['__builtin__','io']:
pyopen = open # because we'll redefine open below
def open(filename,skip=None):
"called when freecad opens a file"

View File

@@ -27,6 +27,7 @@ import FreeCAD
import Draft
import Mesh
import Part
from builtins import open as pyopen
if FreeCAD.GuiUp:
import FreeCADGui
@@ -37,8 +38,7 @@ else:
def translate(ctxt, txt): return txt
if open.__module__ in ['__builtin__','io']:
pythonopen = open
def export(exportList, filename):
@@ -52,7 +52,7 @@ def export(exportList, filename):
}
# Write file
outfile = pythonopen(filename, "w")
outfile = pyopen(filename, "w")
json.dump(data, outfile, separators = (',', ':'))
outfile.close()

View File

@@ -32,6 +32,7 @@ import Mesh
import MeshPart
import Part
from draftutils import params
from builtins import open as pyopen
if FreeCAD.GuiUp:
from draftutils.translate import translate
@@ -50,8 +51,7 @@ else:
# and supports exporting faces with more than 3 vertices
# and supports object colors / materials
if open.__module__ in ['__builtin__','io']:
pythonopen = open
def findVert(aVertex,aList):
"finds aVertex in aList, returns index"
@@ -260,7 +260,7 @@ def export(exportList,filename,colors=None):
outfile.close()
FreeCAD.Console.PrintMessage(translate("Arch","Successfully written") + " " + filename + "\n")
if materials:
outfile = pythonopen(filenamemtl,"w")
outfile = pyopen(filenamemtl,"w")
outfile.write("# FreeCAD v" + ver[0] + "." + ver[1] + " build" + ver[2] + " Arch module\n")
outfile.write("# https://www.freecad.org\n")
kinds = {"AmbientColor":"Ka ","DiffuseColor":"Kd ","SpecularColor":"Ks ","EmissiveColor":"Ke ","Transparency":"Tr ","Dissolve":"d "}
@@ -306,7 +306,7 @@ def insert(filename,docname):
doc = FreeCAD.newDocument(docname)
FreeCAD.ActiveDocument = doc
with pythonopen(filename,"r") as infile:
with pyopen(filename,"r") as infile:
verts = []
facets = []
activeobject = None
@@ -327,7 +327,7 @@ def insert(filename,docname):
if line[:7] == "mtllib ":
matlib = os.path.join(os.path.dirname(filename),line[7:])
if os.path.exists(matlib):
with pythonopen(matlib,"r") as matfile:
with pyopen(matlib,"r") as matfile:
mname = None
color = None
trans = None

View File

@@ -34,6 +34,7 @@ import Arch
import Draft
import Mesh
import Part
from builtins import open as pyopen
## @package importSH3D
# \ingroup ARCH
@@ -43,8 +44,7 @@ import Part
DEBUG = True
if open.__module__ in ['__builtin__','io']:
pyopen = open # because we'll redefine open below
def open(filename):

View File

@@ -22,10 +22,10 @@
import os
import FreeCAD
from builtins import open as pyopen
translate = FreeCAD.Qt.translate
if open.__module__ in ['__builtin__','io']:
pythonopen = open
def open(filename):
@@ -142,7 +142,7 @@ def checkShapeFileLibrary():
return False
b = u.read()
fp = os.path.join(FreeCAD.getUserMacroDir(True),"shapefile.py")
f = pythonopen(fp,"wb")
f = pyopen(fp,"wb")
f.write(b)
f.close()
try:

View File

@@ -44,6 +44,7 @@ import Part
import OfflineRenderingUtils
import json
import textwrap
from builtins import open as pyopen
if FreeCAD.GuiUp:
import FreeCADGui
@@ -52,7 +53,7 @@ else:
FreeCADGui = None
def translate(ctxt, txt): return txt
if open.__module__ in ['__builtin__','io']: pythonopen = open
## @package importWebGL
# \ingroup ARCH
@@ -868,7 +869,7 @@ def export( exportList, filename, colors = None, camera = None ):
html = html.replace('$data', json.dumps(data, separators=(',', ':')) ) # Shape Data
outfile = pythonopen(filename, "w")
outfile = pyopen(filename, "w")
outfile.write( html )
outfile.close()
FreeCAD.Console.PrintMessage( translate("Arch", "Successfully written") + ' ' + filename + "\n" )