-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
99 lines (69 loc) · 3.04 KB
/
main.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os, sys
from findPathWidget import FindPathWidget
from imageView import SplittedImageView
# Get the absolute path of the current script file
script_path = os.path.abspath(__file__)
# Get the root directory by going up one level from the script directory
project_root = os.path.dirname(os.path.dirname(script_path))
sys.path.insert(0, project_root)
sys.path.insert(0, os.getcwd()) # Add the current directory as well
from PyQt5.QtWidgets import QMainWindow, QPushButton, QApplication, QHBoxLayout, QWidget, QVBoxLayout, QFrame
from PyQt5.QtCore import Qt, QCoreApplication, QThread
from PyQt5.QtGui import QFont
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps) # HighDPI support
QApplication.setFont(QFont('Arial', 12))
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.__initUi()
def __initUi(self):
self.setWindowTitle('PyQt Splitted Graphics View Example')
findPathWidget1 = FindPathWidget()
findPathWidget1.getLineEdit().setPlaceholderText('Set Image File to Left...')
findPathWidget1.added.connect(self.__addLeft)
findPathWidget2 = FindPathWidget()
findPathWidget2.getLineEdit().setPlaceholderText('Set Image File to Right...')
findPathWidget2.added.connect(self.__addRight)
sep = QFrame()
sep.setFrameShape(QFrame.VLine)
sep.setFrameShadow(QFrame.Sunken)
lay = QHBoxLayout()
lay.addWidget(findPathWidget1)
lay.addWidget(sep)
lay.addWidget(findPathWidget2)
lay.setContentsMargins(0, 0, 0, 0)
topWidget = QWidget()
topWidget.setLayout(lay)
self.__imageView = SplittedImageView(self)
self.__removeImageOnTheLeftBtn = QPushButton('Remove Image on the Left')
self.__removeImageOnTheLeftBtn.clicked.connect(self.__removeImageOnTheLeft)
self.__removeImageOnTheRightBtn = QPushButton('Remove Image on the Right')
self.__removeImageOnTheRightBtn.clicked.connect(self.__removeImageOnTheRight)
lay = QHBoxLayout()
lay.addWidget(self.__removeImageOnTheLeftBtn)
lay.addWidget(self.__removeImageOnTheRightBtn)
lay.setContentsMargins(0, 0, 0, 0)
bottomWidget = QWidget()
bottomWidget.setLayout(lay)
lay = QVBoxLayout()
lay.addWidget(topWidget)
lay.addWidget(self.__imageView)
lay.addWidget(bottomWidget)
mainWidget = QWidget(self)
mainWidget.setLayout(lay)
self.setCentralWidget(mainWidget)
def __addLeft(self, filename):
self.__imageView.setFilenameToLeft(filename)
def __addRight(self, filename):
self.__imageView.setFilenameToRight(filename)
def __removeImageOnTheLeft(self):
self.__imageView.removeItemOnTheLeft()
def __removeImageOnTheRight(self):
self.__imageView.removeItemOnTheRight()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec())