1 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
10 #Only import the _core to save import time
14 class CuraApp(wx.App):
15 def __init__(self, files):
16 if platform.system() == "Windows" and not 'PYCHARM_HOSTED' in os.environ:
17 super(CuraApp, self).__init__(redirect=True, filename='output.txt')
19 super(CuraApp, self).__init__(redirect=False)
21 self.mainWindow = None
23 self.loadFiles = files
25 if sys.platform.startswith('win'):
26 #Check for an already running instance, if another instance is running load files in there
27 from Cura.util import version
28 from ctypes import windll
33 portNr = 0xCA00 + sum(map(ord, version.getVersion(False)))
36 other_hwnd = windll.user32.FindWindowA(None, ctypes.c_char_p('Cura - ' + version.getVersion()))
38 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
39 sock.sendto('\0'.join(files), ("127.0.0.1", portNr))
41 windll.user32.SetForegroundWindow(other_hwnd)
46 socketListener = threading.Thread(target=self.Win32SocketListener, args=(portNr,))
47 socketListener.daemon = True
48 socketListener.start()
50 if sys.platform.startswith('darwin'):
51 #Do not show a splashscreen on OSX, as by Apple guidelines
52 self.afterSplashCallback()
54 from Cura.gui import splashScreen
55 self.splash = splashScreen.splashScreen(self.afterSplashCallback)
57 def MacOpenFile(self, path):
59 self.mainWindow.OnDropFiles([path])
60 except Exception as e:
61 warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e)))
63 def Win32SocketListener(self, port):
66 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
67 sock.bind(("127.0.0.1", port))
69 data, addr = sock.recvfrom(2048)
70 self.mainWindow.OnDropFiles(data.split('\0'))
74 def afterSplashCallback(self):
75 #These imports take most of the time and thus should be done after showing the splashscreen
77 from Cura.gui import mainWindow
78 from Cura.gui import configWizard
79 from Cura.gui import newVersionDialog
80 from Cura.util import profile
81 from Cura.util import resources
82 from Cura.util import version
84 resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _
86 #If we do not have preferences yet, try to load it from a previous Cura install
87 if profile.getMachineSetting('machine_type') == 'unknown':
89 otherCuraInstalls = profile.getAlternativeBasePaths()
90 otherCuraInstalls.sort()
91 if len(otherCuraInstalls) > 0:
92 profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
93 profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
96 print traceback.print_exc()
98 #If we haven't run it before, run the configuration wizard.
99 if profile.getMachineSetting('machine_type') == 'unknown':
100 if platform.system() == "Windows":
101 exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
103 #Check if we need to copy our examples
104 exampleFile = os.path.expanduser('~/CuraExamples/UltimakerRobot_support.stl')
105 if not os.path.isfile(exampleFile):
107 os.makedirs(os.path.dirname(exampleFile))
110 for filename in glob.glob(os.path.normpath(os.path.join(resources.resourceBasePath, 'example', '*.*'))):
111 shutil.copy(filename, os.path.join(os.path.dirname(exampleFile), os.path.basename(filename)))
112 self.loadFiles = [exampleFile]
113 if self.splash is not None:
114 self.splash.Show(False)
115 configWizard.configWizard()
117 if profile.getPreference('check_for_updates') == 'True':
118 newVersion = version.checkForNewerVersion()
119 if newVersion is not None:
120 if self.splash is not None:
121 self.splash.Show(False)
122 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:
123 webbrowser.open(newVersion)
125 if profile.getMachineSetting('machine_name') == '':
127 self.mainWindow = mainWindow.mainWindow()
128 if self.splash is not None:
129 self.splash.Show(False)
130 self.mainWindow.Show()
131 self.mainWindow.OnDropFiles(self.loadFiles)
132 if profile.getPreference('last_run_version') != version.getVersion(False):
133 profile.putPreference('last_run_version', version.getVersion(False))
134 newVersionDialog.newVersionDialog().Show()
136 setFullScreenCapable(self.mainWindow)
138 if platform.system() == "Darwin": #Mac magic. Dragons live here. THis sets full screen options.
141 _objc = ctypes.PyDLL(objc._objc.__file__)
143 # PyObject *PyObjCObject_New(id objc_object, int flags, int retain)
144 _objc.PyObjCObject_New.restype = ctypes.py_object
145 _objc.PyObjCObject_New.argtypes = [ctypes.c_void_p, ctypes.c_int, ctypes.c_int]
147 def setFullScreenCapable(frame):
148 frameobj = _objc.PyObjCObject_New(frame.GetHandle(), 0, 1)
150 NSWindowCollectionBehaviorFullScreenPrimary = 1 << 7
151 window = frameobj.window()
152 newBehavior = window.collectionBehavior() | NSWindowCollectionBehaviorFullScreenPrimary
153 window.setCollectionBehavior_(newBehavior)
155 def setFullScreenCapable(frame):
159 def setFullScreenCapable(frame):