[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 13:47:45 EST 2012
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
==============================================
More information about the Qgis-developer
mailing list