Base: move class ProgressIndicatorPy to its own files

This commit is contained in:
wmayer
2022-11-22 15:07:33 +01:00
parent 56965e4244
commit 6770b0ba7d
6 changed files with 155 additions and 93 deletions

View File

@@ -71,8 +71,8 @@
#include <Base/Persistence.h>
#include <Base/PlacementPy.h>
#include <Base/PrecisionPy.h>
#include <Base/ProgressIndicatorPy.h>
#include <Base/RotationPy.h>
#include <Base/Sequencer.h>
#include <Base/Tools.h>
#include <Base/Translate.h>
#include <Base/Type.h>

View File

@@ -247,6 +247,7 @@ SET(FreeCADBase_CPP_SRCS
Placement.cpp
PlacementPyImp.cpp
PrecisionPyImp.cpp
ProgressIndicatorPy.cpp
PyExport.cpp
PyObjectBase.cpp
QtTools.cpp
@@ -313,6 +314,7 @@ SET(FreeCADBase_HPP_SRCS
Persistence.h
Placement.h
Precision.h
ProgressIndicatorPy.h
PyExport.h
PyObjectBase.h
QtTools.h

View File

@@ -0,0 +1,95 @@
/***************************************************************************
* Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#include "PreCompiled.h"
#include "ProgressIndicatorPy.h"
using namespace Base;
void ProgressIndicatorPy::init_type()
{
behaviors().name("ProgressIndicator");
behaviors().doc("Progress indicator");
// you must have overwritten the virtual functions
behaviors().supportRepr();
behaviors().supportGetattr();
behaviors().supportSetattr();
behaviors().set_tp_new(PyMake);
add_varargs_method("start",&ProgressIndicatorPy::start,"start(string,int)");
add_varargs_method("next",&ProgressIndicatorPy::next,"next()");
add_varargs_method("stop",&ProgressIndicatorPy::stop,"stop()");
}
PyObject *ProgressIndicatorPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
{
return new ProgressIndicatorPy();
}
ProgressIndicatorPy::ProgressIndicatorPy() = default;
ProgressIndicatorPy::~ProgressIndicatorPy() = default;
Py::Object ProgressIndicatorPy::repr()
{
std::string s = "Base.ProgressIndicator";
return Py::String(s);
}
Py::Object ProgressIndicatorPy::start(const Py::Tuple& args)
{
char* text;
unsigned int steps;
if (!PyArg_ParseTuple(args.ptr(), "sI",&text,&steps))
throw Py::Exception();
if (!_seq.get())
_seq.reset(new SequencerLauncher(text,steps));
return Py::None();
}
Py::Object ProgressIndicatorPy::next(const Py::Tuple& args)
{
int b=0;
if (!PyArg_ParseTuple(args.ptr(), "|i",&b))
throw Py::Exception();
if (_seq.get()) {
try {
_seq->next(b ? true : false);
}
catch (const Base::AbortException&) {
_seq.reset();
throw Py::RuntimeError("abort progress indicator");
}
}
return Py::None();
}
Py::Object ProgressIndicatorPy::stop(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
_seq.reset();
return Py::None();
}

View File

@@ -0,0 +1,57 @@
/***************************************************************************
* Copyright (c) 2022 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_PROGRESSINDICATORPY_H
#define BASE_PROGRESSINDICATORPY_H
#include <memory>
#include <CXX/Extensions.hxx>
#include <Base/Sequencer.h>
namespace Base
{
class BaseExport ProgressIndicatorPy : public Py::PythonExtension<ProgressIndicatorPy>
{
public:
static void init_type(); // announce properties and methods
ProgressIndicatorPy();
~ProgressIndicatorPy() override;
Py::Object repr() override;
Py::Object start(const Py::Tuple&);
Py::Object next(const Py::Tuple&);
Py::Object stop(const Py::Tuple&);
private:
static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
private:
std::unique_ptr<SequencerLauncher> _seq;
};
} // namespace Base
#endif // BASE_PROGRESSINDICATORPY_H

View File

@@ -287,71 +287,3 @@ bool SequencerLauncher::wasCanceled() const
{
return SequencerBase::Instance().wasCanceled();
}
// ---------------------------------------------------------
void ProgressIndicatorPy::init_type()
{
behaviors().name("ProgressIndicator");
behaviors().doc("Progress indicator");
// you must have overwritten the virtual functions
behaviors().supportRepr();
behaviors().supportGetattr();
behaviors().supportSetattr();
behaviors().set_tp_new(PyMake);
add_varargs_method("start",&ProgressIndicatorPy::start,"start(string,int)");
add_varargs_method("next",&ProgressIndicatorPy::next,"next()");
add_varargs_method("stop",&ProgressIndicatorPy::stop,"stop()");
}
PyObject *ProgressIndicatorPy::PyMake(struct _typeobject *, PyObject *, PyObject *)
{
return new ProgressIndicatorPy();
}
ProgressIndicatorPy::ProgressIndicatorPy() = default;
ProgressIndicatorPy::~ProgressIndicatorPy() = default;
Py::Object ProgressIndicatorPy::repr()
{
std::string s = "Base.ProgressIndicator";
return Py::String(s);
}
Py::Object ProgressIndicatorPy::start(const Py::Tuple& args)
{
char* text;
unsigned int steps;
if (!PyArg_ParseTuple(args.ptr(), "sI",&text,&steps))
throw Py::Exception();
if (!_seq.get())
_seq.reset(new SequencerLauncher(text,steps));
return Py::None();
}
Py::Object ProgressIndicatorPy::next(const Py::Tuple& args)
{
int b=0;
if (!PyArg_ParseTuple(args.ptr(), "|i",&b))
throw Py::Exception();
if (_seq.get()) {
try {
_seq->next(b ? true : false);
}
catch (const Base::AbortException&) {
_seq.reset();
throw Py::RuntimeError("abort progress indicator");
}
}
return Py::None();
}
Py::Object ProgressIndicatorPy::stop(const Py::Tuple& args)
{
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();
_seq.reset();
return Py::None();
}

View File

@@ -24,9 +24,6 @@
#ifndef BASE_SEQUENCER_H
#define BASE_SEQUENCER_H
#include <memory>
#include <CXX/Extensions.hxx>
#include "Exception.h"
@@ -384,27 +381,6 @@ inline SequencerBase& Sequencer ()
return SequencerBase::Instance();
}
class BaseExport ProgressIndicatorPy : public Py::PythonExtension<ProgressIndicatorPy>
{
public:
static void init_type(); // announce properties and methods
ProgressIndicatorPy();
~ProgressIndicatorPy() override;
Py::Object repr() override;
Py::Object start(const Py::Tuple&);
Py::Object next(const Py::Tuple&);
Py::Object stop(const Py::Tuple&);
private:
static PyObject *PyMake(struct _typeobject *, PyObject *, PyObject *);
private:
std::unique_ptr<SequencerLauncher> _seq;
};
} // namespace Base
#endif // BASE_SEQUENCER_H