Forced the FreeCAD bin and lib directories to be in the sys.path on module startup.

This commit is contained in:
Jeremy Wright 2014-12-04 11:04:04 -05:00
parent 4ce894f604
commit ab5a4e5225
2 changed files with 33 additions and 20 deletions

View File

@ -38,10 +38,14 @@ class CadQueryWorkbench (Workbench):
#Set up so that we can import from our embedded packages #Set up so that we can import from our embedded packages
module_base_path = module_locator.module_path() module_base_path = module_locator.module_path()
libs_dir_path = os.path.join(module_base_path, 'Libs') 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, 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 import cadquery
from Gui import ImportCQ from Gui import ImportCQ
@ -102,15 +106,11 @@ class CadQueryWorkbench (Workbench):
#Windows needs some exra help with paths #Windows needs some exra help with paths
if sys.platform.startswith('win'): 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 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: else:
codePane = PyCodeEdit(server_script=server_path, interpreter=interpreter 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") codePane.setObjectName("cqCodePane")

View File

@ -52,7 +52,7 @@ import os
import sys import sys
import logging import logging
__version__ = '2.4.dev' __version__ = '2.5.dev'
#: Qt API environment variable name #: Qt API environment variable name
@ -78,16 +78,16 @@ def setup_apiv2():
""" """
# setup PyQt api to version 2 # setup PyQt api to version 2
if sys.version_info[0] == 2: if sys.version_info[0] == 2:
try: logging.getLogger(__name__).debug(
'setting up SIP API to version 2')
import sip import sip
try:
sip.setapi("QString", 2) sip.setapi("QString", 2)
sip.setapi("QVariant", 2) sip.setapi("QVariant", 2)
except: except ValueError:
logging.getLogger(__name__).critical( logging.getLogger(__name__).critical(
"pyQode: failed to set PyQt api to version 2" "failed to set up sip api to version 2 for PyQt4")
"\nTo solve this problem, import " raise ImportError('PyQt4')
"pyqode before any other PyQt modules "
"in your main script...")
def autodetect(): def autodetect():
@ -99,18 +99,25 @@ def autodetect():
2) PyQt4 2) PyQt4
3) PySide 3) PySide
""" """
logging.getLogger(__name__).debug('auto-detecting QT_API')
try: try:
logging.getLogger(__name__).debug('trying PyQt5')
import PyQt5 import PyQt5
os.environ[QT_API] = PYQT5_API os.environ[QT_API] = PYQT5_API
logging.getLogger(__name__).debug('imported PyQt5')
except ImportError: except ImportError:
try: try:
logging.getLogger(__name__).debug('trying PyQt4')
setup_apiv2() setup_apiv2()
import PyQt4 import PyQt4
os.environ[QT_API] = PYQT4_API os.environ[QT_API] = PYQT4_API
logging.getLogger(__name__).debug('imported PyQt4')
except ImportError: except ImportError:
try: try:
logging.getLogger(__name__).debug('trying PySide')
import PySide import PySide
os.environ[QT_API] = PYSIDE_API os.environ[QT_API] = PYSIDE_API
logging.getLogger(__name__).debug('imported PySide')
except ImportError: except ImportError:
raise PythonQtError('No Qt bindings could be found') 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 # check if the selected QT_API is available
try: try:
if os.environ[QT_API].lower() == PYQT5_API.lower(): 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 os.environ[QT_API] = PYQT5_API
logging.getLogger(__name__).debug('imported PyQt5')
elif os.environ[QT_API].lower() == PYQT4_API.lower(): elif os.environ[QT_API].lower() == PYQT4_API.lower():
logging.getLogger(__name__).debug('importing PyQt4')
setup_apiv2() setup_apiv2()
from PyQt4 import * import PyQt4
os.environ[QT_API] = PYQT4_API os.environ[QT_API] = PYQT4_API
logging.getLogger(__name__).debug('imported PyQt4')
elif os.environ[QT_API].lower() == PYSIDE_API.lower(): 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 os.environ[QT_API] = PYSIDE_API
logging.getLogger(__name__).debug('imported PySide')
except ImportError: except ImportError:
logging.getLogger(__name__).warning( 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]) os.environ[QT_API])
# use the auto-detected API if possible # use the auto-detected API if possible
autodetect() autodetect()