chiark / gitweb /
added comments
[cura.git] / Cura / gui / app.py
index e557c2eca61b2e10a3eea9e5e6143afd5962e23a..fd5fbc04097186e79f1b5d275e4026a56576dc92 100644 (file)
@@ -1,4 +1,3 @@
-from __future__ import absolute_import
 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
 
 import sys
@@ -22,8 +21,8 @@ class CuraApp(wx.App):
                self.mainWindow = None
                self.splash = None
                self.loadFiles = files
-               
-               if sys.platform.startswith('win') and len(files) > 0:
+
+               if sys.platform.startswith('win'):
                        #Check for an already running instance, if another instance is running load files in there
                        from Cura.util import version
                        from ctypes import windll
@@ -31,14 +30,18 @@ class CuraApp(wx.App):
                        import socket
                        import threading
 
-                       other_hwnd = windll.user32.FindWindowA(None, ctypes.c_char_p('Cura - ' + version.getVersion()))
                        portNr = 0xCA00 + sum(map(ord, version.getVersion(False)))
-                       if other_hwnd != 0:
-                               sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-                               sock.sendto('\0'.join(files), ("127.0.0.1", portNr))
-
-                               windll.user32.SetForegroundWindow(other_hwnd)
-                               return
+                       if len(files) > 0:
+                               try:
+                                       other_hwnd = windll.user32.FindWindowA(None, ctypes.c_char_p('Cura - ' + version.getVersion()))
+                                       if other_hwnd != 0:
+                                               sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+                                               sock.sendto('\0'.join(files), ("127.0.0.1", portNr))
+
+                                               windll.user32.SetForegroundWindow(other_hwnd)
+                                               return
+                               except:
+                                       pass
 
                        socketListener = threading.Thread(target=self.Win32SocketListener, args=(portNr,))
                        socketListener.daemon = True
@@ -59,17 +62,21 @@ class CuraApp(wx.App):
 
        def Win32SocketListener(self, port):
                import socket
-               sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
-               sock.bind(("127.0.0.1", port))
-               while True:
-                       data, addr = sock.recvfrom(2048)
-                       self.mainWindow.OnDropFiles(data.split('\0'))
+               try:
+                       sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+                       sock.bind(("127.0.0.1", port))
+                       while True:
+                               data, addr = sock.recvfrom(2048)
+                               self.mainWindow.OnDropFiles(data.split('\0'))
+               except:
+                       pass
 
        def afterSplashCallback(self):
                #These imports take most of the time and thus should be done after showing the splashscreen
                import webbrowser
                from Cura.gui import mainWindow
                from Cura.gui import configWizard
+               from Cura.gui import newVersionDialog
                from Cura.util import profile
                from Cura.util import resources
                from Cura.util import version
@@ -122,10 +129,13 @@ class CuraApp(wx.App):
                        self.splash.Show(False)
                self.mainWindow.Show()
                self.mainWindow.OnDropFiles(self.loadFiles)
+               if profile.getPreference('last_run_version') != version.getVersion(False):
+                       profile.putPreference('last_run_version', version.getVersion(False))
+                       newVersionDialog.newVersionDialog().Show()
 
                setFullScreenCapable(self.mainWindow)
 
-if platform.system() == "Darwin":
+if platform.system() == "Darwin": #Mac magic. Dragons live here. THis sets full screen options.
        try:
                import ctypes, objc
                _objc = ctypes.PyDLL(objc._objc.__file__)