forked from PyQt5/PyQt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
PageSwitching.py
83 lines (67 loc) · 2.62 KB
/
PageSwitching.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on 2018年11月24日
author: Irony
site: https://pyqt5.com , https://github.com/892768447
email: 892768447@qq.com
file: PageSwitching
description:
"""
import os
from PyQt5.QtCore import QEasingCurve, Qt
from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QWidget, QLabel
from Lib.UiImageSlider import Ui_Form # @UnresolvedImport
__Author__ = """By: Irony
QQ: 892768447
Email: 892768447@qq.com"""
__Copyright__ = 'Copyright (c) 2018 Irony'
__Version__ = 1.0
class ImageSliderWidget(QWidget, Ui_Form):
def __init__(self, *args, **kwargs):
super(ImageSliderWidget, self).__init__(*args, **kwargs)
self.setupUi(self)
# 初始化动画曲线类型
curve_types = [(n, c) for n, c in QEasingCurve.__dict__.items()
if isinstance(c, QEasingCurve.Type)]
curve_types.sort(key=lambda ct: ct[1])
curve_types = [c[0] for c in curve_types]
self.comboBoxEasing.addItems(curve_types)
# 绑定信号槽
self.spinBoxSpeed.valueChanged.connect(self.stackedWidget.setSpeed)
self.comboBoxEasing.currentTextChanged.connect(self.setEasing)
self.radioButtonHor.toggled.connect(self.setOrientation)
self.radioButtonVer.toggled.connect(self.setOrientation)
self.pushButtonPrev.clicked.connect(self.stackedWidget.slideInPrev)
self.pushButtonNext.clicked.connect(self.stackedWidget.slideInNext)
self.pushButtonStart.clicked.connect(self.autoStart)
self.pushButtonStop.clicked.connect(self.autoStop)
# 添加图片页面
for name in os.listdir('Data/Images'):
label = QLabel(self.stackedWidget)
label.setScaledContents(True)
label.setPixmap(QPixmap('Data/Images/' + name))
self.stackedWidget.addWidget(label)
def autoStart(self):
self.pushButtonNext.setEnabled(False)
self.pushButtonPrev.setEnabled(False)
self.stackedWidget.autoStart()
def autoStop(self):
self.pushButtonNext.setEnabled(True)
self.pushButtonPrev.setEnabled(True)
self.stackedWidget.autoStop()
def setEasing(self, name):
self.stackedWidget.setEasing(getattr(QEasingCurve, name))
def setOrientation(self, checked):
hor = self.sender() == self.radioButtonHor
if checked:
self.stackedWidget.setOrientation(
Qt.Horizontal if hor else Qt.Vertical)
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = ImageSliderWidget()
w.show()
sys.exit(app.exec_())