chiark / gitweb /
Revert the multiprocessing, as multiprocessing with wxPython does not work for MacOS
authordaid303 <daid303@gmail.com>
Wed, 2 Jan 2013 12:46:02 +0000 (13:46 +0100)
committerdaid303 <daid303@gmail.com>
Wed, 2 Jan 2013 12:46:02 +0000 (13:46 +0100)
Cura/cura.py
Cura/gui/printWindow.py

index 3008bc8022259c9dfa0e254f11e2a52c5897ab50..07b901c1c9b4999d055fe7334f303a253b47118a 100644 (file)
@@ -11,7 +11,6 @@ The slicing code is the same as Skeinforge. But the UI has been revamped to be..
 from __future__ import absolute_import
 
 from optparse import OptionParser
-from multiprocessing import freeze_support
 
 from Cura.util import profile
 
@@ -76,5 +75,4 @@ def main():
                app.CuraApp().MainLoop()
 
 if __name__ == '__main__':
-       freeze_support()
        main()
index 728983d918c5cf708b56c8aece2fed6a0d7933c9..f7f3c88ce2b7af49d7121cc1a9698b87de754466 100644 (file)
@@ -4,7 +4,6 @@ from __future__ import absolute_import
 import threading
 import re
 import subprocess
-import multiprocessing
 import sys
 import time
 import platform
@@ -29,11 +28,11 @@ def printFile(filename):
        printWindowMonitorHandle.loadFile(filename)
 
 
-def startPrintInterface(filename, queue):
-       #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).
+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(queue)
+       printWindowHandle = printWindow()
        printWindowHandle.Show(True)
        printWindowHandle.Raise()
        printWindowHandle.OnConnect(None)
@@ -45,16 +44,36 @@ def startPrintInterface(filename, queue):
 class printProcessMonitor():
        def __init__(self):
                self.handle = None
-               self.queue = multiprocessing.Queue()
 
        def loadFile(self, filename):
-               if self.handle is None or not self.handle.is_alive():
-                       if self.handle is not None:
-                               self.handle.join()
-                       self.handle = multiprocessing.Process(target=startPrintInterface, args=(filename, self.queue))
-                       self.handle.start()
+               if self.handle is None:
+                       if platform.system() == "Darwin" and hasattr(sys, 'frozen'):
+                               cmdList = [os.path.join(os.path.dirname(sys.executable), 'Cura')] 
+                       else:
+                               cmdList = [sys.executable, '-m', 'Cura.cura']
+                       cmdList.append('-r')
+                       cmdList.append(filename)
+                       if platform.system() == "Darwin":
+                               if platform.machine() == 'i386':
+                                       cmdList.insert(0, 'arch')
+                                       cmdList.insert(1, '-i386')
+                       self.handle = subprocess.Popen(cmdList, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+                               stderr=subprocess.PIPE)
+                       self.thread = threading.Thread(target=self.Monitor)
+                       self.thread.start()
                else:
-                       self.queue.put(filename)
+                       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.communicate()
+               self.handle = None
+               self.thread = None
+
 
 class PrintCommandButton(buttons.GenBitmapButton):
        def __init__(self, parent, commandList, bitmapFilename, size=(20, 20)):
@@ -80,7 +99,7 @@ class PrintCommandButton(buttons.GenBitmapButton):
 class printWindow(wx.Frame):
        "Main user interface window"
 
-       def __init__(self, queue):
+       def __init__(self):
                super(printWindow, self).__init__(None, -1, title='Printing')
                self.machineCom = None
                self.gcode = None
@@ -97,7 +116,6 @@ class printWindow(wx.Frame):
                self.pause = False
                self.termHistory = []
                self.termHistoryIdx = 0
-               self.filenameQueue = queue
 
                self.cam = None
                if webcam.hasWebcamSupport():
@@ -320,16 +338,7 @@ class printWindow(wx.Frame):
 
                self.UpdateButtonStates()
 
-               t = threading.Thread(target=self._readQueue)
-               t.daemon = True
-               t.start()
-
-       def _readQueue(self):
-               while True:
-                       filename = self.filenameQueue.get()
-                       while self.machineCom is not None and self.machineCom.isPrinting():
-                               time.sleep(1)
-                       self.LoadGCodeFile(filename)
+       #self.UpdateProgress()
 
        def OnCameraTimer(self, e):
                if not self.campreviewEnable.GetValue():