1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
11 #Only import the _core to save import time
14 class CuraApp(wx.App):
15 def __init__(self, files):
16 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
17 super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
19 super(CuraApp, self).__init__(redirect = False)
21 self.mainWindow = None
23 self.loadFiles = files
25 if sys.platform.startswith('darwin'):
26 #Do not show a splashscreen on OSX, as by Apple guidelines
27 self.afterSplashCallback()
29 from Cura.gui import splashScreen
30 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
32 def MacOpenFile(self, path):
34 self.mainWindow.OnDropFiles([path])
35 except Exception as e:
36 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
38 def afterSplashCallback(self):
39 #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
43 from Cura.util import profile
44 from Cura.util import resources
45 from Cura.util import version
47 #If we haven't run it before, run the configuration wizard.
48 if profile.getPreference('machine_type') == 'unknown':
49 if platform.system() == "Windows":
50 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
52 #Check if we need to copy our examples
53 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
54 if not os.path.isfile(exampleFile):
56 os.makedirs(os.path.dirname(exampleFile))
59 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
60 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
61 self.loadFiles = [exampleFile]
62 if self.splash is not None:
63 self.splash.Show(False)
64 configWizard.configWizard()
66 if profile.getPreference('check_for_updates') == 'True':
67 newVersion = version.checkForNewerVersion()
68 if newVersion is not None:
69 if self.splash is not None:
70 self.splash.Show(False)
71 if wx.MessageBox('A new version of Cura is available, would you like to download?', 'New version available', wx.YES_NO | wx.ICON_INFORMATION) == wx.YES:
72 webbrowser.open(newVersion)
74 self.mainWindow = mainWindow.mainWindow()
75 if self.splash is not None:
76 self.splash.Show(False)
77 self.mainWindow.Show()
78 self.mainWindow.OnDropFiles(self.loadFiles)
80 setFullScreenCapable(self.mainWindow)
82 if platform.system() == "Darwin":
84 _objc = ctypes.PyDLL(objc._objc.__file__)
86 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
87 _objc.PyObjCObject_New.restype = ctypes.py_object
88 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
90 def setFullScreenCapable(frame):
91 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
93 NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
94 window = frameobj.window()
95 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
96 window.setCollectionBehavior_(newBehavior)
99 def setFullScreenCapable(frame):