<div dir="ltr">Is-it possible to remove this function from SIP bindings? According to SIP version?<div><br></div><div>It's a common issue, already raised on the mailing list and in plugin issue trackers.</div><div><br></div><div>I'm copy/pasting another message/snippet from Martin which works perfectly:</div><div><br></div><div><span style="font-size:12.800000190734863px">Not sure if that is related, was just looking into code of a plugin we</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">use with QGIS 2.18 and there for getting composer items we have this</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">helper method:</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">    @staticmethod</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">    def get_composition_item(comp, item_id, item_class):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">        for item in comp.items():</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">            if isinstance(item, item_class):</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">                if </span><a href="http://item.id/" rel="noreferrer" target="_blank" style="font-size:12.800000190734863px">item.id</a><span style="font-size:12.800000190734863px">() == item_id:</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">                    return item</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">And you would call it e.g.:</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">ver_label = self.get_composition_item(</span><wbr style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">self.oview_compn, 'version',</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">QgsComposerLabel)</span><br style="font-size:12.800000190734863px"><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">Not sure if that is to work around the same problem as you have - I</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">didn't write that code. And to get composer map items, we use</span><br style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">composition.</span><wbr style="font-size:12.800000190734863px"><span style="font-size:12.800000190734863px">getComposerMapById(id)</span><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2018-01-24 10:09 GMT+03:00 Nyall Dawson <span dir="ltr"><<a href="mailto:nyall.dawson@gmail.com" target="_blank">nyall.dawson@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 23 January 2018 at 22:34, Enrico Ferreguti <<a href="mailto:enricofer@gmail.com">enricofer@gmail.com</a>> wrote:<br>
> I'm trying to programmatically set a QgsLayoutPicture content in QGIS3.0:<br>
><br>
> 1) I create a new print composition and I name it 'test'<br>
> 2) I create a picture frame in the composition and I call it 'picture'<br>
> 3) I run the following code:<br>
><br>
> from qgis.core import QgsProject<br>
> myLayout = QgsProject.instance().<wbr>layoutManager().layoutByName('<wbr>test')<br>
> myLayoutPicture = myLayout.itemById("picture")<br>
> myLayoutPicture.<wbr>setPicturePath("path to an image")<br>
><br>
> and I get the following Exception:<br>
> AttributeError: 'QgsLayoutItem' object has no attribute 'setPicturePath'<br>
><br>
> If I inspect myLayoutPicture object I found it is a qgis._core.QgsLayoutItem<br>
> not a QgsLayoutPicture<br>
><br>
> Is this a correct behaviour or is it an issue? How can I get the right<br>
> Layout object?<br>
<br>
</span>This became an issue after a certain sip version. It affects QGIS 2.x<br>
also, and seems to be caused by sip being unable to automatically cast<br>
classes which use multiple inheritance (like QgsComposerItem,<br>
QgsLayoutItem). The consequence is that Python is only aware of the<br>
base class, not the actual item subclass.<br>
<br>
I can't find anyway to fix this properly. So I hack around by forcing<br>
sip to manually cast to the correct item type, e.g. by inserting two<br>
lines* which look like this:<br>
<br>
        # screw you sip, I'll just manually cast<br>
        real_item = sip.cast(item, QgsLayoutItemPicture)<br>
<br>
It's not pretty, but it works...<br>
<br>
Nyall<br>
<br>
* the first line is critical for the fix to work correctly<br>
<div class="HOEnZb"><div class="h5">______________________________<wbr>_________________<br>
QGIS-Developer mailing list<br>
<a href="mailto:QGIS-Developer@lists.osgeo.org">QGIS-Developer@lists.osgeo.org</a><br>
List info: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a><br>
Unsubscribe: <a href="https://lists.osgeo.org/mailman/listinfo/qgis-developer" rel="noreferrer" target="_blank">https://lists.osgeo.org/<wbr>mailman/listinfo/qgis-<wbr>developer</a></div></div></blockquote></div><br></div>