Python PyQt4.QtCore 模块,QPointF() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用PyQt4.QtCore.QPointF()

项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def __init__(self, editor, token, count, qpos, parent=None):        
        '''Create a token.

        :param editor: DiagramEditor. Editor to show in. 
        :param token: Token value.
        :param count: Number of Tokens to create.
        :param qpos: Parent top right position.  
        :param parent=None: Parent Place Element
        '''
        QtGui.QGraphicsEllipseItem.__init__(self, qpos, parent)
        self.editor = editor
        self.setZValue(19)
        self.countToken = count
        self.countTokenLabel = QtGui.QGraphicsTextItem("%d"%self.countToken, self)
        self.countTokenLabel.setPos(QtCore.QPointF( qpos.x()-1, qpos.y()-4 ))
        self.setBrush(QtGui.QBrush(QtCore.Qt.green))
        self.token = token
        self.setToolTip( str(self.token) )
        self.setFlags(self.ItemIsSelectable | self.ItemIsMovable )
    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def deleteItemLocal(self):
        '''Capture delete event and call editor delete function.'''
        self.parent.deleteItem([self])   
    #------------------------------------------------------------------------------------------------


#     def itemChange(self, change, value):                    
#         if change == self.ItemScenePositionHasChanged:
#             rect = self.boundingRect()
#             pos = self.scenePos()
#             for cb in self.posCallbacks:                
#                 for connection in self.parent.visualConnectionList:
#                     if connection[0] is self or connection[2] is self:
#                         inputCoordinates = QtCore.QPointF(connection[0].x(), connection[0].y())
#                         outputCoordinates = QtCore.QPointF(connection[2].x(), connection[2].y())
#                         if connection[0] is self:                        
#                             value = self.determineBorder( connection[1], connection[2], rect, pos, inputCoordinates, outputCoordinates )  
#                         if connection[2] is self:
#                             value = self.determineBorder( connection[1], connection[0], rect, pos, outputCoordinates, inputCoordinates )     
#                 cb(value)
#             return value
#         return super(AbstractItem, self).itemChange(change, value)
#     #-----------------------------------------------------------------------------------------------

#========================================================================================================================
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def setPolygon(self):
        '''Calculate position and rotation of the arc arrow head.'''
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arrowPolygonObject.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arrowPolygonObject.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 

    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def itemChange(self, change, value):
        '''Item position has changed, calculate new position.

        :param change: Change value.
        :param value: QtCore.QPointF().
        :return value: QtCore.QPointF(x, y) or super(PortItem, self).itemChange(change, value).
        '''
        if change == self.ItemPositionChange:
            x, y = value.x(), value.y()
            # TODO: make this a signal?
            # This cannot be a signal because this is not a QObject
            for cb in self.posChangeCallbacks:
                res = cb(x, y)
                if res:
                    x, y = res
                    value = QtCore.QPointF(x, y)

            return value
        # Call superclass method:
        return super(PortItem, self).itemChange(change, value)
    #------------------------------------------------------------------------------------------------

#========================================================================================================================
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def stackTokens(self):        
        '''Method to order the visual stacking of different tokens.'''
        self.toolTipString = ""        
        self.setToolTip( self.toolTipString )
        self.descCanvas.setCanvasString( self.toolTipString )

        pos = self.scenePos()
        rect = self.boundingRect()
        lenTok = len( self.tokens )
        tokens = list( self.tokens )
        for idx in range(0, lenTok):
            token = tokens.pop()
            token.setPos( QtCore.QPointF( rect.x()  + (lenTok - idx)*10 , rect.y() - (lenTok - idx)*10 ) )
            self.toolTipString += "%s' %s ++\n" %(token.countTokenLabel.toPlainText(), token.token)

        self.setToolTip( self.toolTipString )
        self.editor.diagramScene.removeItem( self.descCanvas )
        self.descCanvas.setCanvasString( self.toolTipString )
        self.editor.diagramScene.addItem( self.descCanvas )
    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def setPolygon(self):
        rotDeg = 0            
        xlength = self.pos1.x() - self.pos2.x()
        ylength = self.pos1.y() - self.pos2.y()
        d = math.sqrt( math.pow( xlength , 2) + math.pow( ylength , 2) )        
        if d > 0:
            beta = math.acos( xlength / d )
            rotDeg = math.degrees( beta ) 

        self.arcLinePolygon.setPolygon( QtGui.QPolygonF( [
                                                 QtCore.QPointF( (self.pos2.x() -10),  (self.pos2.y() +5)), 
                                                 QtCore.QPointF( (self.pos2.x() -10) , (self.pos2.y() -5)), 
                                                 QtCore.QPointF(       self.pos2.x() ,      self.pos2.y())
                                                 ] ) ) 

        self.arcLinePolygon.setBrush( QtGui.QBrush(QtCore.Qt.black) )

        """ self.angle()!!!!!!!!!"""
