1 from __future__ import absolute_import
10 #Only import the _core to save import time
13 class CuraApp(wx.App):
14 def __init__(self, files):
15 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
16 super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
18 super(CuraApp, self).__init__(redirect = False)
20 self.mainWindow = None
22 self.loadFiles = files
24 if sys.platform.startswith('darwin'):
25 #Do not show a splashscreen on OSX, as by Apple guidelines
26 self.afterSplashCallback()
28 from Cura.gui import splashScreen
29 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
31 def MacOpenFile(self, path):
33 self.mainWindow.OnDropFiles([path])
34 except Exception as e:
35 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
37 def afterSplashCallback(self):
38 #These imports take most of the time and thus should be done after showing the splashscreen
40 from Cura.gui import mainWindow
41 from Cura.gui import configWizard
42 from Cura.util import profile
43 from Cura.util import resources
44 from Cura.util import version
46 #If we haven't run it before, run the configuration wizard.
47 if profile.getPreference('machine_type') == 'unknown':
48 if platform.system() == "Windows":
49 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
51 #Check if we need to copy our examples
52 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
53 if not os.path.isfile(exampleFile):
55 os.makedirs(os.path.dirname(exampleFile))
58 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
59 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
60 self.loadFiles = [exampleFile]
61 if self.splash is not None:
62 self.splash.Show(False)
63 configWizard.configWizard()
65 if profile.getPreference('check_for_updates') == 'True':
66 newVersion = version.checkForNewerVersion()
67 if newVersion is not None:
68 if self.splash is not None:
69 self.splash.Show(False)
70 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:
71 webbrowser.open(newVersion)
73 self.mainWindow = mainWindow.mainWindow()
74 if self.splash is not None:
75 self.splash.Show(False)
76 self.mainWindow.Show()
77 self.mainWindow.OnDropFiles(self.loadFiles)
79 setFullScreenCapable(self.mainWindow)
81 if platform.system() == "Darwin":
83 _objc = ctypes.PyDLL(objc._objc.__file__)
85 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
86 _objc.PyObjCObject_New.restype = ctypes.py_object
87 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
89 def setFullScreenCapable(frame):
90 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
92 NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
93 window = frameobj.window()
94 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
95 window.setCollectionBehavior_(newBehavior)
98 def setFullScreenCapable(frame):