-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogressManager.py
More file actions
83 lines (68 loc) · 2.65 KB
/
Copy pathprogressManager.py
File metadata and controls
83 lines (68 loc) · 2.65 KB
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
# This Python file uses the following encoding: utf-8
import os
from PySide6.QtCore import QObject, Slot, Signal, QThread
from PySide6 import QtTest
class Player(QThread):
s = Signal()
def __init__(self):
super(Player, self).__init__(None)
self.working = True
def run(self):
while self.working:
self.s.emit()
QtTest.QTest.qWait(40) # sleep 40ms
class ProgressManager(QObject):
switchFrame = Signal(list)
setPause = Signal()
setPos = Signal(float)
def __init__(self):
super(ProgressManager, self).__init__()
self.path = None
self.player = Player()
self.currentFrame = 0
self.countFrame = 0
self.player.s.connect(self.next)
self.frame = []
@Slot(str)
def readPath(self, path):
self.path = path
self.countFrame = len(os.listdir(path + "images/"))
self.frame.clear()
for img_item in os.listdir(path + "images/"):
self.frame.append(img_item[:-4])
self.currentFrame = 0
# 将图像设置为第一帧
self.switchFrame.emit(["", ""])
self.switchFrame.emit(["file:///" + self.path + "images/" + self.frame[self.currentFrame] + ".jpg",
"file:///" + self.path + "recolored/" + self.frame[self.currentFrame] + ".png"])
self.setPos.emit(self.currentFrame / self.countFrame)
@Slot()
def next(self):
if self.currentFrame < self.countFrame:
self.switchFrame.emit(["file:///" + self.path + "images/" + self.frame[self.currentFrame] + ".jpg",
"file:///" + self.path + "recolored/" + self.frame[self.currentFrame] + ".png"])
self.setPos.emit(self.currentFrame / self.countFrame)
self.currentFrame += 1
else:
self.setPause.emit()
self.player.working = False
@Slot()
def pause(self):
self.player.working = False
@Slot()
def play(self):
if self.currentFrame >= self.countFrame:
self.currentFrame = 0
self.player.working = True
self.player.run()
@Slot(int, int)
def switchPos(self, pos, width):
self.currentFrame = pos * self.countFrame // width
if self.currentFrame > self.countFrame:
self.currentFrame = self.countFrame
elif self.currentFrame < 0:
self.currentFrame = 0
self.switchFrame.emit(["file:///" + self.path + "images/" + self.frame[self.currentFrame] + ".jpg",
"file:///" + self.path + "recolored/" + self.frame[self.currentFrame] + ".png"])
if __name__ == "__main__":
pass