Python PyQt4.QtCore.QPointF() Examples

The following are 30 code examples of PyQt4.QtCore.QPointF(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module PyQt4.QtCore , or try the search function .
Example #1
Source File: LicUndoActions.py    From lic with GNU General Public License v3.0 6 votes vote down vote up
def doAction(self, redo):

        if (redo and self.addGuide) or (not redo and not self.addGuide):
            self.scene.guides.append(self.guide)
            self.scene.addItem(self.guide)
            
            if self.scene.guides.__len__() > 1:
                cg = self.guide.pos() 
                for g in self.scene.guides:
                    lg = g.pos()  
                    if self.guide.orientation == g.orientation:
                        if g.orientation == LicLayout.Horizontal:
                            if cg[1] == lg[1]:
                                cg = QPointF(cg[0], cg[1] + LicLayout.PageDefaultMargin)
                        elif g.orientation == LicLayout.Vertical:
                            if cg[0] == lg[0]:
                                cg = QPointF(cg[0] + LicLayout.PageDefaultMargin, cg[1])
                self.guide.setPos(cg)
        else:
            self.scene.removeItem(self.guide)
            self.scene.guides.remove(self.guide) 
Example #2
Source File: uiBasicWidget.py    From InplusTrader_Linux with MIT License 6 votes vote down vote up
def generatePicture(self):
        ## pre-computing a QPicture object allows paint() to run much more quickly,
        ## rather than re-drawing the shapes every time.
        self.picture = QtGui.QPicture()
        p = QtGui.QPainter(self.picture)
        p.setPen(pg.mkPen(color='r', width=0.4))  # 0.4 means w*2
        # w = (self.data[1][0] - self.data[0][0]) / 3.
        w = 0.2
        for (t, open, close, min, max) in self.data:
            p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
            if open > close:
                p.setBrush(pg.mkBrush('g'))
            else:
                p.setBrush(pg.mkBrush('r'))
            p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
        p.end() 
Example #3
Source File: uiBasicWidget.py    From InplusTrader_Linux with MIT License 6 votes vote down vote up
def generatePicture(self):
            ## pre-computing a QPicture object allows paint() to run much more quickly,
            ## rather than re-drawing the shapes every time.
            self.picture = QtGui.QPicture()
            p = QtGui.QPainter(self.picture)
            p.setPen(pg.mkPen(color='r', width=0.4))  # 0.4 means w*2
            # w = (self.data[1][0] - self.data[0][0]) / 3.
            w = 0.2
            for (t, open, close, min, max) in self.data:
                p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
                if open > close:
                    p.setBrush(pg.mkBrush('g'))
                else:
                    p.setBrush(pg.mkBrush('r'))
                p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
            p.end() 
Example #4
Source File: uiBasicWidget修改.py    From chanlun with MIT License 6 votes vote down vote up
def generatePicture(self):
            ## pre-computing a QPicture object allows paint() to run much more quickly,
            ## rather than re-drawing the shapes every time.
            self.picture = QtGui.QPicture()
            p = QtGui.QPainter(self.picture)
            p.setPen(pg.mkPen(color='w', width=0.4))  # 0.4 means w*2
            # w = (self.data[1][0] - self.data[0][0]) / 3.
            w = 0.2
            for (t, open, close, min, max) in self.data:
                p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
                if open > close:
                    p.setBrush(pg.mkBrush('g'))
                else:
                    p.setBrush(pg.mkBrush('r'))
                p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
            p.end() 
Example #5
Source File: demoUi.py    From chanlun with MIT License 6 votes vote down vote up
def generatePicture(self):
            ## pre-computing a QPicture object allows paint() to run much more quickly,
            ## rather than re-drawing the shapes every time.
            self.picture = QtGui.QPicture()
            p = QtGui.QPainter(self.picture)
            p.setPen(pg.mkPen(color='w', width=0.4))  # 0.4 means w*2
            # w = (self.data[1][0] - self.data[0][0]) / 3.
            w = 0.2
            for (t, open, close, min, max) in self.data:
                p.drawLine(QtCore.QPointF(t, min), QtCore.QPointF(t, max))
                if open > close:
                    p.setBrush(pg.mkBrush('g'))
                else:
                    p.setBrush(pg.mkBrush('r'))
                p.drawRect(QtCore.QRectF(t-w, open, w*2, close-open))
            p.end() 
Example #6
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 5 votes vote down vote up
def getClosestPoint( self, poly, pt ):
        closest = (-1,-1)
        distTh    = 4.0
        dist      = 1e9 # should be enough
        for i in range(poly.size()):
            curDist = self.ptDist(poly[i],pt)
            if curDist < dist:
                closest = (i,i)
                dist = curDist
        # Close enough?
        if dist <= distTh:
            return closest

        # Otherwise see if the polygon is closed, but a line is close enough
        if self.drawPolyClosed and poly.size() >= 2:
            for i in range(poly.size()):
                pt1 = poly[i]
                j = i+1
                if j == poly.size():
                    j = 0
                pt2 = poly[j]
                edge = QtCore.QLineF(pt1,pt2)
                normal = edge.normalVector()
                normalThroughMouse = QtCore.QLineF( pt.x(),pt.y(),pt.x()+normal.dx(),pt.y()+normal.dy() )
                intersectionPt = QtCore.QPointF()
                intersectionType = edge.intersect( normalThroughMouse , intersectionPt )
                if intersectionType == QtCore.QLineF.BoundedIntersection:
                    curDist = self.ptDist(intersectionPt,pt)
                    if curDist < dist:
                        closest = (i,j)
                        dist = curDist

        # Close enough?
        if dist <= distTh:
            return closest

        # If we didnt return yet, we didnt find anything
        return (-1,-1)

    # Get distance between two points 
Example #7
Source File: pressure.py    From wacom-gui with GNU General Public License v3.0 5 votes vote down vote up
def tabletEvent(self, event):
        senId = ""
        if self.sensor == "stylus" :
            senId = QtGui.QTabletEvent.Pen
        elif self.sensor == "eraser":
            senId = QtGui.QTabletEvent.Eraser
        elif self.sensor == "cursor":
            senId = QtGui.QTabletEvent.Cursor
        if event.pointerType() == senId:
            curpressure = event.pressure()
            if curpressure < 0:
                curpressure += 1
            amp = int(curpressure * 50)
            color = (1 - amp/50.0) * 255
            pen = QtGui.QPen(QtGui.QColor(color,color,color,0))

            radial = QtGui.QRadialGradient(QtCore.QPointF(event.x(),event.y()),amp,QtCore.QPointF(event.xTilt() * amp/50 ,event.yTilt() * amp))
            radial.setColorAt(0,QtGui.QColor(color,color,color,255))
            radial.setColorAt(1,QtGui.QColor(color,color,color,0))
            brush = QtGui.QBrush(radial)
            if(amp >= 1):
                if len(self.scene.items()) >= 50:
                    render = QtGui.QPixmap(250,250)
                    painter = QtGui.QPainter(render)
                    rect = QtCore.QRectF(0,0,250,250)
                    self.scene.render(painter,rect,rect,QtCore.Qt.KeepAspectRatio)
                    self.scene.clear()
                    self.scene.addPixmap(render)
                    painter.end()
                self.scene.addEllipse(event.x() - amp, event.y() -amp, amp, amp, pen, brush)
            self.info.updateInfo(event.xTilt(),event.yTilt(),amp) 
Example #8
Source File: RoundWindow.py    From openQPA with GNU General Public License v3.0 5 votes vote down vote up
def round(self):
        bmp = QBitmap(self.size())
        p = QPainter()
        p.begin(bmp)
        p.fillRect(bmp.rect(), Qt.white)
        p.setBrush(QColor(0,0,0))
        p.drawRoundedRect(bmp.rect(), 5, 5)
        p.setPen(QColor(255,255,255,255))
        p.drawPoints(QPointF(self.width()-2,self.height()-1), QPointF(self.width()-1,self.height()-2))
        p.setPen(QColor(0,0,0))
        p.drawPoints(QPointF(0,2),QPointF(3,0),QPointF(2,0),QPointF(1,1))
        p.end()
        self.setMask(bmp) 
Example #9
Source File: LicHelpers.py    From lic with GNU General Public License v3.0 5 votes vote down vote up
def polygonToCurvedPath(polygon, radius):
    
    path = QPainterPath()
    for i, pt in enumerate(polygon):
        
        #TODO: if two points are too close to draw the desired radius, either remove those points or draw at smaller radius
        px, py = polygon[i - 1] if i > 0 else polygon[-1]
        nx, ny = polygon[i + 1] if i < len(polygon) - 1 else polygon[0]
        x, y = pt
        
        if px == x:
            dy = y - py
            r = radius if dy < 0 else -radius
            p1 = QPointF(x, y + r)
        else:
            dx = x - px
            r = radius if dx < 0 else -radius
            p1 = QPointF(x + r, y)
        
        if x == nx:
            dy = y - ny
            r = radius if dy < 0 else -radius
            p2 = QPointF(x, y + r)
        else:
            dx = x - nx
            r = radius if dx < 0 else -radius
            p2 = QPointF(x + r, y)
        
        if i == 0:
            path.moveTo(p1)
        else:
            path.lineTo(p1)
        path.cubicTo(pt, pt, p2)

    path.closeSubpath()
    return path 
Example #10
Source File: LicGLHelpers.py    From lic with GNU General Public License v3.0 5 votes vote down vote up
def initImgSize(size, glDispID, filename, scale, rotation, partRotation):
    """
    Draw this piece to the already initialized GL Frame Buffer Object, in order to calculate
    its displayed width and height.  These dimensions are required to properly lay out PLIs and CSIs.
    
    Parameters:
        size: Width & height of buffer to render to, in pixels (always square).
        glDispID: The GL Display List ID to be rendered and dimensioned.
        filename: String name of this thing to draw.
        rotation: An [x, y, z] rotation to use for this rendering's default rotation
        partRotation: An extra [x, y, z] rotation to use when rendering this part, or None.
    
    Returns:
        None, if the rendered image has been rendered partially or wholly out of frame.
        Otherwise, returns the (width, height, centerPoint, leftInset, bottomInset) parameters of this image.
    """
    
    # Draw piece to frame buffer, then calculate bounding box
    left, top, right, bottom, leftInset, bottomInset = _getBounds(size, glDispID, filename, scale, rotation, partRotation)
    
    if _checkImgBounds(top, bottom, left, right, size):
        return None  # Drew at least one edge out of bounds - try next buffer size
    
    imgWidth = right - left + 1
    imgHeight = bottom - top
    
    w = (left + (imgWidth / 2)) - (size / 2)
    h = (top + (imgHeight / 2)) - (size / 2)
    imgCenter = QPointF(-w, h - 1)

    return (imgWidth, imgHeight, imgCenter, leftInset, bottomInset) 
Example #11
Source File: FrameLayout.py    From pyqt-collapsible-widget with MIT License 5 votes vote down vote up
def __init__(self, parent=None, collapsed=False):
            QtGui.QFrame.__init__(self, parent=parent)

            self.setMaximumSize(24, 24)

            # horizontal == 0
            self._arrow_horizontal = (QtCore.QPointF(7.0, 8.0), QtCore.QPointF(17.0, 8.0), QtCore.QPointF(12.0, 13.0))
            # vertical == 1
            self._arrow_vertical = (QtCore.QPointF(8.0, 7.0), QtCore.QPointF(13.0, 12.0), QtCore.QPointF(8.0, 17.0))
            # arrow
            self._arrow = None
            self.setArrow(int(collapsed)) 
Example #12
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 5 votes vote down vote up
def getClosestPoint( self, poly, pt ):
        closest = (-1,-1)
        distTh    = 4.0
        dist      = 1e9 # should be enough
        for i in range(poly.size()):
            curDist = self.ptDist(poly[i],pt)
            if curDist < dist:
                closest = (i,i)
                dist = curDist
        # Close enough?
        if dist <= distTh:
            return closest

        # Otherwise see if the polygon is closed, but a line is close enough
        if self.drawPolyClosed and poly.size() >= 2:
            for i in range(poly.size()):
                pt1 = poly[i]
                j = i+1
                if j == poly.size():
                    j = 0
                pt2 = poly[j]
                edge = QtCore.QLineF(pt1,pt2)
                normal = edge.normalVector()
                normalThroughMouse = QtCore.QLineF( pt.x(),pt.y(),pt.x()+normal.dx(),pt.y()+normal.dy() )
                intersectionPt = QtCore.QPointF()
                intersectionType = edge.intersect( normalThroughMouse , intersectionPt )
                if intersectionType == QtCore.QLineF.BoundedIntersection:
                    curDist = self.ptDist(intersectionPt,pt)
                    if curDist < dist:
                        closest = (i,j)
                        dist = curDist

        # Close enough?
        if dist <= distTh:
            return closest

        # If we didnt return yet, we didnt find anything
        return (-1,-1)

    # Get distance between two points 
Example #13
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 5 votes vote down vote up
def updateMousePos( self, mousePosOrig ):
        if self.config.zoomFactor <= 1 or (self.drawPolyClosed or self.drawPoly.isEmpty()):
            sens = 1.0
        else :
            sens = 1.0/pow(self.config.zoomFactor, 3);

        if self.config.zoom and self.mousePosOnZoom is not None:
            mousePos       = QtCore.QPointF(round((1-sens)*self.mousePosOnZoom.x() + (sens)*mousePosOrig.x()), round((1-sens)*self.mousePosOnZoom.y() + sens*mousePosOrig.y()))
        else :
            mousePos       = mousePosOrig
        mousePosScaled = QtCore.QPointF( float(mousePos.x() - self.xoff) / self.scale , float(mousePos.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            self.mousePos = None
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePos          = mousePos
        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

    # Toggle the zoom and update all mouse positions 
Example #14
Source File: cityscapesLabelTool.py    From Detectron-PYTORCH with Apache License 2.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #15
Source File: cityscapesViewer.py    From TFSegmentation with Apache License 2.0 5 votes vote down vote up
def mouseMoveEvent(self,event):
        if self.image.isNull() or self.w == 0 or self.h == 0:
            return

        mousePosOrig = QtCore.QPointF( event.x() , event.y() )
        mousePosScaled = QtCore.QPointF( float(mousePosOrig.x() - self.xoff) / self.scale , float(mousePosOrig.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            print(self.image.rect())
            print(mousePosScaled.toPoint())
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

        # Redraw
        self.updateMouseObject()
        self.update()

    # Mouse left the widget 
Example #16
Source File: cityscapesViewer.py    From TFSegmentation with Apache License 2.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #17
Source File: cityscapesLabelTool.py    From fcn8s_tensorflow with GNU General Public License v3.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #18
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 5 votes vote down vote up
def updateMousePos( self, mousePosOrig ):
        if self.config.zoomFactor <= 1 or (self.drawPolyClosed or self.drawPoly.isEmpty()):
            sens = 1.0
        else :
            sens = 1.0/pow(self.config.zoomFactor, 3);

        if self.config.zoom and self.mousePosOnZoom is not None:
            mousePos       = QtCore.QPointF(round((1-sens)*self.mousePosOnZoom.x() + (sens)*mousePosOrig.x()), round((1-sens)*self.mousePosOnZoom.y() + sens*mousePosOrig.y()))
        else :
            mousePos       = mousePosOrig
        mousePosScaled = QtCore.QPointF( float(mousePos.x() - self.xoff) / self.scale , float(mousePos.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            self.mousePos = None
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePos          = mousePos
        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

    # Toggle the zoom and update all mouse positions 
Example #19
Source File: cityscapesLabelTool.py    From TFSegmentation with Apache License 2.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #20
Source File: cityscapesViewer.py    From LightNet with MIT License 5 votes vote down vote up
def mouseMoveEvent(self,event):
        if self.image.isNull() or self.w == 0 or self.h == 0:
            return

        mousePosOrig = QtCore.QPointF( event.x() , event.y() )
        mousePosScaled = QtCore.QPointF( float(mousePosOrig.x() - self.xoff) / self.scale , float(mousePosOrig.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            print(self.image.rect())
            print(mousePosScaled.toPoint())
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

        # Redraw
        self.updateMouseObject()
        self.update()

    # Mouse left the widget 
Example #21
Source File: cityscapesViewer.py    From LightNet with MIT License 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #22
Source File: cityscapesLabelTool.py    From LightNet with MIT License 5 votes vote down vote up
def getClosestPoint( self, poly, pt ):
        closest = (-1,-1)
        distTh    = 4.0
        dist      = 1e9 # should be enough
        for i in range(poly.size()):
            curDist = self.ptDist(poly[i],pt)
            if curDist < dist:
                closest = (i,i)
                dist = curDist
        # Close enough?
        if dist <= distTh:
            return closest

        # Otherwise see if the polygon is closed, but a line is close enough
        if self.drawPolyClosed and poly.size() >= 2:
            for i in range(poly.size()):
                pt1 = poly[i]
                j = i+1
                if j == poly.size():
                    j = 0
                pt2 = poly[j]
                edge = QtCore.QLineF(pt1,pt2)
                normal = edge.normalVector()
                normalThroughMouse = QtCore.QLineF( pt.x(),pt.y(),pt.x()+normal.dx(),pt.y()+normal.dy() )
                intersectionPt = QtCore.QPointF()
                intersectionType = edge.intersect( normalThroughMouse , intersectionPt )
                if intersectionType == QtCore.QLineF.BoundedIntersection:
                    curDist = self.ptDist(intersectionPt,pt)
                    if curDist < dist:
                        closest = (i,j)
                        dist = curDist

        # Close enough?
        if dist <= distTh:
            return closest

        # If we didnt return yet, we didnt find anything
        return (-1,-1)

    # Get distance between two points 
Example #23
Source File: cityscapesLabelTool.py    From LightNet with MIT License 5 votes vote down vote up
def updateMousePos( self, mousePosOrig ):
        if self.config.zoomFactor <= 1 or (self.drawPolyClosed or self.drawPoly.isEmpty()):
            sens = 1.0
        else :
            sens = 1.0/pow(self.config.zoomFactor, 3);

        if self.config.zoom and self.mousePosOnZoom is not None:
            mousePos       = QtCore.QPointF(round((1-sens)*self.mousePosOnZoom.x() + (sens)*mousePosOrig.x()), round((1-sens)*self.mousePosOnZoom.y() + sens*mousePosOrig.y()))
        else :
            mousePos       = mousePosOrig
        mousePosScaled = QtCore.QPointF( float(mousePos.x() - self.xoff) / self.scale , float(mousePos.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            self.mousePos = None
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePos          = mousePos
        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

    # Toggle the zoom and update all mouse positions 
Example #24
Source File: cityscapesLabelTool.py    From LightNet with MIT License 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #25
Source File: xmlelement.py    From cross3d with MIT License 5 votes vote down vote up
def findPointF(self, name):
		return self._findPoint(name, QPointF, float) 
Example #26
Source File: cityscapesViewer.py    From rec-attend-public with MIT License 5 votes vote down vote up
def mouseMoveEvent(self,event):
        if self.image.isNull() or self.w == 0 or self.h == 0:
            return

        mousePosOrig = QtCore.QPointF( event.x() , event.y() )
        mousePosScaled = QtCore.QPointF( float(mousePosOrig.x() - self.xoff) / self.scale , float(mousePosOrig.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            print self.image.rect()
            print mousePosScaled.toPoint()
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

        # Redraw
        self.updateMouseObject()
        self.update()

    # Mouse left the widget 
Example #27
Source File: cityscapesViewer.py    From rec-attend-public with MIT License 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #28
Source File: cityscapesViewer.py    From fcn8s_tensorflow with GNU General Public License v3.0 5 votes vote down vote up
def mouseMoveEvent(self,event):
        if self.image.isNull() or self.w == 0 or self.h == 0:
            return

        mousePosOrig = QtCore.QPointF( event.x() , event.y() )
        mousePosScaled = QtCore.QPointF( float(mousePosOrig.x() - self.xoff) / self.scale , float(mousePosOrig.y() - self.yoff) / self.scale )
        mouseOutsideImage = not self.image.rect().contains( mousePosScaled.toPoint() )

        mousePosScaled.setX( max( mousePosScaled.x() , 0. ) )
        mousePosScaled.setY( max( mousePosScaled.y() , 0. ) )
        mousePosScaled.setX( min( mousePosScaled.x() , self.image.rect().right() ) )
        mousePosScaled.setY( min( mousePosScaled.y() , self.image.rect().bottom() ) )

        if not self.image.rect().contains( mousePosScaled.toPoint() ):
            print(self.image.rect())
            print(mousePosScaled.toPoint())
            self.mousePosScaled = None
            self.mousePosOrig = None
            self.updateMouseObject()
            self.update()
            return

        self.mousePosScaled    = mousePosScaled
        self.mousePosOrig      = mousePosOrig
        self.mouseOutsideImage = mouseOutsideImage

        # Redraw
        self.updateMouseObject()
        self.update()

    # Mouse left the widget 
Example #29
Source File: cityscapesViewer.py    From fcn8s_tensorflow with GNU General Public License v3.0 5 votes vote down vote up
def getPolygon(self, obj):
        poly = QtGui.QPolygonF()
        for pt in obj.polygon:
            point = QtCore.QPointF(pt.x,pt.y)
            poly.append( point )
        return poly

    # Draw the labels in the given QPainter qp
    # optionally provide a list of labels to ignore 
Example #30
Source File: cityscapesLabelTool.py    From fcn8s_tensorflow with GNU General Public License v3.0 5 votes vote down vote up
def getClosestPoint( self, poly, pt ):
        closest = (-1,-1)
        distTh    = 4.0
        dist      = 1e9 # should be enough
        for i in range(poly.size()):
            curDist = self.ptDist(poly[i],pt)
            if curDist < dist:
                closest = (i,i)
                dist = curDist
        # Close enough?
        if dist <= distTh:
            return closest

        # Otherwise see if the polygon is closed, but a line is close enough
        if self.drawPolyClosed and poly.size() >= 2:
            for i in range(poly.size()):
                pt1 = poly[i]
                j = i+1
                if j == poly.size():
                    j = 0
                pt2 = poly[j]
                edge = QtCore.QLineF(pt1,pt2)
                normal = edge.normalVector()
                normalThroughMouse = QtCore.QLineF( pt.x(),pt.y(),pt.x()+normal.dx(),pt.y()+normal.dy() )
                intersectionPt = QtCore.QPointF()
                intersectionType = edge.intersect( normalThroughMouse , intersectionPt )
                if intersectionType == QtCore.QLineF.BoundedIntersection:
                    curDist = self.ptDist(intersectionPt,pt)
                    if curDist < dist:
                        closest = (i,j)
                        dist = curDist

        # Close enough?
        if dist <= distTh:
            return closest

        # If we didnt return yet, we didnt find anything
        return (-1,-1)

    # Get distance between two points