From 870d4fd96f619447452cd08a0d522bdb58503514 Mon Sep 17 00:00:00 2001 From: daid Date: Fri, 13 Apr 2012 18:14:38 +0200 Subject: [PATCH] Seperate print interface into a different process. --- Cura/cura.py | 6 ++++++ Cura/gui/printWindow.py | 45 ++++++++++++++++++++++++++++++++++------- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Cura/cura.py b/Cura/cura.py index 2d2d7e43..b65ac355 100644 --- a/Cura/cura.py +++ b/Cura/cura.py @@ -46,9 +46,15 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp def main(): parser = OptionParser(usage="usage: %prog [options] .stl") parser.add_option("-p", "--profile", action="store", type="string", dest="profile", help="Use these profile settings instead of loading current_profile.ini") + parser.add_option("-r", "--print", action="store", type="string", dest="printfile", help="Open the printing interface, instead of the normal cura interface.") (options, args) = parser.parse_args() if options.profile != None: profile.loadGlobalProfileFromString(options.profile) + if options.printfile != None: + from gui import printWindow + printWindow.startPrintInterface(options.printfile) + return + if len( args ) > 0: sliceRun.runSlice(args) else: diff --git a/Cura/gui/printWindow.py b/Cura/gui/printWindow.py index a7f2770a..96538271 100644 --- a/Cura/gui/printWindow.py +++ b/Cura/gui/printWindow.py @@ -1,23 +1,54 @@ from __future__ import absolute_import import __init__ -import wx, threading, re +import wx, threading, re, subprocess, sys from gui import machineCom from gui import icon from util import profile from util import gcodeInterpreter -printWindowHandle = None +printWindowMonitorHandle = None def printFile(filename): - global printWindowHandle - if printWindowHandle == None: - printWindowHandle = printWindow() - printWindowHandle.OnConnect(None) + global printWindowMonitorHandle + if printWindowMonitorHandle == 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 seperate process. + # It needs to run in a seperate process, as any running python code blocks the GCode sender pyton code (http://wiki.python.org/moin/GlobalInterpreterLock). + app = wx.App(False) + printWindowHandle = printWindow() printWindowHandle.Show(True) printWindowHandle.Raise() + printWindowHandle.OnConnect(None) printWindowHandle.LoadGCodeFile(filename) + app.MainLoop() + +class printProcessMonitor(): + def __init__(self): + self.handle = None + + def loadFile(self, filename): + if self.handle == None: + self.handle = subprocess.Popen([sys.executable, sys.argv[0], '-r', filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + self.thread = threading.Thread(target=self.Monitor) + self.thread.start() + else: + self.handle.stdin.write(filename + '\n') + + def Monitor(self): + p = self.handle + line = p.stdout.readline() + while(len(line) > 0): + print line.rstrip() + line = p.stdout.readline() + p.wait() + self.handle = None + self.thread = None class printWindow(wx.Frame): "Main user interface window" @@ -110,8 +141,8 @@ class printWindow(wx.Frame): if self.gcodeList != None: status += 'Line: -/%d\n' % (len(self.gcodeList)) else: - self.progress.SetValue(self.printIdx) status += 'Line: %d/%d\n' % (self.printIdx, len(self.gcodeList)) + self.progress.SetValue(self.printIdx) if self.temp != None: status += 'Temp: %d\n' % (self.temp) self.statsText.SetLabel(status.strip()) -- 2.30.2