[Qgis-developer] quick noob python question
Germán Carrillo
carrillo.german at gmail.com
Thu Dec 15 08:25:30 EST 2011
Hi Duarte,
if I understood well, you would like to simulate a click in QGIS buttons.
For this you can use the slot trigger() of the available QAction's in the
class QgisInteface [1]. For example, if you want to open the "Open
Project..." dialog you can type this in the Python Console (inside QGIS):
iface=qgis.utils.iface
iface.actionOpenProject().trigger()
Regarding Toolbars, you can also access them from the QgisInterface class.
For example, to access the Layer menu do this:
iface=qgis.utils.iface
m=iface.layerMenu()
Since a menu consists of a set of actions you could trigger any action of
the menu:
iface=qgis.utils.iface
m=iface.layerMenu()
for a in m.actions():
print a.text()
m.actions()[2].trigger()
Hope this helps.
Regards,
Germán
-------------------------
[1] http://www.qgis.org/api/classQgisInterface.html
2011/12/15 Duarte Carreira <DCarreira at edia.pt>
> Just an additional question: generally speaking the gui is not accessible
> from python? We cannot simulate a toolbar button click, or menu item?****
>
> ** **
>
> Duarte****
>
> ** **
>
> *De:* Duarte Carreira [mailto:DCarreira at edia.pt]
> *Enviada:* quarta-feira, 14 de Dezembro de 2011 17:05
> *Para:* Germán Carrillo; qgis-developer at lists.osgeo.org
> *Assunto:* RE: [Qgis-developer] quick noob python question****
>
> ** **
>
> Germán, thanks.****
>
> ** **
>
> Maybe that’s what I’ll do, but it pains me to duplicate code…****
>
> ** **
>
> Duarte****
>
> ** **
>
> *De:* Germán Carrillo [mailto:carrillo.german at gmail.com]
> *Enviada:* quarta-feira, 14 de Dezembro de 2011 12:30
> *Para:* qgis-developer at lists.osgeo.org; Duarte Carreira
> *Assunto:* Re: [Qgis-developer] quick noob python question****
>
> ** **
>
> Hi Duarte,
>
> from my experience it is not possible. You can of course re-use the ui
> file and implement the whole functionality on your own based on the cpp
> file, basically a translation from C++ to Python. I've done this before and
> it is not a complex process, but it requires time.
>
> By the way, the folder app of QGIS source code contains
> QGIS-application-specific code, so I would say you won't find there
> functionality available in PyQGIS, for that you would have to have a look
> to the gui and core folders.
>
> Perhaps there are other ways to set the project file programmatically from
> Python, but I don't know them, sorry.
>
> Regards,
>
> Germán****
>
> 2011/12/14 Duarte Carreira <DCarreira at edia.pt>****
>
> Using python is it possible to call QgsEmbedLayerDialog and set the
> project file programmatically (mProjectFileLineEdit)?****
>
> ****
>
>
> https://github.com/qgis/Quantum-GIS/blob/release-1_8/src/app/qgsembedlayerdialog.cpp
> ****
>
>
> https://github.com/qgis/Quantum-GIS/blob/release-1_8/src/ui/qgsembedlayerdialogbase.ui
> ****
>
> ****
>
> Thanks,
> Duarte Carreira****
>
> ****
>
>
> _______________________________________________
> 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/****
>
--
-----------
|\__
(:>__)(
|/
Soluciones Geoinformáticas Libres
http://geotux.tuxfamily.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20111215/d919f4a8/attachment-0001.html
More information about the Qgis-developer
mailing list