1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
| import sys
import time
from PyQt5 import QtCore
from PyQt5.QtCore import QThread, pyqtSignal
from PyQt5.QtWidgets import QWidget, QPushButton, QProgressBar, QVBoxLayout, QApplication, QLabel
from PyQt5.QtGui import QIcon, QPixmap
class Thread(QThread):
_signal = pyqtSignal(int)
def __init__(self):
super(Thread, self).__init__()
self.timerStop = False
def stoptimer(self):
print("Close Event")
self.timerStop = True
def run(self):
i=0
while True:
print(self.timerStop)
if self.timerStop ==True:
print("Stop Timer")
self.timerStop = False
break
time.sleep(0.2)
self._signal.emit(i)
i+=10
if i == 110 : i=0
class Gui_Attente(QWidget):
def __init__(self):
super(Gui_Attente, self).__init__()
self.timerStop =False
self.setWindowTitle('En Cours')
self.resize(180, 80)
self.label = QLabel(self)
self.ImageBar = './UIQT/attente/logos_0.png'
pixmap = QPixmap(self.ImageBar)
self.label.setPixmap(pixmap)
self.btn_start = QPushButton('start')
self.btn_stop = QPushButton('stop')
self.btn_hidewin = QPushButton('hide')
self.btn_showwin = QPushButton('show')
self.btn_start.clicked.connect(self.startTimer)
self.btn_stop.clicked.connect(self.stopTimer)
self.btn_hidewin.clicked.connect(self.hide_win)
self.btn_showwin.clicked.connect(self.show_win)
self.vbox = QVBoxLayout()
self.vbox.addWidget(self.label)
self.vbox.addWidget(self.btn_start)
self.vbox.addWidget(self.btn_stop)
self.vbox.addWidget(self.btn_hidewin)
self.vbox.addWidget(self.btn_showwin)
self.setLayout(self.vbox)
self.show()
def hide_win(self):
self.hide()
def show_win(self):
self.setWindowFlags(self.windowFlags() | QtCore.Qt.WindowStaysOnTopHint)
self.show()
def startthread(self):
self.thread = Thread()
self.thread._signal.connect(self.signal_accept)
def startTimer(self):
self.thread.start()
def stopTimer(self):
self.thread.stoptimer()
def closeEvent(self, event):
self.thread.stoptimer()
def signal_accept(self, msg):
if msg == 110:
msg = "0"
self.ImageBar = './UIQT/attente/logos_' + str(int(msg) )+ '.png'
#print(self.ImageBar)
pixmap = QPixmap(self.ImageBar)
self.label.setPixmap(pixmap)
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = Gui_Attente()
ex.startthread()
sys.exit(app.exec_()) |
Partager