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 do not have preferences yet, try to load it from a previous Cura install
48 if profile.getPreference('machine_type') == 'unknown':
50 otherCuraInstalls = profile.getAlternativeBasePaths()
51 otherCuraInstalls.sort()
52 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
53 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
57 #If we haven't run it before, run the configuration wizard.
58 if profile.getPreference('machine_type') == 'unknown':
59 if platform.system() == "Windows":
60 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
62 #Check if we need to copy our examples
63 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
64 if not os.path.isfile(exampleFile):
66 os.makedirs(os.path.dirname(exampleFile))
69 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
70 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
71 self.loadFiles = [exampleFile]
72 if self.splash is not None:
73 self.splash.Show(False)
74 configWizard.configWizard()
76 if profile.getPreference('check_for_updates') == 'True':
77 newVersion = version.checkForNewerVersion()
78 if newVersion is not None:
79 if self.splash is not None:
80 self.splash.Show(False)
81 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:
82 webbrowser.open(newVersion)
84 self.mainWindow = mainWindow.mainWindow()
85 if self.splash is not None:
86 self.splash.Show(False)
87 self.mainWindow.Show()
88 self.mainWindow.OnDropFiles(self.loadFiles)
90 setFullScreenCapable(self.mainWindow)
92 if platform.system() == "Darwin":
94 _objc = ctypes.PyDLL(objc._objc.__file__)
96 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
97 _objc.PyObjCObject_New.restype = ctypes.py_object
98 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
100 def setFullScreenCapable(frame):
101 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
103 NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
104 window = frameobj.window()
105 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
106 window.setCollectionBehavior_(newBehavior)
109 def setFullScreenCapable(frame):