[Qgis-developer] Re : [Qgis-user] Pyqt4 : which signal is sent when dialog comes to foreground?
Junior Delaz
delazj at gmail.com
Tue Apr 7 13:07:48 PDT 2015
Thank you Matthias for your perseverance. It's very helpful and encouraging
for beginners.
I have already tried composerRemoved but when loading the plugin, QGIS
complains :
Impossible de charger l'extension MapsPrinter provoque une erreur lors de
l'appel de sa méthode initGui()
Traceback (most recent call last):
File "C:/OSGeo4W/apps/qgis/./python\qgis\utils.py", line 228, in startPlugin
plugins[packageName].initGui()
File "C:/Users/harrissou/.qgis2/python/plugins\MapsPrinter\maps_printer.py",
line 129, in initGui
self.iface.composerRemoved.connect(self.refreshList)
AttributeError: 'QgisInterface' object has no attribute 'composerRemoved'
This happens with all the versions of QGIS I use :
- osgeo4w 32bits (windows 8), osgeo4w 64bits (windows 7): either with
QGIS 2.8, 2.8rel-dev and 2.9
- and Mac OS 10.9 (it is a QGIS 2.4 but composerRemoved is supposed to
have been added since QGIS 2.3 [0])
About Qt.QueuedConnection, my first tests were on the Mac OS (x86-64)
and Osgeo4w 64bits versions. But I never encountered crash with the 32
bits version, using the same code. Can the bug be bound to the
architecture?
[0] https://github.com/qgis/QGIS/blob/master/src/app/qgisapp.h#L1260
2015-04-06 22:11 GMT+02:00 Matthias Kuhn <matthias at opengis.ch>:
> Hi Junior,
>
> The following lines work for a short test-case.
>
> def compAdded( composer ):
> print composer
>
> def compRemoved( composer ):
> print composer
>
> iface.composerAdded.connect( compAdded )
> iface.composerRemoved.connect( compRemoved )
>
> It is possible that the QueuedConnection crashes because along with it a
> composer is emitted which at the time the slot is executed is already
> deleted. That was only a possible approach which I did not test and reading
> your report seems unstable.
>
> Matthias
>
>
> On 04/06/2015 12:33 AM, Junior Delaz wrote:
>
> Hi,
> I do understand nothing.
> After I read your message, Matthias, I told myself that using QT.
> QueuedConnection should be the easiest way. Then i wrote
> self.iface.composerWillBeRemoved.connect(self.refreshList,
> Qt.QueuedConnection)
> But each time i delete a composer, QGIS crashes.
> So I've spent the week on reading about Qt.QueuedConnection and then
> signal and slots, function partial, QSignalMapper, sender trying to
> understand how I can catch the sender and manage to update my list. All
> this without success in the code.
> And today, I tried again Qt.QueuedConnection, QGIS crashed. Without any
> changes, I tried again and it worked and continues to work. Adding and
> deleting composer in the composer manager echoes in my list.
> I hope it will remain like that.
>
> But now I realize that I didn't take into account the renaming of a
> composer. :(
>
> I think I'd wisely keep the refreshlist button unless someone tells me
> how I can reach the composer manager dialog programmatically. So that I
> will try to synchronize my list with its widgetlistitems...
>
> Thanks for all...
>
>
> 2015-03-31 14:50 GMT+02:00 Matthias Kuhn <matthias at opengis.ch>:
>
>> You should get a parameter containing the composer that is being deleted
>> with composerWillBeRemoved signal. Try to use that to infer which composer
>> has been removed. As the signal name indicates, at the time it is emitted,
>> the composer is not deleted yet.
>> As an alternative you may make the connection with Qt.QueuedConnection.
>> It is possible that with this connection style you will receive the signal
>> after deletion and are able to continue using your current update method.
>>
>> Best
>> Matthias
>>
>>
>> On 03/31/2015 02:04 PM, Junior Delaz wrote:
>>
>> Matthias,
>> Thanks. I just give it a try it and all goes well with composerAdded.
>> But not really well with composerWillBeRemoved signal. The first
>> deletion in the composer manager does nothing and deleting a second
>> composer does remove the first one in my list. and so on...
>> My update function should be rewritten I think. I'll try to see how
>> improving it and may (surely) ask again for help (if needed).
>>
>> While seeking information about composerWillBeRemoved, I found a
>> composerRemoved [1] [2] signal (that doesn't appear in the API doc) and
>> without being able to use it. :(
>> [1]
>> https://github.com/qgis/QGIS/blob/master/src/app/composer/qgscomposermanager.cpp
>> (line 48
>> [2] https://github.com/qgis/QGIS/blob/master/src/app/qgisapp.cpp (line
>> 5601)
>>
>> Another thing that may not be related : what the deletePrintComposers
>> function (https://github.com/qgis/QGIS/blob/master/src/app/qgisapp.cpp
>> line 5698) is for?
>>
>> Thanks again for the clue.
>>
>> 2015-03-31 9:43 GMT+02:00 Matthias Kuhn <matthias at opengis.ch>:
>>
>>> QgisInterface (iface) has a composerAdded and composerWillBeRemoved
>>> signal.
>>>
>>> Did you try to connect to these?
>>>
>>> Best,
>>> Matthias
>>>
>>>
>>> On 03/31/2015 09:34 AM, Junior wrote:
>>>
>>> Hi all, Luca
>>> Thanks for answering. But i already have an update function that I
>>> linked to an update list button. I even linked it to the icon on the
>>> toolbar so that when user calls foreground the dialog it's already updated.
>>> The case I'd like to manage: user can open plugin dialog and composer
>>> manager. The two dialogs are visible (to the eyes) even though composer
>>> manager is the one at foreground. He makes changes and directly clicked on
>>> the plugin dialog. He should update list but if he forgets and executes,
>>> this may lead to bug I don't want to / can't yet manage.
>>> Reason why I want to ensure that list is always up to date when he
>>> interacts with the dialog
>>>
>>> Envoyé depuis mon HTC
>>>
>>> ----- Reply message -----
>>> De : "Luca Manganelli" <luca76 at gmail.com> <luca76 at gmail.com>
>>> Pour :
>>> Cc : "qgis-user at lists.osgeo.org" <qgis-user at lists.osgeo.org>
>>> <qgis-user at lists.osgeo.org> <qgis-user at lists.osgeo.org>,
>>> "qgis-developer" <qgis-developer at lists.osgeo.org>
>>> <qgis-developer at lists.osgeo.org>
>>> Objet : [Qgis-developer] [Qgis-user] Pyqt4 : which signal is sent when
>>> dialog comes to foreground?
>>> Date : mar., mars 31, 2015 07:56
>>>
>>> On Mon, Mar 30, 2015 at 6:12 PM, Junior Delaz <delazj at gmail.com> <delazj at gmail.com> wrote:
>>> > I've read about defining a custom showEvent function but can't understand
>>> > where to put it and what inside.
>>> > If somebody can give some tips...
>>>
>>> You could add a "Update list" button
>>> _______________________________________________
>>> Qgis-developer mailing listQgis-developer at lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>>
>>>
>>> _______________________________________________
>>> Qgis-developer mailing listQgis-developer at lists.osgeo.orghttp://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>>
>>>
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>
>>
>>
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20150407/3c78f7d5/attachment.html>
More information about the Qgis-developer
mailing list