#         self.arcLinePolygon.angle()
#         self.arcLinePolygon.rotate(rotDeg)
#         self.arcLinePolygon.setPos( self.pos2 ) 
    #------------------------------------------------------------------------------------------------
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mouseDoubleClickEvent(self, event):
        if self._move_grid:
            p = self.mapToLonLat(event.pos())
            self._grid_coord.append([p.y(), p.x()])
            self.delStation(self._station_to_move)
            self._station_to_move.grid_line = '(' + str(self._grid_coord[0][0]) + ',' + str(self._grid_coord[0][1]) + ')'
            for i in range(1, len(self._grid_coord)):
                self._station_to_move.grid_line += ',(' + str(self._grid_coord[i][0]) + ',' + str(self._grid_coord[i][1]) + ')'
            self.scene().addStation(self._station_to_move)
            if not self.scene().show_station_name:
                self.scene()._current_name.setText(self._station_to_move.name)
                pp = self.mapFromLonLat(QtCore.QPointF(self._station_to_move.lon, self._station_to_move.lat))
                self.scene()._current_name.setPos(pp + QtCore.QPointF(1.5, -0.5))
                if self._station_to_move.technology[:6] == 'Fossil':
                    self.scene()._current_name.setBrush(QtGui.QColor(self.scene().colors['fossil_name']))
                else:
                    self.scene()._current_name.setBrush(QtGui.QColor(self.scene().colors['station_name']))
            self._move_grid = False
            self._grid_start = None
            for itm in self._grid_line:
                self.scene().removeItem(itm)
            self._grid_line = None
            self._grid_coord = None
            self.scene().refreshGrid()
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def go_ToLoad(self):
        if len(self.view.scene().load_centre) == 1:
            j = 0
        else:
            menu = QtGui.QMenu()
            ctrs = []
            for ctr in self.view.scene().load_centre:
                ctrs.append(menu.addAction(ctr[0]))
           #      ctrs[-1].setIconVisibleInMenu(True)
            x = self.frameGeometry().left() + 50
            y = self.frameGeometry().y() + 50
            action = menu.exec_(QtCore.QPoint(x, y))
            if action is not None:
                for j in range(len(self.view.scene().load_centre)):
                    if action.text() == self.view.scene().load_centre[j][0]:
                        break
        if j < len(self.view.scene().load_centre):
            go_to = self.mapFromLonLat(QtCore.QPointF(self.view.scene().load_centre[j][2],
                    self.view.scene().load_centre[j][1]))
            self.view.centerOn(go_to)
            comment = '(%s,%s) Centred on %s Load Centre' % (
                      '{:0.4f}'.format(self.view.scene().load_centre[j][1]),
                      '{:0.4f}'.format(self.view.scene().load_centre[j][2]),
                      self.view.scene().load_centre[j][0])
            self.view.emit(QtCore.SIGNAL('statusmsg'), comment)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def showArea(self, event):
        if self.ignore:
            return
        if self.sender() == self.southSpin or self.sender() == self.eastSpin:
            if self.southSpin.value() > self.northSpin.value():
                y = self.northSpin.value()
                self.northSpin.setValue(self.southSpin.value())
                self.southSpin.setValue(y)
            if self.eastSpin.value() < self.westSpin.value():
                x = self.westSpin.value()
                self.westSpin.setValue(self.eastSpin.value())
                self.eastSpin.setValue(x)
        if self.worldwindow is None:
            return
        approx_area = self.worldwindow.view.drawRect([QtCore.QPointF(self.westSpin.value(), self.northSpin.value()),
                                   QtCore.QPointF(self.eastSpin.value(), self.southSpin.value())])
        self.approx_area.setText(approx_area)
        merra_dims = worldwindow.merra_cells(self.northSpin.value(), self.westSpin.value(),
                     self.southSpin.value(), self.eastSpin.value())
        self.merra_cells.setText(merra_dims)
        if event != 'init':
            self.worldwindow.view.emit(QtCore.SIGNAL('statusmsg'), approx_area + ' ' + merra_dims)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def _setupTowns(self):
        self._towns = {}
        self._towns = Towns(ul_lat=self.upper_left[3], ul_lon=self.upper_left[2],
                      lr_lat=self.lower_right[3], lr_lon=self.lower_right[2])
        for st in self._towns.towns:
            p = self.mapFromLonLat(QtCore.QPointF(st.lon, st.lat))
            el = QtGui.QGraphicsEllipseItem(p.x() - 1, p.y() - 1, 2, 2)   # here to adjust town circles
            el.setBrush(QtGui.QColor(self.colors['town']))
            el.setPen(QtGui.QColor(self.colors['town']))
            el.setZValue(0)
            self._townGroup.addToGroup(el)
            txt = QtGui.QGraphicsSimpleTextItem(st.name)
            new_font = txt.font()
            new_font.setPointSizeF(self.width() / 20)
            txt.setFont(new_font)
            txt.setPos(p + QtCore.QPointF(1.5, -0.5))
            txt.scale(0.1, 0.1)
            txt.setBrush(QtGui.QColor(self.colors['town_name']))
            txt.setZValue(0)
            self._townGroup.addToGroup(txt)
        return
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def showArea(self, event):
        if self.ignore:
            return
        if self.sender() == self.southSpin or self.sender() == self.eastSpin:
            if self.southSpin.value() > self.northSpin.value():
                y = self.northSpin.value()
                self.northSpin.setValue(self.southSpin.value())
                self.southSpin.setValue(y)
            if self.eastSpin.value() < self.westSpin.value():
                x = self.westSpin.value()
                self.westSpin.setValue(self.eastSpin.value())
                self.eastSpin.setValue(x)
        if self.worldwindow is None:
            return
        approx_area = self.worldwindow.view.drawRect([QtCore.QPointF(self.westSpin.value(), self.northSpin.value()),
                                   QtCore.QPointF(self.eastSpin.value(), self.southSpin.value())])
        self.approx_area.setText(approx_area)
        if event != 'init':
            self.worldwindow.view.emit(QtCore.SIGNAL('statusmsg'), approx_area)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def drawMany(self):
        grids = GetMany.getList()
        if grids is None:
            return
        self.clear_Rect()
        self.rect_items = []
        color = QtGui.QColor()
        color.setNamedColor((self.scene().colors['border']))
        pen = QtGui.QPen(color, self.scene().line_width)
        pen.setJoinStyle(QtCore.Qt.RoundJoin)
        pen.setCapStyle(QtCore.Qt.RoundCap)
        for g in range(len(grids)):
            fromm = self.mapFromLonLat(QtCore.QPointF(grids[g][1], grids[g][0]))
            too = self.mapFromLonLat(QtCore.QPointF(grids[g][3], grids[g][2]))
            self.rect_items.append(QtGui.QGraphicsRectItem(fromm.x(), fromm.y(),
                                   too.x() - fromm.x(), too.y() - fromm.y()))
            self.rect_items[-1].setPen(pen)
            self.rect_items[-1].setZValue(3)
            self.scene().addItem(self.rect_items[-1])
        self.emit(QtCore.SIGNAL('statusmsg'), str(len(grids)) + ' Areas drawn')
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, startp=Point(), endp=None,
                 length=60.0, angle=50.0,
                 color=QtCore.Qt.red, pencolor=QtCore.Qt.green,
                 startarrow=True):
        """
        Initialisation of the class.
        """
        self.sc = None
        super(Arrow, self).__init__()

        self.startp = QtCore.QPointF(startp.x, -startp.y)
        self.endp = endp

        self.length = length
        self.angle = angle
        self.startarrow = startarrow
        self.allwaysshow = False

        self.arrowHead = QPolygonF()
        self.setFlag(QGraphicsItem.ItemIsSelectable, False)
        self.myColor = color
        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)
        self.arrowSize = 8.0
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def contains_point(self, point):
        """
        Method to determine the minimal distance from the point to the shape
        @param point: a QPointF
        @return: minimal distance
        """
        min_distance = float(0x7fffffff)
        ref_point = Point(point.x(), point.y())
        t = 0.0
        while t < 1.0:
            per_point = self.path.pointAtPercent(t)
            spline_point = Point(per_point.x(), per_point.y())
            distance = ref_point.distance(spline_point)
            if distance < min_distance:
                min_distance = distance
            t += 0.01
        return min_distance
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, text='S', startp=Point(x=0.0, y=0.0),):
        """
        Initialisation of the class.
        """
        QGraphicsItem.__init__(self)

        self.setFlag(QGraphicsItem.ItemIsSelectable, False)

        self.text = text
        self.sc = 1.0
        self.startp = QtCore.QPointF(startp.x, -startp.y)

        pencolor = QColor(0, 200, 255)
        self.brush = QColor(0, 100, 255)

        self.pen = QPen(pencolor, 1, QtCore.Qt.SolidLine)
        self.pen.setCosmetic(True)

        self.path = QPainterPath()
        self.path.addText(QtCore.QPointF(0, 0),
                          QFont("Arial", 10/self.sc),
                          self.text)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def resizeEventVertical(self, event):
        if self.label_pos == TOP:
            y = self.label_font_metrics.height()+self.spacing
            height = y
            self.label_rect = QtCore.QRect(0, 0, self.width(), height)
        elif self.label_pos == BOTTOM:
            y = 0
            height = self.label_font_metrics.height()+self.spacing
            self.label_rect = QtCore.QRect(0, self.height()-height, self.width(), height)
        else:
            y = height = 0
        self.range_rect = QtCore.QRectF((self.width()-self.range_size)/2., self.range_size/2.+y, self.range_size, self.height()-self.range_size-height)
        self.range_range = self.range_rect.y()+4, self.range_rect.height()-8
        pos = QtCore.QPointF(self.range_rect.center().x(), self.get_pos())
        self.slider_rect.moveCenter(pos)
        self.cursor.move(pos.x(), pos.y())
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def wheelEvent(self, event):
        if event.modifiers() & QtCore.Qt.ControlModifier:
