-
Notifications
You must be signed in to change notification settings - Fork 0
/
PDF_Popup.py
83 lines (73 loc) · 2.44 KB
/
PDF_Popup.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
import sys
from PyQt5.QtWidgets import QShortcut,QWidget,QApplication
from PyQt5.QtCore import Qt,pyqtSignal
from PyQt5.QtGui import QKeySequence,QIcon
from ui_PDFWidget import Ui_PDFWidget
class PDF_Popup(QWidget):
pdf_page_change = pyqtSignal(int)
def __init__(self,parent = None):
"""
:param parent: 父类,默认为None
"""
super().__init__(parent)
self.__ui = Ui_PDFWidget()
self.__ui.setupUi(self)
self.__actions()
self.__max_page = 0 # self.pdf.pageCount - 1最大页数
self.__current_page = 0
self.setWindowTitle('书籍预览')
self.setWindowIcon(QIcon(':/icons/icons/readingIcon.ico'))
def set_max_page(self,max_page:int) -> None:
"""
:param max_page: int,最大的页数
:return: 无
"""
self.__max_page = max_page
def pdf_Label_height(self):
"""
:param: 无
:return: 无
"""
return self.__ui.reading_area.height() # 返回书籍那里的height
def __actions(self):
"""
:param: 无
:return: 无
"""
# 这几个是用方向键来左右控制
switch_left = QShortcut(QKeySequence(Qt.Key_Left),self)
switch_right = QShortcut(QKeySequence(Qt.Key_Right),self)
switch_left.activated.connect(self.__left) # self.__left是自己的方法
switch_right.activated.connect(self.__right)
def __left(self):
self.__switch_page(right = False)
def __right(self):
"""
:param: 无
:return: 无
"""
self.__switch_page(right = True)
def __switch_page(self,right:bool) -> None:
"""
:param right: bool,向左:False或向右:True
:return: 无
"""
if right and self.__current_page < self.__max_page: # 小于最后一页才加
self.__current_page += 1
elif not right and self.__current_page > 0:
self.__current_page -= 1
self.pdf_page_change.emit(self.__current_page)
def set_currentPage(self,input_book_page):
"""
:param input_book_page: PyQt5.QtGui.QPixmap,当前输入的页面
:return: 无
"""
self.__ui.reading_area.setPixmap(input_book_page)
self.__ui.reading_area.setScaledContents(True)
def main():
app = QApplication(sys.argv)
form = PDF_Popup()
form.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()