cura_app.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env python3
  2. # Copyright (c) 2015 Ultimaker B.V.
  3. # Cura is released under the terms of the AGPLv3 or higher.
  4. import os
  5. import sys
  6. import platform
  7. from UM.Platform import Platform
  8. #WORKAROUND: GITHUB-88 GITHUB-385 GITHUB-612
  9. if Platform.isLinux(): # Needed for platform.linux_distribution, which is not available on Windows and OSX
  10. # For Ubuntu: https://bugs.launchpad.net/ubuntu/+source/python-qt4/+bug/941826
  11. if platform.linux_distribution()[0] in ("debian", "Ubuntu", "LinuxMint"): # TODO: Needs a "if X11_GFX == 'nvidia'" here. The workaround is only needed on Ubuntu+NVidia drivers. Other drivers are not affected, but fine with this fix.
  12. import ctypes
  13. from ctypes.util import find_library
  14. libGL = find_library("GL")
  15. ctypes.CDLL(libGL, ctypes.RTLD_GLOBAL)
  16. #WORKAROUND: GITHUB-704 GITHUB-708
  17. # It looks like setuptools creates a .pth file in
  18. # the default /usr/lib which causes the default site-packages
  19. # to be inserted into sys.path before PYTHONPATH.
  20. # This can cause issues such as having libsip loaded from
  21. # the system instead of the one provided with Cura, which causes
  22. # incompatibility issues with libArcus
  23. if "PYTHONPATH" in os.environ.keys(): # If PYTHONPATH is used
  24. PYTHONPATH = os.environ["PYTHONPATH"].split(os.pathsep) # Get the value, split it..
  25. PYTHONPATH.reverse() # and reverse it, because we always insert at 1
  26. for PATH in PYTHONPATH: # Now beginning with the last PATH
  27. PATH_real = os.path.realpath(PATH) # Making the the path "real"
  28. if PATH_real in sys.path: # This should always work, but keep it to be sure..
  29. sys.path.remove(PATH_real)
  30. sys.path.insert(1, PATH_real) # Insert it at 1 after os.curdir, which is 0.
  31. def exceptHook(hook_type, value, traceback):
  32. import cura.CrashHandler
  33. cura.CrashHandler.show(hook_type, value, traceback)
  34. sys.excepthook = exceptHook
  35. # Workaround for a race condition on certain systems where there
  36. # is a race condition between Arcus and PyQt. Importing Arcus
  37. # first seems to prevent Sip from going into a state where it
  38. # tries to create PyQt objects on a non-main thread.
  39. import Arcus #@UnusedImport
  40. from UM.Platform import Platform
  41. import cura.CuraApplication
  42. import cura.Settings.CuraContainerRegistry
  43. if Platform.isWindows() and hasattr(sys, "frozen"):
  44. dirpath = os.path.expanduser("~/AppData/Local/cura/")
  45. os.makedirs(dirpath, exist_ok = True)
  46. sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w")
  47. sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w")
  48. # Force an instance of CuraContainerRegistry to be created and reused later.
  49. cura.Settings.CuraContainerRegistry.getInstance()
  50. app = cura.CuraApplication.CuraApplication.getInstance()
  51. app.run()