#            center = QtCore.QPointF(self.mapToScene(event.pos()).x(), self.wavepath.boundingRect().center().y())
            center = QtCore.QPointF(self.mapToScene(event.pos()).x(), self.mapToScene(self.viewport().rect().center()).y())
            if event.delta() > 0:
                self.zoom = self.zoom - 1 if self.zoom > 0 else 0
            else:
                self.zoom = self.zoom + 1 if self.zoom < len(self.zoom_values) - 1 else self.zoom
            self.fitInView(0, 0, self.zoom_values[self.zoom], self.current_sampwidth_int)
            visible = self.mapToScene(self.viewport().rect()).boundingRect()
            if visible.width() > self.wavepath.boundingRect().width():
                self.scene().setSceneRect(-self.left_margin, 0, visible.width(), self.current_sampwidth_int)
            else:
                self.scene().setSceneRect(-self.left_margin, 0, self.wavepath.boundingRect().width(), self.current_sampwidth_int)
            self.centerOn(center)
        elif event.modifiers() & QtCore.Qt.ShiftModifier:
            event = QtGui.QWheelEvent(event.pos(), event.delta()*5, event.buttons(), event.modifiers(), QtCore.Qt.Horizontal)
            QtGui.QGraphicsView.wheelEvent(self, event)
            self.mouseMoveEvent(event)
        else:
            event = QtGui.QWheelEvent(event.pos(), event.delta(), event.buttons(), event.modifiers(), QtCore.Qt.Horizontal)
            QtGui.QGraphicsView.wheelEvent(self, event)
            self.mouseMoveEvent(event)
