本文整理汇总了Python中PyQt4.QtCore.QPoint.setY方法的典型用法代码示例。如果您正苦于以下问题:Python QPoint.setY方法的具体用法?Python QPoint.setY怎么用?Python QPoint.setY使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QPoint
的用法示例。
在下文中一共展示了QPoint.setY方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: readSettings
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def readSettings(self):
self.imageFolder = os.path.normpath(str(self.settings.value("imageFolder").toString()))
self.ui.actionIgnore_Transparent_Pixels.setChecked( self.settings.value("ignoreAlpha", True).toBool())
self.ui.actionCheck_for_update_at_start.setChecked( self.settings.value("checkupdate", True).toBool())
self.ui.tolerance_le.setText( self.settings.value("tolerance").toString())
self.settings.beginGroup("/geometry")
p = QPoint() # position
s = QSize() # size
x = self.settings.value("X", -1).toInt()[0]
y = self.settings.value("Y", -1).toInt()[0]
# don't position outside current screen
qRect = QtGui.QDesktopWidget.availableGeometry(app.desktop())
if x > qRect.right():
x = 10
if y > qRect.bottom():
y = 10
p.setX(x)
p.setY(y)
s.setWidth(self.settings.value("W", -1).toInt()[0])
s.setHeight(self.settings.value("H", -1).toInt()[0])
self.settings.endGroup()
if p.x() > 0 and p.y() > 0 and s.width() > 0 and s.height() > 0:
self.resize(s) # restore size
self.move(p) # restore position
示例2: MovingMessage
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
class MovingMessage(FadeMessage):
def __init__(self, message, str = None, pos = None):
cfg = Config('messages', message)
if (pos is None):
self.pos = QPoint(*cfg.get('position'))
else:
self.pos = QPoint(*pos)
self.velocity = cfg.get('velocity')
FadeMessage.__init__(self, message, str)
def with_controller(self):
self.rect = QRect(0, 0, self.controller.width(), self.controller.height())
self.rect.moveCenter(self.pos)
def tick(self, elapsed):
FadeMessage.tick(self, elapsed)
self.pos.setX(self.pos.x() + self.velocity[0] * elapsed)
self.pos.setY(self.pos.y() + self.velocity[1] * elapsed)
self.rect.moveCenter(self.pos)
def draw(self):
FadeMessage.draw(self)
if (self.color.alpha() == 0):
self.rect = self.bounding_text_rect
示例3: open_link
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def open_link(self, x, y):
self.__upostda_condition.acquire()
p = QPoint()
p.setX(int(x))
p.setY(int(y))
self.emit(QtCore.SIGNAL('signalUPosDA(QPoint *)'), p)
self.__upostda_condition.wait()
self.__upostda_condition.release()
示例4: tryMove
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def tryMove(self, oldPos, newPos, directions):
p = QPoint(oldPos)
if directions & 1: #X轴方向
gridX = self.parent().width() / 40
delta = newPos.x() - oldPos.x()
if abs(delta) / gridX > 0.5:
newX = oldPos.x() + delta / abs(delta) * gridX * round(abs(delta) / gridX)
newX = gridX * round(newX / gridX)
p.setX(newX)
if directions & 2:
gridY = self.parent().height() / 30
delta = newPos.y() - oldPos.y()
if abs(delta) / gridY > 0.5:
newY = oldPos.y() + delta / abs(delta) * gridY * round(abs(delta) / gridY)
newY = gridY * round(newY / gridY)
p.setY(newY)
return p
示例5: adjustPosition
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def adjustPosition(self, eventPos):
'''
@param eventPos - QPoint
'''
prop = MaeMoneyProperties.instance()
newPos = QPoint(eventPos.x(), eventPos.y())
if prop.isPortraitMode():
offset = 50
else:
offset = 72
newY = max(0, eventPos.y() - offset)
newPos.setY(newY)
return newPos
示例6: kineticAddDelta
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def kineticAddDelta(self, delta ):
"""Add a kinetic delta to an already started kinetic move."""
speed = QPoint(0,0)
# Get the remaining scroll amount.
currentSpeed = abs( self._kineticData._speed.y() )
leftToScroll = (currentSpeed+1)*currentSpeed / 2 ;
if self._kineticData._speed.y() < 0:
leftToScroll *= -1
leftToScroll += delta
speed.setY((sqrt(1+8*abs(leftToScroll))-1)/2)
speed.setX( self._kineticData._speed.x() )
if leftToScroll < 0:
speed.setY(-speed.y())
self.kineticStart(speed)
示例7: paintEvent
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def paintEvent(self, event):
def _drawitem(pixmap, text, itempostion):
painter.drawPixmap(itempostion, pixmap)
textrect = QRectF(pixmap.width() + 40,
itempostion.y(),
framerect.width() - pixmap.width() - 40,
pixmap.height())
painter.drawText(textrect, text, QTextOption(Qt.AlignVCenter))
if not self.pixmap:
return
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.drawPixmap(event.rect(), self.pixmap)
rect = event.rect()
framerect = QRect(rect)
newwidth = (rect.width() / 100) * 40
framerect.setWidth(newwidth)
painter.setBrush(self.legendareabrush)
painter.setPen(self.legendareapen)
painter.drawRect(framerect)
self.framerect = framerect
painter.setPen(Qt.black)
currenty = 40
position = rect.topLeft() + QPoint(30, currenty)
for layer, items in self.items.iteritems():
if len(items) == 1:
itempostion = QPoint(position)
itempostion.setY(currenty)
_drawitem(items[0][1], layer, itempostion)
currenty += 40
else:
for text, icon in items:
if not text:
continue
itempostion = QPoint(position)
itempostion.setY(currenty)
_drawitem(icon, text, itempostion)
currenty += 40
position.setY(currenty + 40)
示例8: drawXInfos
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def drawXInfos(self):
pen = self.painter.pen()
i = 1
scale = 6
x = self.yLeftMargin
y = self.ploter.height - self.m
if not self.selDateMin:
date = self.baseDateMin
shift_date = (self.baseDateMax - self.baseDateMin) / scale
else:
date = self.selDateMin
shift_date = (self.selDateMax - self.selDateMin) / scale
while i <= scale + 1:
pen.setColor(Qt.black)
pen.setStyle(Qt.SolidLine)
pos = QPoint(x - 40, y + 17)
self.painter.setPen(pen)
# Draw vertical doted line
self.painter.drawLine(x, y - 3, x, y + 3)
# Draw date
self.painter.drawText(pos, str(self.timeline.fromUSec(date).strftime('%d.%m.%Y')))
# If number of days shown < scale, draw time
if shift_date <= (86400 * 1000000):
pos.setY(pos.y() + 15)
pos.setX(pos.x() + 9)
# Draw time
self.painter.drawText(pos, str(self.timeline.fromUSec(date).strftime('%H:%M:%S')))
pen.setColor(Qt.gray)
pen.setStyle(Qt.DotLine)
self.painter.setPen(pen)
if i != 1:
self.painter.drawLine(x, y + 3, x, self.m / 3)
x = self.yLeftMargin + (i * ((self.ploter.width - self.m - self.yLeftMargin) / (scale)))
i += 1
date += shift_date
pen.setStyle(Qt.SolidLine)
self.painter.setPen(pen)
示例9: GLWidget
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
#.........这里部分代码省略.........
# frameBufferA.bind()
# frameBufferA.release()
glViewport(0, 0, self.width(), self.height())
orthoMatrix = QMatrix4x4()
orthoMatrix.ortho(
0 + self.__scrollOffset.x(),
self.width() + self.__scrollOffset.x(),
self.height() + self.__scrollOffset.y(),
0 + self.__scrollOffset.y(),
-100,
100,
)
transformMatrix = QMatrix4x4()
transformMatrix.setToIdentity()
transformMatrix.scale(self.__zoomFactor)
### activate shader program
# self.__shaderProgram.bind()
### set a shader attribute (0 means use texture, 1 means use color)
# self.__shaderProgram.setUniformValue(self.__use_color_location, 0.0)
### feed the mpv matrix
mpvMatrix = orthoMatrix * transformMatrix
# self.__shaderProgram.setUniformValue(self.__mvpMatrixLocation, mpvMatrix)
# Draw Something
self.__myBufferPainter.paintGL(
self.__scrollOffset.x(), self.__scrollOffset.y(), self.width(), self.height(), self.__zoomFactor, mpvMatrix
)
"""
### DRAW SOMETHING
### bind texture
glBindTexture(GL_TEXTURE_2D, self.__ori_tex)
### bind VAO
glBindVertexArray(self.__VAO)
### draw triangle
glDrawArrays(GL_TRIANGLES, 0, 18)
"""
### unbind
# glBindVertexArray(0)
# glUseProgram(0)
# self.__shaderProgram.release()
def SetSomething(self):
pass
def DrawSomething(self):
pass
def ZoomIn(self):
self.__zoomFactor += 0.1
def ZoomOut(self):
self.__zoomFactor -= 0.1
if self.__zoomFactor < 0.1:
self.__zoomFactor = 0.1
"""
Get / Set
"""
def GetImageSize(self):
"""
Get the size of the canvas / image
"""
return QSize(self.__image_width, self.__image_height)
def SetZoomFactor(self, val):
"""
Set the value of magnification
"""
self.__zoomFactor = val
def GetZoomFactor(self):
"""
Obtain the value of the magnification
"""
return self.__zoomFactor
def SetMouseDown(self, val):
"""
Set the value of mouse down
"""
self.__isMouseDown = val
def SetHorizontalScroll(self, val):
"""
Set horizontal scroll value
"""
self.__scrollOffset.setX(val)
def SetVerticalScroll(self, val):
"""
Set vertical scroll value
"""
self.__scrollOffset.setY(val)
示例10: paintEvent
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def paintEvent(self, event):
def itemlist(items):
for layer, items in self.items.iteritems():
if len(items) == 1:
yield layer, items[0][1]
else:
for text, icon in items:
if not text:
continue
yield text, icon
def _drawitem(pixmap, text, itempostion):
painter.drawPixmap(itempostion, pixmap)
textrect = QRectF(pixmap.width() + currentx + 10,
itempostion.y(),
event.rect().width() - pixmap.width() - OFFSET_X,
pixmap.height())
painter.drawText(textrect, text, QTextOption(Qt.AlignVCenter))
def calcitems():
font = painter.font()
metrices = QFontMetrics(font)
maxwidth = 0
maxheight = 0
for item, _ in itemlist(self.items):
maxwidth = max(metrices.boundingRect(item).width(), maxwidth)
maxheight = max(metrices.boundingRect(item).height(), maxheight)
return maxwidth, maxheight
if not self.pixmap:
return
painter = QPainter(self)
painter.setRenderHints(QPainter.Antialiasing)
painter.drawPixmap(event.rect(), self.pixmap)
itemwidths, itemmaxheight = calcitems()
OFFSET_X = 30
OFFSET_Y = itemmaxheight + 10
rect = event.rect()
neededheight = (len(self.items) * OFFSET_Y)
runs = 1
if neededheight > rect.height():
import math
runs = math.ceil(neededheight / float(rect.height()))
print runs
framerect = QRect(rect)
framewidth = (itemwidths + OFFSET_X + ICON_SIZE.width() + 100) * runs
framerect.setWidth(framewidth)
painter.setBrush(self.legendareabrush)
painter.setPen(self.legendareapen)
painter.drawRect(framerect)
self.framerect = framerect
painter.setPen(Qt.black)
currenty = OFFSET_Y
currentx = OFFSET_X
position = rect.topLeft() + QPoint(OFFSET_X, currenty)
for text, icon in itemlist(self.items):
itempostion = QPoint(position)
if currenty > rect.height():
currentx = itemwidths + OFFSET_X + 100
currenty = itemmaxheight + 10
itempostion.setX(currentx)
itempostion.setY(currenty)
_drawitem(icon, text, itempostion)
currenty += OFFSET_Y
position.setY(currenty + OFFSET_Y)
示例11: VisionneurImagePourEKD
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
class VisionneurImagePourEKD(QScrollArea):
''' Classe pour l'affichage des images (avec des barres de
défilement)'''
def __init__(self, img=None):
QScrollArea.__init__(self)
# Déclaration du drapeau: a-t-on chargé un *.gif
if img and os.path.splitext(img)[1]!=".gif":
self.gif = 1
else:
self.gif = 0
# Facteur de redimensionnement de l'image à afficher par rapport à la taille réelle de l'image
self.factor = 1
# Variables de paramètres
self.modeTransformation=Qt.SmoothTransformation
#self.modeTransformation=Qt.FastTransformation
# widget qui contiendra l'image
self.imageLabel = QLabel()
self.imageLabel.setAlignment(Qt.AlignCenter)
self.setBackgroundRole(QPalette.Dark)
self.setWidget(self.imageLabel)
# Indispensable pour ne pas avoir d'images tronquées, lors du chargement de nvll img
self.setWidgetResizable(True)
# Position du curseur dans le QScrollArea au moment du clic de la souris
self.positionPresseeSourisIni = QPoint()
# Position du point haut-gauche du QScrollArea par rapport au QPixMap entier au
# moment du clic de la souris (par la suite appelée "position de la barre de défilement")
self.positionBarrePresseeSourisIni = QPoint()
# Création du menu contextuel
self.menuZoom=QMenu("Zoom")
# Entrée zoom taille réelle
self.menuTailleReelle=self.menuZoom.addAction(_(u'&Taille Réelle'))
self.menuTailleReelle.setIcon(QIcon("Icones" + os.sep + "taillereelle.png"))
self.connect(self.menuTailleReelle, SIGNAL("triggered()"), self.setTailleReelle)
# Entrée zoom taille fenetre
self.menuTailleFenetre=self.menuZoom.addAction(_(u'&Adapter à la fenêtre'))
self.menuTailleFenetre.setIcon(QIcon("Icones" + os.sep + "fenetre.png"))
self.connect(self.menuTailleFenetre, SIGNAL("triggered()"), self.setTailleFenetre)
# Entrée zoom +
self.menuZoomPlus=self.menuZoom.addAction(_(u'&Zoom Avant'))
self.menuZoomPlus.setIcon(QIcon("Icones" + os.sep + "zoomplus.png"))
self.connect(self.menuZoomPlus, SIGNAL("triggered()"), self.zoomAvant)
# Entrée zoom -
self.menuZoomMoins=self.menuZoom.addAction(_(u'&Zoom Arrière'))
self.menuZoomMoins.setIcon(QIcon("Icones" + os.sep + "zoommoins.png"))
self.connect(self.menuZoomMoins, SIGNAL("triggered()"), self.zoomArriere)
# Entrée mettre en pause/démarrer l'animation du gif
self.menuStartPauseGif=self.menuZoom.addAction(_(u"Mettre en pause/démarrer l'animation"))
self.menuStartPauseGif.setIcon(QIcon("Icones" + os.sep + "player_end.png"))
self.connect(self.menuStartPauseGif, SIGNAL("triggered()"), self.startPauseGif)
# Entrée mettre en pause/démarrer l'animation du gif
self.menuStopGif=self.menuZoom.addAction(_(u"Arrêter l'animation"))
self.menuStopGif.setIcon(QIcon("Icones" + os.sep + "player_stop.png"))
self.connect(self.menuStopGif, SIGNAL("triggered()"), self.stopGif)
# On cache les 2 menus de *.gif si on ne traite pas ce format
if not self.gif:
self.menuStartPauseGif.setVisible(False)
self.menuStopGif.setVisible(False)
# Si une image est en paramètre de classe, on l'affiche directement
# sinon on pourra toujours l'afficher plus tard en appelant la
# méthode setImage(), le moment venu
if img:
self.setImage(img)
self.setToolTip(img)
else:
# image par défaut
self.setImage("Icones" + os.sep + "avant-image.png")
self.setToolTip(_(u"image d'accueil"))
self.setTailleReelle()
def mousePressEvent(self, event):
"Menu contextuel et enregistrement de données préparant le déplacement de l'image par pincement"
# Menu contextuel
if event.button() == Qt.RightButton:
self.menuZoom.popup(event.globalPos())
# On enregistre la position du curseur et de la barre de défilement au moment du clic
elif event.button() == Qt.LeftButton:
self.positionPresseeSourisIni = QPoint(event.pos())
self.positionBarrePresseeSourisIni.setX(self.horizontalScrollBar().value())
self.positionBarrePresseeSourisIni.setY(self.verticalScrollBar().value())
if PYQT_VERSION_STR >= "4.1.0":
# curseur main fermée
self.setCursor(Qt.ClosedHandCursor)
else: self.setCursor(Qt.SizeAllCursor)
#.........这里部分代码省略.........
示例12: MikiView
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
class MikiView(QWebView):
def __init__(self, parent=None):
super(MikiView, self).__init__(parent)
self.parent = parent
self.settings().clearMemoryCaches()
self.notePath = parent.settings.notePath
self.settings().setUserStyleSheetUrl(
QUrl('file://'+self.parent.settings.cssfile))
print(QUrl('file://'+self.parent.settings.cssfile))
self.page().setLinkDelegationPolicy(QWebPage.DelegateAllLinks)
self.page().linkClicked.connect(self.linkClicked)
self.page().linkHovered.connect(self.linkHovered)
self.page().mainFrame(
).contentsSizeChanged.connect(self.contentsSizeChanged)
self.scrollPosition = QPoint(0, 0)
def linkClicked(self, qurl):
'''three kinds of link:
external uri: http/https
page ref link:
toc anchor link: #
'''
name = qurl.toString()
http = re.compile('https?://')
if http.match(name): # external uri
QDesktopServices.openUrl(qurl)
return
self.load(qurl)
name = name.replace('file://', '')
name = name.replace(self.notePath, '').split('#')
item = self.parent.notesTree.pageToItem(name[0])
if not item or item == self.parent.notesTree.currentItem():
return
else:
self.parent.notesTree.setCurrentItem(item)
if len(name) > 1:
link = "file://" + self.notePath + "/#" + name[1]
self.load(QUrl(link))
viewFrame = self.page().mainFrame()
self.scrollPosition = viewFrame.scrollPosition()
def linkHovered(self, link, title, textContent):
'''show link in status bar
ref link shown as: /parent/child/pageName
toc link shown as: /parent/child/pageName#anchor (ToFix)
'''
# TODO: link to page by: /parent/child/pageName#anchor
if link == '': # not hovered
self.parent.statusBar.showMessage(self.parent.notesTree.currentPage())
else: # beautify link
link = link.replace('file://', '')
link = link.replace(self.notePath, '')
self.parent.statusBar.showMessage(link)
def contentsSizeChanged(self, newSize):
'''scroll notesView while editing (adding new lines)
Whithout this, every `updateView` will result in scroll to top.
'''
if self.scrollPosition == QPoint(0, 0):
return
viewFrame = self.page().mainFrame()
newY = self.scrollPosition.y(
) + newSize.height() - self.contentsSize.height()
self.scrollPosition.setY(newY)
viewFrame.setScrollPosition(self.scrollPosition)
def updateView(self):
# url_notebook = 'file://' + os.path.join(self.notePath, '/')
viewFrame = self.page().mainFrame()
# Store scrollPosition before update notesView
self.scrollPosition = viewFrame.scrollPosition()
self.contentsSize = viewFrame.contentsSize()
url_notebook = 'file://' + self.notePath + '/'
self.setHtml(self.parent.notesEdit.toHtml(), QUrl(url_notebook))
# Restore previous scrollPosition
viewFrame.setScrollPosition(self.scrollPosition)
def updateLiveView(self):
if self.parent.actions.get('split').isChecked():
QTimer.singleShot(1000, self.updateView)
示例13: kineticMove
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
def kineticMove(self, oldx, oldy, newx, newy ):
"""Start a kinetic move from (oldx, oldy) to (newx, newy)"""
if newx == oldx and newy == oldy:
return
speed = QPoint(0,0)
# solve speed*(speed+1)/2 = delta to ensure 1+2+3+...+speed is as close as possible under delta..
speed.setX((sqrt(1+8*abs(newx-oldx))-1)/2)
speed.setY((sqrt(1+8*abs(newy-oldy))-1)/2)
# compute the amount of displacement still needed because we're dealing with integer values.
diff = QPoint(0,0)
diff.setX(-abs(newx-oldx) + speed.x()*(speed.x()+1)/2)
diff.setY(-abs(newy-oldy) + speed.y()*(speed.y()+1)/2)
# Since this function is called for exact moves (not free scrolling)
# limit the kinetic time to 2 seconds, which means 100 ticks, 5050 pixels.
if speed.y() > 100:
speed.setY(100)
diff.setY(-abs(newy-oldy) + 5050)
# Although it is less likely to go beyond that limit for horizontal scrolling,
# do it for x as well.
if speed.x() > 100:
speed.setX(100)
diff.setX(-abs(newx-oldx) + 5050)
# move left or right, up or down
if newx > oldx :
speed.setX(-speed.x())
diff.setX(-diff.x())
if newy > oldy :
speed.setY(-speed.y())
diff.setY(-diff.y())
# move immediately by the step that cannot be handled by kinetic scrolling.
# By construction that step is smaller that the initial speed value.
self.fastScrollBy(diff)
self.kineticStart(speed)
示例14: MapSwipeTool
# 需要导入模块: from PyQt4.QtCore import QPoint [as 别名]
# 或者: from PyQt4.QtCore.QPoint import setY [as 别名]
class MapSwipeTool(QgsMapTool):
def __init__(self, iface):
canvas = iface.mapCanvas()
super(MapSwipeTool, self).__init__( canvas )
self.view = iface.layerTreeView()
self.msgBar = iface.messageBar()
self.swipe = SwipeMap( canvas )
self.checkDirection = self.hasSwipe = self.disabledSwipe = None
self.firstPoint = QPoint()
self.cursorV = QCursor( Qt.SplitVCursor )
self.cursorH = QCursor( Qt.SplitHCursor )
def activate(self):
self.canvas().setCursor( QCursor( Qt.CrossCursor ) )
self._connect()
self.hasSwipe = False
self.disabledSwipe = False
self.setLayersSwipe( self.view.currentIndex() )
def canvasPressEvent(self, e):
if len(self.swipe.layers) == 0:
msg = "Select active Layer or Group(with layers) in legend."
self.msgBar.clearWidgets()
self.msgBar.pushMessage( "MapSwipeTool", msg, QgsMessageBar.WARNING, 4 )
return
self.hasSwipe = True
self.firstPoint.setX( e.x() )
self.firstPoint.setY( e.y() )
self.checkDirection = True
def canvasReleaseEvent(self, e):
self.hasSwipe = False
self.canvas().setCursor( QCursor( Qt.CrossCursor ) )
def canvasMoveEvent(self, e):
if self.hasSwipe:
if self.checkDirection:
dX = abs( e.x() - self.firstPoint.x() )
dY = abs( e.y() - self.firstPoint.y() )
isVertical = dX > dY
self.swipe.setIsVertical( isVertical )
self.checkDirection = False
self.canvas().setCursor( self.cursorH if isVertical else self.cursorV )
self.swipe.setLength( e.x(), e.y() )
def _connect(self, isConnect = True):
signal_slot = (
{ 'signal': self.canvas().mapCanvasRefreshed, 'slot': self.swipe.setMap },
{ 'signal': self.view.activated, 'slot': self.setLayersSwipe },
{ 'signal': QgsMapLayerRegistry.instance().removeAll, 'slot': self.disable }
)
if isConnect:
for item in signal_slot:
item['signal'].connect( item['slot'] )
else:
for item in signal_slot:
item['signal'].disconnect( item['slot'] )
@pyqtSlot( "QModelIndex" )
def setLayersSwipe(self, index):
if self.disabledSwipe:
return
ids = msg = None
node = self.view.currentNode()
if isinstance( node, QgsLayerTreeLayer ):
layer = node.layer()
ids = [ layer.id() ]
msg = "Active layer is '%s'." % layer.name()
else:
group = self.view.currentGroupNode()
if group.parent() is None: # Root
return
ids = group.findLayerIds()
msg = "Active group is '%s'." % group.name()
self.swipe.clear()
self.swipe.setLayersId( ids )
self.msgBar.clearWidgets()
self.msgBar.pushMessage( "MapSwipeTool", msg, QgsMessageBar.INFO, 2 )
self.swipe.setMap()
@pyqtSlot()
def disable(self):
self.swipe.clear()
self.hasSwipe = False
self.disabledSwipe = True
def deactivate(self):
super( MapSwipeTool, self ).deactivate()
self.deactivated.emit()
self.swipe.clear()
self._connect( False )