From 7529754c34b7e086f1e8694ea63cf86c044756d7 Mon Sep 17 00:00:00 2001 From: looooo Date: Tue, 24 Oct 2017 23:34:09 +0200 Subject: [PATCH] py3: some diff for fem with py3 --- src/Mod/Fem/FemToolsCcx.py | 12 ++++++++---- src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py | 4 ++++ src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py | 4 ++++ src/Mod/Material/Material.py | 15 +++++++++++---- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/src/Mod/Fem/FemToolsCcx.py b/src/Mod/Fem/FemToolsCcx.py index e1cd25deab..7d3f003be4 100644 --- a/src/Mod/Fem/FemToolsCcx.py +++ b/src/Mod/Fem/FemToolsCcx.py @@ -28,6 +28,7 @@ __url__ = "http://www.freecadweb.org" ## \addtogroup FEM # @{ +import sys import FreeCAD import FemTools from PySide import QtCore @@ -121,7 +122,10 @@ class FemToolsCcx(FemTools.FemTools): import subprocess p1 = subprocess.Popen(['which', 'ccx'], stdout=subprocess.PIPE) if p1.wait() == 0: - ccx_path = p1.stdout.read().split('\n')[0] + if sys.version_info.major >= 3: + ccx_path = str(p1.stdout.read()).split('\n')[0] + else: + ccx_path = p1.stdout.read().split('\n')[0] elif p1.wait() == 1: error_message = "FEM: CalculiX binary ccx not found in standard system binary path. Please install ccx or set path to binary in FEM preferences tab CalculiX.\n" if FreeCAD.GuiUp: @@ -153,20 +157,20 @@ class FemToolsCcx(FemTools.FemTools): stderr=subprocess.PIPE, shell=False, startupinfo=startup_info) ccx_stdout, ccx_stderr = p.communicate() - if ccx_binary_sig in ccx_stdout: + if ccx_binary_sig in str(ccx_stdout): self.ccx_binary_present = True else: raise Exception("FEM: wrong ccx binary") # since we raise an exception the try will fail and the exception later with the error popup will be raised # TODO: I'm still able to break it. If user gives not a file but a path without a file or a file which is not a binary no excetion at all is raised. except OSError as e: - FreeCAD.Console.PrintError(e.message) + FreeCAD.Console.PrintError(str(e)) if e.errno == 2: error_message = "FEM: CalculiX binary ccx \'{}\' not found. Please set the CalculiX binary ccx path in FEM preferences tab CalculiX.\n".format(ccx_binary) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) raise Exception(error_message) except Exception as e: - FreeCAD.Console.PrintError(e.message) + FreeCAD.Console.PrintError(str(e)) error_message = "FEM: CalculiX ccx \'{}\' output \'{}\' doesn't contain expected phrase \'{}\'. Please use ccx 2.6 or newer\n".format(ccx_binary, ccx_stdout, ccx_binary_sig) if FreeCAD.GuiUp: QtGui.QMessageBox.critical(None, error_title, error_message) diff --git a/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py b/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py index a45e12debe..d1447d5577 100644 --- a/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py +++ b/src/Mod/Fem/PyGui/_TaskPanelFemMaterial.py @@ -27,12 +27,16 @@ __url__ = "http://www.freecadweb.org" ## @package TaskPanelFemMaterial # \ingroup FEM +import sys import FreeCAD import FreeCADGui from FreeCAD import Units from PySide import QtCore, QtGui from PySide.QtGui import QFileDialog, QMessageBox +if sys.version_info.major >= 3: + unicode = str + class _TaskPanelFemMaterial: '''The editmode TaskPanel for FemMaterial objects''' diff --git a/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py b/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py index 03229b0d7a..f25f647de4 100644 --- a/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py +++ b/src/Mod/Fem/PyGui/_TaskPanelFemSolverCalculix.py @@ -30,6 +30,7 @@ __url__ = "http://www.freecadweb.org" import FemToolsCcx import FreeCAD import os +import sys import time import FreeCADGui import FemGui @@ -38,6 +39,9 @@ from PySide.QtCore import Qt from PySide.QtGui import QApplication +if sys.version_info.major >= 3: + unicode = str + class _TaskPanelFemSolverCalculix: def __init__(self, solver_object): self.form = FreeCADGui.PySideUic.loadUi(FreeCAD.getHomePath() + "Mod/Fem/PyGui/TaskPanelFemSolverCalculix.ui") diff --git a/src/Mod/Material/Material.py b/src/Mod/Material/Material.py index 53954af64d..cd8056e37e 100644 --- a/src/Mod/Material/Material.py +++ b/src/Mod/Material/Material.py @@ -51,8 +51,12 @@ Version: def importFCMat(fileName): "Read a FCMat file into a dictionary" - import ConfigParser - Config = ConfigParser.ConfigParser() + try: + import ConfigParser as configparser + except ImportError: + import configparser + + Config = configparser.ConfigParser() Config.optionxform = str Config.read(fileName) dict1 = {} @@ -66,9 +70,12 @@ def importFCMat(fileName): def exportFCMat(fileName,matDict): "Write a material dictionary to a FCMat file" - import ConfigParser + try: + import ConfigParser as configparser + except ImportError: + import configparser import string - Config = ConfigParser.ConfigParser() + Config = configparser.ConfigParser() # create groups for x in matDict.keys():