diff options
author | Pranav P | 2023-06-03 17:35:25 +0530 |
---|---|---|
committer | Pranav P | 2023-06-03 17:35:25 +0530 |
commit | abf7ef8beebf78552d068ebeed1393fd79a81abc (patch) | |
tree | 40b8ebba9619dd5634a0c2494fe010f37340b2af /src | |
parent | d8a2de2ef6126654184a1924cd21d242bea1be18 (diff) | |
download | eSim-abf7ef8beebf78552d068ebeed1393fd79a81abc.tar.gz eSim-abf7ef8beebf78552d068ebeed1393fd79a81abc.tar.bz2 eSim-abf7ef8beebf78552d068ebeed1393fd79a81abc.zip |
Got rid of simulationEssentials
Diffstat (limited to 'src')
-rw-r--r-- | src/frontEnd/Application.py | 40 | ||||
-rwxr-xr-x | src/frontEnd/DockArea.py | 4 | ||||
-rw-r--r-- | src/ngspiceSimulation/NgspiceWidget.py | 37 |
3 files changed, 51 insertions, 30 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index d3025fe4..563ebb94 100644 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -558,7 +558,11 @@ class Application(QtWidgets.QMainWindow): :param exitCode: The exit status of the ngspice QProcess :type exitCode: int """ - self.toggleToolbarButtons(True) + self.ngspice.setEnabled(True) + self.conversion.setEnabled(True) + self.closeproj.setEnabled(True) + self.wrkspce.setEnabled(True) + if exitCode == 0: try: self.obj_Mainview.obj_dockarea.plottingEditor() @@ -575,30 +579,36 @@ class Application(QtWidgets.QMainWindow): self.obj_appconfig.print_error('Exception Message : ' + str(e)) - def toggleToolbarButtons(self, state): + def startSimulation(self, process, function): """This function is used to disable buttons related to simulation - during the ngspice simulation and to enable it back once the - simulation is completed - param: state: Decides whether to enable or disable the button - type: state: bool""" - self.ngspice.setEnabled(state) - self.conversion.setEnabled(state) - self.closeproj.setEnabled(state) - self.wrkspce.setEnabled(state) + during the ngspice simulation and to connect the + `self.checkChangeInPlotData` function to finished signal if not + already connected. + param: process: The QProcess that runs the simulation + type: process: :class:`QtCore.QProcess`""" + self.ngspice.setEnabled(False) + self.conversion.setEnabled(False) + self.closeproj.setEnabled(False) + self.wrkspce.setEnabled(False) + + if process.isFinishConnected is False: + process.isFinishConnected = True + +# Calls the finished connect exactly once. + process.finished.connect( + lambda exitCode, exitStatus: + function(exitCode, exitStatus, self.checkChangeInPlotData) + ) def open_ngspice(self): """This Function execute ngspice on current project.""" self.projDir = self.obj_appconfig.current_project["ProjectName"] if self.projDir is not None: - simulationEssentials = { - 'checkChangeInPlotData': self.checkChangeInPlotData, - 'toggleToolbarButtons': self.toggleToolbarButtons - } # Edited by Sumanto Kar 25/08/2021 if self.obj_Mainview.obj_dockarea.ngspiceEditor( - self.projDir, simulationEssentials) is False: + self.projDir, self.startSimulation) is False: print( "Netlist file (*.cir.out) not found." ) diff --git a/src/frontEnd/DockArea.py b/src/frontEnd/DockArea.py index e4ea42cd..dbf43cf4 100755 --- a/src/frontEnd/DockArea.py +++ b/src/frontEnd/DockArea.py @@ -121,7 +121,7 @@ class DockArea(QtWidgets.QMainWindow): ) count = count + 1 - def ngspiceEditor(self, projDir, simulationEssentials): + def ngspiceEditor(self, projDir, startSimulation): """ This function creates widget for Ngspice window.""" self.projDir = projDir self.projName = os.path.basename(self.projDir) @@ -138,7 +138,7 @@ class DockArea(QtWidgets.QMainWindow): self.ngspiceLayout = QtWidgets.QVBoxLayout() self.ngspiceLayout.addWidget( - NgspiceWidget(self.ngspiceNetlist, simulationEssentials) + NgspiceWidget(self.ngspiceNetlist, startSimulation) ) # Adding to main Layout diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index d6f75853..aa175bf6 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -1,12 +1,13 @@ from PyQt5 import QtWidgets, QtCore from configuration.Appconfig import Appconfig from frontEnd import TerminalUi +import os # This Class creates NgSpice Window class NgspiceWidget(QtWidgets.QWidget): - def __init__(self, command, simulationEssentials): + def __init__(self, command, startSimulation): """ - Creates constructor for NgspiceWidget class. - Checks whether OS is Linux or Windows and @@ -20,18 +21,21 @@ class NgspiceWidget(QtWidgets.QWidget): self.terminalUi = TerminalUi.TerminalUi(self.process, self.args) self.layout = QtWidgets.QVBoxLayout(self) self.layout.addWidget(self.terminalUi) - self.checkChangeInPlotData = \ - simulationEssentials['checkChangeInPlotData'] - toggleToolbarButtons = simulationEssentials['toggleToolbarButtons'] - print("Argument to ngspice command : ", command) - self.process.started.connect(lambda: toggleToolbarButtons(state=False)) +# This variable makes sure that finished.connect is called exactly once + self.process.isFinishConnected = False + + self.process.\ + started.\ + connect(lambda: + startSimulation(process=self.process, + function=self.finishSimulation)) + self.process.setWorkingDirectory(self.projDir) self.process.start('ngspice', self.args) 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) ( @@ -39,12 +43,14 @@ class NgspiceWidget(QtWidgets.QWidget): [self.obj_appconfig.current_project['ProjectName']].append( self.process.pid()) ) - self.gawProcess = QtCore.QProcess(self) - self.gawCommand = "gaw " + command.replace(".cir.out", ".raw") - self.gawProcess.start('sh', ['-c', self.gawCommand]) - print(self.gawCommand) - def finishSimulation(self, exitCode, exitStatus): + if os.name != "nt": + self.gawProcess = QtCore.QProcess(self) + self.gawCommand = "gaw " + command.replace(".cir.out", ".raw") + self.gawProcess.start('sh', ['-c', self.gawCommand]) + print(self.gawCommand) + + def finishSimulation(self, exitCode, exitStatus, checkChangeInPlotData): """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 @@ -56,6 +62,11 @@ class NgspiceWidget(QtWidgets.QWidget): :param exitStatus: The exit status signal of the qprocess that runs ngspice :type exitStatus: class:`QtCore.QProcess.ExitStatus` + :param checkChangeInPlotData: Takes the plotting function + as input and uses it to generate the plots. The reason + why this is passed in such a way is to minimize the no. + of functions passed through a chain of objects. + :type checkChangeInPlotData: function """ # To stop progressbar from running after simulation is completed @@ -65,7 +76,7 @@ class NgspiceWidget(QtWidgets.QWidget): # st = os.stat(os.path.join(self.projDir, "plot_data_i.txt")) # if st.st_mtime >= self.currTime: if exitStatus == QtCore.QProcess.NormalExit: - self.checkChangeInPlotData(exitCode) + checkChangeInPlotData(exitCode) # self.terminalUi.writeSimulationStatusToConsole() failedFormat = '<span style="color:#ff3333; font-size:26px;"> \ |