项目:Bigglesworth    作者:MaurizioB    | 项目源码 | 文件源码
def itemChange(self, change, value):
        if change == self.ItemPositionChange:
            pos = value.toPyObject()
            if self.isVisible():
                if QtGui.QApplication.keyboardModifiers() == QtCore.Qt.ShiftModifier:
                    colliding = [i for i in self.collidingItems() if isinstance(i, ControlPoint)]
                    if colliding:
                        if colliding[0].contains(self.mapFromScene(pos)):
                            pos = colliding[0].pos()
                            self.moved.emit(pos.x(), pos.y())
                            return pos
                elif QtGui.QApplication.keyboardModifiers() == QtCore.Qt.ControlModifier:
                    if self.wave_path in self.collidingItems():
                        sample = int(pos.x() / 16384)
                        pos = self.wave_path.path().elementAt(sample)
                        self.moved.emit(pos.x, pos.y)
                        return QtCore.QPointF(pos.x, pos.y)
#            if not self.move(self, pos.x(), pos.y()):
#                return self.pos()
            self.moved.emit(pos.x(), pos.y())
        return QtGui.QGraphicsWidget.itemChange(self, change, value)
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def itemChange(self, change, value):                    
        '''Item position has changed, calculate new position.

        :param change: Change event.
        :param value: QtCore.QPointF().
        :return value: QtCore.QPointF(x, y) or super(Connector, self).itemChange(change, value).
        '''
        if change == self.ItemScenePositionHasChanged:
            for cb in self.posCallbacks:                
                cb( value )
            return value
        return super(Connector, self).itemChange(change, value)
    #------------------------------------------------------------------------------------------------

#========================================================================================================================
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def setBeginPos(self, pos1):
        '''Callback method to keep `pos1` up to date.

        :param pos1: `QtCore.QPointF()`.
        '''
        rect = self.srcConnector.rect()
        pos = self.mapFromItem( self.srcConnector, self.srcConnector.position )
        self.pos1 = QtCore.QPointF(pos.x() + rect.width()/2, pos.y() + rect.height()/2  )
#         self.pos1 = pos1
        self.setName(self.name)                    
        self.arcLine.setLine(QtCore.QLineF(self.pos1, self.pos2))
    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def __init__(self, direction, parent=None):
        '''Create a port

        :param direction:  Port direction: (i)nput, (o)utput, (io) bidirectional.
        :param parent: Parent port place.
        '''
        super(PortItem, self).__init__(QtCore.QRectF(-4.0,-4.0,17.0,17.0), parent)
        self.posChangeCallbacks = []
        self.setBrush(QtGui.QBrush(QtCore.Qt.white))
        self.setFlags(self.ItemIsSelectable | self.ItemIsMovable | self.ItemSendsScenePositionChanges)
        self.label = QtGui.QGraphicsTextItem("", self)
        self.label.setPos(QtCore.QPointF( -4, -7))
        self.direction = direction
        self.setZValue(9)
    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def shortcutCreateNode(self):
        '''Create CPN elements with keyboard shortcuts.'''
        if "transition" in self.nodeType:
            if self.diag.checkBox.checkState() == 2:
                subnet = self.diag.getName()
                substitutionTransition = True
            else:
                subnet = self.subnet
                substitutionTransition = False
            self.mainWindow.simulator.uniqueNameBase += 1

            b1 = TransitionItem( self, self.diag.getName(),QtCore.QPointF(), guardExpression = "True", substitutionTransition=substitutionTransition, uniqueName="t%d"%self.mainWindow.simulator.uniqueNameBase, subnet=subnet)

