diff --git a/src/Mod/OpenSCAD/OpenSCADCommands.py b/src/Mod/OpenSCAD/OpenSCADCommands.py index 39f711de88..d3f0a2c4f6 100644 --- a/src/Mod/OpenSCAD/OpenSCADCommands.py +++ b/src/Mod/OpenSCAD/OpenSCADCommands.py @@ -28,19 +28,26 @@ __url__ = ["https://www.freecadweb.org"] This Script includes the GUI Commands of the OpenSCAD module ''' -import FreeCAD,FreeCADGui -from PySide import QtCore, QtGui +import FreeCAD import OpenSCADUtils -try: - _encoding = QtGui.QApplication.UnicodeUTF8 - def translate(context, text): - "convenience function for Qt translator" - return QtGui.QApplication.translate(context, text, None, _encoding) -except AttributeError: - def translate(context, text): - "convenience function for Qt translator" - return QtGui.QApplication.translate(context, text, None) +if FreeCAD.GuiUp: + import FreeCADGui + from PySide import QtCore, QtGui + gui = True +else: + gui = False + +if gui: + try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def translate(context, text): + "convenience function for Qt translator" + return QtGui.QApplication.translate(context, text, None, _encoding) + except AttributeError: + def translate(context, text): + "convenience function for Qt translator" + return QtGui.QApplication.translate(context, text, None) class ExplodeGroup: "Ungroup Objects" diff --git a/src/Mod/OpenSCAD/OpenSCADUtils.py b/src/Mod/OpenSCAD/OpenSCADUtils.py index 644df882f4..feed11e303 100644 --- a/src/Mod/OpenSCAD/OpenSCADUtils.py +++ b/src/Mod/OpenSCAD/OpenSCADUtils.py @@ -29,22 +29,22 @@ This Script includes various python helper functions that are shared across the module ''' from exportCSG import mesh2polyhedron -try: - from PySide import QtGui - _encoding = QtGui.QApplication.UnicodeUTF8 - def translate(context, text): - "convenience function for Qt translator" - return QtGui.QApplication.translate(context, text, None, _encoding) -except AttributeError: - def translate(context, text): - "convenience function for Qt translator" +import FreeCAD, io + +if FreeCAD.GuiUp: + try: from PySide import QtGui - return QtGui.QApplication.translate(context, text, None) - -import io + _encoding = QtGui.QApplication.UnicodeUTF8 + def translate(context, text): + "convenience function for Qt translator" + return QtGui.QApplication.translate(context, text, None, _encoding) + except AttributeError: + def translate(context, text): + "convenience function for Qt translator" + from PySide import QtGui + return QtGui.QApplication.translate(context, text, None) try: - import FreeCAD BaseError = FreeCAD.Base.FreeCADError except (ImportError, AttributeError): BaseError = RuntimeError diff --git a/src/Mod/OpenSCAD/exportCSG.py b/src/Mod/OpenSCAD/exportCSG.py index 951ad36748..3e9c2000fa 100644 --- a/src/Mod/OpenSCAD/exportCSG.py +++ b/src/Mod/OpenSCAD/exportCSG.py @@ -32,9 +32,11 @@ __url__ = ["http://www.sloan-home.co.uk/Export/Export.html"] import FreeCAD, os, Part, math from FreeCAD import Vector -try: import FreeCADGui -except ValueError: gui = False -else: gui = True +if FreeCAD.GuiUp: + import FreeCADGui + gui = True +else: + gui = False #*************************************************************************** # Tailor following to your requirements ( Should all be strings ) * diff --git a/src/Mod/OpenSCAD/importCSG.py b/src/Mod/OpenSCAD/importCSG.py index 31b576a19d..d826781278 100644 --- a/src/Mod/OpenSCAD/importCSG.py +++ b/src/Mod/OpenSCAD/importCSG.py @@ -57,17 +57,18 @@ printverbose = True import tokrules from tokrules import tokens -try: - _encoding = QtGui.QApplication.UnicodeUTF8 - def translate(context, text): - "convenience function for Qt translator" - from PySide import QtGui - return QtGui.QApplication.translate(context, text, None, _encoding) -except AttributeError: - def translate(context, text): - "convenience function for Qt translator" - from PySide import QtGui - return QtGui.QApplication.translate(context, text, None) +if gui: + try: + _encoding = QtGui.QApplication.UnicodeUTF8 + def translate(context, text): + "convenience function for Qt translator" + from PySide import QtGui + return QtGui.QApplication.translate(context, text, None, _encoding) + except AttributeError: + def translate(context, text): + "convenience function for Qt translator" + from PySide import QtGui + return QtGui.QApplication.translate(context, text, None) def open(filename): "called when freecad opens a file."