Skip to content

Commit

Permalink
Merge pull request #3 from felferrari/qgis3
Browse files Browse the repository at this point in the history
Qgis3
  • Loading branch information
lcoandrade authored Sep 25, 2019
2 parents 6a68dcd + 61b2d0d commit 20c940f
Show file tree
Hide file tree
Showing 18 changed files with 331 additions and 256 deletions.
11 changes: 9 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,14 @@ Network Trash Folder
Temporary Items
.apdisk

# Byte-compiled / optimized / DLL files
# Python
*.pyc
__pycache__/
*.py[cod]
*.pydevproject
*.project

# VSCode
*.json

#Linux
.directory
72 changes: 42 additions & 30 deletions MultLayerSelection.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@
* *
***************************************************************************/
"""
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.gui import *
from qgis.core import *
from MultiLayerSelection import MultiLayerSelection
from MultiLayerRectangleSelection import MultiLayerRectangleSelection
from __future__ import absolute_import
from builtins import object
from qgis.PyQt.QtCore import QSettings, QTranslator, QCoreApplication, Qt
from qgis.PyQt.QtWidgets import QToolButton, QAction
from qgis.PyQt.QtGui import QIcon
from qgis.core import QgsMapLayer
from .MultiLayerSelection import MultiLayerSelection
from .MultiLayerRectangleSelection import MultiLayerRectangleSelection
# Initialize Qt resources from file resources.py
import resources
from . import resources

import os.path

class MultLayerSelection:
class MultLayerSelection(object):
"""QGIS Plugin Implementation."""

def __init__(self, iface):
Expand Down Expand Up @@ -61,6 +63,7 @@ def __init__(self, iface):

self.toolbar = self.iface.addToolBar(u'MultipleSelection')
self.toolbar.setObjectName(u'MultipleSelection')
self.actionList = []

def createToolButton(self, parent, text):
button = QToolButton(parent)
Expand All @@ -70,24 +73,19 @@ def createToolButton(self, parent, text):
parent.addWidget(button)
return button

def createAction(self, icon_path, text, callback):
def createAction(self, icon_path, text, callback, checkable=True):
action = QAction(
QIcon(icon_path),
text,
self.iface.mainWindow())
# connect the action to the run method
action.setCheckable(True)
action.toggled.connect(callback)
return action

def createClearAction(self, icon_path, text):
action = QAction(
QIcon(icon_path),
text,
self.iface.mainWindow())
# connect the action to the run method
action.setCheckable(False)
action.triggered.connect(self.clear)
action.setCheckable(checkable)
if checkable:
action.toggled.connect(callback)
else:
action.triggered.connect(callback)
self.iface.registerMainWindowAction(action, '')
self.actionList.append(action)
return action

def initGui(self):
Expand All @@ -102,8 +100,10 @@ def initGui(self):
self.runRectangle)

# Create action that will start plugin configuration
self.actionClear = self.createClearAction(":/plugins/MultipleLayerSelection/icon_clear.png",
u"Clear selections")
self.actionClear = self.createAction(":/plugins/MultipleLayerSelection/icon_clear.png",
u"Clear selections",
self.clear,
checkable=False)

self.tool = MultiLayerSelection(self.iface.mapCanvas(), self.actionCriar)
self.toolRectangle = MultiLayerRectangleSelection(self.iface.mapCanvas(), self.actionCriarRectangle)
Expand All @@ -118,29 +118,41 @@ def initGui(self):
def unload(self):
# Remove the plugin menu item and icon
self.iface.mainWindow().removeToolBar(self.toolbar)
for action in self.actionList:
try:
self.iface.unregisterMainWindowAction(action)
except:
pass
self.tool.deactivate()
self.toolRectangle.deactivate()

def clear(self):
self.actionCriar.setChecked(False)
self.actionCriarRectangle.setChecked(False)
self.selectionButton.setDefaultAction(self.selectionButton.sender())
try:
self.selectionButton.setDefaultAction(self.actionClear)
except:
pass
layers = self.iface.mapCanvas().layers()
for layer in layers:
if layer.type() == QgsMapLayer.RasterLayer:
continue
layer.removeSelection()

def run(self, b):
self.actionCriarRectangle.setChecked(False)
self.selectionButton.setDefaultAction(self.selectionButton.sender())
if b:
try:
self.selectionButton.setDefaultAction(self.actionCriar)
except:
pass
self.iface.mapCanvas().setMapTool(self.tool)
else:
self.iface.mapCanvas().unsetMapTool(self.tool)

def runRectangle(self, b):
self.actionCriar.setChecked(False)
self.selectionButton.setDefaultAction(self.selectionButton.sender())
if b:
try:
self.selectionButton.setDefaultAction(self.actionCriarRectangle)
except:
pass
self.iface.mapCanvas().setMapTool(self.toolRectangle)
else:
self.iface.mapCanvas().unsetMapTool(self.toolRectangle)
Expand Down
35 changes: 21 additions & 14 deletions MultiLayerRectangleSelection.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
@author: ferrari
'''
from qgis.gui import *
from qgis.core import *
from PyQt4.Qt import *
from qgis.core import QgsMapLayer, QgsPointXY, QgsRectangle, QgsWkbTypes
from qgis.gui import QgsMapTool, QgsRubberBand
from qgis.PyQt.QtGui import QColor

class MultiLayerRectangleSelection(QgsMapTool):

Expand All @@ -14,7 +14,7 @@ def __init__(self, canvas, action):
self.active = False
QgsMapTool.__init__(self, self.canvas)
self.setAction(action)
self.rubberBand = QgsRubberBand(self.canvas, QGis.Polygon)
self.rubberBand = QgsRubberBand(self.canvas, QgsWkbTypes.PolygonGeometry)
mFillColor = QColor( 254, 178, 76, 63 );
self.rubberBand.setColor(mFillColor)
self.rubberBand.setWidth(1)
Expand All @@ -23,7 +23,7 @@ def __init__(self, canvas, action):
def reset(self):
self.startPoint = self.endPoint = None
self.isEmittingPoint = False
self.rubberBand.reset(QGis.Polygon)
self.rubberBand.reset(QgsWkbTypes.PolygonGeometry)

def canvasPressEvent(self, e):
self.startPoint = self.toMapCoordinates(e.pos())
Expand All @@ -40,7 +40,7 @@ def canvasReleaseEvent(self, e):
continue
if r is not None:
lRect = self.canvas.mapSettings().mapToLayerCoordinates(layer, r)
layer.select(lRect, False)
layer.selectByRect(lRect, False)

self.rubberBand.hide()

Expand All @@ -51,13 +51,13 @@ def canvasMoveEvent(self, e):
self.showRect(self.startPoint, self.endPoint)

def showRect(self, startPoint, endPoint):
self.rubberBand.reset(QGis.Polygon)
self.rubberBand.reset(QgsWkbTypes.PolygonGeometry)
if startPoint.x() == endPoint.x() or startPoint.y() == endPoint.y():
return
point1 = QgsPoint(startPoint.x(), startPoint.y())
point2 = QgsPoint(startPoint.x(), endPoint.y())
point3 = QgsPoint(endPoint.x(), endPoint.y())
point4 = QgsPoint(endPoint.x(), startPoint.y())
point1 = QgsPointXY(startPoint.x(), startPoint.y())
point2 = QgsPointXY(startPoint.x(), endPoint.y())
point3 = QgsPointXY(endPoint.x(), endPoint.y())
point4 = QgsPointXY(endPoint.x(), startPoint.y())

self.rubberBand.addPoint(point1, False)
self.rubberBand.addPoint(point2, False)
Expand All @@ -74,9 +74,16 @@ def rectangle(self):
return QgsRectangle(self.startPoint, self.endPoint)

def deactivate(self):
self.rubberBand.hide()
QgsMapTool.deactivate(self)
self.rubberBand.reset()
try:
if self is not None:
QgsMapTool.deactivate(self)
except:
pass

def activate(self):
QgsMapTool.activate(self)


def unload(self):
self.deactivate()

23 changes: 16 additions & 7 deletions MultiLayerSelection.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
@author: ferrari
'''
from qgis.gui import *
from qgis.core import *
from PyQt4.Qt import *
from qgis.core import QgsRectangle, QgsMapLayer
from qgis.gui import QgsMapTool

class MultiLayerSelection(QgsMapTool):

Expand All @@ -24,12 +23,22 @@ def canvasPressEvent(self, e):
if layer.type() == QgsMapLayer.RasterLayer:
continue
lRect = self.canvas.mapSettings().mapToLayerCoordinates(layer, rect)
layer.select(lRect, False)
layer.selectByRect(lRect, False)

def deactivate(self):
if self is not None:
QgsMapTool.deactivate(self)
try:
if self is not None:
QgsMapTool.deactivate(self)
except:
pass

def activate(self):
QgsMapTool.activate(self)

try:
self.selectionButton.setDefaultAction(self.sender())
except:
pass

def unload(self):
self.deactivate()

Empty file modified README.txt
100644 → 100755
Empty file.
3 changes: 2 additions & 1 deletion __init__.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* *
***************************************************************************/
"""
from __future__ import absolute_import


