forked from OOAD-SSamGPT/gpt-plugin-ssam
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpageview_widget.py
34 lines (25 loc) · 911 Bytes
/
pageview_widget.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
import fitz
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
class PageviewWidget(QLabel):
def __init__(self):
super().__init__()
self.page = None
self.setMinimumSize(1, 1)
self.setAlignment(Qt.AlignCenter)
def set_page(self, page):
self.page = page
self.draw_page()
def draw_page(self):
if not self.page:
return
x_scale = self.width() / self.page.rect.width
y_scale = self.height() / self.page.rect.height
scale = min(x_scale, y_scale)
pix = self.page.get_pixmap(matrix=fitz.Matrix(scale, scale))
qimage = QImage(pix.samples_ptr, pix.width, pix.height, pix.stride, QImage.Format_RGB888)
pixmap = QPixmap.fromImage(qimage)
self.setPixmap(pixmap)
def resizeEvent(self, event):
self.draw_page()