chiark / gitweb /
Add feature which checks for newer releases on startup.
[cura.git] / Cura / gui / app.py
1 from __future__ import absolute_import
2
3 import sys
4 import os
5 import platform
6 import shutil
7 import glob
8 import warnings
9
10 #Only import the _core to save import time
11 import wx._core
12
13 class CuraApp(wx.App):
14         def __init__(self):
15                 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
16                         super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
17                 else:
18                         super(CuraApp, self).__init__(redirect = False)
19
20                 self.mainWindow = None
21                 self.splash = None
22
23                 if sys.platform.startswith('darwin'):
24                         #Do not show a splashscreen on OSX, as by Apple guidelines
25                         self.afterSplashCallback()
26                 else:
27                         from Cura.gui import splashScreen
28                         self.splash = splashScreen.splashScreen(self.afterSplashCallback)
29
30         def MacOpenFile(self, path):
31                 try:
32                         self.mainWindow._loadModels([path])
33                 except Exception as e:
34                         warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
35
36         def afterSplashCallback(self):
37                 #These imports take most of the time and thus should be done after showing the splashscreen
38                 import webbrowser
39                 from Cura.gui import mainWindow
40                 from Cura.gui import configWizard
41                 from Cura.util import profile
42                 from Cura.util import resources
43                 from Cura.util import version
44
45                 #If we haven't run it before, run the configuration wizard.
46                 if profile.getPreference('machine_type') == 'unknown':
47                         if platform.system() == "Darwin":
48                                 #Check if we need to copy our examples
49                                 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
50                                 if not os.path.isfile(exampleFile):
51                                         try:
52                                                 os.makedirs(os.path.dirname(exampleFile))
53                                         except:
54                                                 pass
55                                         for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
56                                                 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
57                                         profile.putPreference('lastFile', exampleFile)
58                         configWizard.configWizard()
59
60                 #Hide the splashscreen before showing the main window.
61                 if self.splash is not None:
62                         self.splash.Show(False)
63                 if profile.getPreference('check_for_updates') == 'True':
64                         newVersion = version.checkForNewerVersion()
65                         if newVersion is not None:
66                                 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:
67                                         webbrowser.open(newVersion)
68                                         return
69                 self.mainWindow = mainWindow.mainWindow()
70
71                 setFullScreenCapable(self.mainWindow)
72
73 if platform.system() == "Darwin":
74         import ctypes, objc
75         _objc = ctypes.PyDLL(objc._objc.__file__)
76
77         # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
78         _objc.PyObjCObject_New.restype = ctypes.py_object
79         _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
80
81         def setFullScreenCapable(frame):
82                 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
83
84                 NSWindowCollectionBehaviorFullScreenPrimary = 1<<7
85                 window = frameobj.window()
86                 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
87                 window.setCollectionBehavior_(newBehavior)
88
89 else:
90         def setFullScreenCapable(frame):
91                 pass