cura_app.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #WORKAROUND: GITHUB-704 GITHUB-708
  7. # It looks like setuptools creates a .pth file in
  8. # the default /usr/lib which causes the default site-packages
  9. # to be inserted into sys.path before PYTHONPATH.
  10. # This can cause issues such as having libsip loaded from
  11. # the system instead of the one provided with Cura, which causes
  12. # incompatibility issues with libArcus
  13. if "PYTHONPATH" in os.environ.keys(): # If PYTHONPATH is used
  14. PYTHONPATH = os.environ["PYTHONPATH"].split(os.pathsep) # Get the value, split it..
  15. PYTHONPATH.reverse() # and reverse it, because we always insert at 1
  16. for PATH in PYTHONPATH: # Now beginning with the last PATH
  17. PATH_real = os.path.realpath(PATH) # Making the the path "real"
  18. if PATH_real in sys.path: # This should always work, but keep it to be sure..
  19. sys.path.remove(PATH_real)
  20. sys.path.insert(1, PATH_real) # Insert it at 1 after os.curdir, which is 0.
  21. def exceptHook(hook_type, value, traceback):
  22. import cura.CrashHandler
  23. cura.CrashHandler.show(hook_type, value, traceback)
  24. sys.excepthook = exceptHook
  25. # Workaround for a race condition on certain systems where there
  26. # is a race condition between Arcus and PyQt. Importing Arcus
  27. # first seems to prevent Sip from going into a state where it
  28. # tries to create PyQt objects on a non-main thread.
  29. import Arcus #@UnusedImport
  30. from UM.Platform import Platform
  31. import cura.CuraApplication
  32. import cura.CuraContainerRegistry
  33. if Platform.isWindows() and hasattr(sys, "frozen"):
  34. dirpath = os.path.expanduser("~/AppData/Local/cura/")
  35. os.makedirs(dirpath, exist_ok = True)
  36. sys.stdout = open(os.path.join(dirpath, "stdout.log"), "w")
  37. sys.stderr = open(os.path.join(dirpath, "stderr.log"), "w")
  38. # Force an instance of CuraContainerRegistry to be created and reused later.
  39. cura.CuraContainerRegistry.CuraContainerRegistry.getInstance()
  40. app = cura.CuraApplication.CuraApplication.getInstance()
  41. app.run()