From f7008ac97d30fed24171aecf82d286cc414625e2 Mon Sep 17 00:00:00 2001 From: daid Date: Fri, 28 Jun 2013 11:07:59 +0200 Subject: [PATCH] Improve USB printing window <-> main GUI communications. --- Cura/gui/printWindow.py | 55 ++++++++++++++++++++++++----------------- Cura/gui/sceneView.py | 3 ++- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index 4577052f..1a4818ba 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -20,31 +20,13 @@ from Cura.util import machineCom from Cura.util import gcodeInterpreter from Cura.util.resources import getPathForImage -printWindowMonitorHandle = None - -def printFile(filename): - global printWindowMonitorHandle - if printWindowMonitorHandle is None: - printWindowMonitorHandle = printProcessMonitor() - printWindowMonitorHandle.loadFile(filename) - - -def startPrintInterface(filename): - #startPrintInterface is called from the main script when we want the printer interface to run in a separate process. - # It needs to run in a separate process, as any running python code blocks the GCode sender python code (http://wiki.python.org/moin/GlobalInterpreterLock). - app = wx.App(False) - printWindowHandle = printWindow() - printWindowHandle.Show(True) - printWindowHandle.Raise() - printWindowHandle.OnConnect(None) - t = threading.Thread(target=printWindowHandle.LoadGCodeFile, args=(filename,)) - t.daemon = True - t.start() - app.MainLoop() - +#The printProcessMonitor is used from the main GUI python process. This monitors the printing python process. +# This class also handles starting of the 2nd process for printing and all communications with it. class printProcessMonitor(): def __init__(self): self.handle = None + self._state = 'CLOSED' + self._z = 0.0 def loadFile(self, filename): if self.handle is None: @@ -68,16 +50,36 @@ class printProcessMonitor(): p = self.handle line = p.stdout.readline() while len(line) > 0: + try: + if line.startswith('Z:'): + self._z = float(line[2:]) + elif line.startswith('STATE:'): + self._state = float(line[6:]) + except: + pass #print '>' + line.rstrip() line = p.stdout.readline() line = p.stderr.readline() while len(line) > 0: - #print '>>' + line.rstrip() + print '>>' + line.rstrip() line = p.stderr.readline() p.communicate() self.handle = None self.thread = None +def startPrintInterface(filename): + #startPrintInterface is called from the main script when we want the printer interface to run in a separate process. + # It needs to run in a separate process, as any running python code blocks the GCode sender python code (http://wiki.python.org/moin/GlobalInterpreterLock). + app = wx.App(False) + printWindowHandle = printWindow() + printWindowHandle.Show(True) + printWindowHandle.Raise() + printWindowHandle.OnConnect(None) + t = threading.Thread(target=printWindowHandle.LoadGCodeFile, args=(filename,)) + t.daemon = True + t.start() + app.MainLoop() + class PrintCommandButton(buttons.GenBitmapButton): def __init__(self, parent, commandList, bitmapFilename, size=(20, 20)): self.bitmap = wx.Bitmap(getPathForImage(bitmapFilename)) @@ -617,6 +619,12 @@ class printWindow(wx.Frame): taskbar.setBusy(self, False) if self.machineCom.isPaused(): taskbar.setPause(self, True) + if self.machineCom.isClosedOrError(): + print 'STATE:CLOSED' + elif self.machineCom.isPrinting(): + print 'STATE:PRINTING' + else: + print 'STATE:IDLE' wx.CallAfter(self.UpdateButtonStates) wx.CallAfter(self.UpdateProgress) @@ -628,6 +636,7 @@ class printWindow(wx.Frame): def mcZChange(self, newZ): self.currentZ = newZ + print 'Z:%f' % newZ if self.cam is not None: wx.CallAfter(self.cam.takeNewImage) wx.CallAfter(self.camPreview.Refresh) diff --git a/Cura/gui/sceneView.py b/Cura/gui/sceneView.py index ee4e1cb0..fa7c1ffa 100644 --- a/Cura/gui/sceneView.py +++ b/Cura/gui/sceneView.py @@ -53,6 +53,7 @@ class SceneView(openglGui.glGuiPanel): self._platformMesh = meshLoader.loadMeshes(resources.getPathForMesh('ultimaker_platform.stl'))[0] self._platformMesh._drawOffset = numpy.array([0,0,2.5], numpy.float32) self._isSimpleMode = True + self._usbPrintMonitor = printWindow.printProcessMonitor() self._viewport = None self._modelMatrix = None @@ -194,7 +195,7 @@ class SceneView(openglGui.glGuiPanel): def showPrintWindow(self): if self._gcodeFilename is None: return - printWindow.printFile(self._gcodeFilename) + self._usbPrintMonitor.loadFile(self._gcodeFilename) if self._gcodeFilename == self._slicer.getGCodeFilename(): self._slicer.submitSliceInfoOnline() -- 2.30.2