当前位置: 首页>>代码示例>>Python>>正文


Python QtCore.qrand方法代码示例

本文整理汇总了Python中PyQt4.QtCore.qrand方法的典型用法代码示例。如果您正苦于以下问题:Python QtCore.qrand方法的具体用法?Python QtCore.qrand怎么用?Python QtCore.qrand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt4.QtCore的用法示例。


在下文中一共展示了QtCore.qrand方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onEntry

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def onEntry(self, event):
        n = QtCore.qrand() % self.m_stateCount + 1
        while n == self.m_lastIndex:
            n = QtCore.qrand() % self.m_stateCount + 1

        self.m_lastIndex = n
        self.machine().postEvent(StateSwitchEvent(n))
开发者ID:bebee,项目名称:OpenSoft14,代码行数:9,代码来源:blocks.py

示例2: keyPressEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def keyPressEvent(self, event):
        key = event.key()

        if key == QtCore.Qt.Key_Up:
            self.centerNode.moveBy(0, -20)
        elif key == QtCore.Qt.Key_Down:
            self.centerNode.moveBy(0, 20)
        elif key == QtCore.Qt.Key_Left:
            self.centerNode.moveBy(-20, 0)
        elif key == QtCore.Qt.Key_Right:
            self.centerNode.moveBy(20, 0)
        elif key == QtCore.Qt.Key_Plus:
            self.scaleView(1.2)
        elif key == QtCore.Qt.Key_Minus:
            self.scaleView(1 / 1.2)
        elif key == QtCore.Qt.Key_A:
            node10=Node(self)
            self.s.addItem(node10)
            self.s.addItem(Edge(self.lastN, node10))
            self.lastN=node10
        elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter:
            for item in self.scene().items():
                if isinstance(item, Node):
                    item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300)
                    
                    item.setScale(item.scale()*1.1)
        else:   
            super(GraphWidget, self).keyPressEvent(event)
开发者ID:fengxxx,项目名称:fengxMind,代码行数:30,代码来源:fengxMind.py

示例3: timerEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def timerEvent(self):
        # Don't move too far away.
        lineToCenter = QtCore.QLineF(QtCore.QPointF(0, 0), self.mapFromScene(0, 0))
        if lineToCenter.length() > 150:
            angleToCenter = math.acos(lineToCenter.dx() / lineToCenter.length())
            if lineToCenter.dy() < 0:
                angleToCenter = Mouse.TwoPi - angleToCenter;
            angleToCenter = Mouse.normalizeAngle((Mouse.Pi - angleToCenter) + Mouse.Pi / 2)

            if angleToCenter < Mouse.Pi and angleToCenter > Mouse.Pi / 4:
                # Rotate left.
                self.angle += [-0.25, 0.25][self.angle < -Mouse.Pi / 2]
            elif angleToCenter >= Mouse.Pi and angleToCenter < (Mouse.Pi + Mouse.Pi / 2 + Mouse.Pi / 4):
                # Rotate right.
                self.angle += [-0.25, 0.25][self.angle < Mouse.Pi / 2]
        elif math.sin(self.angle) < 0:
            self.angle += 0.25
        elif math.sin(self.angle) > 0:
            self.angle -= 0.25

        # Try not to crash with any other mice.
        dangerMice = self.scene().items(QtGui.QPolygonF([self.mapToScene(0, 0),
                                                         self.mapToScene(-30, -50),
                                                         self.mapToScene(30, -50)]))

        for item in dangerMice:
            if item is self:
                continue
        
            lineToMouse = QtCore.QLineF(QtCore.QPointF(0, 0), self.mapFromItem(item, 0, 0))
            angleToMouse = math.acos(lineToMouse.dx() / lineToMouse.length())
            if lineToMouse.dy() < 0:
                angleToMouse = Mouse.TwoPi - angleToMouse
            angleToMouse = Mouse.normalizeAngle((Mouse.Pi - angleToMouse) + Mouse.Pi / 2)

            if angleToMouse >= 0 and angleToMouse < Mouse.Pi / 2:
                # Rotate right.
                self.angle += 0.5
            elif angleToMouse <= Mouse.TwoPi and angleToMouse > (Mouse.TwoPi - Mouse.Pi / 2):
                # Rotate left.
                self.angle -= 0.5

        # Add some random movement.
        if len(dangerMice) > 1 and (QtCore.qrand() % 10) == 0:
            if QtCore.qrand() % 1:
                self.angle += (QtCore.qrand() % 100) / 500.0
            else:
                self.angle -= (QtCore.qrand() % 100) / 500.0

        self.speed += (-50 + QtCore.qrand() % 100) / 100.0

        dx = math.sin(self.angle) * 10
        self.mouseEyeDirection = [dx / 5, 0.0][QtCore.qAbs(dx / 5) < 1]

        self.rotate(dx)
        self.setPos(self.mapToParent(0, -(3 + math.sin(self.speed) * 3)))
