chiark / gitweb /
Change how the engine is interfaced from the python code. Put the GCode viewer in...
[cura.git] / Cura / gui / app.py
index 5ab0e28d7a2de944cb731596c4f1c9012733af9b..47932c60c5e163b1415a7f1536cd9a15ba8af560 100644 (file)
@@ -23,6 +23,31 @@ class CuraApp(wx.App):
                self.splash = None
                self.loadFiles = files
 
+               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
+                       import ctypes
+                       import socket
+                       import threading
+
+                       portNr = 0xCA00 + sum(map(ord, version.getVersion(False)))
+                       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
+                       socketListener.start()
+
                if sys.platform.startswith('darwin'):
                        #Do not show a splashscreen on OSX, as by Apple guidelines
                        self.afterSplashCallback()
@@ -36,27 +61,43 @@ 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
+               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
 
+               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.getPreference('machine_type') == 'unknown':
+               if profile.getMachineSetting('machine_type') == 'unknown':
                        try:
                                otherCuraInstalls = profile.getAlternativeBasePaths()
                                otherCuraInstalls.sort()
-                               profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
-                               profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
+                               if len(otherCuraInstalls) > 0:
+                                       profile.loadPreferences(os.path.join(otherCuraInstalls[-1], 'preferences.ini'))
+                                       profile.loadProfile(os.path.join(otherCuraInstalls[-1], 'current_profile.ini'))
                        except:
-                               print sys.exc_info()
+                               import traceback
+                               print traceback.print_exc()
 
                #If we haven't run it before, run the configuration wizard.
-               if profile.getPreference('machine_type') == 'unknown':
+               if profile.getMachineSetting('machine_type') == 'unknown':
                        if platform.system() == "Windows":
                                exampleFile = os.path.normpath(os.path.join(resources.resourceBasePath, 'example', 'UltimakerRobot_support.stl'))
                        else:
@@ -79,14 +120,19 @@ class CuraApp(wx.App):
                        if newVersion is not None:
                                if self.splash is not None:
                                        self.splash.Show(False)
-                               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:
+                               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:
                                        webbrowser.open(newVersion)
                                        return
+               if profile.getMachineSetting('machine_name') == '':
+                       return
                self.mainWindow = mainWindow.mainWindow()
                if self.splash is not None:
                        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)