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'):
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 portNr = 0xCA00 + sum(map(ord, version.getVersion(False)))
37 other_hwnd = windll.user32.FindWindowA(None, ctypes.c_char_p('Cura - ' + version.getVersion()))
39 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
40 sock.sendto('\0'.join(files), ("127.0.0.1", portNr))
42 windll.user32.SetForegroundWindow(other_hwnd)
47 socketListener = threading.Thread(target=self.Win32SocketListener, args=(portNr,))
48 socketListener.daemon = True
49 socketListener.start()
51 if sys.platform.startswith('darwin'):
52 #Do not show a splashscreen on OSX, as by Apple guidelines
53 self.afterSplashCallback()
55 from Cura.gui import splashScreen
56 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
58 def MacOpenFile(self, path):
60 self.mainWindow.OnDropFiles([path])
61 except Exception as e:
62 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
64 def Win32SocketListener(self, port):
67 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
68 sock.bind(("127.0.0.1", port))
70 data, addr = sock.recvfrom(2048)
71 self.mainWindow.OnDropFiles(data.split('\0'))
75 def afterSplashCallback(self):
76 #These imports take most of the time and thus should be done after showing the splashscreen
78 from Cura.gui import mainWindow
79 from Cura.gui import configWizard
80 from Cura.gui import newVersionDialog
81 from Cura.util import profile
82 from Cura.util import resources
83 from Cura.util import version
85 resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _
87 #If we do not have preferences yet, try to load it from a previous Cura install
88 if profile.getMachineSetting('machine_type') == 'unknown':
90 otherCuraInstalls = profile.getAlternativeBasePaths()
91 otherCuraInstalls.sort()
92 if len(otherCuraInstalls) > 0:
93 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
94 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
97 print traceback.print_exc()
99 #If we haven't run it before, run the configuration wizard.
100 if profile.getMachineSetting('machine_type') == 'unknown':
101 if platform.system() == "Windows":
102 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
104 #Check if we need to copy our examples
105 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
106 if not os.path.isfile(exampleFile):
108 os.makedirs(os.path.dirname(exampleFile))
111 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
112 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
113 self.loadFiles = [exampleFile]
114 if self.splash is not None:
115 self.splash.Show(False)
116 configWizard.configWizard()
118 if profile.getPreference('check_for_updates') == 'True':
119 newVersion = version.checkForNewerVersion()
120 if newVersion is not None:
121 if self.splash is not None:
122 self.splash.Show(False)
123 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:
124 webbrowser.open(newVersion)
126 if profile.getMachineSetting('machine_name') == '':
128 self.mainWindow = mainWindow.mainWindow()
129 if self.splash is not None:
130 self.splash.Show(False)
131 self.mainWindow.Show()
132 self.mainWindow.OnDropFiles(self.loadFiles)
133 if profile.getPreference('last_run_version') != version.getVersion(False):
134 profile.putPreference('last_run_version', version.getVersion(False))
135 newVersionDialog.newVersionDialog().Show()
137 setFullScreenCapable(self.mainWindow)
139 if platform.system() == "Darwin":
142 _objc = ctypes.PyDLL(objc._objc.__file__)
144 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
145 _objc.PyObjCObject_New.restype = ctypes.py_object
146 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
148 def setFullScreenCapable(frame):
149 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
151 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
152 window = frameobj.window()
153 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
154 window.setCollectionBehavior_(newBehavior)
156 def setFullScreenCapable(frame):
160 def setFullScreenCapable(frame):