An example of creating QGIS 2.18 plugin using Python
Using this plugin you can create a definition query from selected objects on different layers in qgis project. Also you can clear a defenition query.
You need to have QGIS on your computer
QGIS API - http://qgis.org/api/2.0/annotated.html
PyQGIS Developer Cookbook - http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/
Tutorials - http://www.qgistutorials.com/ru/index.html
Developing python Plugins - http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/plugins.html
Writing plugins tutorial - http://www.qgistutorials.com/ru/docs/building_a_python_plugin.html