FlatCAM.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import sys
  2. import os
  3. from PyQt5 import QtWidgets, QtGui
  4. from PyQt5.QtCore import QSettings, Qt
  5. from FlatCAMApp import App
  6. from flatcamGUI import VisPyPatches
  7. from multiprocessing import freeze_support
  8. if sys.platform == "win32":
  9. # cx_freeze 'module win32' workaround
  10. pass
  11. def debug_trace():
  12. """
  13. Set a tracepoint in the Python debugger that works with Qt
  14. :return: None
  15. """
  16. from PyQt5.QtCore import pyqtRemoveInputHook
  17. # from pdb import set_trace
  18. pyqtRemoveInputHook()
  19. # set_trace()
  20. if __name__ == '__main__':
  21. # All X11 calling should be thread safe otherwise we have strange issues
  22. # QtCore.QCoreApplication.setAttribute(QtCore.Qt.AA_X11InitThreads)
  23. # NOTE: Never talk to the GUI from threads! This is why I commented the above.
  24. freeze_support()
  25. debug_trace()
  26. VisPyPatches.apply_patches()
  27. # apply High DPI support
  28. settings = QSettings("Open Source", "FlatCAM")
  29. if settings.contains("hdpi"):
  30. hdpi_support = settings.value('hdpi', type=int)
  31. else:
  32. hdpi_support = 0
  33. if hdpi_support == 2:
  34. os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "1"
  35. else:
  36. os.environ["QT_AUTO_SCREEN_SCALE_FACTOR"] = "0"
  37. app = QtWidgets.QApplication(sys.argv)
  38. # apply style
  39. settings = QSettings("Open Source", "FlatCAM")
  40. if settings.contains("style"):
  41. style = settings.value('style', type=str)
  42. app.setStyle(style)
  43. if hdpi_support == 2:
  44. app.setAttribute(Qt.AA_EnableHighDpiScaling, True)
  45. else:
  46. app.setAttribute(Qt.AA_EnableHighDpiScaling, False)
  47. # Create and display the splash screen
  48. # from here: https://eli.thegreenplace.net/2009/05/09/creating-splash-screens-in-pyqt
  49. splash_pix = QtGui.QPixmap('share/flatcam_icon256.png')
  50. splash = QtWidgets.QSplashScreen(splash_pix, Qt.WindowStaysOnTopHint)
  51. # splash.setMask(splash_pix.mask())
  52. splash.show()
  53. app.processEvents()
  54. splash.showMessage("FlatCAM is initializing ...",
  55. alignment=Qt.AlignBottom | Qt.AlignLeft,
  56. color=QtGui.QColor("gray"))
  57. fc = App()
  58. splash.finish(fc.ui)
  59. fc.ui.show()
  60. sys.exit(app.exec_())