NSLS2 / pymca

PyMca Toolkit git repository
Other
0 stars 3 forks source link

Docs: Adding a Passthrough Event Filter to a QWidget #16

Open padraic-shafer opened 1 month ago

padraic-shafer commented 1 month ago

In the major refactoring that is expected to happen during the early stages of our https://github.com/NSLS2/pymca/milestone/1 work, some code examples might get lost from the active branch.

Here, I'm documenting the idea of using a PassThroughEventFilter helper class to simplify adding non-consuming event filters from a view model to a view widget. This is extracted from commit f0b87e5 .

padraic-shafer commented 1 month ago

Here the PassThroughEventFilter helper class is defined with an eventFilter() method that runs a matching event handler and then sends the event to the filter of the parent QObject.

https://github.com/NSLS2/pymca/blob/f0b87e5fa1b1bd2e1d2cd5d1d7e88d0136b3abee/PyMca5/PyMcaGui/io/QTiledCatalogSelectorDialog.py#L16-L43

If a handler has been registeredduring PassThroughEventFilter initialization for the type of event being processed, then it will be called. Otherwise a 'no-op' handler is called.

padraic-shafer commented 1 month ago

Here is an example of an event handler being registered by the connect_model_slots() method of the QTiledCatalogSelectorDialog widget.

https://github.com/NSLS2/pymca/blob/f0b87e5fa1b1bd2e1d2cd5d1d7e88d0136b3abee/PyMca5/PyMcaGui/io/QTiledCatalogSelectorDialog.py#L114-L126

padraic-shafer commented 1 month ago

Finally, here is an example of a simple event handler that responds to the FocusIn event, that is described above.

https://github.com/NSLS2/pymca/blob/f0b87e5fa1b1bd2e1d2cd5d1d7e88d0136b3abee/PyMca5/PyMcaGui/io/TiledCatalogSelector.py#L69-L76