-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimageViewer.py
More file actions
56 lines (46 loc) · 1.99 KB
/
Copy pathimageViewer.py
File metadata and controls
56 lines (46 loc) · 1.99 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
from PyQt5.QtWidgets import *
from PyQt5 import uic
from userdataclass import jsondata
from PyQt5.QtGui import QIcon, QPixmap
import sys
class ImageViewer(QWidget):
def __init__(self, images):
super().__init__()
uic.loadUi("ui/imageViewer.ui", self)
self.images = images
self.imagefield = self.findChild(QLabel, 'image')
self.previousBtn = self.findChild(QPushButton, 'previousImage')
self.nextBtn = self.findChild(QPushButton, 'nextImage')
self.imageCounter = self.findChild(QLabel, 'imageCounter')
self.previousBtn.clicked.connect(self.loadPreviousImage)
self.nextBtn.clicked.connect(self.loadNextImage)
self.counter = 0
self.total = len(self.images)
self.pixmap = QPixmap(self.images[self.counter])
self.imagefield.setPixmap(self.pixmap)
self.imagefield.setScaledContents(True)
self.imageCounter.setText(str(self.counter+1) + "/" + str(self.total))
def loadPreviousImage(self):
self.counter -= 1
if self.counter < 0:
self.counter = self.total - 1
self.pixmap = QPixmap(self.images[self.counter])
self.imagefield.setPixmap(self.pixmap)
self.imageCounter.setText(str(self.counter+1) + "/" + str(self.total))
def loadNextImage(self):
self.counter += 1
if self.counter > self.total - 1:
self.counter = 0
self.pixmap = QPixmap(self.images[self.counter])
self.imagefield.setPixmap(self.pixmap)
self.imageCounter.setText(str(self.counter+1) + "/" + str(self.total))
# app = QApplication([])
# images = [
# "/home/suvashkumar/Desktop/programming/pdm_database/images/3505_Mri_0.jpg",
# "/home/suvashkumar/Desktop/programming/pdm_database/images/3508_Pics_0.jpg",
# "/home/suvashkumar/Desktop/programming/pdm_database/images/hello.png",
# "/home/suvashkumar/Desktop/programming/pdm_database/images/3508_Mri_0.png"
# ]
# window = ImageViewer(images)
# window.show()
# app.exec_()