[Qgis-developer] How to debug and unit test Python plugins outside QGIS (e.g. in Ecplise IDE + PyDev)

Tim Sutton lists at linfiniti.com
Tue Jan 10 14:44:49 EST 2012


Hi

2012/1/10 Germán Carrillo <carrillo.german at gmail.com>:
> Hi,
>
> you can find an example at [1], namely a class called "QgisInterface" in the
> postgis_viewer.py, line 313.
>

Awesome thanks! Testing it now....

Regards

Tim

> Hope it helps.
>
> Regards,
>
> Germán
>
> -------------------
> [1]
> http://downloads.tuxfamily.org/tuxgis/geoblogs/visor_postgis_pgadmin_3/postgis_viewer.zip
>
>
> 2012/1/10 Tim Sutton <lists at linfiniti.com>
>>
>> Hi
>>
>> On Tue, Jan 10, 2012 at 7:08 PM, Martin Dobias <wonder.sk at gmail.com>
>> wrote:
>> >> On Thu, Mar 3, 2011 at 10:40 AM, Martin Dobias <wonder.sk at gmail.com>
>> >> wrote:
>> >>
>> >>> The only difference when running unit-tests (i.e. standalone apps) is
>> >>> that you cannot access QGIS interface (qgis.utils.iface) since there
>> >>> is no QGIS running. But that should not pose a big problem. In case
>> >>> you really need access to that interface you can create your own
>> >>> implementation of QgisInterface class and assign it to
>> >>> qgis.utils.iface.
>> >>>
>> >>> Regards
>> >>> Martin
>> >>
>> >> Martin do you (or anyone else) have example code for creating an iface
>> >> instance from a standalone python / QGIS app?
>> >
>> > Hi Tim
>> >
>> > no I do not have a working example. In general it should be something
>> > like this:
>> >
>> > import qgis.utils
>> > import qgis.gui
>> >
>> > class MyQgisInterface(qgis.gui.QgisInterface):
>> >  def __init__(self):
>> >    QgisInterface.__init__(self)
>> >  def mapCanvas(self):
>> >    return FOO
>> >  def mainWindow(self):
>> >    return BAR
>> >  def activeLayer(self):
>> >    return BAZ
>> >  # ... more methods ...
>> >
>> > # use our interface instance
>> > qgis.utils.iface = MyQgisInterface()
>> >
>> > You will have to provide implementation of all the abstract virtual
>> > functions defined in QgisInterface. Luckily most of them are not used
>> > by plugins, so you may provide just implementations not
>> > doing/returning anything - depending on how precisely would you like
>> > to imitate QGIS environment.
>> >
>>
>> Thanks Martin. Yes I have used the same approach in openModeller
>> desktop some years ago to allow it to use QGIS (C++) plugins - I was
>> just interested to know if someone had already baked a python
>> equivalent in keeping with DRAY (dont repeat anyone else :-)).
>>
>> I'll go ahead and make an attempt at a python one then, thanks.
>>
>> Regards
>>
>> Tim
>>
>>
>> > Regards
>> > Martin
>>
>>
>>
>> --
>> Tim Sutton - QGIS Project Steering Committee Member (Release  Manager)
>> ==============================================
>> Please do not email me off-list with technical
>> support questions. Using the lists will gain
>> more exposure for your issues and the knowledge
>> surrounding your issue will be shared with all.
>>
>> Visit http://linfiniti.com to find out about:
>>  * QGIS programming and support services
>>  * Mapserver and PostGIS based hosting plans
>>  * FOSS Consulting Services
>> Skype: timlinux
>> Irc: timlinux on #qgis at freenode.net
>> ==============================================
>> _______________________________________________
>> Qgis-developer mailing list
>> Qgis-developer at lists.osgeo.org
>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>
> --
> -----------
>   |\__
> (:>__)(
>   |/
>
> Soluciones Geoinformáticas Libres
> http://geotux.tuxfamily.org/
>



-- 
Tim Sutton - QGIS Project Steering Committee Member (Release  Manager)
==============================================
Please do not email me off-list with technical
support questions. Using the lists will gain
more exposure for your issues and the knowledge
surrounding your issue will be shared with all.

Visit http://linfiniti.com to find out about:
 * QGIS programming and support services
 * Mapserver and PostGIS based hosting plans
 * FOSS Consulting Services
Skype: timlinux
Irc: timlinux on #qgis at freenode.net
==============================================


More information about the Qgis-developer mailing list