diff options
-rw-r--r-- | src/frontEnd/Application.py | 29 | ||||
-rw-r--r-- | src/frontEnd/TerminalUi.py | 115 | ||||
-rw-r--r-- | src/ngspiceSimulation/NgspiceWidget.py | 36 |
3 files changed, 119 insertions, 61 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 8375e0e3..a78f7cd8 100644 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -550,12 +550,14 @@ class Application(QtWidgets.QMainWindow): psutil.AccessDenied, psutil.ZombieProcess): pass return False - + def checkChangeInPlotData(self, currTime, exitStatus): - """Checks whether there is a change in the analysis files(To see if simulation was successful) + """Checks whether there is a change in the analysis files. + (To see if simulation was successful) and displays the plotter where graphs can be plotted. - :param currTime: The time stamp of the analysis file before simulation starts + :param currTime: The time stamp of the analysis file + before simulation starts :type currTime: float :param exitStatus: The exit status of the ngspice QProcess :type exitStatus: class:`QtCore.QProcess.ExitStatus` @@ -578,15 +580,17 @@ class Application(QtWidgets.QMainWindow): ' Please look at console for more details.' ) self.msg.exec_() - print("Exception Message:", str(e), traceback.format_exc()) - self.obj_appconfig.print_error('Exception Message : ' + str(e)) - + print("Exception Message:", str(e), + traceback.format_exc()) + self.obj_appconfig.print_error('Exception Message : ' + + str(e)) + self.currTime = time.time() return except Exception: pass - + def toggleToolbarButtons(self, state): self.ngspice.setEnabled(state) self.conversion.setEnabled(state) @@ -601,14 +605,17 @@ class Application(QtWidgets.QMainWindow): "toggleToolbarButtons": self.toggleToolbarButtons, "checkChangeInPlotData": self.checkChangeInPlotData, } - + if self.projDir is not None: self.currTime = time.time() process = self.obj_Mainview.obj_dockarea.qprocess - process.started.connect(lambda: self.toggleToolbarButtons(state=False)) - process.finished.connect(lambda exitCode, exitStatus: self.checkChangeInPlotData(self.currTime, exitStatus)) + process.started.connect(lambda: + self.toggleToolbarButtons(state=False)) + process.finished.connect(lambda exitCode, exitStatus: + self.checkChangeInPlotData(self.currTime, + exitStatus)) # Edited by Sumanto Kar 25/08/2021 if self.obj_Mainview.obj_dockarea.ngspiceEditor( @@ -625,7 +632,7 @@ class Application(QtWidgets.QMainWindow): ) self.msg.exec_() return - + else: self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) diff --git a/src/frontEnd/TerminalUi.py b/src/frontEnd/TerminalUi.py index ddae32f3..21b5b557 100644 --- a/src/frontEnd/TerminalUi.py +++ b/src/frontEnd/TerminalUi.py @@ -1,52 +1,81 @@ from PyQt5 import QtCore, QtGui, QtWidgets, uic import os + class TerminalUi(QtWidgets.QMainWindow): def __init__(self, qProcess, args): super(TerminalUi, self).__init__() - #Other variables +# Other variables self.darkColor = True self.qProcess = qProcess self.args = args self.iconDir = "../../images" - # def setupUi(self, Form): - #Load the ui file +# 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") +# 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.redoSimulationButton = self.findChild(QtWidgets.QPushButton, "redoSimulationButton") + self.lightDarkModeButton = self.findChild( + QtWidgets.QPushButton, + "lightDarkModeButton" + ) + self.cancelSimulationButton = self.findChild( + QtWidgets.QPushButton, + "cancelSimulationButton" + ) + self.redoSimulationButton = self.findChild( + QtWidgets.QPushButton, + "redoSimulationButton" + ) - #Add functionalities to Widgets - self.lightDarkModeButton.setIcon(QtGui.QIcon(os.path.join(self.iconDir, 'light_mode.png'))) +# 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) - #show app +# show app self.show() def writeSimulationStatusToConsole(self, isSuccess): """Writes simulation status to the console with appropriate style to the :class:`Form_Ui` console. - - :param isSuccess: A boolean flag used to indicate whether the simulation was a success or not + + :param isSuccess: A boolean flag used to indicate whether the + simulation was a success or not :type isSuccess: bool """ - failedFormat = '<span style="color:#ff3333; font-size:18px;">{}</span>' - successFormat = '<span style="color:#00ff00; font-size:18px;">{}</span>' + failedFormat = '<span style="color:#ff3333; font-size:18px;"> \ + {} \ + </span>' + successFormat = '<span style="color:#00ff00; font-size:18px;"> \ + {} \ + </span>' if self.qProcess.exitStatus() == QtCore.QProcess.NormalExit: if isSuccess: - self.simulationConsole.append(successFormat.format("Simulation Completed Successfully!")) + self.simulationConsole.append( + successFormat.format("Simulation Completed Successfully!")) else: - self.simulationConsole.append(failedFormat.format("Simulation Failed!")) + self.simulationConsole.append( + failedFormat.format("Simulation Failed!")) def cancelSimulation(self): """This function cancels the ongoing ngspice simulation. @@ -55,12 +84,13 @@ class TerminalUi(QtWidgets.QMainWindow): return cancelFormat = '<span style="color:#3385ff; font-size:18px;">{}</span>' self.qProcess.kill() - - #To show progressBar completed + +# To show progressBar completed self.progressBar.setMaximum(100) self.progressBar.setProperty("value", 100) - self.simulationConsole.append(cancelFormat.format("Simulation Cancelled!")) + self.simulationConsole.append( + cancelFormat.format("Simulation Cancelled!")) self.simulationConsole.verticalScrollBar().setValue( self.simulationConsole.verticalScrollBar().maximum() ) @@ -70,8 +100,8 @@ class TerminalUi(QtWidgets.QMainWindow): """ if (self.qProcess.state() == QtCore.QProcess.Running): return - - #To make the progressbar running + +# To make the progressbar running self.progressBar.setMaximum(0) self.progressBar.setProperty("value", -1) @@ -79,19 +109,34 @@ class TerminalUi(QtWidgets.QMainWindow): self.qProcess.start('ngspice', self.args) def changeColor(self): - """Toggles the :class:`Ui_Form` console between dark mode and light mode + """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.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
\ No newline at end of file + 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 diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index b19936de..1aa8e15d 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -1,6 +1,6 @@ from PyQt5 import QtWidgets, QtCore from configuration.Appconfig import Appconfig -from configparser import ConfigParser +# from configparser import ConfigParser from frontEnd import TerminalUi import os import time @@ -43,12 +43,12 @@ class NgspiceWidget(QtWidgets.QWidget): # os.chdir(tempdir) # else: # For Linux OS - # Creating argument for process self.currTime = time.time() self.process.setWorkingDirectory(self.projDir) self.process.start('ngspice', self.args) - self.process.readyReadStandardOutput.connect(lambda: self.readyReadAll()) + self.process.readyReadStandardOutput.connect( + lambda: self.readyReadAll()) self.process.finished.connect(self.finishSimulation) self.obj_appconfig.process_obj.append(self.process) print(self.obj_appconfig.proc_dict) @@ -63,17 +63,20 @@ class NgspiceWidget(QtWidgets.QWidget): print(self.gawCommand) def finishSimulation(self, exitCode, exitStatus): - """This function is intended to run when the ngspice simulation finishes. - It singals to the function that generates the plots and also writes in the - appropriate status of the simulation (Whether it was a success or not). + """This function is intended to run when the ngspice + simulation finishes. It singals to the function that generates + the plots and also writes in the appropriate status of the + simulation (Whether it was a success or not). - :param exitCode: The exit code signal of the qprocess that runs ngspice + :param exitCode: The exit code signal of the qprocess + that runs ngspice :type exitCode: int - :param exitStatus: The exit status signal of the qprocess that runs ngspice + :param exitStatus: The exit status signal of the + qprocess that runs ngspice :type exitStatus: class:`QtCore.QProcess.ExitStatus` """ - #To stop progressbar from running after simulation is completed +# To stop progressbar from running after simulation is completed self.terminalUi.progressBar.setMaximum(100) self.terminalUi.progressBar.setProperty("value", 100) @@ -87,22 +90,25 @@ class NgspiceWidget(QtWidgets.QWidget): self.terminalUi.simulationConsole.verticalScrollBar().maximum() ) - #To set the current time stamp of the generated file so as for re-simulation +# To set the current time stamp of the generated +# file so as for re-simulation self.currTime = time.time() @QtCore.pyqtSlot() def readyReadAll(self): - """Outputs the ngspice process standard output and standard error to :class:`TerminalUi.TerminalUi` console + """Outputs the ngspice process standard output and standard error + to :class:`TerminalUi.TerminalUi` console """ self.terminalUi.simulationConsole.insertPlainText( str(self.process.readAllStandardOutput().data(), encoding='utf-8') ) - stderror = str(self.process.readAllStandardError().data(), encoding='utf-8') - #For suppressing the PrinterOnly error that batch mode throws - stderror = '\n'.join([line for line in stderror.split('\n') + stderror = str(self.process.readAllStandardError().data(), + encoding='utf-8') +# For suppressing the PrinterOnly error that batch mode throws + stderror = '\n'.join([line for line in stderror.split('\n') if ('PrinterOnly' not in line and 'viewport for graphics' not in line)]) self.terminalUi.simulationConsole.insertPlainText( stderror - )
\ No newline at end of file + ) |