Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Edwards <s.edwards@ultimaker.com>2017-02-02 17:59:09 +0300
committerSimon Edwards <s.edwards@ultimaker.com>2017-02-02 17:59:09 +0300
commit0e306df1bcc0c0e6126530a28a498073be85898c (patch)
treedb3c246bef8babeca36e899ddfb5182e0aa75f80 /cura_app.py
parent9cf0fdc4a3cd16e2ab2df86ea2c3539c92fbcea9 (diff)
Initial basic version of this feature.
CURA-3335
Diffstat (limited to 'cura_app.py')
-rwxr-xr-xcura_app.py36
1 files changed, 35 insertions, 1 deletions
diff --git a/cura_app.py b/cura_app.py
index 5c3ea811b5..c2ee6a72b1 100755
--- a/cura_app.py
+++ b/cura_app.py
@@ -2,11 +2,14 @@
# Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher.
-
+import argparse
+import json
import os
import sys
import platform
+import time
+from PyQt5.QtNetwork import QLocalSocket
from UM.Platform import Platform
#WORKAROUND: GITHUB-88 GITHUB-385 GITHUB-612
@@ -58,5 +61,36 @@ if Platform.isWindows() and hasattr(sys, "frozen"):
# Force an instance of CuraContainerRegistry to be created and reused later.
cura.Settings.CuraContainerRegistry.getInstance()
+# Peek the arguments and look for the 'single-instance' flag.
+parser = argparse.ArgumentParser(prog="cura") # pylint: disable=bad-whitespace
+cura.CuraApplication.CuraApplication.addCommandLineOptions(parser)
+parsed_command_line = vars(parser.parse_args())
+
+if "single_instance" in parsed_command_line and parsed_command_line["single_instance"]:
+ print("Check for single instance")
+ single_instance_socket = QLocalSocket()
+ single_instance_socket.connectToServer("ultimaker-cura")
+ single_instance_socket.waitForConnected()
+ if single_instance_socket.state() == QLocalSocket.ConnectedState:
+ print("Connected to the other Cura instance.")
+ print(repr(parsed_command_line))
+
+ payload = {"command": "clear-all"}
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII"))
+
+ payload = {"command": "focus"}
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII"))
+
+ if len(parsed_command_line["file"]) != 0:
+ for filename in parsed_command_line["file"]:
+ payload = { "command": "open", "filePath": filename }
+ single_instance_socket.write(bytes(json.dumps(payload) + "\n", encoding="ASCII"))
+
+ single_instance_socket.flush()
+
+
+ single_instance_socket.close()
+ sys.exit(0)
+
app = cura.CuraApplication.CuraApplication.getInstance()
app.run()