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
15 class CuraApp(wx.App):
16 def __init__(self, files):
17 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
18 super(CuraApp, self).__init__(redirect=True, filename='output.txt')
20 super(CuraApp, self).__init__(redirect=False)
22 self.mainWindow = None
24 self.loadFiles = files
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.OnDropFiles([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
42 from Cura.gui import mainWindow
43 from Cura.gui import configWizard
44 from Cura.util import profile
45 from Cura.util import resources
46 from Cura.util import version
48 resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _
50 #If we do not have preferences yet, try to load it from a previous Cura install
51 if profile.getMachineSetting('machine_type') == 'unknown':
53 otherCuraInstalls = profile.getAlternativeBasePaths()
54 otherCuraInstalls.sort()
55 if len(otherCuraInstalls) > 0:
56 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
57 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
60 print traceback.print_exc()
62 #If we haven't run it before, run the configuration wizard.
63 if profile.getMachineSetting('machine_type') == 'unknown':
64 if platform.system() == "Windows":
65 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
67 #Check if we need to copy our examples
68 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
69 if not os.path.isfile(exampleFile):
71 os.makedirs(os.path.dirname(exampleFile))
74 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
75 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
76 self.loadFiles = [exampleFile]
77 if self.splash is not None:
78 self.splash.Show(False)
79 configWizard.configWizard()
81 if profile.getPreference('check_for_updates') == 'True':
82 newVersion = version.checkForNewerVersion()
83 if newVersion is not None:
84 if self.splash is not None:
85 self.splash.Show(False)
86 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:
87 webbrowser.open(newVersion)
89 if profile.getMachineSetting('machine_name') == '':
91 self.mainWindow = mainWindow.mainWindow()
92 if self.splash is not None:
93 self.splash.Show(False)
94 self.mainWindow.Show()
95 self.mainWindow.OnDropFiles(self.loadFiles)
97 setFullScreenCapable(self.mainWindow)
99 if platform.system() == "Darwin":
102 _objc = ctypes.PyDLL(objc._objc.__file__)
104 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
105 _objc.PyObjCObject_New.restype = ctypes.py_object
106 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
108 def setFullScreenCapable(frame):
109 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
111 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
112 window = frameobj.window()
113 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
114 window.setCollectionBehavior_(newBehavior)
116 def setFullScreenCapable(frame):
120 def setFullScreenCapable(frame):