On Mon, 29 Jun 2020 at 14:39, Jan Růžička <[email protected]> wrote:
>
> Thank you. As you wrote, the problem is that this works only for the Widged
> of the plugin. There is not a way to override the closeEvent() method of the
> main QGIS Window from the plugin, since the plugin has only an interface
> given by the QGIS.
>
> I have decided to use the workaround for now, so when the QGIS is closed it
> will start again. The solution is not so perfect, but at least it is a
> solution.
>
> Another way to do this is to rewrite C++ code. The code is not so complicated
> and I can rewrite it, but then I have to build QGIS for all police stations
> and keep it updated and it is not so simple for me.
Not sure how to intercept the quit action cleanly, but you can
intercept the "X" button click:
class NoClose(QObject):
def __init__(self, parent=None):
super().__init__(parent)
def ok_to_close(self):
return False
def eventFilter(self, object, event):
if isinstance(event, QCloseEvent):
if not self.ok_to_close():
event.ignore()
return True
return super().eventFilter( object, event )
no_close = NoClose()
iface.mainWindow().installEventFilter(no_close)
>
> Thank you again
>
> Jan Růžička, Ph.D.
> freelancer, researcher and volontaire
> Geoinformatics
> tel: +420 775 032 091
> e-mail: [email protected]
> http://github.com/ruz76/
> http://gismentors.eu/
> http://dolnilhota.info/
>
>
> Le ven. 26 juin 2020 à 09:09, Ujaval Gandhi <[email protected]> a
> écrit :
>>
>> The way to achieve this would be to override the closeEvent() method of the
>> main QGIs Window. I don't know how to do that. But you can do that on your
>> plugin widget - which will at least prevent that dialog to be closed if
>> certain conditions are not met.
>>
>> def closeEvent(self, event):
>> if condition:
>> event.accept()
>> else:
>> event.ignore()
>> Ujaval Gandhi
>> Spatial Thoughts
>> mobile: +91-8095684687
>> email: [email protected]
>>
>> Subscribe to our newsletter http://bit.ly/spatialthoughts-newsletter
>>
>>
>>
>> On Fri, Jun 26, 2020 at 10:02 AM Jan Růžička <[email protected]>
>> wrote:
>>>
>>> Thank you very much, the same is possible in the unload method of the
>>> plugin, but the question is how to stop QGIS to exit.
>>> I need to inform the user that he did not enter the result of the search
>>> and keep QGIS open for the user to enter the result.
>>>
>>> The possible workaround may be, to run the QGIS again, when it quits, but I
>>> thought that there may be some better way.
>>>
>>> Jan Růžička, Ph.D.
>>> freelancer, researcher and volontaire
>>> Geoinformatics
>>> tel: +420 775 032 091
>>> e-mail: [email protected]
>>> http://github.com/ruz76/
>>> http://gismentors.eu/
>>> http://dolnilhota.info/
>>>
>>>
>>> Le jeu. 25 juin 2020 à 17:25, Ujaval Gandhi <[email protected]> a
>>> écrit :
>>>>
>>>> I saw that there is a aboutToQuit signal emitted just before a
>>>> QApplication exists. The following works from QGIS Python Console.
>>>>
>>>> def test():
>>>> with open('/tmp/test.txt', 'w') as f:
>>>> f.write('wrote while exiting')
>>>>
>>>> qApp.aboutToQuit.connect(test)
>>>> Ujaval Gandhi
>>>> Spatial Thoughts
>>>> mobile: +91-8095684687
>>>> email: [email protected]
>>>>
>>>> Subscribe to our newsletter http://bit.ly/spatialthoughts-newsletter
>>>>
>>>>
>>>>
>>>> On Thu, Jun 25, 2020 at 5:00 PM Jan Růžička <[email protected]>
>>>> wrote:
>>>>>
>>>>> Dear developers,
>>>>>
>>>>> I have developed a plugin for the Police of the Czech Republic for Search
>>>>> and Rescue operations. It works quite well, but one important feature is
>>>>> missing.
>>>>>
>>>>> After the search event is finished the user should enter the result of
>>>>> the search.
>>>>>
>>>>> I was not able to find a way to catch an event when the user closes the
>>>>> whole QGIS. I need similar functionality like when closing in the case of
>>>>> a dirty project (no all changes were saved).
>>>>>
>>>>> I have searched a lot and did not find any solution. I was able to catch
>>>>> the unload event of the plugin, but I did not find a way to keep QGIS
>>>>> opened.
>>>>>
>>>>> Any help appreciated
>>>>> Jan Růžička, Ph.D.
>>>>> freelancer, researcher and volontaire
>>>>> Geoinformatics
>>>>> tel: +420 775 032 091
>>>>> e-mail: [email protected]
>>>>> http://github.com/ruz76/
>>>>> http://gismentors.eu/
>>>>> http://dolnilhota.info/
>>>>> _______________________________________________
>>>>> QGIS-Developer mailing list
>>>>> [email protected]
>>>>> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>>>>> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
> _______________________________________________
> QGIS-Developer mailing list
> [email protected]
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
_______________________________________________
QGIS-Developer mailing list
[email protected]
List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer