zoukankan      html  css  js  c++  java
  • 转载: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_()
    

      

  • 相关阅读:
    js对象的深度克隆
    通用事件监听函数
    JavaScript封装
    Ajax
    MarkDown怎么在博客园展现出来
    MarkDown语法学习
    暑期培训第三周SDN总结
    暑期培训遇到的floodlight+mininet+ubuntu的问题
    Ubuntu14.04搭建mininet与可视化工具miniedit介绍
    Ubuntu 14.04 安装 Sublime Text 3,并用Sublime Text 3 安装Package Control
  • 原文地址:https://www.cnblogs.com/ribavnu/p/5015333.html
Copyright © 2011-2022 走看看