开发者ID:gmeeresyoung,项目名称:NagapiMocap,代码行数:58,代码来源:serverUI.py

示例4: __init__

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
 def __init__(self,x,y,w,h):
     super(MocapBox, self).__init__(x,y,w,h)        
     self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
                     QtCore.qrand() % 256)
     
     self.setBrush(self.color)
     self.mocapPointName = "unclasified"
     self.lable = QtGui.QGraphicsSimpleTextItem(self.mocapPointName,self)
     self.lable.rotate(180)
     self.lable.setPos(self.rect().x(),self.rect().y())
开发者ID:gmeeresyoung,项目名称:NagapiMocap,代码行数:12,代码来源:MocapGraphicsView.py

示例5: __init__

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def __init__(self):
        super(ColorItem, self).__init__()

        self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
                QtCore.qrand() % 256)

        self.setToolTip(
            "QColor(%d, %d, %d)\nClick and drag this color onto the robot!" % 
              (self.color.red(), self.color.green(), self.color.blue())
        )
        self.setCursor(QtCore.Qt.OpenHandCursor)
开发者ID:CapB1ack,项目名称:PyQt4,代码行数:13,代码来源:dragdroprobot.py

示例6: keyPressEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
 def keyPressEvent(self, event):
     key = event.key()
     if key == QtCore.Qt.Key_Plus:
         self.scaleView(1.2)
     elif key == QtCore.Qt.Key_Minus:
         self.scaleView(1 / 1.2)
     elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter:
         for item in self.scene().items():
             if isinstance(item, Node):
                 item.setPos(-150 + QtCore.qrand() % 300,
                             -150 + QtCore.qrand() % 300)
     else:
         super(GraphWidget, self).keyPressEvent(event)
开发者ID:lucasdaddiego,项目名称:staticnodes,代码行数:15,代码来源:graphics_view.py

示例7: docollision

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def docollision(self):

        # changement d'angle random
        if QtCore.qrand() % 1:  # en gros un booleen true flase..
            self.setRotation(self.rotation() + (180 + QtCore.qrand() % 10))
        else:
            self.setRotation(self.rotation() + (180 + QtCore.qrand() % -10))

        new_point = self.mapToParent(-self.boundingRect().width(), -self.boundingRect().width() + 2)

        if not self.scene().sceneRect().contains(new_point):
            new_point = self.mapToParent(0, 0)
        else:
            self.setPos(new_point)
开发者ID:Guilouf,项目名称:jeu_IA,代码行数:16,代码来源:myitem.py

示例8: __init__

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
 def __init__(self, image, scene, lines, x, y):
     QtGui.QGraphicsItem.__init__(self)
     self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
             QtCore.qrand() % 256)
     self.setToolTip("Drag this item over the axis to remove lines")
     self.setCursor(QtCore.Qt.OpenHandCursor)
     # Internal variable to get the global selection position on the axis
     self.axisPosY = y
     self.axisPosX = x
     self.setPos(x, y)
     self.scene = scene
     self.lines = lines
     self.axislimits = {}
     self.axisid = self.axisGetfromX(self.axisPosX)
     self.image = image
开发者ID:jpierre03,项目名称:pcoords-gui,代码行数:17,代码来源:selection_graphics_item.py