#             b1 = TransitionItem( self, self.diag.getName(), self.mouseScreenPos, net=self.mainWindow.simulator.net, guardExpression = "True", uniqueName="t%d"%self.mainWindow.simulator.uniqueNameBase)
            self.mainWindow.simulator.uniqueNameBase += 1
        elif "place" in self.nodeType:            
            b1 = PlaceItem( self, self.diag.getName(), self.mouseScreenPos, initMarking = [], uniqueName="p%d"%self.mainWindow.simulator.uniqueNameBase, subnet=self.subnet)
            self.mainWindow.simulator.uniqueNameBase += 1
        else:
            errorString = str( "no valid target, dropping aborted" )
            item = QtGui.QListWidgetItem( errorString )
            item.setTextColor(QtCore.Qt.yellow)
            self.logWidget.addItem( item ) 
            logging.warning(errorString)
            return
        self.diagramScene.addItem(b1) 
        del self.diag
        del self.nodeType
        pass
    #------------------------------------------------------------------------------------------------
项目:CPNSimulatorGui    作者:chris-kuhr    | 项目源码 | 文件源码
def __init__(self, parent=None, scene=None):
        super(ArcItem, self).__init__(None)
        self.scene = scene
        self.parent = parent
        self.arcLine = LineItem(self)
        self.parent.diagramScene.addItem(self.arcLine)  
        arrowPolygon = QtGui.QPolygonF( [ 
                                         QtCore.QPointF(  0.0,  0.0),
                                         QtCore.QPointF(  0.0, 10.0), 
                                         QtCore.QPointF( 10.0,  5.0)
                                         ] )
        self.arcLinePolygon = self.parent.diagramScene.addPolygon( arrowPolygon ) 
        self.pos1 = QtCore.QPointF(20,20)
        self.pos2 = QtCore.QPointF(200,200)
