[QGIS-Developer] Need Help Programmatically Creating a New Composition
Joshua Quesenberry
engnfrc at gmail.com
Tue Oct 17 09:22:14 PDT 2017
All,
Issue #1
Im trying to create a Composer Layout using Python and Im having issues
with addComposerHtmlFrame. I currently have QGIS 2.16.2 installed so the API
documentation Im finding online doesnt always match up with what Im
having to actually do. At this point when I add a Composer HTML Frame I see
the frame in the layout, but the HTML isnt rendered, even if I click on
Refresh HTML.
Ive tried a few variations of my code, heres the current variation:
----------------------------------------------------------------------------
------------------
comp = self.iface.createNewComposer('Map_Layout')
c = comp.composition()
paper_w = 279.4
paper_h = 215.9
c.setPaperSize(paper_w, paper_h)
c.setPlotStyle(QgsComposition.Print)
# Add Mag Decl / Datum Info
info1 = QgsComposerHtml(c, False)
info1.setContentMode(QgsComposerHtml.ManualHtml)
info1.setHtml('''Mag Decl: 8.16° W<br>
Horz. Datum: WGS84''')
frame1 = QgsComposerFrame(c, info1, 27., 195., 42., 12.)
frame1.setId('Info 1')
c.addComposerHtmlFrame(info1, frame1)
# Add Map Name / Scale / Print Date / Contour Interval Info
info2 = QgsComposerHtml(c, False)
info2.setContentMode(QgsComposerHtml.ManualHtml)
info2.setHtml('''<table>
<tr>
<td width="68%">
Map Name: STUART (VA)
</td>
<td>
Scale: 1 inch = 2,000 ft
</td>
</tr>
<tr>
<td>
Print Date: Thu Oct 17 07:34:36 2013
</td>
<td>
Contour Interval: 20 Feet
</td>
</tr>
</table>''')
frame2 = QgsComposerFrame(c, info2, 73., 193., 125., 15.)
frame2.setFrameEnabled(True)
frame2.setId('Info 2')
c.addComposerHtmlFrame(info2, frame2)
----------------------------------------------------------------------------
------------------
The documentation says that the 2nd parameter to QgsComposerFrame needs to
be a QgsComposerMultiFrame. Since QgsComposerMultiFrame is an abstract class
the only two options I know to try are either setting this parameter to None
(variation 1) or setting it to the QgsComposerHtml item itself (variation
2), where the latter is what Im doing above.
Are there any ideas why the contents of the QgsComposerHtml never appear?
Also, if I save my project, close QGIS, and then re-open QGIS and the
project, the QgsComposerHtml elements are missing.
Issue #2
Is there any way to create a new Composer without opening the Composer
window? I tried hiding the window after creating the new Composer, but that
just gave me a Composer window that was in a somewhat odd state.
Issue #3
Whats the recommended way to pull in magnetic declination? Is this possible
offline?
Thanks in advance!
Josh Q
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171017/c489f143/attachment.html>
More information about the QGIS-Developer
mailing list