|
[php]
#!/usr/bin/python
#Filename:helloA.py
from PyQt4 import QtCore,QtGui
import sys,random
class Main(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.frame = QtGui.QFrame(self)
self.frame.setGeometry(QtCore.QRect(0,0,640,480))
self.forever = CircleWidget(self.frame)
self.forever.setGeometry(100,100,175,175)
self.timer = QtCore.QTimer(self)
self.connect(self.timer,QtCore.SIGNAL("timeout()"),self.forever.nextAnimationFrame)
self.forever.setVisible(False)
random.seed()
x = random.randint(0,1280)
y = random.randint(0,800)
self.setGeometry(QtCore.QRect(x,y,640,480))
def mousePressEvent(self,event):
if event.buttons() == QtCore.Qt.LeftButton:
x = event.x()
y = event.y()
print x,y
self.forever.setGeometry(x-125,y-75,250,155)
self.forever.setVisible(True)
self.timer.start(25)
self.forever.frameNo = 0
#timer = QtCore.QTimer(self)
#self.connect(timer,QtCore.SIGNAL("timeout()"),self.flash.nextAnimationFrame)
#timer.start(100)
class CircleWidget(QtGui.QWidget):
def __init__(self, parent = None):
QtGui.QWidget.__init__(self, parent)
self.frameNo = 0
self.setBackgroundRole(QtGui.QPalette.Base)
self.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
def minimumSizeHint(self):
return QtCore.QSize(50, 50)
def sizeHint(self):
return QtCore.QSize(180, 180)
def nextAnimationFrame(self):
self.frameNo += 1
self.update()
def paintEvent(self, event):
painter = QtGui.QPainter()
painter.begin(self)
painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
painter.translate(self.width() / 2, self.height() / 2)
for diameter in range(0, 256, 9):
delta = abs((self.frameNo % 128) - diameter / 2)
alpha = 255 - (delta * delta) / 4 - diameter
if alpha > 0:
painter.setPen(QtGui.QPen(QtGui.QColor(0, diameter / 2, 127, alpha), 3))
painter.drawEllipse(QtCore.QRectF(-diameter / 2.0, -diameter / 2.0,
diameter, diameter))
painter.end()
########################
# main routine #
########################
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
run = Main()
run.show()
app.exec_()
[/php] |
|