-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestGUI.py
148 lines (112 loc) · 5.49 KB
/
TestGUI.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
import os
import subprocess
import sys
from PySide2 import QtCore, QtGui, QtWidgets
from PySide2.QtCore import QObject, QRectF
from PySide2.QtWidgets import QMainWindow, QFileDialog, QWidget, QVBoxLayout, QGraphicsScene, QGraphicsView, \
QDesktopWidget, QApplication
from PySide2.QtGui import QPixmap
class Color(QWidget):
def __init__(self, color):
super().__init__()
self.setAutoFillBackground(True)
palette = self.palette()
palette.setColor(QtGui.QPalette.Window, QtGui.QColor(color))
self.setPalette(palette)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
self.centralWidget = QtWidgets.QWidget(MainWindow)
# self.gridLayout = QtWidgets.QGridLayout(self.centralWidget)
self.gridLayout = QtWidgets.QGridLayout()
self.gridLayout.addWidget(self.centralWidget)
window_label = QtWidgets.QLabel("This is our protocol upload")
window_label.setParent(self.centralWidget)
window_label.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignTop)
window_label_font = window_label.font()
window_label_font.setPointSize(20)
window_label.setFont(window_label_font)
self.file_Select_Btn = QtWidgets.QPushButton()
# self.file_Select_Btn = QtWidgets.QPushButton(self.centralWidget)
# self.file_Select_Btn.setGeometry(QtCore.QRect(1082, 80, 121, 28))
self.file_Select_Btn.setGeometry(QtCore.QRect(500, 200, 181, 41))
self.file_Select_Btn.setObjectName("file_Select_Btn")
self.file_Select_Btn.setText("Select Procedure File")
self.simulate_run_btn = QtWidgets.QPushButton()
self.simulate_run_btn.setGeometry(QtCore.QRect(380, 140, 181, 41))
self.file_Select_Btn.setObjectName("simulate_run_btn")
self.file_Select_Btn.setText("Simulate Protocol")
#self.gridLayout.addWidget(self.file_Select_Btn)
self.file_Select_Btn.setParent(self.centralWidget)
self.simulate_run_btn.setParent(self.centralWidget)
window_label.setParent(self.centralWidget)
MainWindow.setCentralWidget(self.centralWidget)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
class CustomDialog(QtWidgets.QDialog):
def __init__(self, dialog, parent=None):
super().__init__(parent)
self.setWindowTitle("HELLO!")
QBtn = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel
self.buttonBox = QtWidgets.QDialogButtonBox(QBtn)
self.buttonBox.accepted.connect(self.accept)
self.buttonBox.rejected.connect(self.reject)
self.layout = QVBoxLayout()
message = QtWidgets.QLabel(dialog)
self.layout.addWidget(message)
self.layout.addWidget(self.buttonBox)
self.setLayout(self.layout)
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self):
super(MainWindow, self).__init__()
Ui_MainWindow.__init__(self)
# Initialize UI
self.setupUi(self)
self.file_Select_Btn.clicked.connect(self.file_transfer)
def tr(self, text):
return QObject.tr(self, text)
def file_transfer(self):
path_to_file, _ = QFileDialog.getOpenFileName(self, self.tr("Upload File"),
self.tr("C:{0}Users{0}dennis{0}Documents{0}".format(os.sep)))
if path_to_file:
cmd = "scp -i ot2_ssh_key {} root@169.254.48.252:/var/lib/jupyter/notebooks/ProcedureFile.tsv"\
.format(path_to_file)
proc = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
print("CMD: ", cmd)
print(proc.stdout.decode())
if proc.stderr:
# dlg = QtWidgets.QMessageBox(self)
QtWidgets.QMessageBox.critical(self, "Well, that didn't go so well.", proc.stderr.decode())
# dlg.setIcon(QtWidgets.QMessageBox.Critical)
# dlg.setWindowTitle("Well, that didn't go so well.")
# dlg.setText(proc.stderr.decode())
# dlg.exec_()
elif proc.stdout:
QtWidgets.QMessageBox.information(self, "Transfer Succeeded", proc.stdout.decode())
self.image_viewer = ImageViewer(path_to_file)
# self.image_viewer.show()
class ImageViewer(QWidget):
def __init__(self, image_path):
super().__init__()
self.scene = QGraphicsScene()
self.view = QGraphicsView(self.scene)
layout = QVBoxLayout()
layout.addWidget(self.view)
self.setLayout(layout)
self.load_image(image_path)
def load_image(self, image_path):
pixmap = QPixmap(image_path)
self.scene.addPixmap(pixmap)
self.view.fitInView(QRectF(0, 0, pixmap.width(), pixmap.height()), QtCore.Qt.KeepAspectRatio)
self.scene.update()
def center_window(centralWidget):
screen_geometry = QtGui.QGuiApplication.primaryScreen().availableGeometry()
centralWidget.setWindowTitle("Opentrons Python Interface")
centralWidget.resize(screen_geometry.width()*0.40, screen_geometry.height()*0.40)
centralWidget.setGeometry(QtWidgets.QStyle.alignedRect(QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
centralWidget.size(), screen_geometry, ), )
if __name__ == "__main__":
app = QtWidgets.QApplication([])
main_window = MainWindow()
main_window.show()
center_window(main_window)
# QtCore.QTimer.singleShot(0, lambda: center_window(main_window))
sys.exit(app.exec_())