chiark / gitweb /
Remove the start/end code tab for UltiGCode flavor.
[cura.git] / Cura / gui / app.py
1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
3
4 import sys
5 import os
6 import platform
7 import shutil
8 import glob
9 import warnings
10
11 #Only import the _core to save import time
12 import wx._core
13
14
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')
19                 else:
20                         super(CuraApp, self).__init__(redirect=False)
21
22                 self.mainWindow = None
23                 self.splash = None
24                 self.loadFiles = files
25
26                 if sys.platform.startswith('darwin'):
27                         #Do not show a splashscreen on OSX, as by Apple guidelines
28                         self.afterSplashCallback()
29                 else:
30                         from Cura.gui import splashScreen
31                         self.splash = splashScreen.splashScreen(self.afterSplashCallback)
32
33         def MacOpenFile(self, path):
34                 try:
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)))
38
39         def afterSplashCallback(self):
40                 #These imports take most of the time and thus should be done after showing the splashscreen
41                 import webbrowser
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
47
48                 #If we do not have preferences yet, try to load it from a previous Cura install
49                 if profile.getPreference('machine_type') == 'unknown':
50                         try:
51                                 otherCuraInstalls = profile.getAlternativeBasePaths()
52                                 otherCuraInstalls.sort()
53                                 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
54                                 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
55                         except:
56                                 print sys.exc_info()
57
58                 #If we haven't run it before, run the configuration wizard.
59                 if profile.getPreference('machine_type') == 'unknown':
60                         if platform.system() == "Windows":
61                                 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
62                         else:
63                                 #Check if we need to copy our examples
64                                 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
65                                 if not os.path.isfile(exampleFile):
66                                         try:
67                                                 os.makedirs(os.path.dirname(exampleFile))
68                                         except:
69                                                 pass
70                                         for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
71                                                 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
72                         self.loadFiles = [exampleFile]
73                         if self.splash is not None:
74                                 self.splash.Show(False)
75                         configWizard.configWizard()
76
77                 if profile.getPreference('check_for_updates') == 'True':
78                         newVersion = version.checkForNewerVersion()
79                         if newVersion is not None:
80                                 if self.splash is not None:
81                                         self.splash.Show(False)
82                                 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:
83                                         webbrowser.open(newVersion)
84                                         return
85                 self.mainWindow = mainWindow.mainWindow()
86                 if self.splash is not None:
87                         self.splash.Show(False)
88                 self.mainWindow.Show()
89                 self.mainWindow.OnDropFiles(self.loadFiles)
90
91                 setFullScreenCapable(self.mainWindow)
92
93 if platform.system() == "Darwin":
94         import ctypes, objc
95         _objc = ctypes.PyDLL(objc._objc.__file__)
96
97         # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
98         _objc.PyObjCObject_New.restype = ctypes.py_object
99         _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
100
101         def setFullScreenCapable(frame):
102                 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
103
104                 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
105                 window = frameobj.window()
106                 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
107                 window.setCollectionBehavior_(newBehavior)
108
109 else:
110         def setFullScreenCapable(frame):
111                 pass