File indexing completed on 2024-04-21 04:40:43

0001 /*
0002     SPDX-FileCopyrightText: 2020 David Faure <faure@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 #include <boost/python/class.hpp>
0007 #include <boost/python/module.hpp>
0008 #include <boost/python/enum.hpp>
0009 #include "python_qt_wrappers.h"
0010 #include <KOpeningHours/OpeningHours>
0011 
0012 using namespace boost::python;
0013 using namespace KOpeningHours;
0014 
0015 BOOST_PYTHON_MODULE(PyKOpeningHours)
0016 {
0017     register_qt_wrappers();
0018 
0019     enum_<OpeningHours::Mode>("Mode")
0020             .value("IntervalMode", OpeningHours::IntervalMode)
0021             .value("PointInTimeMode", OpeningHours::PointInTimeMode);
0022     class_<OpeningHours::Modes>("Modes", init<OpeningHours::Mode>());
0023 
0024     // select the right overload of setExpression
0025     using SetExpressionFunc = void(OpeningHours::*)(const QByteArray&,OpeningHours::Modes);
0026     class_<OpeningHours>("OpeningHours", init<>())
0027         .def("setExpression", static_cast<SetExpressionFunc>(&OpeningHours::setExpression),
0028              (arg("expression"), arg("modes")=OpeningHours::Modes{OpeningHours::IntervalMode}))
0029         .def("error", &OpeningHours::error)
0030         .def("normalizedExpression", &OpeningHours::normalizedExpression);
0031 
0032     enum_<OpeningHours::Error>("Error")
0033             .value("Null", OpeningHours::Null) ///< no expression is set
0034             .value("NoError", OpeningHours::NoError) ///< there is no error, the expression is valid and can be used
0035             .value("SyntaxError", OpeningHours::SyntaxError) ///< syntax error in the opening hours expression
0036             .value("MissingRegion", OpeningHours::MissingRegion) ///< expression refers to public or school holidays, but that information is not available
0037             .value("MissingLocation", OpeningHours::MissingLocation) ///< evaluation requires location information and those aren't set
0038             .value("IncompatibleMode", OpeningHours::IncompatibleMode) ///< expression mode doesn't match the expected mode
0039             .value("UnsupportedFeature", OpeningHours::UnsupportedFeature) ///< expression uses a feature that isn't implemented/supported (yet)
0040             .value("EvaluationError", OpeningHours::EvaluationError) ///< runtime error during evaluating the expression
0041             ;
0042 }