This scripts works fine for me, but every time its called, a new composer-template is created (Composer 1, Composer2 etc). If the user saves the project, also the composers are saved and the list grows up...
So I want to remove the new item OR name it, so only one of them is in the list:
from qgis.PyQt.QtXml import QDomDocument
from qgis import gui
scale = 10000
templateFile='c:/1temp/mylayout.qpt'
activetool = 15# 'MoveItemContent'
composerview = iface.createNewComposer()
#load template
f= file(templateFile, 'r')
templateContent = f.read()
f.close()
doc=QDomDocument()
doc.setContent(templateContent)
composerview.composition().loadFromTemplate(doc)
#show composer
composerview.show()
#setup map
map = composerview.composition().getComposerMapById(0)#QgsComposerMap
#extent
map.zoomToExtent(iface.mapCanvas().extent())
#scale
if scale >0:
map.setNewScale(int(scale))
#set activetool
if activetool is not None and activetool<>'':
composerview.setCurrentTool(gui.QgsComposerView.Tool(activetool))
#finally
composerview.composition().refreshItems()