From c0fd5bf851357dd2fbdedd7fe523ce2b3348ae04 Mon Sep 17 00:00:00 2001 From: Jeremy Wright Date: Mon, 29 Dec 2014 23:36:27 -0500 Subject: [PATCH] Redirected stdout so that the print statement will work within FreeCAD. --- CadQuery/Gui/__init__.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CadQuery/Gui/__init__.py b/CadQuery/Gui/__init__.py index 8b13789..11454d3 100644 --- a/CadQuery/Gui/__init__.py +++ b/CadQuery/Gui/__init__.py @@ -1 +1,18 @@ +class PrintHook: + def __init__(self): + import sys + self.origOut = None + sys.stdout = self + self.origOut = sys.__stdout__ + + def write(self, text): + import FreeCAD + + FreeCAD.Console.PrintMessage(text) + + #pass all other methods to __stdout__ so that we don't have to override them + def __getattr__(self, name): + return self.origOut.__getattr__(name) + +PrintHook()