转载:python原生态的输入窗口抖动+输入特效

python原生态的输入窗口抖动+输入特效

出处:https://coding.net/u/acee/p/PythonPowerInput/git/blob/master/test_power_input.py

__author__ = 'Administrator'
import sys
from lib.qm_app import App
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import random
import time
class MoveThread(QThread):
MoveValue = pyqtSignal(QPoint)
def __init__(self, source_pos, parent):
super(MoveThread, self).__init__(parent)
self.source_pos = source_pos
def run(self):
for a in xrange(5):
self.MoveValue.emit(self.source_pos + QPoint(random.randint(1, 5),
random.randint(1, 5)))
time.sleep(0.05)
class LoadWidget(QLabel):
Start = pyqtSignal()
def __init__(self, gif_path, parent=None):
super(LoadWidget, self).__init__(parent)
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.Window | Qt.FramelessWindowHint)
self.movie = QMovie(gif_path)
self.movie.setScaledSize(QSize(50, 50))
self.setMovie(self.movie)
self.movie.frameChanged.connect(self.stop)
self.movie.start()
def start(self):
self.movie.start()
self.show()
self.Start.emit()
def stop(self, frame):
if frame == 11:
self.movie.stop()
self.close()
class PowerInput(QTextEdit):
def __init__(self):
super(PowerInput, self).__init__()
self.textChanged.connect(self.play_effect)
self.move_thread = MoveThread(None, self)
self.move_thread.MoveValue.connect(self.move)
def showEvent(self, event):
super(PowerInput, self).showEvent(event)
self.move_thread.source_pos = self.mapToGlobal(self.pos())
def play_effect(self, *args, **k):
rect = self.cursorRect()
pos = self.mapToGlobal(QPoint(rect.x(), rect.y()))
self.w = LoadWidget('d:/test.gif', self)
self.w.Start.connect(self.set_f)
self.w.move(pos)
self.w.start()
def set_f(self):
self.setFocus()
self.activateWindow()
self.move_thread.start()
if __name__ == '__main__':
app = App(sys.argv)
windows = PowerInput()
windows.show()
app.exec_()

  

上一篇:vue获取dom元素高度的方法


下一篇:Session随便写的(抄书笔记)