示例9: mouseMoveEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def mouseMoveEvent(self, event):
        if QtCore.QLineF(QtCore.QPointF(event.screenPos()), QtCore.QPointF(event.buttonDownScreenPos(QtCore.Qt.LeftButton))).length() < QtGui.QApplication.startDragDistance():
            return

        drag = QtGui.QDrag(event.widget())
        mime = QtCore.QMimeData()
        drag.setMimeData(mime)

        ColorItem.n += 1
        if ColorItem.n > 2 and QtCore.qrand() % 3 == 0:
            image = QtGui.QImage(':/images/head.png')
            mime.setImageData(image)
            drag.setPixmap(QtGui.QPixmap.fromImage(image).scaled(30,40))
            drag.setHotSpot(QtCore.QPoint(15, 30))
        else:
            mime.setColorData(self.color)
            mime.setText("#%02x%02x%02x" % (self.color.red(), self.color.green(), self.color.blue()))

            pixmap = QtGui.QPixmap(34, 34)
            pixmap.fill(QtCore.Qt.white)

            painter = QtGui.QPainter(pixmap)
            painter.translate(15, 15)
            painter.setRenderHint(QtGui.QPainter.Antialiasing)
            self.paint(painter, None, None)
            painter.end()

            pixmap.setMask(pixmap.createHeuristicMask())

            drag.setPixmap(pixmap)
            drag.setHotSpot(QtCore.QPoint(15, 20))

        drag.exec_()
        self.setCursor(QtCore.Qt.OpenHandCursor)
开发者ID:CapB1ack,项目名称:PyQt4,代码行数:36,代码来源:dragdroprobot.py

示例10: __init__

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def __init__(self):
        super(Mouse, self).__init__()

        self.angle = 0.0
        self.speed = 0.0
        self.mouseEyeDirection = 0.0
        self.color = QtGui.QColor(QtCore.qrand() % 256, QtCore.qrand() % 256,
                QtCore.qrand() % 256)

        self.rotate(QtCore.qrand() % (360 * 16))

        # In the C++ version of this example, this class is also derived from
        # QObject in order to receive timer events.  PyQt does not support
        # deriving from more than one wrapped class so we just create an
        # explicit timer instead.
        self.timer = QtCore.QTimer()
        self.timer.timeout.connect(self.timerEvent)
        self.timer.start(1000 / 33)
开发者ID:gmeeresyoung,项目名称:NagapiMocap,代码行数:20,代码来源:serverUI.py

示例11: keyPressEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
def keyPressEvent(self, event):
    key = event.key()
    if key == QtCore.Qt.Key_Up:
        self.translate(0, -20)
    elif key == QtCore.Qt.Key_Down:
        self.translate(0, 20)
    elif key == QtCore.Qt.Key_Left:
        self.translate(-20, 0)
    elif key == QtCore.Qt.Key_Right:
        self.translate(20, 0)
    elif key == QtCore.Qt.Key_Plus:
        self.scaleView(1.2)
    elif key == QtCore.Qt.Key_Minus:
        self.scaleView(1 / 1.2)
    elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter:
        for item in self.scene().items():
            if isinstance(item, Polygon):
                item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300)
    else:
        QtGui.QGraphicsView.keyPressEvent(self, event)
开发者ID:fccoelho,项目名称:epigrass,代码行数:22,代码来源:dgraph.py

示例12: keyPressEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def keyPressEvent(self, event):
        #todo:Implementar esto para poder hacer cosas interesantes con la scena
        key = event.key()

        if key == QtCore.Qt.Key_Up:
            self.centerNode.moveBy(0, -20)
        elif key == QtCore.Qt.Key_Down:
            self.centerNode.moveBy(0, 20)
        elif key == QtCore.Qt.Key_Left:
            self.centerNode.moveBy(-20, 0)
        elif key == QtCore.Qt.Key_Right:
            self.centerNode.moveBy(20, 0)
        elif key == QtCore.Qt.Key_Plus:
            self.scaleView(1.2)
        elif key == QtCore.Qt.Key_Minus:
            self.scaleView(1 / 1.2)
        elif key == QtCore.Qt.Key_Space or key == QtCore.Qt.Key_Enter:
            for item in self.scene().items():
                if isinstance(item, Node):
                    item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300)
        else:
            super(GraphWidget, self).keyPressEvent(event)
