Bug 384461

Summary: PyKF5 bindings: no way to construct a KColorScheme from Python
Product: [Frameworks and Libraries] frameworks-kconfigwidgets Reporter: Philipp A. <flying-sheep>
Component: generalAssignee: kdelibs bugs <kdelibs-bugs-null>
Status: RESOLVED WORKSFORME    
Severity: normal CC: simonandric5, srhaque, steveire
Priority: NOR    
Version First Reported In: 5.37.0   
Target Milestone: ---   
Platform: Arch Linux   
OS: All   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Philipp A. 2017-09-07 09:45:41 UTC
When building KConfigWidgets, the only non-copying constructor for KColorScheme is skipped by some rule:

    [...]
    KColorScheme(const KColorScheme & __0);
    [...]
    // Discarded CONSTRUCTOR on line 327 'KColorScheme' (by Qt5Ruleset.py:FunctionRuleDb[11],function_discard)
    [...]


Also, there seems to be no way to customize templates for the binding generator (please correct me if i’m wrong), so this bug isn’t fixable until the sip customizations in extra-cmake-modules are modified to allow custom templates per project.
Comment 1 Philipp A. 2017-09-07 10:17:57 UTC
This bug is fixed in shaheed’s fork of extra-cmake-modules:

https://github.com/ShaheedHaque/extra-cmake-modules
Comment 3 Shaheed Haque 2017-09-21 13:32:46 UTC
As Phil noted in comment #1, I don't think there is any reasonable fix for the fork in the KDE repos, because this fork basically ignored templates. SIP needs
something called a %MappedType to implement the template, and
%MethodCode to call the template logic.

Now, my version of the code has rules+logic which trigger template
generation causing, for example, this to be emitted in KConfigWidgets/KColorScheme.sip:

===========
class KColorScheme
{
...
    KColorScheme(QPalette::ColorGroup __0, KColorScheme::ColorSet __1
= KColorScheme::View, QExplicitlySharedDataPointer<KSharedConfig> __2
= KSharedConfigPtr())
        [(QPalette::ColorGroup __0, KColorScheme::ColorSet __1 =
KColorScheme::View, QExplicitlySharedDataPointer<KSharedConfig> __2 =
KSharedConfigPtr())];
%MethodCode
// Generated for CONSTRUCTOR on line 324 'KColorScheme::KColorScheme'
(by builtin_rules.py:function_rules[1],function_uses_templates):
{'(void)': ['QPalette::ColorGroup(INTEGER)',
'KColorScheme::ColorSet(INTEGER)',
'QExplicitlySharedDataPointer<KSharedConfig>(OBJECT)']}

    Py_BEGIN_ALLOW_THREADS
    sipCpp = new sipKColorScheme(a0, a1, *a2);
    Py_END_ALLOW_THREADS

%End
}
===========

plus the following autogenerated template logic in
KConfigWidgets/KConfigWidgetsmod.sip:

===========
%MappedType QExplicitlySharedDataPointer<KSharedConfig>
{
// Generated for PARM_DECL on line 534
'KStatefulBrush::KStatefulBrush::__2' (by
PyQt.py:parameter_rules[4],pointer_parameter):
['KSharedConfig(OBJECT)']

%TypeHeaderCode
#include <QExplicitlySharedDataPointer>
%End
%ConvertFromTypeCode
    typedef KSharedConfig CxxvalueT;
    const sipTypeDef *genvalueT = sipType_KSharedConfig;

    // Convert the value from C++.
    PyObject *value = sipConvertFromType((void *)sipCpp->data(),
genvalueT, sipTransferObj);
    if (value == NULL) {
        PyErr_Format(PyExc_TypeError, "cannot convert value");
        return 0;
    }
    return value;
%End
%ConvertToTypeCode
    const char *cxxvalueS = "KSharedConfig";
    typedef KSharedConfig CxxvalueT;
    const sipTypeDef *genvalueT = sipType_KSharedConfig;
    PyObject *value;

    // Convert the value to C++.
    value = sipPy;
        int valueState;
        CxxvalueT *cxxvalue = reinterpret_cast<CxxvalueT
*>(sipForceConvertToType(value, genvalueT, sipTransferObj,
SIP_NOT_NONE, &valueState, sipIsErr));

    if (*sipIsErr) {
        if (cxxvalue == NULL) {
            PyErr_Format(PyExc_TypeError, "value has type '%s' but
'%s' is expected",
                         Py_TYPE(value)->tp_name, cxxvalueS);
        }
        sipReleaseType((void *)cxxvalue, genvalueT, valueState);
        return 0;
    }
        sipReleaseType((void *)cxxvalue, genvalueT, valueState);
    *sipCppPtr = new QExplicitlySharedDataPointer<CxxvalueT>(cxxvalue);
    return sipGetState(sipTransferObj);
%End
};
===========

(Note, as I stated in my post, the above code has not been tested,
only compiled).

The KDE version has no equivalent, afaik.
Comment 4 Justin Zobel 2022-11-10 08:52:48 UTC
Thank you for reporting this issue in KDE software. As it has been a while since this issue was reported, can we please ask you to see if you can reproduce the issue with a recent software version?

If you can reproduce the issue, please change the status to "REPORTED" when replying. Thank you!
Comment 5 Bug Janitor Service 2022-11-25 05:17:30 UTC
Dear Bug Submitter,

This bug has been in NEEDSINFO status with no change for at least
15 days. Please provide the requested information as soon as
possible and set the bug status as REPORTED. Due to regular bug
tracker maintenance, if the bug is still in NEEDSINFO status with
no change in 30 days the bug will be closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

If you have already provided the requested information, please
mark the bug as REPORTED so that the KDE team knows that the bug is
ready to be confirmed.

Thank you for helping us make KDE software even better for everyone!
Comment 6 Bug Janitor Service 2022-12-10 05:14:38 UTC
This bug has been in NEEDSINFO status with no change for at least
30 days. The bug is now closed as RESOLVED > WORKSFORME
due to lack of needed information.

For more information about our bug triaging procedures please read the
wiki located here:
https://community.kde.org/Guidelines_and_HOWTOs/Bug_triaging

Thank you for helping us make KDE software even better for everyone!