chiark / gitweb /
Seperate print interface into a different process.
authordaid <daid303@gmail.com>
Fri, 13 Apr 2012 16:14:38 +0000 (18:14 +0200)
committerdaid <daid303@gmail.com>
Fri, 13 Apr 2012 16:14:38 +0000 (18:14 +0200)
Cura/cura.py
Cura/gui/printWindow.py

index 2d2d7e43eb94552ed0d0f93b60732e9ed4f4c5e3..b65ac355aefd7f73c0467cb9c4b014319f0348e1 100644 (file)
@@ -46,9 +46,15 @@ __license__ = 'GNU Affero General Public License http://www.gnu.org/licenses/agp
 def main():
        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("-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:
index a7f2770a91c880263bed0a5b3aeb827d83a3c678..96538271f795fe0d6a281233dd5e91d67d95795a 100644 (file)
@@ -1,23 +1,54 @@
 from __future__ import absolute_import\r
 import __init__\r
 \r
-import wx, threading, re\r
+import wx, threading, re, subprocess, sys\r
 \r
 from gui import machineCom\r
 from gui import icon\r
 from util import profile\r
 from util import gcodeInterpreter\r
 \r
-printWindowHandle = None\r
+printWindowMonitorHandle = None\r
 \r
 def printFile(filename):\r
-       global printWindowHandle\r
-       if printWindowHandle == None:\r
-               printWindowHandle = printWindow()\r
-               printWindowHandle.OnConnect(None)\r
+       global printWindowMonitorHandle\r
+       if printWindowMonitorHandle == None:\r
+               printWindowMonitorHandle = printProcessMonitor()\r
+       printWindowMonitorHandle.loadFile(filename)\r
+\r
+\r
+def startPrintInterface(filename):\r
+       #startPrintInterface is called from the main script when we want the printer interface to run in a seperate process.\r
+       # 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).\r
+       app = wx.App(False)\r
+       printWindowHandle = printWindow()\r
        printWindowHandle.Show(True)\r
        printWindowHandle.Raise()\r
+       printWindowHandle.OnConnect(None)\r
        printWindowHandle.LoadGCodeFile(filename)\r
+       app.MainLoop()\r
+\r
+class printProcessMonitor():\r
+       def __init__(self):\r
+               self.handle = None\r
+       \r
+       def loadFile(self, filename):\r
+               if self.handle == None:\r
+                       self.handle = subprocess.Popen([sys.executable, sys.argv[0], '-r', filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)\r
+                       self.thread = threading.Thread(target=self.Monitor)\r
+                       self.thread.start()\r
+               else:\r
+                       self.handle.stdin.write(filename + '\n')\r
+       \r
+       def Monitor(self):\r
+               p = self.handle\r
+               line = p.stdout.readline()\r
+               while(len(line) > 0):\r
+                       print line.rstrip()\r
+                       line = p.stdout.readline()\r
+               p.wait()\r
+               self.handle = None\r
+               self.thread = None\r
 \r
 class printWindow(wx.Frame):\r
        "Main user interface window"\r
@@ -110,8 +141,8 @@ class printWindow(wx.Frame):
                        if self.gcodeList != None:\r
                                status += 'Line: -/%d\n' % (len(self.gcodeList))\r
                else:\r
-                       self.progress.SetValue(self.printIdx)\r
                        status += 'Line: %d/%d\n' % (self.printIdx, len(self.gcodeList))\r
+                       self.progress.SetValue(self.printIdx)\r
                if self.temp != None:\r
                        status += 'Temp: %d\n' % (self.temp)\r
                self.statsText.SetLabel(status.strip())\r