diff options
author | Rahul P | 2023-06-13 18:21:12 +0530 |
---|---|---|
committer | GitHub | 2023-06-13 18:21:12 +0530 |
commit | 3436aa4615dcc1310db8dc8a85f36418db641fb4 (patch) | |
tree | e9cf9d33ed2c137f3ac463c7b272e27fe23be75d /src/frontEnd/TerminalUi.py | |
parent | 172debd60ec1bae09c6b9c9180a388628e819909 (diff) | |
parent | 9a5f3dabc357277b384c51ccf047f5580772f454 (diff) | |
download | eSim-3436aa4615dcc1310db8dc8a85f36418db641fb4.tar.gz eSim-3436aa4615dcc1310db8dc8a85f36418db641fb4.tar.bz2 eSim-3436aa4615dcc1310db8dc8a85f36418db641fb4.zip |
Merge branch 'master' into sky130-dev
Diffstat (limited to 'src/frontEnd/TerminalUi.py')
-rw-r--r-- | src/frontEnd/TerminalUi.py | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/frontEnd/TerminalUi.py b/src/frontEnd/TerminalUi.py new file mode 100644 index 00000000..4c53548f --- /dev/null +++ b/src/frontEnd/TerminalUi.py @@ -0,0 +1,143 @@ +from PyQt5 import QtCore, QtGui, QtWidgets, uic +import os + + +class TerminalUi(QtWidgets.QMainWindow): + """This is a class that represents the GUI required to provide + details regarding the ngspice simulation. This GUI consists of + a progress bar, a console window which displays the log of the + simulation and button required for re-simulation and cancellation + of the simulation""" + def __init__(self, qProcess, args): + """The constructor of the TerminalUi class + param: qProcess: a PyQt QProcess that runs ngspice + type: qProcess: :class:`QtCore.QProcess` + param: args: arguments to be passed on to the ngspice call + type: args: list + """ + super(TerminalUi, self).__init__() + + # Other variables + self.darkColor = True + self.qProcess = qProcess + self.args = args + self.iconDir = "../../images" + + # Load the ui file + uic.loadUi("TerminalUi.ui", self) + + # Define Our Widgets + self.progressBar = self.findChild( + QtWidgets.QProgressBar, + "progressBar" + ) + self.simulationConsole = self.findChild( + QtWidgets.QTextEdit, + "simulationConsole" + ) + + self.lightDarkModeButton = self.findChild( + QtWidgets.QPushButton, + "lightDarkModeButton" + ) + self.cancelSimulationButton = self.findChild( + QtWidgets.QPushButton, + "cancelSimulationButton" + ) + self.cancelSimulationButton.setEnabled(True) + + self.redoSimulationButton = self.findChild( + QtWidgets.QPushButton, + "redoSimulationButton" + ) + self.redoSimulationButton.setEnabled(False) + + # Add functionalities to Widgets + self.lightDarkModeButton.setIcon( + QtGui.QIcon( + os.path.join( + self.iconDir, + 'light_mode.png' + ) + ) + ) + self.lightDarkModeButton.clicked.connect(self.changeColor) + self.cancelSimulationButton.clicked.connect(self.cancelSimulation) + self.redoSimulationButton.clicked.connect(self.redoSimulation) + + self.simulationCancelled = False + self.show() + + def cancelSimulation(self): + """This function cancels the ongoing ngspice simulation. + """ + self.cancelSimulationButton.setEnabled(False) + self.redoSimulationButton.setEnabled(True) + + if (self.qProcess.state() == QtCore.QProcess.NotRunning): + return + + self.simulationCancelled = True + self.qProcess.kill() + + # To show progressBar completed + self.progressBar.setMaximum(100) + self.progressBar.setProperty("value", 100) + + cancelFormat = '<span style="color:#FF8624; font-size:26px;">{}</span>' + self.simulationConsole.append( + cancelFormat.format("Simulation Cancelled!")) + self.simulationConsole.verticalScrollBar().setValue( + self.simulationConsole.verticalScrollBar().maximum() + ) + + def redoSimulation(self): + """This function reruns the ngspice simulation + """ + self.cancelSimulationButton.setEnabled(True) + self.redoSimulationButton.setEnabled(False) + + if (self.qProcess.state() != QtCore.QProcess.NotRunning): + return + + # To make the progressbar running + self.progressBar.setMaximum(0) + self.progressBar.setProperty("value", -1) + + self.simulationConsole.setText("") + self.simulationCancelled = False + + self.qProcess.start('ngspice', self.args) + + def changeColor(self): + """Toggles the :class:`Ui_Form` console between dark mode + and light mode + """ + if self.darkColor is True: + self.simulationConsole.setStyleSheet("QTextEdit {\n \ + background-color: white;\n \ + color: black;\n \ + }") + self.lightDarkModeButton.setIcon( + QtGui.QIcon( + os.path.join( + self.iconDir, + "dark_mode.png" + ) + ) + ) + self.darkColor = False + else: + self.simulationConsole.setStyleSheet("QTextEdit {\n \ + background-color: rgb(36, 31, 49);\n \ + color: white;\n \ + }") + self.lightDarkModeButton.setIcon( + QtGui.QIcon( + os.path.join( + self.iconDir, + "light_mode.png" + ) + ) + ) + self.darkColor = True |