X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=Cura%2Fgui%2Fapp.py;h=e557c2eca61b2e10a3eea9e5e6143afd5962e23a;hb=7178ce11eb451ed2df188ee626d22a39b5cb317e;hp=3ef52ba21cbf6251209a2881d6471caeaf9b11eb;hpb=38e1927ba2df99fe98ef97c878b694598a9482c6;p=cura.git diff --git a/Cura/gui/app.py b/Cura/gui/app.py index 3ef52ba2..e557c2ec 100644 --- a/Cura/gui/app.py +++ b/Cura/gui/app.py @@ -22,6 +22,27 @@ class CuraApp(wx.App): self.mainWindow = None self.splash = None self.loadFiles = files + + if sys.platform.startswith('win') and len(files) > 0: + #Check for an already running instance, if another instance is running load files in there + from Cura.util import version + from ctypes import windll + import ctypes + 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 + + socketListener = threading.Thread(target=self.Win32SocketListener, args=(portNr,)) + socketListener.daemon = True + socketListener.start() if sys.platform.startswith('darwin'): #Do not show a splashscreen on OSX, as by Apple guidelines @@ -36,6 +57,14 @@ class CuraApp(wx.App): except Exception as e: warnings.warn("File at {p} cannot be read: {e}".format(p=path, e=str(e))) + 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')) + def afterSplashCallback(self): #These imports take most of the time and thus should be done after showing the splashscreen import webbrowser @@ -45,7 +74,7 @@ class CuraApp(wx.App): from Cura.util import resources from Cura.util import version - resources.setupLocalization() # it's important to set up localization at very beginning to install _ + resources.setupLocalization(profile.getPreference('language')) # it's important to set up localization at very beginning to install _ #If we do not have preferences yet, try to load it from a previous Cura install if profile.getMachineSetting('machine_type') == 'unknown':