For those who want to know “how Blender works” to write their own scripts and add-ons, the developers have provided a very convenient option – the ability to view any element source code in a single click.
To see the source code of any element: open the “Text Editor” window; then simply click on the desired element with the right mouse button and select “Edit Source”.
A file with the source code of this element will open in the “Text Editor” window. And the cursor will be placed on the desired line.
This method will work for any elements written in Python. For elements that were compiled to the Blender core in C++ (for example, elements of the “File Browser” window), their code cannot be displayed.
If the “Edit Source” item does not appear in the right-click menu, check the “Developers Extras” checkbox in Blender preferences.