From ba092d2fa9bdb2be5de509c7c4a22b55b0644a7c Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 24 Sep 2017 15:15:48 +0200 Subject: [PATCH] 0002303: 404 from auto-generated Help > Automatic python modules documentation --- src/Gui/OnlineDocumentation.cpp | 64 ++++++++++++++++--- src/Gui/OnlineDocumentation.h | 1 + src/Mod/Robot/RobotExample.py | 8 ++- .../RobotExampleTrajectoryOutOfShapes.py | 1 + src/Mod/Sketcher/SketcherExample.py | 1 + 5 files changed, 64 insertions(+), 11 deletions(-) diff --git a/src/Gui/OnlineDocumentation.cpp b/src/Gui/OnlineDocumentation.cpp index e87642b229..ac8c086be3 100644 --- a/src/Gui/OnlineDocumentation.cpp +++ b/src/Gui/OnlineDocumentation.cpp @@ -24,6 +24,7 @@ #include "PreCompiled.h" #ifndef _PreComp_ # include +# include # include # include #endif @@ -33,6 +34,8 @@ #include #include #include +#include +#include #include #include "MainWindow.h" @@ -83,10 +86,24 @@ QByteArray PythonOnlineHelp::loadResource(const QString& filename) const QByteArray res; if (fn == QLatin1String("favicon.ico")) { - // Return an resource icon in ico format - res.reserve(navicon_data_len); - for (int i=0; i<(int)navicon_data_len;i++) { - res[i] = navicon_data[i]; + // Return a resource icon in ico format + QBuffer buffer; + buffer.open(QBuffer::WriteOnly); + QImageWriter writer; + writer.setDevice(&buffer); + writer.setFormat("ICO"); + if (writer.canWrite()) { + QPixmap px = qApp->windowIcon().pixmap(24,24); + writer.write(px.toImage()); + buffer.close(); + res = buffer.data(); + } + else { + // fallback + res.reserve(navicon_data_len); + for (int i=0; i<(int)navicon_data_len;i++) { + res[i] = navicon_data[i]; + } } } else if (filename == QLatin1String("/")) { @@ -163,8 +180,8 @@ QByteArray PythonOnlineHelp::loadResource(const QString& filename) const } else { // load the error page - PyErr_Clear(); - res = fileNotFound(); + Base::PyException e; + res = loadFailed(QString::fromUtf8(e.what())); } Py_DECREF(dict); @@ -198,9 +215,10 @@ QByteArray PythonOnlineHelp::loadResource(const QString& filename) const else { // get information about the error Base::PyException e; - Base::Console().Warning("PythonOnlineHelp::loadResource: %s\n", e.what()); + //Base::Console().Error("loadResource: %s\n", e.what()); // load the error page - res = fileNotFound(); + //res = fileNotFound(); + res = loadFailed(QString::fromUtf8(e.what())); } Py_DECREF(dict); @@ -241,6 +259,36 @@ QByteArray PythonOnlineHelp::fileNotFound() const return res; } +QByteArray PythonOnlineHelp::loadFailed(const QString& error) const +{ + QString contentType = QString::fromLatin1( + "text/html\r\n" + "\r\n" + "Error" + "" + "" + "" + "" + "
 
" + " 
FreeCAD Documentation
" + " 
" + "

" + "

%1

" + "" + "" + "\r\n" + ).arg(error); + + QString header = QString::fromLatin1("content-type: %1\r\n").arg(contentType); + + QString http(QLatin1String("HTTP/1.1 %1 %2\r\n%3\r\n")); + QString httpResponseHeader = http.arg(404).arg(QLatin1String("File not found")).arg(header); + + QByteArray res; + res.append(httpResponseHeader); + return res; +} + HttpServer::HttpServer(QObject* parent) : QTcpServer(parent), disabled(false) { diff --git a/src/Gui/OnlineDocumentation.h b/src/Gui/OnlineDocumentation.h index 3a7cf57447..07a36a4017 100644 --- a/src/Gui/OnlineDocumentation.h +++ b/src/Gui/OnlineDocumentation.h @@ -49,6 +49,7 @@ public: QByteArray loadResource(const QString& filename) const; QByteArray fileNotFound() const; + QByteArray loadFailed(const QString& error) const; }; /** diff --git a/src/Mod/Robot/RobotExample.py b/src/Mod/Robot/RobotExample.py index c22111a84e..eee4297123 100644 --- a/src/Mod/Robot/RobotExample.py +++ b/src/Mod/Robot/RobotExample.py @@ -5,6 +5,8 @@ from Robot import * from Part import * from FreeCAD import * +import FreeCAD as App +import tempfile # === Basic robot stuff === # create the robot. If you not specify a other kinematic it becomes a Puma 560 @@ -66,10 +68,10 @@ App.activeDocument().Robot.Axis2 = -90 App.activeDocument().Robot.Axis3 = 90 # retrive the Tcp position -pos = FreeCAD.getDocument("Unnamed").getObject("Robot").Tcp +pos = App.getDocument("Unnamed").getObject("Robot").Tcp # move the robot pos.move(App.Vector(-10,0,0)) -FreeCAD.getDocument("Unnamed").getObject("Robot").Tcp = pos +App.getDocument("Unnamed").getObject("Robot").Tcp = pos # create an empty Trajectory object in the active document App.activeDocument().addObject("Robot::TrajectoryObject","Trajectory") @@ -97,7 +99,7 @@ print(App.activeDocument().Trajectory.Trajectory) # python module. Here is in detail the Kuka Postprocessor descriped from KukaExporter import ExportCompactSub -ExportCompactSub(App.activeDocument().Robot,App.activeDocument().Trajectory,'D:/Temp/TestOut.src') +ExportCompactSub(App.activeDocument().Robot,App.activeDocument().Trajectory,tempfile.gettempdir()+'/TestOut.src') # and thats kind of how its done: for w in App.activeDocument().Trajectory.Trajectory.Waypoints: diff --git a/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py b/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py index 3a20b5a90d..b8f919944d 100644 --- a/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py +++ b/src/Mod/Robot/RobotExampleTrajectoryOutOfShapes.py @@ -1,4 +1,5 @@ # Examples to generate trajectories out of shapes +import FreeCADGui as Gui # geting selected edges from the selection and sort them count = 0 diff --git a/src/Mod/Sketcher/SketcherExample.py b/src/Mod/Sketcher/SketcherExample.py index f9da889ec2..ca8fbb40df 100644 --- a/src/Mod/Sketcher/SketcherExample.py +++ b/src/Mod/Sketcher/SketcherExample.py @@ -2,6 +2,7 @@ from Sketcher import * from Part import * from FreeCAD import * +import FreeCAD as App # set some constances for the constraints StartPoint = 1