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.gui import newVersionDialog
74 from Cura.util import profile
75 from Cura.util import resources
76 from Cura.util import version
78 resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _
80 #If we do not have preferences yet, try to load it from a previous Cura install
81 if profile.getMachineSetting('machine_type') == 'unknown':
83 otherCuraInstalls = profile.getAlternativeBasePaths()
84 otherCuraInstalls.sort()
85 if len(otherCuraInstalls) > 0:
86 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
87 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
90 print traceback.print_exc()
92 #If we haven't run it before, run the configuration wizard.
93 if profile.getMachineSetting('machine_type') == 'unknown':
94 if platform.system() == "Windows":
95 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
97 #Check if we need to copy our examples
98 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
99 if not os.path.isfile(exampleFile):
101 os.makedirs(os.path.dirname(exampleFile))
104 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
105 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
106 self.loadFiles = [exampleFile]
107 if self.splash is not None:
108 self.splash.Show(False)
109 configWizard.configWizard()
111 if profile.getPreference('check_for_updates') == 'True':
112 newVersion = version.checkForNewerVersion()
113 if newVersion is not None:
114 if self.splash is not None:
115 self.splash.Show(False)
116 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:
117 webbrowser.open(newVersion)
119 if profile.getMachineSetting('machine_name') == '':
121 self.mainWindow = mainWindow.mainWindow()
122 if self.splash is not None:
123 self.splash.Show(False)
124 self.mainWindow.Show()
125 self.mainWindow.OnDropFiles(self.loadFiles)
126 if profile.getPreference('last_run_version') != version.getVersion(False):
127 profile.putPreference('last_run_version', version.getVersion(False))
128 newVersionDialog.newVersionDialog().Show()
130 setFullScreenCapable(self.mainWindow)
132 if platform.system() == "Darwin":
135 _objc = ctypes.PyDLL(objc._objc.__file__)
137 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
138 _objc.PyObjCObject_New.restype = ctypes.py_object
139 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
141 def setFullScreenCapable(frame):
142 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
144 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
145 window = frameobj.window()
146 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
147 window.setCollectionBehavior_(newBehavior)
149 def setFullScreenCapable(frame):
153 def setFullScreenCapable(frame):