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