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
149
150
151
152
153
154
|
from PyQt5 import QtCore, QtGui, QtWidgets
import os
class Ui_Form(object):
def __init__(self, qProcess):
self.qProcess = qProcess
self.iconDir = "../../images"
# super().__init__()
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1244, 644)
self.verticalLayoutWidget = QtWidgets.QWidget(Form)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(10, 10, 1131, 471))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setSizeConstraint(QtWidgets.QLayout.SetDefaultConstraint)
self.verticalLayout.setContentsMargins(15, 15, 15, 15)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout.setContentsMargins(-1, -1, -1, 0)
self.horizontalLayout.setSpacing(6)
self.horizontalLayout.setObjectName("horizontalLayout")
self.terminalUi = QtWidgets.QProgressBar(self.verticalLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.terminalUi.sizePolicy().hasHeightForWidth())
self.terminalUi.setSizePolicy(sizePolicy)
self.terminalUi.setMaximumSize(QtCore.QSize(16777215, 35))
self.terminalUi.setStyleSheet("QProgressBar::chunk {\n"
" background-color: rgb(54,158,225);\n"
"}")
self.terminalUi.setMaximum(0)
self.terminalUi.setProperty("value", -1)
self.terminalUi.setFormat("")
self.terminalUi.setObjectName("progressBar")
self.horizontalLayout.addWidget(self.terminalUi)
self.redo_simulation_button = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.redo_simulation_button.setMaximumSize(QtCore.QSize(16777215, 35))
self.redo_simulation_button.setObjectName("redo_simulation_button")
self.horizontalLayout.addWidget(self.redo_simulation_button)
self.cancel_simulation_button = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.cancel_simulation_button.setMaximumSize(QtCore.QSize(16777215, 35))
self.cancel_simulation_button.setObjectName("cancel_simulation_button")
self.horizontalLayout.addWidget(self.cancel_simulation_button)
self.light_dark_mode_button = QtWidgets.QPushButton(self.verticalLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.light_dark_mode_button.sizePolicy().hasHeightForWidth())
self.light_dark_mode_button.setSizePolicy(sizePolicy)
self.light_dark_mode_button.setMaximumSize(QtCore.QSize(35, 35))
self.light_dark_mode_button.setText("")
self.light_dark_mode_button.setObjectName("light_dark_mode_button")
self.horizontalLayout.addWidget(self.light_dark_mode_button)
self.verticalLayout.addLayout(self.horizontalLayout)
self.simulationConsole = QtWidgets.QTextEdit(self.verticalLayoutWidget)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.simulationConsole.sizePolicy().hasHeightForWidth())
self.simulationConsole.setSizePolicy(sizePolicy)
self.simulationConsole.setMinimumSize(QtCore.QSize(0, 400))
self.simulationConsole.setStyleSheet("QTextEdit {\n"
" background-color: rgb(36, 31, 49);\n"
" color: white;\n"
"}")
self.simulationConsole.setTextInteractionFlags(QtCore.Qt.NoTextInteraction)
self.simulationConsole.setObjectName("simulationConsole")
self.verticalLayout.addWidget(self.simulationConsole)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.redo_simulation_button.setText(_translate("Form", "Redo Simulation"))
self.cancel_simulation_button.setText(_translate("Form", "Cancel Simulation"))
self.simulationConsole.setHtml(_translate("Form", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Ubuntu\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">The quick brown fox jumped over the lazy dog</p></body></html>"))
self.simulationConsole.setText("")
self.dark_color = True
self.light_dark_mode_button.setIcon(QtGui.QIcon(os.path.join(self.iconDir, 'light_mode.png')))
self.light_dark_mode_button.clicked.connect(self.changeColor)
self.cancel_simulation_button.clicked.connect(self.cancelSimulation)
self.redo_simulation_button.clicked.connect(self.redoSimulation)
def writeIntoConsole(self, consoleLog):
self.simulationConsole.insertPlainText(consoleLog)
def writeSimulationStatusToConsole(self, isSuccess):
failedFormat = '<span style="color:#ff3333;">{}</span>'
successFormat = '<span style="color:#00ff00;">{}</span>'
if self.qProcess.exitStatus() == QtCore.QProcess.NormalExit:
if isSuccess:
self.simulationConsole.append(successFormat.format("Simulation Completed Successfully!"))
else:
self.simulationConsole.append(failedFormat.format("Simulation Failed!"))
def scrollConsoleToBottom(self):
scrollLength = self.simulationConsole.verticalScrollBar().maximum()
self.simulationConsole.verticalScrollBar().setValue(scrollLength)
def showProgressRunning(self):
self.terminalUi.setMaximum(0)
self.terminalUi.setProperty("value", -1)
def showProgressCompleted(self):
self.terminalUi.setMaximum(100)
self.terminalUi.setProperty("value", 100)
def cancelSimulation(self):
if (self.qProcess.state() == QtCore.QProcess.NotRunning):
return
cancelFormat = '<span style="color:#3385ff;">{}</span>'
self.qProcess.kill()
self.showProgressCompleted()
self.simulationConsole.append(cancelFormat.format("Simulation Cancelled!"))
self.scrollConsoleToBottom()
def setNgspiceArgs(self, args):
self.args = args
def redoSimulation(self):
if (self.qProcess.state() == QtCore.QProcess.Running):
return
self.showProgressRunning()
self.simulationConsole.setText("")
self.qProcess.start('ngspice', self.args)
def changeColor(self):
if self.dark_color is True:
self.simulationConsole.setStyleSheet("QTextEdit {\n"
" background-color: white;\n"
" color: black;\n"
"}")
self.light_dark_mode_button.setIcon(QtGui.QIcon(os.path.join(self.iconDir, "dark_mode.png")))
self.dark_color = False
else:
self.simulationConsole.setStyleSheet("QTextEdit {\n"
" background-color: rgb(36, 31, 49);\n"
" color: white;\n"
"}")
self.light_dark_mode_button.setIcon(QtGui.QIcon(os.path.join(self.iconDir, "light_mode.png")))
self.dark_color = True
|