1 from __future__ import absolute_import
10 #Only import the _core to save import time
13 from Cura.util import profile
14 from Cura.util import resources
16 class CuraApp(wx.App):
18 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
19 super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
21 super(CuraApp, self).__init__(redirect = False)
23 self.mainWindow = None
26 if sys.platform.startswith('darwin'):
27 #Do not show a splashscreen on OSX, as by Apple guidelines
28 self.afterSplashCallback()
30 from Cura.gui import splashScreen
31 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
33 def MacOpenFile(self, path):
35 self.mainWindow._loadModels([path])
36 except Exception as e:
37 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
39 def afterSplashCallback(self):
40 #These imports take most of the time and thus should be done after showing the splashscreen
41 from Cura.gui import mainWindow
42 from Cura.gui import configWizard
44 #If we haven't run it before, run the configuration wizard.
45 if profile.getPreference('machine_type') == 'unknown':
46 if platform.system() == "Darwin":
47 #Check if we need to copy our examples
48 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
49 if not os.path.isfile(exampleFile):
51 os.makedirs(os.path.dirname(exampleFile))
54 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
55 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
56 profile.putPreference('lastFile', exampleFile)
57 configWizard.configWizard()
59 #Hide the splashscreen before showing the main window.
60 if self.splash is not None:
61 self.splash.Show(False)
62 self.mainWindow = mainWindow.mainWindow()
64 setFullScreenCapable(self.mainWindow)
66 if platform.system() == "Darwin":
68 _objc = ctypes.PyDLL(objc._objc.__file__)
70 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
71 _objc.PyObjCObject_New.restype = ctypes.py_object
72 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
74 def setFullScreenCapable(frame):
75 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
77 NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
78 window = frameobj.window()
79 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
80 window.setCollectionBehavior_(newBehavior)
83 def setFullScreenCapable(frame):