#         self.setFlags( self.ItemIsSelectable | self.ItemIsMoveable )
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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()
项目:InplusTrader_Linux    作者:zhengwsh    | 项目源码 | 文件源码
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()
项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def __init__(self):
        super(MyArrow, self).__init__()
        self.source = QPointF(0, 250)
        self.dest = QPointF(120, 120)
        self.line = QLineF(self.source, self.dest)
        self.line.setLength(self.line.length() - 20)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def destinationxy(self, lon1, lat1, bearing, distance):
        """
        Given a start point, initial bearing, and distance, calculate
        the destination point and final bearing travelling along a
        (shortest distance) great circle arc
        """
        radius = 6367.  # km is the radius of the Earth
      # convert decimal degrees to radians
        ln1, lt1, baring = map(math.radians, [lon1, lat1, bearing])
      # "reverse" haversine formula
        lat2 = math.asin(math.sin(lt1) * math.cos(distance / radius) +
               math.cos(lt1) * math.sin(distance / radius) * math.cos(baring))
        lon2 = ln1 + math.atan2(math.sin(baring) * math.sin(distance / radius) * math.cos(lt1),
               math.cos(distance / radius) - math.sin(lt1) * math.sin(lat2))
        return QtCore.QPointF(math.degrees(lon2), math.degrees(lat2))
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def destinationxy(self, lon1, lat1, bearing, distance):
        """
        Given a start point, initial bearing, and distance, calculate
        the destination point and final bearing travelling along a
        (shortest distance) great circle arc
        """
        radius = 6367.  # km is the radius of the Earth
     # convert decimal degrees to radians
        ln1, lt1, baring = map(math.radians, [lon1, lat1, bearing])
     # "reverse" haversine formula
        lat2 = math.asin(math.sin(lt1) * math.cos(distance / radius) +
               math.cos(lt1) * math.sin(distance / radius) * math.cos(baring))
        lon2 = ln1 + math.atan2(math.sin(baring) * math.sin(distance / radius) * math.cos(lt1),
               math.cos(distance / radius) - math.sin(lt1) * math.sin(lat2))
        return QtCore.QPointF(math.degrees(lon2), math.degrees(lat2))
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def destinationx(self, lon1, lat1, distance):
        radius = 6367.  # km is the radius of the Earth
     # convert decimal degrees to radians
        lt1 = math.radians(lat1)
        circum = radius * 2 * math.pi * math.cos(lt1)
        lon2 =  lon1 + distance / circum * 360
        return QtCore.QPointF(lon2, lat1)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def go_ToTown(self):
     #   to cater for windows I've created submenus
        menu = QtGui.QMenu()
        twns = []
        submenus = []
        submenus.append(QtGui.QMenu('A...'))
        titl = ''
        ctr = 0
        for town in sorted(self.view.scene()._towns.towns, key=lambda town: town.name):
            if titl == '':
                titl = town.name + ' to '
            twns.append(submenus[-1].addAction(town.name))
            twns[-1].setIconVisibleInMenu(True)
            ctr += 1
            if ctr > 25:
                titl += town.name
                submenus[-1].setTitle(titl)
                titl = ''
                menu.addMenu(submenus[-1])
                submenus.append(QtGui.QMenu(town.name[0] + '...'))
                ctr = 0
        titl += town.name
        submenus[-1].setTitle(titl)
        menu.addMenu(submenus[-1])
        x = self.frameGeometry().left() + 50
        y = self.frameGeometry().y() + 50
        action = menu.exec_(QtCore.QPoint(x, y))
        if action is not None:
            town = self.view.scene()._towns.Get_Town(action.text())
            go_to = self.mapFromLonLat(QtCore.QPointF(town.lon, town.lat))
            self.view.centerOn(go_to)
            comment = '(%s,%s) Centred on town %s' % ('{:0.4f}'.format(town.lon), '{:0.4f}'.format(town.lat),
                          town.name)
            self.view.emit(QtCore.SIGNAL('statusmsg'), comment)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def _setupGrid(self):
        def do_them(lines, width=self.line_width, grid2=False):
            for line in lines:
                color = QtGui.QColor()
                color.setNamedColor(line.style)
                pen = QtGui.QPen(color, width)
                pen.setJoinStyle(QtCore.Qt.RoundJoin)
                pen.setCapStyle(QtCore.Qt.RoundCap)
                start = self.mapFromLonLat(QtCore.QPointF(line.coordinates[0][1], line.coordinates[0][0]))
                for pt in range(1, len(line.coordinates)):
                    end = self.mapFromLonLat(QtCore.QPointF(line.coordinates[pt][1], line.coordinates[pt][0]))
                    ln = QtGui.QGraphicsLineItem(QtCore.QLineF(start, end))
                    ln.setPen(pen)
                    ln.setZValue(0)
                    self.addItem(ln)
                    if grid2:
                        self._gridGroup2.addToGroup(ln)
                    else:
                        self._gridGroup.addToGroup(ln)
                    start = end
            return
        self.lines = Grid()
        do_them(self.lines.lines)
        self.grid_lines = len(self.lines.lines)
        lines = Grid_Boundary()
        if len(lines.lines) > 0:
            lines.lines[0].style = self.colors['grid_boundary']
            do_them(lines.lines, width=0)
        if self.existing_grid2:
            lines2 = Grid(grid2=True)
            do_them(lines2.lines, grid2=True)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mapToLonLat(self, p):
        x = p.x() / self._lon_scale + self._orig_lon
        y = p.y() / self._lat_scale + self._orig_lat
        lon, lat = self._proj(x, y, inverse=True)
        return QtCore.QPointF(round(lon, 4), round(lat, 4))
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mapFromLonLat(self, p):
        lon, lat = p.x(), p.y()
        x, y = self._proj(lon, lat)
        x = (x - self._orig_lon) * self._lon_scale
        y = (y - self._orig_lat) * self._lat_scale
        return QtCore.QPointF(x, y)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mapToLonLat(self, p):
        x = p.x() / self._lon_scale + self._orig_lon
        y = p.y() / self._lat_scale + self._orig_lat
        lon, lat = self._proj(x, y, inverse=True)
        return QtCore.QPointF(round(lon, 4), round(lat, 4))
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mapFromLonLat(self, p):
        lon, lat = p.x(), p.y()
        x, y = self._proj(lon, lat)
        x = (x - self._orig_lon) * self._lon_scale
        y = (y - self._orig_lat) * self._lat_scale
        return QtCore.QPointF(x, y)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def destinationxy(self, lon1, lat1, bearing, distance):
        """
        Given a start point, initial bearing, and distance, calculate
        the destination point and final bearing travelling along a
        (shortest distance) great circle arc
        """
        radius = RADIUS  # km is the radius of the Earth
     # convert decimal degrees to radians
        ln1, lt1, baring = map(radians, [lon1, lat1, bearing])
     # "reverse" haversine formula
        lat2 = asin(sin(lt1) * cos(distance / radius) +
               cos(lt1) * sin(distance / radius) * cos(baring))
        lon2 = ln1 + atan2(sin(baring) * sin(distance / radius) * cos(lt1),
               cos(distance / radius) - sin(lt1) * sin(lat2))
        return QtCore.QPointF(degrees(lon2), degrees(lat2))
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def destinationx(self, lon1, lat1, distance):
        radius = RADIUS  # km is the radius of the Earth
     # convert decimal degrees to radians
        lt1 = radians(lat1)
        circum = radius * 2 * pi * cos(lt1)
        lon2 = lon1 + distance / circum * 360
        return QtCore.QPointF(lon2, lat1)
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def mousePressEvent(self, event):
        if QtCore.Qt.LeftButton == event.button():
            where = self.mapToLonLat(event.pos())
            pl = self.mapToLonLat(event.pos())
            self.emit(QtCore.SIGNAL('statusmsg'), p2str(pl) + ' ' + p2str(event.pos()))
            if self._rectangle is None:
                self._rectangle = [where]
                hb = self.horizontalScrollBar()
                vb = self.verticalScrollBar()
                self._sb_start = QtCore.QPoint(hb.value(), vb.value())
            else:
                self._rectangle.append(where)
                if self._rectangle[0].x() > self._rectangle[1].x():
                    x = self._rectangle[0].x()
                    self._rectangle[0] = QtCore.QPointF(self._rectangle[1].x(), self._rectangle[0].y())
                    self._rectangle[1] = QtCore.QPointF(x, self._rectangle[1].y())
                if self._rectangle[0].y() < self._rectangle[1].y():
                    y = self._rectangle[0].y()
                    self._rectangle[0] = QtCore.QPointF(self._rectangle[0].x(), self._rectangle[1].y())
                    self._rectangle[1] = QtCore.QPointF(self._rectangle[1].x(), y)
                approx_area = self.drawRect(self._rectangle)
                self.emit(QtCore.SIGNAL('statusmsg'), p2str(pl) + ' ' + approx_area)
                self.emit(QtCore.SIGNAL('tellarea'), self._rectangle, approx_area)
                self._rectangle = None
            self._drag_start = QtCore.QPoint(event.pos())
            hb = self.horizontalScrollBar()
            vb = self.verticalScrollBar()
            self._sb_start = QtCore.QPoint(hb.value(), vb.value())