开发者ID:KmiQ,项目名称:ERSN,代码行数:24,代码来源:testing_nodes.py

示例13: keyPressEvent

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def keyPressEvent(self, event):
        key = event.key()
#
#        if key == QtCore.Qt.Key_Up:            
#            self.scrollContentsBy(0,-20)
#        elif key == QtCore.Qt.Key_Down:
#            self.scrollContentsBy(0, 20)            
#        elif key == QtCore.Qt.Key_Left:
#            self.scrollContentsBy(-20, 0)            
#        elif key == QtCore.Qt.Key_Right:
#            self.scrollContentsBy(20, 0)            
        if key == QtCore.Qt.Key_Plus:
            self.scaleView(1.2)
        elif key == QtCore.Qt.Key_Minus:
            self.scaleView(1 / 1.2)
        elif key==key == QtCore.Qt.Key_Enter:
            for item in self.scene().items():
                if isinstance(item, GraphicsNode):
                    item.setPos(-150 + QtCore.qrand() % 300, -150 + QtCore.qrand() % 300)            
        elif key == QtCore.Qt.Key_Space :
            self.centerOn(self.center)
        else:
            super(CustomGraphicsWidget, self).keyPressEvent(event) 
开发者ID:KmiQ,项目名称:ERSN,代码行数:25,代码来源:graph_viewer_core_extended.py

示例14: __init__

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    def __init__(self):
        super(Myitem, self).__init__()

        # rotation de départ
        angle = (QtCore.qrand() % 360)
        self.setRotation(angle)

        # la vitesse (nb de pixel)
        self.speed = 5

        # position de départ aléatoire
        start_x = 0
        start_y = 0

        if (QtCore.qrand() % 1):  # en gros un booleen true flase..
            start_x = QtCore.qrand() % 200
            start_y = QtCore.qrand() % 200
        else:
            start_x = QtCore.qrand() % -100
            start_y = QtCore.qrand() % -100

        self.setPos(self.mapToParent(start_x, start_y))
开发者ID:Guilouf,项目名称:jeu_IA,代码行数:24,代码来源:myitem.py

示例15: enumerate

# 需要导入模块: from PyQt4 import QtCore [as 别名]
# 或者: from PyQt4.QtCore import qrand [as 别名]
    # Values.
    for i, item in enumerate(items):
        # Ellipse.
        ellipseState.assignProperty(item, 'pos',
                QtCore.QPointF(math.cos((i / 63.0) * 6.28) * 250,
                        math.sin((i / 63.0) * 6.28) * 250))

        # Figure 8.
        figure8State.assignProperty(item, 'pos',
                QtCore.QPointF(math.sin((i / 63.0) * 6.28) * 250,
                        math.sin(((i * 2)/63.0) * 6.28) * 250))

        # Random.
        randomState.assignProperty(item, 'pos',
                QtCore.QPointF(-250 + QtCore.qrand() % 500,
                        -250 + QtCore.qrand() % 500))

        # Tiled.
        tiledState.assignProperty(item, 'pos',
                QtCore.QPointF(((i % 8) - 4) * kineticPix.width() + kineticPix.width() / 2,
                        ((i // 8) - 4) * kineticPix.height() + kineticPix.height() / 2))

        # Centered.
        centeredState.assignProperty(item, 'pos', QtCore.QPointF())

    # Ui.
    view = View(scene)
    view.setWindowTitle("Animated Tiles")
    view.setViewportUpdateMode(QtGui.QGraphicsView.BoundingRectViewportUpdate)
    view.setBackgroundBrush(QtGui.QBrush(bgPix))
开发者ID:AlexDoul,项目名称:PyQt4,代码行数:32,代码来源:animatedtiles.py


注:本文中的PyQt4.QtCore.qrand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。