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

@@ -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();
}