-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
113 lines (85 loc) · 3.17 KB
/
app.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QFileDialog, QGraphicsView,
QGraphicsScene, QHBoxLayout, QVBoxLayout, QGridLayout,
QGraphicsPixmapItem, QCheckBox)
from PyQt5.QtGui import QPixmap
import sys
from xstitch import *
class App(QWidget):
def __init__(self):
super().__init__()
self.timesRendered = 0
self.setup_ui()
def render(self):
self.timesRendered += 1
print("Rendered " + str(self.timesRendered) + " times.")
def open(self):
self.path, _ = QFileDialog.getOpenFileName(self, "Pick Image", "", "Image Files (*.png *.jpg *.jpeg *.bmp")
if self.path:
print("File opened.")
scene = QGraphicsScene(self)
pixmap = QPixmap(self.path)
pixItem = QGraphicsPixmapItem(pixmap)
self.s1.addItem(pixItem)
self.render()
def toggleInputView(self):
if self.showInputBox.isChecked():
self.inputImage.show()
else:
self.inputImage.hide()
def toggleProcessedView(self):
if self.showProcessedBox.isChecked():
self.processedImage.show()
else:
self.processedImage.hide()
def toggleOutputView(self):
if self.showOutputBox.isChecked():
self.outputImage.show()
else:
self.outputImage.hide()
def setup_ui(self):
controls = QWidget()
controlsStack = QVBoxLayout()
controls.setLayout(controlsStack)
LoadFileButton = QPushButton('Load Image')
LoadFileButton.clicked.connect(self.open)
RenderButton = QPushButton('Render')
RenderButton.clicked.connect(self.render)
self.showInputBox = QCheckBox("Show Input Image")
self.showInputBox.setChecked(True)
self.showInputBox.stateChanged.connect(self.toggleInputView)
self.showProcessedBox = QCheckBox("Show Processed Image")
self.showProcessedBox.setChecked(True)
self.showProcessedBox.stateChanged.connect(self.toggleProcessedView)
self.showOutputBox = QCheckBox("Show Output")
self.showOutputBox.setChecked(True)
self.showOutputBox.stateChanged.connect(self.toggleOutputView)
for item in [LoadFileButton, RenderButton, self.showInputBox,
self.showProcessedBox, self.showOutputBox]:
controlsStack.addWidget(item)
preview = QWidget()
previewStack = QVBoxLayout()
preview.setLayout(previewStack)
self.s1 = QGraphicsScene()
self.s1.addText("Nothing Loaded")
self.s2 = QGraphicsScene()
self.s2.addText("Nothing Processed")
self.s3 = QGraphicsScene()
self.s3.addText("Nothing Processed")
self.inputImage = QGraphicsView(self.s1)
self.processedImage = QGraphicsView(self.s2)
self.outputImage = QGraphicsView(self.s3)
for item in [self.inputImage, self.processedImage, self.outputImage]:
previewStack.addWidget(item)
hsplit = QHBoxLayout()
hsplit.addWidget(controls)
hsplit.addWidget(preview)
self.setLayout(hsplit)
self.setGeometry(1200, 200, 600, 600)
self.setWindowTitle('XSB')
self.show()
if __name__=="__main__":
app = QApplication(sys.argv)
win = App()
win.show()
app.exec()