项目:siren    作者:ozsolarwind    | 项目源码 | 文件源码
def show_Grid(self):
        comment = 'Grid Toggled '
        if self.view.scene().show_grid:
            self.view.scene().show_grid = False
            self.view.scene()._gridGroup.setVisible(False)
            self.showGrid.setIcon(QtGui.QIcon('blank.png'))
            comment += 'Off'
        else:
            if self.view.scene()._gridGroup is None:
                self.view.scene()._gridGroup = QtGui.QGraphicsItemGroup()
                self.view.scene().addItem(self.view.scene()._gridGroup)
                color = QtGui.QColor()
                color.setNamedColor((self.view.scene().colors['grid']))
                pen = QtGui.QPen(color, self.view.scene().line_width)
                pen.setJoinStyle(QtCore.Qt.RoundJoin)
                pen.setCapStyle(QtCore.Qt.RoundCap)
                for lat in range(90, -90, -10):
                    if lat == 90:
                        continue
                    fromm = self.mapFromLonLat(QtCore.QPointF(-180, lat))
                    too = self.mapFromLonLat(QtCore.QPointF(180, lat))
                    item = QtGui.QGraphicsLineItem(fromm.x(), fromm.y(), too.x(), too.y())
                    item.setPen(pen)
                    item.setZValue(3)
                    self.view.scene()._gridGroup.addToGroup(item)
                for lon in range(-180, 181, 10):
                    fromm = self.mapFromLonLat(QtCore.QPointF(lon, self.view.scene().map_upper_left[0]))
                    too = self.mapFromLonLat(QtCore.QPointF(lon, self.view.scene().map_lower_right[0]))
                    item = QtGui.QGraphicsLineItem(fromm.x(), fromm.y(), too.x(), too.y())
                    item.setPen(pen)
                    item.setZValue(3)
                    self.view.scene()._gridGroup.addToGroup(item)
            self.view.scene().show_grid = True
            self.view.scene()._gridGroup.setVisible(True)
            self.showGrid.setIcon(QtGui.QIcon(self.view.scene().check_icon))
            comment += 'On'
        self.view.emit(QtCore.SIGNAL('statusmsg'), comment)
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
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
项目:rec-attend-public    作者:renmengye    | 项目源码 | 文件源码
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
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
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
项目:cityscapes-api    作者:renmengye    | 项目源码 | 文件源码
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
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def __init__(self, diagramType, contextMenu, parent=None, scene=None):
        super(DiagramItem, self).__init__(parent, scene)

        self.arrows = []

        self.diagramType = diagramType
        self.contextMenu = contextMenu

        path = QtGui.QPainterPath()
        if self.diagramType == self.StartEnd:
            path.moveTo(200, 50)
            path.arcTo(150, 0, 50, 50, 0, 90)
            path.arcTo(50, 0, 50, 50, 90, 90)
            path.arcTo(50, 50, 50, 50, 180, 90)
            path.arcTo(150, 50, 50, 50, 270, 90)
            path.lineTo(200, 25)
            self.myPolygon = path.toFillPolygon()
        elif self.diagramType == self.Conditional:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-100, 0), QtCore.QPointF(0, 100),
                    QtCore.QPointF(100, 0), QtCore.QPointF(0, -100),
                    QtCore.QPointF(-100, 0)])
        elif self.diagramType == self.Step:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-100, -100), QtCore.QPointF(100, -100),
                    QtCore.QPointF(100, 100), QtCore.QPointF(-100, 100),
                    QtCore.QPointF(-100, -100)])
        else:
            self.myPolygon = QtGui.QPolygonF([
                    QtCore.QPointF(-120, -80), QtCore.QPointF(-70, 80),
                    QtCore.QPointF(120, 80), QtCore.QPointF(70, -80),
                    QtCore.QPointF(-120, -80)])

        self.setPolygon(self.myPolygon)
        self.setFlag(QtGui.QGraphicsItem.ItemIsMovable, True)
        self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable, True)
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def intersectLineGeometry(self, lineGeo, breakShape):
        """
        Try to break lineGeo with the given breakShape. Will return the intersection points of lineGeo with breakShape.
        """
        # TODO geos should be abs
        intersections = []
        line = QLineF(lineGeo.Ps.x, lineGeo.Ps.y, lineGeo.Pe.x, lineGeo.Pe.y)
        for breakGeo in breakShape.geos.abs_iter():
            if isinstance(breakGeo, LineGeo):
                breakLine = QLineF(breakGeo.Ps.x, breakGeo.Ps.y, breakGeo.Pe.x, breakGeo.Pe.y)
                intersection = QPointF(0, 0)  # values do not matter
                res = line.intersect(breakLine, intersection)
                if res == QLineF.BoundedIntersection:
                    intersections.append(Point(intersection.x(), intersection.y()))
        return intersections