# noinspection PyPep8Naming
Expand All @@ -28,5 +29,5 @@ def classFactory(iface): # pylint: disable=invalid-name
:type iface: QgsInterface
"""
#
from MultLayerSelection import MultLayerSelection
from .MultLayerSelection import MultLayerSelection
return MultLayerSelection(iface)
Empty file modified help/Makefile
100644 → 100755
Empty file.
Empty file modified help/make.bat
100644 → 100755
Empty file.
Empty file modified help/source/conf.py
100644 → 100755
Empty file.
Empty file modified help/source/index.rst
100644 → 100755
Empty file.
Empty file modified i18n/af.ts
100644 → 100755
Empty file.
Empty file modified icon.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified icon_clear.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified icon_rectangle.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file modified metadata.txt
100644 → 100755
Empty file.
55 changes: 36 additions & 19 deletions plugin_upload.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
Authors: A. Pasotti, V. Picavet
git sha : $TemplateVCSFormat
"""
from __future__ import print_function

from future import standard_library
standard_library.install_aliases()
from builtins import input
import sys
import getpass
import xmlrpclib
import xmlrpc.client
from optparse import OptionParser

# Configuration
Expand All @@ -31,25 +35,36 @@ def main(parameters, arguments):
parameters.server,
parameters.port,
ENDPOINT)
print "Connecting to: %s" % hide_password(address)
# fix_print_with_import
print("Connecting to: %s" % hide_password(address))

