|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | + |
| 3 | +""" |
| 4 | +*************************************************************************** |
| 5 | + PointSelectionPanel.py |
| 6 | + --------------------- |
| 7 | + Date : February 2016 |
| 8 | + Copyright : (C) 2016 by Alexander Bruy |
| 9 | + Email : alexander dot bruy at gmail dot com |
| 10 | +*************************************************************************** |
| 11 | +* * |
| 12 | +* This program is free software; you can redistribute it and/or modify * |
| 13 | +* it under the terms of the GNU General Public License as published by * |
| 14 | +* the Free Software Foundation; either version 2 of the License, or * |
| 15 | +* (at your option) any later version. * |
| 16 | +* * |
| 17 | +*************************************************************************** |
| 18 | +""" |
| 19 | + |
| 20 | +__author__ = 'Alexander Bruy' |
| 21 | +__date__ = 'February 2016' |
| 22 | +__copyright__ = '(C) 2016, Alexander Bruy' |
| 23 | + |
| 24 | +# This will get replaced with a git SHA1 when you do a git archive |
| 25 | + |
| 26 | +__revision__ = '$Format:%H$' |
| 27 | + |
| 28 | +import os |
| 29 | + |
| 30 | +from PyQt4 import uic |
| 31 | +from PyQt4.QtGui import QCursor |
| 32 | + |
| 33 | +from qgis.gui import QgsMessageBar |
| 34 | +from qgis.utils import iface |
| 35 | + |
| 36 | +from processing.gui.PointMapTool import PointMapTool |
| 37 | + |
| 38 | +pluginPath = os.path.split(os.path.dirname(__file__))[0] |
| 39 | +WIDGET, BASE = uic.loadUiType( |
| 40 | + os.path.join(pluginPath, 'ui', 'widgetBaseSelector.ui')) |
| 41 | + |
| 42 | + |
| 43 | +class PointSelectionPanel(BASE, WIDGET): |
| 44 | + |
| 45 | + def __init__(self, dialog, default=None): |
| 46 | + super(PointSelectionPanel, self).__init__(None) |
| 47 | + self.setupUi(self) |
| 48 | + |
| 49 | + self.btnSelect.clicked.connect(self.selectOnCanvas) |
| 50 | + |
| 51 | + self.dialog = dialog |
| 52 | + |
| 53 | + canvas = iface.mapCanvas() |
| 54 | + self.prevMapTool = canvas.mapTool() |
| 55 | + |
| 56 | + self.tool = PointMapTool(canvas) |
| 57 | + self.tool.canvasClicked.connect(self.updatePoint) |
| 58 | + |
| 59 | + if default: |
| 60 | + tokens = unicode(default).split(',') |
| 61 | + if len(tokens) == 2: |
| 62 | + try: |
| 63 | + float(tokens[0]) |
| 64 | + float(tokens[1]) |
| 65 | + self.leText.setText(unicode(default)) |
| 66 | + except: |
| 67 | + pass |
| 68 | + |
| 69 | + def selectOnCanvas(self): |
| 70 | + canvas = iface.mapCanvas() |
| 71 | + canvas.setMapTool(self.tool) |
| 72 | + self.dialog.showMinimized() |
| 73 | + |
| 74 | + def updatePoint(self, point, button): |
| 75 | + s = '{},{}'.format(point.x(), point.y()) |
| 76 | + |
| 77 | + self.leText.setText(s) |
| 78 | + canvas = iface.mapCanvas() |
| 79 | + canvas.setMapTool(self.prevMapTool) |
| 80 | + self.dialog.showNormal() |
| 81 | + self.dialog.raise_() |
| 82 | + self.dialog.activateWindow() |
| 83 | + |
| 84 | + def getValue(self): |
| 85 | + if unicode(self.leText.text()).strip() != '': |
| 86 | + return unicode(self.leText.text()) |
| 87 | + else: |
| 88 | + return None |
| 89 | + |
| 90 | + def setPointFromString(self, s): |
| 91 | + self.leText.setText(s) |
0 commit comments