Skip to content

Commit

Permalink
changed __init__ to find the library
Browse files Browse the repository at this point in the history
  • Loading branch information
kylechampley committed Feb 12, 2024
1 parent 94e3a9c commit 38b7a42
Showing 1 changed file with 63 additions and 0 deletions.
63 changes: 63 additions & 0 deletions src/xrayphysics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,68 @@ def __init__(self, lib_dir=""):
else:
current_dir = os.path.abspath(os.path.dirname(__file__))

#'''
if _platform == "linux" or _platform == "linux2":
import readline
from ctypes import cdll

fullPath = os.path.join(current_dir, 'libxrayphysics.so')
fullPath_backup = os.path.join(current_dir, '../build/lib/libxrayphysics.so')

if os.path.isfile(fullPath):
self.libxrayphysics = cdll.LoadLibrary(fullPath)
elif os.path.isfile(fullPath_backup):
self.libxrayphysics = cdll.LoadLibrary(fullPath_backup)
else:
print('Error: could not find LEAP dynamic library at')
print(fullPath)
print('or')
print(fullPath_backup)
self.libxrayphysics = None

elif _platform == "win32":
from ctypes import windll

fullPath = os.path.join(current_dir, 'libxrayphysics.dll')
fullPath_backup = os.path.join(current_dir, r'..\win_build\bin\Release\libxrayphysics.dll')

if os.path.isfile(fullPath):
try:
self.libxrayphysics = windll.LoadLibrary(fullPath)
except:
self.libxrayphysics = ctypes.CDLL(fullPath, winmode=0)
elif os.path.isfile(fullPath_backup):
try:
self.libxrayphysics = windll.LoadLibrary(fullPath_backup)
except:
self.libxrayphysics = ctypes.CDLL(fullPath_backup, winmode=0)
else:
print('Error: could not find LEAP dynamic library at')
print(fullPath)
print('or')
print(fullPath_backup)
self.libxrayphysics = None

elif _platform == "darwin": # Darwin is the name for MacOS in Python's platform module
# there is current no support for LEAP on Mac, but maybe someone can figure this out
from ctypes import cdll

fullPath = os.path.join(current_dir, 'libxrayphysics.dylib')
fullPath_backup = os.path.join(current_dir, '../build/lib/libxrayphysics.dylib')

if os.path.isfile(fullPath):
self.libxrayphysics = cdll.LoadLibrary(fullPath)
elif os.path.isfile(fullPath_backup):
self.libxrayphysics = cdll.LoadLibrary(fullPath_backup)
else:
print('Error: could not find LEAP dynamic library at')
print(fullPath)
print('or')
print(fullPath_backup)
self.libxrayphysics = None
#'''

'''
if _platform == "linux" or _platform == "linux2":
import readline
from ctypes import cdll
Expand All @@ -25,6 +87,7 @@ def __init__(self, lib_dir=""):
from ctypes import cdll
# Adjust the path to where your .dylib file is located
self.libxrayphysics = cdll.LoadLibrary(os.path.join(current_dir, "../build/lib/libxrayphysics.dylib"))
#'''

self.detectorBits = 16
self.length_units = 'cm'
Expand Down

0 comments on commit 38b7a42

Please sign in to comment.