mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-08-06 08:06:05 +08:00
Seperate print interface into a different process.
This commit is contained in:
parent
5994267b29
commit
870d4fd96f
@ -46,9 +46,15 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
|
|||||||
def main():
|
def main():
|
||||||
parser = OptionParser(usage="usage: %prog [options] <filename>.stl")
|
parser = OptionParser(usage="usage: %prog [options] <filename>.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("-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()
|
(options, args) = parser.parse_args()
|
||||||
if options.profile != None:
|
if options.profile != None:
|
||||||
profile.loadGlobalProfileFromString(options.profile)
|
profile.loadGlobalProfileFromString(options.profile)
|
||||||
|
if options.printfile != None:
|
||||||
|
from gui import printWindow
|
||||||
|
printWindow.startPrintInterface(options.printfile)
|
||||||
|
return
|
||||||
|
|
||||||
if len( args ) > 0:
|
if len( args ) > 0:
|
||||||
sliceRun.runSlice(args)
|
sliceRun.runSlice(args)
|
||||||
else:
|
else:
|
||||||
|
@ -1,23 +1,54 @@
|
|||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
import __init__
|
import __init__
|
||||||
|
|
||||||
import wx, threading, re
|
import wx, threading, re, subprocess, sys
|
||||||
|
|
||||||
from gui import machineCom
|
from gui import machineCom
|
||||||
from gui import icon
|
from gui import icon
|
||||||
from util import profile
|
from util import profile
|
||||||
from util import gcodeInterpreter
|
from util import gcodeInterpreter
|
||||||
|
|
||||||
printWindowHandle = None
|
printWindowMonitorHandle = None
|
||||||
|
|
||||||
def printFile(filename):
|
def printFile(filename):
|
||||||
global printWindowHandle
|
global printWindowMonitorHandle
|
||||||
if printWindowHandle == None:
|
if printWindowMonitorHandle == None:
|
||||||
printWindowHandle = printWindow()
|
printWindowMonitorHandle = printProcessMonitor()
|
||||||
printWindowHandle.OnConnect(None)
|
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.Show(True)
|
||||||
printWindowHandle.Raise()
|
printWindowHandle.Raise()
|
||||||
|
printWindowHandle.OnConnect(None)
|
||||||
printWindowHandle.LoadGCodeFile(filename)
|
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):
|
class printWindow(wx.Frame):
|
||||||
"Main user interface window"
|
"Main user interface window"
|
||||||
@ -110,8 +141,8 @@ class printWindow(wx.Frame):
|
|||||||
if self.gcodeList != None:
|
if self.gcodeList != None:
|
||||||
status += 'Line: -/%d\n' % (len(self.gcodeList))
|
status += 'Line: -/%d\n' % (len(self.gcodeList))
|
||||||
else:
|
else:
|
||||||
self.progress.SetValue(self.printIdx)
|
|
||||||
status += 'Line: %d/%d\n' % (self.printIdx, len(self.gcodeList))
|
status += 'Line: %d/%d\n' % (self.printIdx, len(self.gcodeList))
|
||||||
|
self.progress.SetValue(self.printIdx)
|
||||||
if self.temp != None:
|
if self.temp != None:
|
||||||
status += 'Temp: %d\n' % (self.temp)
|
status += 'Temp: %d\n' % (self.temp)
|
||||||
self.statsText.SetLabel(status.strip())
|
self.statsText.SetLabel(status.strip())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user