From ab5a4e522520793469cef1a7ab16f9334c68449c Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Thu, 4 Dec 2014 11:04:04 -0500 Subject: [PATCH] Forced the FreeCAD bin and lib directories to be in the sys.path on module startup. --- CadQuery/InitGui.py | 18 +++++++-------- CadQuery/Libs/pyqode/qt/__init__.py | 35 ++++++++++++++++++++--------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/CadQuery/InitGui.py b/CadQuery/InitGui.py index 1b7b3e4..ef65621 100644 --- a/CadQuery/InitGui.py +++ b/CadQuery/InitGui.py @@ -38,10 +38,14 @@ class CadQueryWorkbench (Workbench): #Set up so that we can import from our embedded packages module_base_path = module_locator.module_path() libs_dir_path = os.path.join(module_base_path, 'Libs') - #libs_path = os.path.join(libs_dir_path, 'libs.zip') sys.path.insert(0, libs_dir_path) - #sys.path.insert(0, os.path.join(libs_dir_path, 'cadquery')) - s#ys.path.insert(0, libs_path) + + #Make sure we get the right libs under the FreeCAD installation + fc_base_path = os.path.dirname(os.path.dirname(module_base_path)) + fc_lib_path = os.path.join(fc_base_path, 'lib') + fc_bin_path = os.path.join(fc_base_path, 'bin') + sys.path.insert(1, fc_lib_path) + sys.path.insert(1, fc_bin_path) import cadquery from Gui import ImportCQ @@ -102,15 +106,11 @@ class CadQueryWorkbench (Workbench): #Windows needs some exra help with paths if sys.platform.startswith('win'): - #The lib directory under the FreeCAD installation - fc_lib_path = os.path.dirname(os.path.dirname(module_base_path)) - fc_lib_path = os.path.join(fc_lib_path, 'lib') - codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter - , args=['-s', libs_path, fc_lib_path, os.path.join(libs_dir_path, 'cadquery')]) + , args=['-s', fc_lib_path, libs_dir_path]) else: codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter - , args=['-s', libs_path, libs_dir_path, os.path.join(libs_dir_path, 'cadquery')]) + , args=['-s', libs_dir_path]) codePane.setObjectName("cqCodePane") diff --git a/CadQuery/Libs/pyqode/qt/__init__.py b/CadQuery/Libs/pyqode/qt/__init__.py index 17fa1cd..94dafac 100644 --- a/CadQuery/Libs/pyqode/qt/__init__.py +++ b/CadQuery/Libs/pyqode/qt/__init__.py @@ -52,7 +52,7 @@ import os import sys import logging -__version__ = '2.4.dev' +__version__ = '2.5.dev' #: Qt API environment variable name @@ -78,16 +78,16 @@ def setup_apiv2(): """ # setup PyQt api to version 2 if sys.version_info[0] == 2: + logging.getLogger(__name__).debug( + 'setting up SIP API to version 2') + import sip try: - import sip sip.setapi("QString", 2) sip.setapi("QVariant", 2) - except: + except ValueError: logging.getLogger(__name__).critical( - "pyQode: failed to set PyQt api to version 2" - "\nTo solve this problem, import " - "pyqode before any other PyQt modules " - "in your main script...") + "failed to set up sip api to version 2 for PyQt4") + raise ImportError('PyQt4') def autodetect(): @@ -99,18 +99,25 @@ def autodetect(): 2) PyQt4 3) PySide """ + logging.getLogger(__name__).debug('auto-detecting QT_API') try: + logging.getLogger(__name__).debug('trying PyQt5') import PyQt5 os.environ[QT_API] = PYQT5_API + logging.getLogger(__name__).debug('imported PyQt5') except ImportError: try: + logging.getLogger(__name__).debug('trying PyQt4') setup_apiv2() import PyQt4 os.environ[QT_API] = PYQT4_API + logging.getLogger(__name__).debug('imported PyQt4') except ImportError: try: + logging.getLogger(__name__).debug('trying PySide') import PySide os.environ[QT_API] = PYSIDE_API + logging.getLogger(__name__).debug('imported PySide') except ImportError: raise PythonQtError('No Qt bindings could be found') @@ -119,18 +126,24 @@ if QT_API in os.environ: # check if the selected QT_API is available try: if os.environ[QT_API].lower() == PYQT5_API.lower(): - from PyQt5 import * + logging.getLogger(__name__).debug('importing PyQt5') + import PyQt5 os.environ[QT_API] = PYQT5_API + logging.getLogger(__name__).debug('imported PyQt5') elif os.environ[QT_API].lower() == PYQT4_API.lower(): + logging.getLogger(__name__).debug('importing PyQt4') setup_apiv2() - from PyQt4 import * + import PyQt4 os.environ[QT_API] = PYQT4_API + logging.getLogger(__name__).debug('imported PyQt4') elif os.environ[QT_API].lower() == PYSIDE_API.lower(): - from PySide import * + logging.getLogger(__name__).debug('importing PySide') + import PySide os.environ[QT_API] = PYSIDE_API + logging.getLogger(__name__).debug('imported PySide') except ImportError: logging.getLogger(__name__).warning( - 'failed to used the selected QT_API: %s, trying auto-detection', + 'failed to import the selected QT_API: %s', os.environ[QT_API]) # use the auto-detected API if possible autodetect()