I'm trying that to create a class that inherits from QgsMapTool and deactivates itself after a canvasPressEvent is called. I've tried three options (in the code below) but none of them is working.
class getCoordinateTool (QgsMapTool):
def __init__(self,owner, canvas,onclick,projectInstance):
"""constructor"""
super().__init__(canvas)
self.owner = owner
self.canvas = canvas
self.onClick = onclick
self.project_instance = projectInstance
def deactivate(self):
#option 1:
#super().deactivate()
#option 2:
#super(getCoordinateTool, self).deactivate()
#option 3:
QgsMapTool.deactivate(self)
self.deactivated.emit()
def canvasPressEvent(self, e):
super().canvasPressEvent(e)
pos=self.toMapCoordinates(e.pos())
crsSrc = QgsProject.instance().crs()
(x,y) = coorTransform(pos, crsSrc,self.project_instance)
self.onClick(x,y)
#deactivate the select tool
self.deactivate()