qgis-sample-QgsMapCanvasSnappingUtils.py
from qgis.core import QgsSnappingUtils
from qgis.gui import QgsMapCanvasSnappingUtils
from qgis.utils import iface
canvas = iface.mapCanvas()
snapping_utils = QgsSnappingUtils()
print(snapping_utils.snapToMapMode())
print(snapping_utils.snapToMapMode())
snapping_utils.readConfigFromProject()
snapping_utils = canvas.snappingUtils()
snapping_utils.defaultSettings()
print([
i for i in ['SnapCurrentLayer', 'SnapAdvanced', 'SnapAllLayers']
if snapping_utils.snapToMapMode() == getattr(QgsSnappingUtils, i)
][0])
print(snapping_utils.layers())
print(snapping_utils.defaultSettings())
map_canvas_snapping_utils = QgsMapCanvasSnappingUtils(canvas)
canvas.setSnappingUtils(map_canvas_snapping_utils)