转载:python原生态的输入窗口抖动+输入特效-阿里云开发者社区

开发者社区> 开发与运维> 正文

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

简介: python原生态的输入窗口抖动+输入特效 出处:https://coding.net/u/acee/p/PythonPowerInput/git/blob/master/test_power_input.

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_()

  

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

分享:
开发与运维
使用钉钉扫一扫加入圈子
+ 订阅

集结各类场景实战经验,助你开发运维畅行无忧

其他文章