def initView(self): self.setWindowTitle("Sin ball") self.setRenderHint(QtGui.QPainter.Antialiasing) self.image = Image() self.image.setPos(5, 150) self.timer = QtCore.QTimeLine(TIME) self.timer.setCurveShape(QtCore.QTimeLine.LinearCurve) self.timer.setFrameRange(0, 100) self.animation = QtGui.QGraphicsItemAnimation() self.animation.setItem(self.image) self.animation.setTimeLine(self.timer) QtCore.QObject.connect(self.timer, QtCore.SIGNAL("frameChanged(int)"), self.doStep) for i in range(20): self.animation.setPosAt(i / 20.0, QtCore.QPointF(i, math.sin(i)) * 40) self.scene = QtGui.QGraphicsScene(self) self.scene.setSceneRect(120, -50, 250, 150) self.scene.addItem(self.image) self.setScene(self.scene) self.timer.start() self.setGeometry(300, 300, 500, 200)
def animate_to(self, t, item, x, y, angle): """ Animate an item in the given time to pos x,y """ # The QGraphicsItemAnimation class is used to # animate an item in specific ways animation = QtGui.QGraphicsItemAnimation() # You create a timeline (in this case, it is 1 second long timeline = QtCore.QTimeLine(t * 1000) # And it has 100 steps timeline.setFrameRange(0, 100) # I want that, at time t, the item be at point x,y animation.setPosAt(t, QtCore.QPointF(x, y)) # And it should be rotated at angle "angle" animation.setRotationAt(t, angle) # It should animate this specific item animation.setItem(item) # And the whole animation is this long, and has # this many steps as I set in timeline. animation.setTimeLine(timeline) # Here is the animation, use it. return animation
def animate_to(t,item,x,y,angle): animation=QtGui.QGraphicsItemAnimation() timeline=QtCore.QTimeLine(1000) timeline.setFrameRange(0,100) animation.setPosAt(t,QtCore.QPointF(x,y)) animation.setRotationAt(t,angle) animation.setItem(item) animation.setTimeLine(timeline) return animation
def start(self): """ Start the animation of the arrow. """ self.a = QtGui.QGraphicsItemAnimation() self.a.setItem(self) self.a.setTimeLine(self.tl) self.a.setTranslationAt(1, -math.cos(self.angle) * 20, math.sin(self.angle) * 20) self.tl.start()
def reset_timers_anims(self, duration): """Resets timers and animations with new durations""" # Timer self.timer = qc.QTimeLine(duration) self.timer.setCurveShape(qc.QTimeLine.LinearCurve) self.timer.setFrameRange(0, duration * 1000) # Animation Object self.anim = qg.QGraphicsItemAnimation() self.anim.setItem(self.parent_obj) self.anim.setTimeLine(self.timer)
def set_timers_and_anims(self): """Sets duration and frames of progress bar animation""" self.duration = 2 * 1000 * 60 # Timer objects self.time_gfx_timer = qc.QTimeLine(self.duration) self.bar_gfx_timer = qc.QTimeLine(self.duration) self.time_gfx_timer.setCurveShape(qc.QTimeLine.LinearCurve) self.bar_gfx_timer.setCurveShape(qc.QTimeLine.LinearCurve) self.time_gfx_timer.setFrameRange(0, self.duration * 1000) self.bar_gfx_timer.setFrameRange(0, self.duration * 1000) # Animation Objects self.time_gfx_anim = qg.QGraphicsItemAnimation() self.bar_gfx_anim = qg.QGraphicsItemAnimation() self.time_gfx_anim.setItem(self.time_gfx) self.bar_gfx_anim.setItem(self.bar_gfx) self.time_gfx_anim.setTimeLine(self.time_gfx_timer) self.bar_gfx_anim.setTimeLine(self.bar_gfx_timer) # Animation Frames self.bar_gfx_timer.frameChanged[int].connect(self.advance_increment) for i in range(1000): self.time_gfx_anim.setPosAt(i / 1000.0, qc.QPointF(i, 0)) self.bar_gfx_anim.setPosAt(i / 1000.0, qc.QPointF(i, 0))
def get_attention(self): self.tl = QtCore.QTimeLine(3000) self.tl.setCurveShape(QtCore.QTimeLine.LinearCurve) self.tl.setLoopCount(1000) self.a = QtGui.QGraphicsItemAnimation() self.a.setItem(self) self.a.setTimeLine(self.tl) self.a.setScaleAt(0.1, 1.1, 1.1) self.a.setScaleAt(0.2, 0.9, 0.9) self.a.setScaleAt(0.3, 1.0, 1.0) self.tl.start()
def setupAnimation(self): self.timer = QtCore.QTimeLine() self.timer.setLoopCount(0) self.timer.setFrameRange(0, 100) self.animation = QtGui.QGraphicsItemAnimation() self.animation.setItem(self.pm) self.animation.setTimeLine(self.timer) QtCore.QObject.connect(self.timer, QtCore.SIGNAL("frameChanged(int)"), self.doStep) self.timer.start()
def setbubbleloc (self,duration,location): tl4loc = QtCore.QTimeLine() tl4loc.setDuration(duration) # self.connect(tl4loc,QtCore.SIGNAL("finished()"),self.updateloc) tl4loc.setFrameRange(30,100) self.changeLoc = QtGui.QGraphicsItemAnimation() self.changeLoc.setItem(self.bubble) self.changeLoc.setTimeLine(tl4loc) tl4loc.start() self.changeLoc.setPosAt(0.00000001,location) self.location = location '''
def animate_to(item, x, y, t): animation = QtGui.QGraphicsItemAnimation() #create a timeline of 1 second timeline = QtCore.QTimeLine(2000) #number of steps in timeline (100) timeline.setFrameRange(0, 100) #set position at time t animation.setPosAt(t, QtCore.QPointF(x, y)) #apply this to "item" animation.setItem(item) #add timeline to the animation animation.setTimeLine(timeline) #output of this definition is "animation" return animation
def __init__(self): super(Robot, self).__init__() self.torsoItem = RobotTorso(self) self.headItem = RobotHead(self.torsoItem) self.upperLeftArmItem = RobotLimb(self.torsoItem) self.lowerLeftArmItem = RobotLimb(self.upperLeftArmItem) self.upperRightArmItem = RobotLimb(self.torsoItem) self.lowerRightArmItem = RobotLimb(self.upperRightArmItem) self.upperRightLegItem = RobotLimb(self.torsoItem) self.lowerRightLegItem = RobotLimb(self.upperRightLegItem) self.upperLeftLegItem = RobotLimb(self.torsoItem) self.lowerLeftLegItem = RobotLimb(self.upperLeftLegItem) self.timeline = QtCore.QTimeLine() settings = [ # item position rotation at # x y time 0 / 1 (self.headItem, 0, -18, 20, -20), (self.upperLeftArmItem, -15, -10, 190, 180), (self.lowerLeftArmItem, 30, 0, 50, 10), (self.upperRightArmItem, 15, -10, 300, 310), (self.lowerRightArmItem, 30, 0, 0, -70), (self.upperRightLegItem, 10, 32, 40, 120), (self.lowerRightLegItem, 30, 0, 10, 50), (self.upperLeftLegItem, -10, 32, 150, 80), (self.lowerLeftLegItem, 30, 0, 70, 10), (self.torsoItem, 0, 0, 5, -20) ] self.animations = [] for item, pos_x, pos_y, rotation1, rotation2 in settings: item.setPos(pos_x, pos_y) animation = QtGui.QGraphicsItemAnimation() animation.setItem(item) animation.setTimeLine(self.timeline) animation.setRotationAt(0, rotation1) animation.setRotationAt(1, rotation2) self.animations.append(animation) self.animations[0].setScaleAt(1, 1.1, 1.1) self.timeline.setUpdateInterval(1000 / 25) self.timeline.setCurveShape(QtCore.QTimeLine.SineCurve) self.timeline.setLoopCount(0) self.timeline.setDuration(2000) self.timeline.start()
def setbubblesize(self,duration,radius): tl4size = QtCore.QTimeLine() # self.connect(tl4size,QtCore.SIGNAL("finished()"),self.updateradius) tl4size.setDuration(duration) tl4size.setFrameRange(30,100) tl4size.start() self.changeSize = QtGui.QGraphicsItemAnimation() self.changeSize.setItem(self.bubble) self.changeSize.setTimeLine(tl4size) # if self.bubble.radius>=radius: # self.changeSize.setShearAt(0.00000000001,self.bubble.radius/radius,self.bubble.radius/radius) # else: self.changeSize.setScaleAt(0.00000001,radius/self.bubble.radius,radius/self.bubble.radius) self.radius = radius '''
def __init__(self): QtGui.QGraphicsView.__init__(self) self.scene = QtGui.QGraphicsScene(self) self.item = QtGui.QGraphicsEllipseItem(-20, -10, 40, 20) self.scene.addItem(self.item) self.setScene(self.scene) # Remember to hold the references to QTimeLine and QGraphicsItemAnimation instances. # They are not kept anywhere, even if you invoke QTimeLine.start(). self.tl = QtCore.QTimeLine(1000) self.tl.setFrameRange(0, 100) self.a = QtGui.QGraphicsItemAnimation() self.a.setItem(self.item) self.a.setTimeLine(self.tl) # Each method determining an animation state (e.g. setPosAt, setRotationAt etc.) # takes as a first argument a step which is a value between 0 (the beginning of the # animation) and 1 (the end of the animation) self.a.setPosAt(0, QtCore.QPointF(0, -10)) self.a.setRotationAt(1, 360) self.tl.start()
def huffman(self): data = str(self.text) frequency = defaultdict(int) for symbol in data: frequency[symbol] += 1 huff = self.encode(frequency) nodes = [] for p in huff: node = p[0] frequencies = str(frequency[p[0]]) weight = p[1] nodes.append([node,frequencies,weight]) item = callbackEllipse(QtCore.QRectF(5, -252, 30, 30)) ilk = self.scene().addSimpleText("MT") ilk.setPos(9,-245) #item.setFlag(QtGui.QGraphicsItem.ItemIsMovable) self.scene().addItem(item) yazi = self.scene().addSimpleText('GIRILEN METIN :%s' %data) yazi.setBrush(QtCore.Qt.red) yazi.setPos(-90,-310) for node,frequencies,weight in nodes: koordinat = 250 koorx = 0 koory = 0 baslangicx = 20 baslangicy = -220 self.list.addItem("%s - %s - %s" %(node,frequencies,weight)) for edge in weight: if edge == '0': koorx += 0 - koordinat koordinat /=2 koory += 50 item = QtGui.QGraphicsLineItem(QtCore.QLineF(baslangicx,baslangicy,10+koorx,-210+koory)) item.setPen(QtGui.QPen(QtCore.Qt.blue, 4)) self.scene().addItem(item) baslangicx = 10+koorx baslangicy = -210+koory self.tl = QtCore.QTimeLine(5500) self.tl.setFrameRange(0, 5200) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(item) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, -360) self.tl.start() item2 = callbackEllipse(QtCore.QRectF(koorx,-210+koory, 20, 20)) item2.setBrush(QtGui.QBrush(QtCore.Qt.red)) self.scene().addItem(item2) self.tl = QtCore.QTimeLine(4500) self.tl.setFrameRange(0, 4500) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(item2) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, 360) self.tl.start() if edge == "1": koorx += koordinat koordinat /=2 koory += 50 item21 = QtGui.QGraphicsLineItem(QtCore.QLineF(baslangicx,baslangicy,10+koorx,-210+koory)) item21.setPen(QtGui.QPen(QtCore.Qt.blue, 4)) self.scene().addItem(item21) baslangicx = 10+koorx baslangicy = -210+koory self.tl = QtCore.QTimeLine(5000) self.tl.setFrameRange(0, 5000) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(item21) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, 360) self.tl.start() item23 = callbackEllipse(QtCore.QRectF(koorx,-210+koory, 20, 20)) item23.setBrush(QtGui.QBrush(QtCore.Qt.yellow)) self.scene().addItem(item23) self.tl = QtCore.QTimeLine(4000) self.tl.setFrameRange(0, 5000) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(item23) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, -360) self.tl.start() frec = self.scene().addSimpleText('%s' %frequencies) frec.setBrush(QtCore.Qt.red) frec.setPos(koorx-10,-195+koory) self.tl = QtCore.QTimeLine(4000) self.tl.setFrameRange(0, 5000) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(frec) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, -360) self.tl.start() yazi = self.scene().addSimpleText('%s' %node) yazi.setBrush(QtCore.Qt.blue) yazi.setPos(koorx+5,-210+koory) self.tl = QtCore.QTimeLine(4000) self.tl.setFrameRange(0, 5000) self.a = QtGui.QGraphicsItemAnimation(self) self.a.setItem(yazi) self.a.setTimeLine(self.tl) self.a.setRotationAt(1, 360) self.tl.start()
def __init__(self): QtGui.QGraphicsView.__init__(self) self.scene = QtGui.QGraphicsScene(self) self.hardPen = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine) self.softPen = QtGui.QPen(QtCore.Qt.black, 0.25, QtCore.Qt.SolidLine) self.frame = list() self.grid = list() self.walls = list() self.wallsAnim = list() self.frame += [QtGui.QGraphicsLineItem(0, 0, 20 * n, 0)] self.frame += [QtGui.QGraphicsLineItem(0, 0, 0, 20 * m)] self.frame += [QtGui.QGraphicsLineItem(20 * n, 0, 20 * n, 20 * m)] self.frame += [QtGui.QGraphicsLineItem(0, 20 * m, 20 * n, 20 * m)] for i in range(n): self.grid += [QtGui.QGraphicsLineItem(20 * i, 0, 20 * i, 20 * m)] for i in range(m): self.grid += [QtGui.QGraphicsLineItem(0, 20 * i, 20 * n, 20 * i)] for w in wall: if w[0] == 0: self.walls = self.walls + [ QtGui.QGraphicsLineItem(w[1] * 20, w[2] * 20 - 20, w[1] * 20, w[2] * 20) ] else: self.walls = self.walls + [ QtGui.QGraphicsLineItem(w[1] * 20 - 20, w[2] * 20, w[1] * 20, w[2] * 20) ] self.walker = QtGui.QGraphicsPixmapItem(QtGui.QPixmap("cross.bmp")) self.scene.addItem(self.walker) for w in self.frame: w.setPen(self.hardPen) self.scene.addItem(w) for w in self.grid: w.setPen(self.softPen) self.scene.addItem(w) for w in self.walls: w.setPen(self.hardPen) self.scene.addItem(w) self.setScene(self.scene) l = len(path) self.tl = QtCore.QTimeLine(1000 * l) self.tl.setFrameRange(0, l * 100) for w in self.walls: a = QtGui.QGraphicsItemAnimation() a.setItem(w) a.setTimeLine(self.tl) self.wallsAnim += [a] self.a = QtGui.QGraphicsItemAnimation() self.a.setItem(self.walker) self.a.setTimeLine(self.tl) for i in range(l): self.a.setPosAt( i / l, QtCore.QPointF(-15 + path[i][1] * 20, -15 + path[i][2] * 20)) if i < l - 1: if path[i + 1][0] > path[i][0]: w = findwall(path[i][1], path[i][2], path[i + 1][1], path[i + 1][2]) j = wall.index(w) self.wallsAnim[j].setPosAt(i / l, QtCore.QPointF(0, 0)) self.wallsAnim[j].setRotationAt(i / l, 0) self.wallsAnim[j].setRotationAt((i + 1) / l, 720) print(n - w[1], m - w[2]) self.wallsAnim[j].setPosAt( (i + 1) / l, QtCore.QPointF(20 * (n - w[1]), 20 * (m - w[2]))) self.tl.start()
def __init__(self): QtGui.QGraphicsView.__init__(self) self.scene = QtGui.QGraphicsScene(self) self.hardPen = QtGui.QPen(QtCore.Qt.black, 2, QtCore.Qt.SolidLine) self.softPen = QtGui.QPen(QtCore.Qt.black, 0.25, QtCore.Qt.SolidLine) self.orange = QtGui.QColor(255, 165, 0) self.blue = QtGui.QColor(0, 191, 255) self.grid = list() self.walls = list() self.wallsAnim = list() self.frame = QtGui.QGraphicsRectItem(0, 0, n * 20, m * 20) self.start = ColoredRect(start[0] * 20 - 19, start[1] * 20 - 19, 19, 19, self.orange) self.finish = ColoredRect(finish[0] * 20 - 19, finish[1] * 20 - 19, 19, 19, self.blue) for i in range(n): self.grid += [QtGui.QGraphicsLineItem(20 * i, 0, 20 * i, 20 * m)] for i in range(m): self.grid += [QtGui.QGraphicsLineItem(0, 20 * i, 20 * n, 20 * i)] for w in wall: if w[0] == 0: self.walls = self.walls + [ QtGui.QGraphicsLineItem(w[1] * 20, w[2] * 20 - 20, w[1] * 20, w[2] * 20) ] else: self.walls = self.walls + [ QtGui.QGraphicsLineItem(w[1] * 20 - 20, w[2] * 20, w[1] * 20, w[2] * 20) ] self.walker = QtGui.QGraphicsPixmapItem(QtGui.QPixmap('cross.bmp')) self.scene.addItem(self.walker) self.frame.setPen(self.hardPen) self.scene.addItem(self.frame) self.scene.addItem(self.start) self.scene.addItem(self.finish) for w in self.grid: w.setPen(self.softPen) self.scene.addItem(w) for w in self.walls: w.setPen(self.hardPen) self.scene.addItem(w) self.scene.setSceneRect(0, 0, n * 20, m * 20) self.scene.setFocusItem(self.walker) self.setScene(self.scene) l = len(path) if l == 0: self.d = QtGui.QMessageBox(self) self.d.setModal(True) self.d.setIcon(QtGui.QMessageBox.Information) self.d.setText( 'Path not found. Try another labyrinth or more bombs.') self.d.setWindowTitle('You shall not pass!') self.d.show() self.tl = QtCore.QTimeLine(1000 * l) self.tl.setFrameRange(0, l * 100) for w in self.walls: a = QtGui.QGraphicsItemAnimation() a.setItem(w) a.setTimeLine(self.tl) self.wallsAnim += [a] self.a = QtGui.QGraphicsItemAnimation() self.a.setItem(self.walker) self.a.setTimeLine(self.tl) for i in range(l): self.a.setPosAt( i / l, QtCore.QPointF(-20 + path[i][1] * 20, -20 + path[i][2] * 20)) if i < l - 1: if path[i + 1][0] > path[i][0]: w = findwall(path[i][1], path[i][2], path[i + 1][1], path[i + 1][2]) j = wall.index(w) self.wallsAnim[j].setPosAt(i / l, QtCore.QPointF(0, 0)) self.wallsAnim[j].setRotationAt(i / l, 0) self.wallsAnim[j].setRotationAt((i + 1) / l, 720) print(n - w[1], m - w[2]) self.wallsAnim[j].setPosAt( (i + 1) / l, QtCore.QPointF(20 * (n - w[1]), 20 * (m - w[2]))) self.tl.start()