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('win') and len(files) > 0:
27 #Check for an already running instance, if another instance is running load files in there
28 from Cura.util import version
29 from ctypes import windll
34 other_hwnd = windll.user32.FindWindowA(None, ctypes.c_char_p('Cura - ' + version.getVersion()))
35 portNr = 0xCA00 + sum(map(ord, version.getVersion(False)))
37 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
38 sock.sendto('\0'.join(files), ("127.0.0.1", portNr))
40 windll.user32.SetForegroundWindow(other_hwnd)
43 socketListener = threading.Thread(target=self.Win32SocketListener, args=(portNr,))
44 socketListener.daemon = True
45 socketListener.start()
47 if sys.platform.startswith('darwin'):
48 #Do not show a splashscreen on OSX, as by Apple guidelines
49 self.afterSplashCallback()
51 from Cura.gui import splashScreen
52 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
54 def MacOpenFile(self, path):
56 self.mainWindow.OnDropFiles([path])
57 except Exception as e:
58 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
60 def Win32SocketListener(self, port):
62 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
63 sock.bind(("127.0.0.1", port))
65 data, addr = sock.recvfrom(2048)
66 self.mainWindow.OnDropFiles(data.split('\0'))
68 def afterSplashCallback(self):
69 #These imports take most of the time and thus should be done after showing the splashscreen
71 from Cura.gui import mainWindow
72 from Cura.gui import configWizard
73 from Cura.util import profile
74 from Cura.util import resources
75 from Cura.util import version
77 resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _
79 #If we do not have preferences yet, try to load it from a previous Cura install
80 if profile.getMachineSetting('machine_type') == 'unknown':
82 otherCuraInstalls = profile.getAlternativeBasePaths()
83 otherCuraInstalls.sort()
84 if len(otherCuraInstalls) > 0:
85 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
86 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
89 print traceback.print_exc()
91 #If we haven't run it before, run the configuration wizard.
92 if profile.getMachineSetting('machine_type') == 'unknown':
93 if platform.system() == "Windows":
94 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
96 #Check if we need to copy our examples
97 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
98 if not os.path.isfile(exampleFile):
100 os.makedirs(os.path.dirname(exampleFile))
103 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
104 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
105 self.loadFiles = [exampleFile]
106 if self.splash is not None:
107 self.splash.Show(False)
108 configWizard.configWizard()
110 if profile.getPreference('check_for_updates') == 'True':
111 newVersion = version.checkForNewerVersion()
112 if newVersion is not None:
113 if self.splash is not None:
114 self.splash.Show(False)
115 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:
116 webbrowser.open(newVersion)
118 if profile.getMachineSetting('machine_name') == '':
120 self.mainWindow = mainWindow.mainWindow()
121 if self.splash is not None:
122 self.splash.Show(False)
123 self.mainWindow.Show()
124 self.mainWindow.OnDropFiles(self.loadFiles)
126 setFullScreenCapable(self.mainWindow)
128 if platform.system() == "Darwin":
131 _objc = ctypes.PyDLL(objc._objc.__file__)
133 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
134 _objc.PyObjCObject_New.restype = ctypes.py_object
135 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
137 def setFullScreenCapable(frame):
138 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
140 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
141 window = frameobj.window()
142 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
143 window.setCollectionBehavior_(newBehavior)
145 def setFullScreenCapable(frame):
149 def setFullScreenCapable(frame):