3

In the QGIS python console, I want to populate a list with compositions names, like in Composer Manager, but I can't figure out how to get the names (titles).

So far:

composerlist = self.iface.activeComposers() 

And I get a list of QgsComposerView objects.

Now I want something like that:

for item in composerlist:
    print item.title()  

enter image description here

0

2 Answers 2

5

I figured out an workaround: item.composerWindow().windowTitle()

1

this is another way:

from PyQt4.QtGui import *

def ListComposerTemplates():
    menubar = iface.mainWindow().menuBar()
    for action in menubar.actions():
        #print action.objectName(),":",action.text()
        if action.objectName() == "mProjectMenu" or action.text()=="Pro&ject":#no objectname?
            #print action.objectName(),":",action.text()
            for a in action.menu().actions():
                #print a.objectName(),":",a.text()
                if a.objectName()=='mPrintComposersMenu' or a.text()=='Print Composers':#no objectname?
                    print a.objectName(),":",a.text()
                    for m in a.menu().actions():
                        print m.objectName(), ":", m.text()
                    return

ListComposerTemplates()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.