server = xmlrpclib.ServerProxy(address, verbose=VERBOSE)
server = xmlrpc.client.ServerProxy(address, verbose=VERBOSE)

try:
plugin_id, version_id = server.plugin.upload(
xmlrpclib.Binary(open(arguments[0]).read()))
print "Plugin ID: %s" % plugin_id
print "Version ID: %s" % version_id
except xmlrpclib.ProtocolError, err:
print "A protocol error occurred"
print "URL: %s" % hide_password(err.url, 0)
print "HTTP/HTTPS headers: %s" % err.headers
print "Error code: %d" % err.errcode
print "Error message: %s" % err.errmsg
except xmlrpclib.Fault, err:
print "A fault occurred"
print "Fault code: %d" % err.faultCode
print "Fault string: %s" % err.faultString
xmlrpc.client.Binary(open(arguments[0]).read()))
# fix_print_with_import
print("Plugin ID: %s" % plugin_id)
# fix_print_with_import
print("Version ID: %s" % version_id)
except xmlrpc.client.ProtocolError as err:
# fix_print_with_import
print("A protocol error occurred")
# fix_print_with_import
print("URL: %s" % hide_password(err.url, 0))
# fix_print_with_import
print("HTTP/HTTPS headers: %s" % err.headers)
# fix_print_with_import
print("Error code: %d" % err.errcode)
# fix_print_with_import
print("Error message: %s" % err.errmsg)
except xmlrpc.client.Fault as err:
# fix_print_with_import
print("A fault occurred")
# fix_print_with_import
print("Fault code: %d" % err.faultCode)
# fix_print_with_import
print("Fault string: %s" % err.faultString)


def hide_password(url, start=6):
Expand Down Expand Up @@ -85,7 +100,8 @@ def hide_password(url, start=6):
help="Specify server name", metavar="plugins.qgis.org")
options, args = parser.parse_args()
if len(args) != 1:
print "Please specify zip file.\n"
# fix_print_with_import
print("Please specify zip file.\n")
parser.print_help()
sys.exit(1)
if not options.server:
Expand All @@ -95,8 +111,9 @@ def hide_password(url, start=6):
if not options.username:
# interactive mode
username = getpass.getuser()
print "Please enter user name [%s] :" % username,
res = raw_input()
# fix_print_with_import
print("Please enter user name [%s] :" % username, end=' ')
res = input()
if res != "":
options.username = res
else:
Expand Down
Loading

0 comments on commit 20c940f

Please sign in to comment.