[Qgis-user] Print composer and Python

Martin Dobias wonder.sk at gmail.com
Mon Jul 26 05:57:39 PDT 2010


Hi Stefan

On Sat, Jul 24, 2010 at 8:16 PM, Ziegler Stefan <Stefan.Ziegler at bd.so.ch> wrote:
> Hi
>
> I'm trying to access the print composer with python:
>
>        self.iface.actionPrintComposer().trigger()
>        composerList = self.iface.activeComposers()
>        composerView = composerList[composerList.index(max(composerList))]
>
>        composition = composerView.composition()
>        composer = composerView.composerWindow()
>        composition.setPaperSize(float(width),  float(height))
>        composer.show()
>
>
> This works twice but the third time two windows will open: one with the standard papersize and one with my custom papersize.

I think the problem is that composers within QGIS are stored in a QSet
(and not in QList data structure) which makes the ordering of
composers different from the order how new composers are added. So the
new composer you trigger will not always be the last one you retrieve
in the list.

You could work this around by checking activeComposers() before and
after triggering a new composer and finding out which composer is the
new one. Not optimal, but probably sufficient.

Regards
Martin



More information about the Qgis-user mailing list