chiark / gitweb /
Do not import splashScreen when platform is darwin.
[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 from Cura.util import profile
14
15 class CuraApp(wx.App):
16         def __init__(self):
17                 if platform.system() == "Windows":
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
25                 if sys.platform.startswith('darwin'):
26                         #Do not show a splashscreen on OSX, as by Apple guidelines
27                         self.afterSplashCallback()
28                 else:
29                         from Cura.gui import splashScreen
30                         self.splash = splashScreen.splashScreen(self.afterSplashCallback)
31
32         def MacOpenFile(self, path):
33                 try:
34                         self.mainWindow._loadModels([path])
35                 except Exception as e:
36                         warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
37
38         def afterSplashCallback(self):
39                 #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
43                 #If we haven't run it before, run the configuration wizard.
44                 if profile.getPreference('machine_type') == 'unknown':
45                         if platform.system() == "Darwin":
46                                 #Check if we need to copy our examples
47                                 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
48                                 if not os.path.isfile(exampleFile):
49                                         try:
50                                                 os.makedirs(os.path.dirname(exampleFile))
51                                         except:
52                                                 pass
53                                         for filename in glob.glob(os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'example', '*.*'))):
54                                                 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
55                                         profile.putPreference('lastFile', exampleFile)
56                         configWizard.configWizard()
57
58                 #Hide the splashscreen before showing the main window.
59                 if self.splash is not None:
60                         self.splash.Show(False)
61                 self.mainWindow = mainWindow.mainWindow()