项目:dxf2gcode    作者:cnc-club    | 项目源码 | 文件源码
def draw_wp_zero(self):
        """
        This function is called while the drawing of all items is done. It plots
        the WPZero to the Point x=0 and y=0. This item will be enabled or
        disabled to be shown or not.
        """
        self.wpzero = WpZero(QtCore.QPointF(0, 0))
        self.addItem(self.wpzero)
项目:ImgAnnotaPyQt4    作者:ZhengRui    | 项目源码 | 文件源码
def mouseMoveEvent(self, event):
        if self._pan:
            self.horizontalScrollBar().setValue(self.horizontalScrollBar().value() - (event.x() - self._panStartX))
            self.verticalScrollBar().setValue(self.verticalScrollBar().value() - (event.y() - self._panStartY))
            self._panStartX = event.x()
            self._panStartY = event.y()

        if self._draw:
            self.scene.removeItem(self._lstRect)
            sceneCoord = self.mapToScene(event.pos())
            tl = QtCore.QPointF(max(min(self._drawStartX, sceneCoord.x())-2, 0), max(min(self._drawStartY, sceneCoord.y())-2, 0))
            br = QtCore.QPointF(min(max(self._drawStartX, sceneCoord.x()-1)+2, self.scene.sceneRect().width()), min(max(self._drawStartY, sceneCoord.y()-1)+2, self.scene.sceneRect().height()))
            self._lstRect = QStrokeRect(QtCore.QRectF(tl, br))
            self._lstRect.setPen(self.pen)
            self._lstRect.setStrokeWidth(6)
            self.scene.addItem(self._lstRect)
            self._moved = True

        event.accept()
        QtGui.QGraphicsView.mouseMoveEvent(self, event)

        sceneCoord = self.mapToScene(event.pos())
        sceneRect = self.scene.sceneRect()
        if sceneRect.contains(sceneCoord):
            self.emit(QtCore.SIGNAL("sendSceneCoord(QString)"), QtCore.QString('{:04.2f}, {:04.2f}'.format(sceneCoord.x(), sceneCoord.y())))
            if not self._pan and not self._draw:
                self.selItem = self.scene.itemAt(sceneCoord)
                if self.selItem is not None and self.selItem.type() != 7:   # 7 is QGraphicsPixmapItem
                    self.viewport().setCursor(QtCore.Qt.ArrowCursor)
                    self._sel = True
                else:
                    self.viewport().setCursor(QtCore.Qt.CrossCursor)
                    self._sel = False
        else:
            self.emit(QtCore.SIGNAL("sendSceneCoord(QString)"), '')
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
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
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
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
项目:cityscapesScripts    作者:mcordts    | 项目源码 | 文件源码
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