<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hello!</p>
    <p>I try to develop some Python modules for construction in
      landsurveying projects. Therefore these tools must be able to snap
      to existiing vertices in a map. I found a class,which snaps to
      existing vertices, settings are taken from qgis, which uses
      QgsMapToolEmitPoint</p>
    <p>class ShowOnMapTool(QgsMapToolEmitPoint):<tt><br>
      </tt></p>
    <p><tt>    def __init__(self, iface, <b>PointXY</b>):</tt><tt><br>
      </tt><tt>        QgsMapToolEmitPoint.__init__(self,
        iface.mapCanvas())</tt><tt><br>
      </tt><tt>        self.iface = iface</tt><tt><br>
      </tt><tt>        self.canvas = iface.mapCanvas()</tt><tt><br>
      </tt><tt>        self.marker = None</tt><tt><br>
      </tt><tt>        self.vertex = None </tt><tt><br>
      </tt><tt>        <b>self.rtnPoint = PointXY</b> <br>
      </tt></p>
    <p><tt>...</tt></p>
    <p><tt>    def canvasPressEvent(self, event):<br>
                '''Capture the coordinate when the mouse button has been
        released,<br>
                format it, and copy it to the clipboard.'''<br>
                self.<b>rtnPoint</b> =
        self.snappoint(event.originalPixelPoint())<br>
                self.removeVertexMarker()<br>
        <br>
                if self.marker is None:<br>
                    self.marker = QgsVertexMarker(self.canvas)<br>
                    self.marker.setIconSize(18)<br>
                    self.marker.setPenWidth(2)<br>
                    self.marker.setIconType(QgsVertexMarker.ICON_CROSS)<br>
                self.marker.setCenter(<b>self.rtnPoint</b>)    <br>
      </tt></p>
    <p><tt>...</tt></p>
    <p>In my form I want to use the snapped coordinates in textboxes.
      Therefore I added the rtnPoint in the init-procedere and in the
      canvasPressEvent-Function listed above.</p>
    <p>In my own class I did this:</p>
    <p><tt>class InputMeasurepoints:</tt><tt><br>
      </tt><tt>    def __init__(self, iface):</tt><tt><br>
      </tt><tt>        self.iface = iface</tt><tt><br>
      </tt><tt>        self.plugin_dir = os.path.dirname(__file__)</tt><tt><br>
      </tt><tt>        locale =
        QSettings().value('locale/userLocale')[0:2]</tt><tt><br>
      </tt><tt>        locale_path = os.path.join(</tt><tt><br>
      </tt><tt>            self.plugin_dir,</tt><tt><br>
      </tt><tt>            'i18n',</tt><tt><br>
      </tt><tt>            'InputMeasurepoints_{}.qm'.format(locale))</tt><tt><br>
      </tt><tt><br>
      </tt><tt>        if os.path.exists(locale_path):</tt><tt><br>
      </tt><tt>            self.translator = QTranslator()</tt><tt><br>
      </tt><tt>            self.translator.load(locale_path)</tt><tt><br>
      </tt><tt>           
        QCoreApplication.installTranslator(self.translator)</tt><tt><br>
      </tt><tt><br>
      </tt><tt>        self.actions = []</tt><tt><br>
      </tt><tt>        self.menu = self.tr(u'&SurveyingTools')</tt><tt><br>
      </tt><tt>        self.first_start = None</tt><tt><br>
      </tt><tt>        self.canvas = iface.mapCanvas()</tt><tt><br>
      </tt><b><tt>        self.Point=QgsPointXY()    </tt></b><b><tt><br>
        </tt></b><b><tt>        self.ShowMapTool =
          ShowOnMapTool(self.iface,self.Point)</tt></b><tt><br>
      </tt><tt><br>
      </tt><tt>        self.marker = None</tt><tt><br>
      </tt><tt>        self.vertex = None</tt></p>
    <p><tt>...</tt></p>
    <p><tt>    def onMouseClick(self,button):<br>
                self.dlg.ledt_Rechts.setText(format("%.3f" %<b>self.ShowMapTool.rtnPoint.x()</b>))<br>
                self.dlg.ledt_Hoch.setText(format("%.3f" %<b>self.ShowMapTool.rtnPoint.y()</b>))       
        <br>
        <br>
            def getPoint(self):                            <br>
                self.canvas.setMapTool(self.ShowMapTool)        <br>
               
self.ShowMapTool.canvasClicked.connect(self.onMouseClick)                
        <br>
        <br>
            def run(self):<br>
                if self.first_start == True:<br>
                    self.first_start = False<br>
                    self.dlg = InputMeasurepointsDialog()<br>
                    self.dlg.btnPickXY.clicked.connect(self.getPoint)</tt></p>
    <p>Nothing happens, the Programm does not reach the
      onMouseClick-Function, and the ShowMapTool does not stop. How can
      I get the rtnPoint of the ShowOnMapTool-Class, what is wrong? I
      found no example Code in the web, I do not understand how
      QgsMapToolEmitPoint and the Mouse events work together. Is there
      any document with simple examples?</p>
    <p>Thank you for investing your time in a stupid beginner like me!</p>
    <p>Sugarfox<br>
    </p>
  </body>
</html>