Adding python bindings for quickprint

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding python bindings for quickprint

Tim Sutton
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
 -  is there something like Doxygen API that I can read the api docs for python
 - 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?

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()

Regards

Tim

--
Tim Sutton
QGIS Project Steering Committee Member - Release  Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net

_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer

quickprint_py.diff (1K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Tim Sutton
Hi Martin

A bit more on this - I discovered my patch actually wasnt  compiling properly:

/Users/timlinux/dev/cpp/qgis/src/gui/qgsquickprint.h: In copy
constructor 'QgsQuickPrint::QgsQuickPrint(const QgsQuickPrint&)':
/Users/timlinux/dev/cpp/qgis/src/gui/qgsquickprint.h:36:
instantiated from 'void* qMetaTypeConstructHelper(const T*) [with T =
QgsQuickPrint]'
/Library/Frameworks/QtCore.framework/Headers/qmetatype.h:144:
instantiated from 'int qRegisterMetaType(const char*, T*) [with T =
QgsQuickPrint]'
sipguicmodule.cpp:702:   instantiated from here
/Library/Frameworks/QtCore.framework/Headers/qobject.h:285: error:
'QObject::QObject(const QObject&)' is private
/Users/timlinux/dev/cpp/qgis/src/gui/qgsquickprint.h:36: error: within
this context
/Library/Frameworks/QtCore.framework/Headers/qmetatype.h: In function
'void* qMetaTypeConstructHelper(const T*) [with T = QgsQuickPrint]':
/Library/Frameworks/QtCore.framework/Headers/qmetatype.h:119: warning:
synthesized method 'QgsQuickPrint::QgsQuickPrint(const
QgsQuickPrint&)' first required here
make[3]: *** [sipguicmodule.o] Error 1
make[2]: *** [python/gui/gui.so] Error 2
make[1]: *** [python/CMakeFiles/python.dir/all] Error 2
make: *** [all] Error 2


I saw in som of your wrapped classes you mentioned problems wih
inheriting QObject in python wrapped code - did you find a work around
for that?

Regards

Tim

2008/1/15, Tim Sutton <[hidden email]>:

> 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
>  -  is there something like Doxygen API that I can read the api docs for python
>  - 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?
>
> 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()
>
> Regards
>
> Tim
>
> --
> Tim Sutton
> QGIS Project Steering Committee Member - Release  Manager
> Visit http://qgis.org for a great open source GIS
> openModeller Desktop Developer
> Visit http://openModeller.sf.net for a great open source ecological
> niche modelling tool
> Home Page: http://tim.linfiniti.com
> Skype: timlinux
> Irc: timlinux on #qgis at freenode.net
>
>


--
Tim Sutton
QGIS Project Steering Committee Member - Release  Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Martin Dobias
In reply to this post by Tim Sutton
Hi Tim,

On Jan 15, 2008 11:06 AM, Tim Sutton <[hidden email]> 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:
http://wiki.qgis.org/qgiswiki/PythonBindings
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.

Regards,
Martin
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Gary Sherman-2
On Jan 15, 2008, at 7:09 PM, Martin Dobias wrote:

> 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.


I think that's the point---a simple way to print a map.

-gary
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-
Gary Sherman
Chair, QGIS Project Steering Committee
-Micro Resources: http://mrcc.com
   *Geospatial Hosting
   *Web Site Hosting
-Desktop GIS Book:
   *http://desktopgisbook.com
"We work virtually everywhere"
-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-






_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Martin Dobias
On Jan 16, 2008 5:29 AM, Gary Sherman <[hidden email]> wrote:
> On Jan 15, 2008, at 7:09 PM, Martin Dobias wrote:
>
> > 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.
>
>
> I think that's the point---a simple way to print a map.

I understand the point, but I think it would be much better to build
upon existing code of map composer than to do the same in different
way.

Martin
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Magnus Homann
Martin Dobias wrote:

