chiark / gitweb /
Make a single entry point for the GUI interface, as Cura.gui.app
[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.gui import splashScreen
14 from Cura.util import profile
15
16 class CuraApp(wx.App):
17         def __init__(self):
18                 if platform.system() == "Windows":
19                         super(CuraApp, self).__init__(redirect = True, filename = 'output.txt')
20                 else:
21                         super(CuraApp, self).__init__(redirect = False)
22
23                 self.mainWindow = None
24                 self.splash = None
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                         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()