silx-kit / silx

silx toolkit
http://www.silx.org/doc/silx/latest/
MIT License
120 stars 71 forks source link

[file dialog] Weird code with listeners #2938

Open vallsv opened 4 years ago

vallsv commented 4 years ago

Feedback from https://github.com/silx-kit/pyFAI/issues/1327

This pattern is used 2 time in AbstractDataFileDialog

        if selectionModel is not None:
            selectionModel.selectionChanged.disconnect()
            selectionModel.clear()
        selectionModel = self.__detailView.selectionModel()
        if selectionModel is not None:
            selectionModel.selectionChanged.disconnect()
            selectionModel.clear()

It looks weird. disconnect is usually used with a callback, and it is used together with connect.

Maybe PyQt was ignoring errors here and that is why it is broken now. No idea. This should be reviewed.

vallsv commented 4 years ago

Obviously that's the code from the guy i was 2 years ago.

vallsv commented 4 years ago

Finally, it looks fine. The only problem is if it is called after a clear, there will be an exception.

Cause disconnect() remove everything, or raise an exception if there is nothing inside. Then signals should be added anyway. From the start. Or we have to check that something can be removed (this API exists in Qt5).

vallsv commented 4 years ago

Anyway, i can't reproduce the problem, that's maybe OS specific.