[Qgis-developer] Adding python bindings for quickprint

Martin Dobias wonder.sk at gmail.com
Tue Jan 15 23:09:23 EST 2008

Hi Tim,

On Jan 15, 2008 11:06 AM, Tim Sutton <tim at linfiniti.com> wrote:
> Hi Martin
> I want to create python bindings for QuickPrint class. I copied work
> you did for other classes (see attached patch) and it all compiles
> fine. Bearing in mind that Im a complete python noob how do I:
>  -  confirm my class is available in the pythond bindings? I tried in
> the python console to do like  qp = QgsQuickPrint but it gave an error

To resolve the compilation problems you must uncomment the base class
in .sip file and remove "public" keyword, so it will look like this:
class QgsQuickPrint : QObject

To create an instance use:
qp = QgsQuickPrint()    <- don't forget the parentheses

>  -  is there something like Doxygen API that I can read the api docs for python

Do you mean doxygen for PyQGIS ? no, there isn't anything like that...
(but could be since PyQt also has class documentation).

>  - I looked through all the examples I could find and none of the
> python stuff I saw seemed to make use of qgis classes directly - they
> all seem to pull objects out of the iface object. Where can I find
> better examples?

What do you mean by direct usage? When you create the object by
yourself? If so, there are some examples on wiki:
there you can find creation of points, geometries, spatial index,
measuring class, vector file writer etc.

> the quick print class *should* work something like this:
> qp = QgsQuickPrint
> qp.setMapCanvas ( iface.getMapCanvas() )
> qp.setOutputPdf ("/tmp/test;pdf")
> qp.setTitle ("QGIS Rocks")
> qp.print()

Besides the parentheses missing in the first command as mentioned
before, there's a problem with the last statement qp.print() because
"print" is a python keyword. So it's not possible to call it directly
and you need to use following workaround to execute it:
getattr(qp, 'print')()

Finally, I don't really like the idea of keeping this class in gui
library. The reason is that its functionality is too basic, limited
and without possibilities for customization. Better would be to move
some backend parts of map composer to gui library and build quickprint
upon that so that we will not develop two things that do same thing.


More information about the Qgis-developer mailing list