> On Jan 16, 2008 5:29 AM, Gary Sherman <[hidden email]> wrote:
>> On Jan 15, 2008, at 7:09 PM, Martin Dobias wrote:
>>
>>> 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.
>>
>> I think that's the point---a simple way to print a map.
>
> I understand the point, but I think it would be much better to build
> upon existing code of map composer than to do the same in different
> way.

You have a point. Let's wait till map composer branch is merged, and see
if we can work on that?

Magnus Homann
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Martin Dobias
On Jan 16, 2008 2:36 PM, Magnus Homann <[hidden email]> wrote:
>
> Martin Dobias wrote:
> >
> > I understand the point, but I think it would be much better to build
> > upon existing code of map composer than to do the same in different
> > way.
>
> You have a point. Let's wait till map composer branch is merged, and see
> if we can work on that?

Yes, that's what I would prefer... QGIS libraries should get support
for map compositions and printing. With some effort we could move map
composer backend to QGIS core library and composer frontend either
leave in app code or move it to gui library. Then I can imagine usage
like:

1. create a composition template or load it from a file
2. create composition, set template and map render class (has list of
layers, extent, coordinate transform)
3. do some action (print to pdf / svg / image / printer)

These all steps can take just 5 lines of code...
And there could be some simple ready to use templates for those who
don't like to prepare their own templates.

Regards
Martin
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Tim Sutton
In reply to this post by Magnus Homann
Hi

Yes I am happy to toss the quickprint code (or make it a thin wrapper
around composer code) when composer is ready. I would prefer to keep
the quickprint class even if it internally delegates to composer stuff
since it provides a simple and convenient way to produce a map
programmatically.

At the moment composer stuff is not in the libs at all (its part of
app) and I think some major refactoring would probably be needed to
separate it out into libqgis_gui. This leaves libqgis programmers
without anyway to easily produce a map - which is the gap quickprint
class is designed to fill.

Regards

Tim

2008/1/16, Magnus Homann <[hidden email]>:

> Martin Dobias wrote:
> > On Jan 16, 2008 5:29 AM, Gary Sherman <[hidden email]> wrote:
> >> On Jan 15, 2008, at 7:09 PM, Martin Dobias wrote:
> >>
> >>> 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.
> >>
> >> I think that's the point---a simple way to print a map.
> >
> > I understand the point, but I think it would be much better to build
> > upon existing code of map composer than to do the same in different
> > way.
>
> You have a point. Let's wait till map composer branch is merged, and see
> if we can work on that?
>
> Magnus Homann
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>


--
Tim Sutton
QGIS Project Steering Committee Member - Release  Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Chris Barker
In reply to this post by Martin Dobias
Martin Dobias wrote:

>> 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')()

Wouldn't it make more sense to rename it in the bindings? You don't want
an API that ugly!

qp.Print() or printMap, or .....

in fact, you can't create a class with a "print" method in python, but
maybe you can in C -- but it sure seems like a bad idea!

-Chris


--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[hidden email]
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
Reply | Threaded
Open this post in threaded view
|

Re: Adding python bindings for quickprint

Tim Sutton
Hi

Yes I was thinking the same thing. In c++ 'print ' is not a reserved
word, just in python it seems. Ill just rename the c++ method
printMap() - and thus python bindings too.

Regards

Tim

2008/1/16, Christopher Barker <[hidden email]>:

> Martin Dobias wrote:
> >> 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')()
>
> Wouldn't it make more sense to rename it in the bindings? You don't want
> an API that ugly!
>
> qp.Print() or printMap, or .....
>
> in fact, you can't create a class with a "print" method in python, but
> maybe you can in C -- but it sure seems like a bad idea!
>
> -Chris
>
>
> --
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> [hidden email]
> _______________________________________________
> Qgis-developer mailing list
> [hidden email]
> http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
>


--
Tim Sutton
QGIS Project Steering Committee Member - Release  Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
_______________________________________________
Qgis-developer mailing list
[hidden email]
http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer