[QGIS-Developer] Replacing a dialogue with another at runtime with Python
Ricardo Filipe Soares Garcia da
ricardo.garcia.silva at gmail.com
Tue Oct 3 07:09:22 PDT 2017
Hi all
Answering my own question for posterity
Turns out I can disconnect all slots from a signal by calling
`my_action.triggered.disconnect()` without any arguments. My goal of
replacing the native QGIS 'Add WMS/WMTS layer' dialogue with another one
can be achieved like this:
```python
def my_handler():
print("Hello")
action = iface.actionAddWmsLayer()
action.triggered.disconnect()
action.triggered.connect(my_handler)
```
This leaves another problem to be solved: How to restore the native QGIS
dialogue when my would-be plugin is deactivated by the user. The following
seems to work on QGIS 2.18:
```
provider_registry = qgis.core.QgsProviderRegistry.instance()
add_wms_dialog = provider_registry.selectWidget("wms")
action.triggered.disconnect()
action.triggered.connect(add_wms_dialog.show)
```
Best regards
On Mon, Oct 2, 2017 at 12:41 PM, Ricardo Filipe Soares Garcia da <
ricardo.garcia.silva at gmail.com> wrote:
> Hi all
>
> Is it possible to replace one of QGIS' dialogues with a custom one during
> runtime by using Python?
>
> My concrete goal is to replace the dialogue that shows when clicking the
> 'Add WMS/WMTS Layer' with something custom. I'd like to enhance the native
> QGIS dialogue with additional elements for selecting additional dimensions,
> like time or elevation.
>
> Can this be done?
>
> I'm thinking that I'd only have to replace whatever slot is currently
> defined on the `iface.actionAddWmsLayer()` action with a custom function
> that would load my UI instead. The problem is that I can't seem to find
> where a signal's connected slots are stored with Qt.
>
> Ideally there would be some introspection mechanism by which I'd be able
> to retrieve which slots are associated with the action's `triggered` signal
> - I can't seem to find it though. After knowing which slot(s) were
> connected to the action's signal, I would presumably be able to
> `disconnect()` them and then connect my own.
>
> By looking at Qt's docs I thought that the QMetaObject class might be the
> place to look, but I still cannot find anything that looks seems to hold
> the registry of a signal's connected slots.
>
> Thanks in advance :)
>
>
>
> --
> ___________________________ ___ __
> Ricardo Garcia Silva
>
--
___________________________ ___ __
Ricardo Garcia Silva
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171003/e8eac490/attachment.html>
More information about the QGIS-Developer
mailing list