From c5d85ce8b196548c052aed69f09f2cad1c9ee2ce Mon Sep 17 00:00:00 2001 From: Oliver Oxtoby Date: Sun, 21 Apr 2019 10:32:26 +0200 Subject: [PATCH] Compile resources if absent - so that can be installed by AddOn manager --- freecad/plot/PlotGui.py | 27 ++++++++++++++++++++++++++- setup.py | 20 ++------------------ 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/freecad/plot/PlotGui.py b/freecad/plot/PlotGui.py index 945dc50..3b1a3aa 100644 --- a/freecad/plot/PlotGui.py +++ b/freecad/plot/PlotGui.py @@ -27,7 +27,32 @@ import FreeCADGui import os -from . import Plot_rc +def CompileResources(): + import subprocess as sub + # try to create a resource file + # assume either pyside2-rcc or pyside-rcc are available. + # if both are available pyside2-rcc is used. + rc_input = os.path.abspath(os.path.join(os.path.dirname(__file__), "resources", "Plot.qrc")) + rc_output = os.path.join(os.path.dirname(__file__), "Plot_rc.py") + try: + try: + proc = sub.Popen(["pyside2-rcc", "-o", rc_output, rc_input], stdout=sub.PIPE, stderr=sub.PIPE, universal_newlines=True) + out, err = proc.communicate() + except FileNotFoundError: + proc = sub.Popen(["pyside-rcc", "-o", rc_output, rc_input], stdout=sub.PIPE, stderr=sub.PIPE, universal_newlines=True) + out, err = proc.communicate() + print(out) + print(err) + except Exception as e: + print("An error occured while trying to create the resource file: \n" + str(e)) + + +try: + from . import Plot_rc +except ImportError: + print("Plot: Trying to compile resources") + CompileResources() + from . import Plot_rc FreeCADGui.addLanguagePath(":/Plot/translations") diff --git a/setup.py b/setup.py index 85da3e8..a313d88 100644 --- a/setup.py +++ b/setup.py @@ -1,29 +1,13 @@ from setuptools import setup import os -import subprocess as sub +from freecad.plot.PlotGui import CompileResources version_path = os.path.join(os.path.abspath(os.path.dirname(__file__)), "freecad", "plot", "version.py") with open(version_path) as fp: exec(fp.read()) -# try to create a resource file -# assume either pyside2-rcc or pyside-rcc are available. -# if both are available pyside2-rcc is used. -rc_input = os.path.abspath(os.path.join("freecad", "plot", "resources", "Plot.qrc")) -rc_output = os.path.join("freecad", "plot", "Plot_rc.py") -try: - try: - proc = sub.Popen(["pyside2-rcc", "-o", rc_output, rc_input], stdout=sub.PIPE, stderr=sub.PIPE) - out, err = proc.communicate() - except FileNotFoundError: - proc = sub.Popen(["pyside-rcc", "-o", rc_output, rc_input], stdout=sub.PIPE, stderr=sub.PIPE) - out, err = proc.communicate() -except Exception as e: - print("An error occured while trying to create the resource file: \n" + str(e)) - -print(out.decode("utf8")) -print(err.decode("utf8")) +CompileResources() setup(name='freecad.plot', version=str(__version__),