chiark / gitweb /
Use an alternative method to check for wxPython if distutils is not available
[cura.git] / Cura / serialCommunication.py
index cf6a0aec0079f8120f7c63ca650f46994dab46e0..1b095484a5477bcc5295aec0f1970fc2f871caeb 100644 (file)
@@ -48,12 +48,17 @@ class serialComm(object):
                sys.stdout.write('progress:%d\n' % (lineNr))
 
        def mcZChange(self, newZ):
-               pass
+               sys.stdout.write('changeZ:%f\n' % (newZ))
 
        def monitorStdin(self):
-               while not self._comm.isClosed():
-                       line = sys.stdin.readline().strip()
-                       line = line.split(':', 1)
+               while not (self._comm.isClosed() or sys.stdin.closed):
+                       line = sys.stdin.readline()
+                        # If readline returns an empty string it means that
+                        # we've hit stdin's EOF, probably because the parent was
+                        # closed, so we need to exit as well instead of spamming stderr.
+                        if line == '':
+                                break
+                       line = line.strip().split(':', 1)
                        if line[0] == 'STOP':
                                self._comm.cancelPrint()
                                self._gcodeList = ['M110']
@@ -63,6 +68,10 @@ class serialComm(object):
                                self._comm.sendCommand(line[1])
                        elif line[0] == 'START':
                                self._comm.printGCode(self._gcodeList)
+                       elif line[0] == 'PAUSE':
+                               self._comm.setPause(True)
+                       elif line[0] == 'RESUME':
+                               self._comm.setPause(False)
                        else:
                                sys.stderr.write(str(line))
 
@@ -72,7 +81,7 @@ def startMonitor(portName, baudrate):
        thread = threading.Thread(target=comm.monitorStdin)
        thread.start()
        while thread.is_alive():
-               time.sleep(0)
+               time.sleep(0.1)
 
 def main():
        if len(sys.argv) != 3: