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
| #!/usr/bin/python
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
import os,tarfile,time
######################### Boite de Dialogue ##################################
class compressWin(QtGui.QWidget):
def __init__(self,parent,saveName,action):
super(compressWin, self).__init__()
self.parent = parent
self.i=1
# # compression Thread
self.thread = compressThread(self,saveName,action)
self.thread.tick.connect(self.close)
self.thread.start()
#thread d'animation
self.animThread = animateThread(self)
self.animThread.tick.connect(self.animate)
self.animThread.start()
#label
if action == 'c':
self.label=QtGui.QLabel('Compression en cours...')
elif action == 'x':
self.label=QtGui.QLabel('Extraction en cours..')
# set up the movie screen on a label
self.movie_screen = QtGui.QLabel()
# resize and center the label
self.movie_screen.resize(QtCore.QSize(80, 80))
self.movie_screen.setAlignment(QtCore.Qt.AlignCenter)
self.picture = QtGui.QImage(self.parent.AbsPath+"/img/throbber/frame-"+str(self.i)+".gif")
pixmap = QtGui.QPixmap.fromImage(self.picture)
pixmap_resized = pixmap.scaled(80, 80, QtCore.Qt.KeepAspectRatio)
self.movie_screen.setPixmap(pixmap_resized)
#set layout
main_layout = QtGui.QVBoxLayout()
main_layout.addWidget(self.label)
main_layout.addWidget(self.movie_screen)
self.setLayout(main_layout)
#position et nom fenetre
self.setGeometry(300,300,100,100)
self.setWindowIcon(QtGui.QIcon(parent.AbsPath+'/img/pasta.png'))
def animate(self):
self.picture = QtGui.QImage(self.parent.AbsPath+"/img/throbber/frame-"+str(self.i)+".gif")
pixmap = QtGui.QPixmap.fromImage(self.picture)
pixmap_resized = pixmap.scaled(80, 80, QtCore.Qt.KeepAspectRatio)
self.movie_screen.setPixmap(pixmap_resized)
def closeEvent(self,event):
event.ignore()
self.thread.terminate()
self.animThread.terminate()
event.accept()
######################### Thread de compression ################################
class compressThread(QtCore.QThread):
tick = QtCore.pyqtSignal()
#Instanciation de la classe compressThread
#L'objet parent doit être passé en paramètre
#Strategy est un paramètre optionnel, permet de définir un comportement
def __init__(self, parent, fName,action):
super(compressThread, self).__init__()
self.fname = fName
self.action = action
def run(self):
if self.action == 'c':
with tarfile.open(self.fname, "w:gz") as tar:
tar.add('/tmp/PASTA')
elif self.action == 'x':
with tarfile.open(self.fname) as tar:
tar.extractall('/')
self.sleep(2)
self.tick.emit()
class animateThread(QtCore.QThread):
tick = QtCore.pyqtSignal()
#Instanciation de la classe compressThread
#L'objet parent doit être passé en paramètre
#Strategy est un paramètre optionnel, permet de définir un comportement
def __init__(self, parent):
super(animateThread, self).__init__()
self.parent = parent
def run(self):
while True:
self.parent.i=(self.parent.i)%18+1
self.tick.emit()
time.sleep(0.1) |
Partager