diff options
author | Pranav P | 2023-05-24 12:14:06 +0530 |
---|---|---|
committer | Pranav P | 2023-05-24 12:14:06 +0530 |
commit | 22570451ec4e2a86f489125ca540b7a86d682286 (patch) | |
tree | 963f18f3ebef703c1781683c514fa4a013e0e12b /src | |
parent | 7b36bfed265309672689cd6ddd04c9a24d115e9c (diff) | |
download | eSim-22570451ec4e2a86f489125ca540b7a86d682286.tar.gz eSim-22570451ec4e2a86f489125ca540b7a86d682286.tar.bz2 eSim-22570451ec4e2a86f489125ca540b7a86d682286.zip |
Reduced passage of functions between objects via simulationEssentials
Diffstat (limited to 'src')
-rw-r--r-- | src/frontEnd/Application.py | 76 | ||||
-rwxr-xr-x | src/frontEnd/DockArea.py | 2 | ||||
-rw-r--r-- | src/ngspiceSimulation/NgspiceWidget.py | 33 | ||||
-rw-r--r-- | src/progressBar/progressBar.py | 6 |
4 files changed, 48 insertions, 69 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py index 3b403279..2eabcb12 100644 --- a/src/frontEnd/Application.py +++ b/src/frontEnd/Application.py @@ -83,7 +83,7 @@ class Application(QtWidgets.QMainWindow): self.systemTrayIcon.setIcon(QtGui.QIcon(init_path + 'images/logo.png')) self.systemTrayIcon.setVisible(True) - self.is_file_changed = False + self.isFileChanged = False def initToolBar(self): """ @@ -552,23 +552,37 @@ class Application(QtWidgets.QMainWindow): pass return False - def check_change_in_plotfile(self, currTime): - try: - # if os.name == 'nt': - # proc = 'mintty' - # else: - # proc = 'xterm' - - st = os.stat(os.path.join(self.projDir, "plot_data_i.txt")) - is_ngspice_running = self.checkIfProcessRunning("ngspice") - if not is_ngspice_running: + def checkChangeInPlotFile(self, currTime, exitStatus): + self.enableButtons(True) + if exitStatus == QtCore.QProcess.NormalExit: + try: + # if os.name == 'nt': + # proc = 'mintty' + # else: + # proc = 'xterm' + + st = os.stat(os.path.join(self.projDir, "plot_data_i.txt")) self.simulationCompleted = True - if st.st_mtime >= currTime - 1: - self.is_file_changed = True - self.plot_simulation() + if st.st_mtime >= currTime: + self.isFileChanged = True + + try: + self.obj_Mainview.obj_dockarea.plottingEditor() + except Exception as e: + self.msg = QtWidgets.QErrorMessage() + self.msg.setModal(True) + self.msg.setWindowTitle("Error Message") + self.msg.showMessage( + 'Error while opening python plotting Editor.' + ' 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)) + return - except Exception: - pass + except Exception: + pass def enableButtons(self, state): self.ngspice.setEnabled(state) @@ -577,30 +591,23 @@ class Application(QtWidgets.QMainWindow): self.wrkspce.setEnabled(state) def isSimulationSuccess(self): - return self.is_file_changed - - def resetSimulationVariables(self): - self.count = 0 - self.currTime = 0 + return self.isFileChanged def open_ngspice(self): """This Function execute ngspice on current project.""" self.projDir = self.obj_appconfig.current_project["ProjectName"] - self.is_file_changed = False + self.isFileChanged = False self.simulationCompleted = False self.simulationEssentials = { "enableButtons": self.enableButtons, - "isSimulationSuccess": self.isSimulationSuccess, - "resetSimulationVariables": self.resetSimulationVariables, - "checkChangeInPlotFile": self.check_change_in_plotfile, + "checkChangeInPlotFile": self.checkChangeInPlotFile, } if self.projDir is not None: self.currTime = time.time() # Edited by Sumanto Kar 25/08/2021 - self.enableButtons(False) if self.obj_Mainview.obj_dockarea.ngspiceEditor( self.projDir, self.simulationEssentials) is False: print( @@ -616,8 +623,6 @@ class Application(QtWidgets.QMainWindow): self.msg.exec_() return - self.count = 0 - else: self.msg = QtWidgets.QErrorMessage() self.msg.setModal(True) @@ -628,21 +633,6 @@ class Application(QtWidgets.QMainWindow): ) self.msg.exec_() - def plot_simulation(self): - try: - self.obj_Mainview.obj_dockarea.plottingEditor() - except Exception as e: - self.msg = QtWidgets.QErrorMessage() - self.msg.setModal(True) - self.msg.setWindowTitle("Error Message") - self.msg.showMessage( - 'Error while opening python plotting Editor.' - ' 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)) - def open_subcircuit(self): """ This function opens 'subcircuit' option in left-tool-bar. diff --git a/src/frontEnd/DockArea.py b/src/frontEnd/DockArea.py index acf5b3d1..2a14b978 100755 --- a/src/frontEnd/DockArea.py +++ b/src/frontEnd/DockArea.py @@ -133,7 +133,7 @@ class DockArea(QtWidgets.QMainWindow): self.ngspiceLayout = QtWidgets.QVBoxLayout() self.ngspiceLayout.addWidget( - NgspiceWidget(self.ngspiceNetlist, self.projDir, simulationEssentials) + NgspiceWidget(self.ngspiceNetlist, simulationEssentials) ) # Adding to main Layout diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index 13a5ece9..928956d5 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -9,7 +9,7 @@ import time # This Class creates NgSpice Window class NgspiceWidget(QtWidgets.QWidget): - def __init__(self, command, projPath, simulationEssentials): + def __init__(self, command, simulationEssentials): """ - Creates constructor for NgspiceWidget class. - Checks whether OS is Linux or Windows and @@ -19,9 +19,10 @@ class NgspiceWidget(QtWidgets.QWidget): self.obj_appconfig = Appconfig() self.process = QtCore.QProcess(self) self.terminal = QtWidgets.QWidget(self) - self.simulationEssentials = simulationEssentials + self.projDir = self.obj_appconfig.current_project["ProjectName"] self.checkChangeInPlotFile = simulationEssentials['checkChangeInPlotFile'] - self.progressBarUi = progressBar.Ui_Form(self.process, self.simulationEssentials) + self.enableButtons = simulationEssentials['enableButtons'] + self.progressBarUi = progressBar.Ui_Form(self.process) self.progressBarUi.setupUi(self.terminal) self.layout = QtWidgets.QVBoxLayout(self) self.layout.addWidget(self.terminal) @@ -46,15 +47,13 @@ class NgspiceWidget(QtWidgets.QWidget): os.chdir(tempdir) else: # For Linux OS - # self.command = "cd " + projPath + \ - # ";ngspice -r " + command.replace(".cir.out", ".raw") + \ - # " " + command # Creating argument for process self.currTime = time.time() self.args = ['-b', '-r', command.replace(".cir.out", ".raw"), command] - self.process.setWorkingDirectory(projPath) + self.process.setWorkingDirectory(self.projDir) self.progressBarUi.setNgspiceArgs(self.args) self.process.start('ngspice', self.args) + self.process.started.connect(lambda: self.enableButtons(state=False)) self.process.readyReadStandardOutput.connect(lambda: self.readyReadAll()) self.process.finished.connect(self.finishSimulation) self.obj_appconfig.process_obj.append(self.process) @@ -70,22 +69,22 @@ class NgspiceWidget(QtWidgets.QWidget): print(self.gawCommand) def finishSimulation(self, exitCode, exitStatus): - if exitStatus == QtCore.QProcess.NormalExit: - self.checkChangeInPlotFile(self.currTime) + self.checkChangeInPlotFile(self.currTime, exitStatus) self.readyToPrintSimulationStatus = True - self.enableButtons = self.simulationEssentials['enableButtons'] - self.enableButtons(True) self.progressBarUi.showProgressCompleted() self.writeSimulationStatus() + #To set the current time stamp of the generated file so as for re-simulation + self.currTime = time.time() + def writeSimulationStatus(self): if self.readyToPrintSimulationStatus is False: return - self.isSimulationSuccess = self.simulationEssentials['isSimulationSuccess'] - if self.isSimulationSuccess(): + st = os.stat(os.path.join(self.projDir, "plot_data_i.txt")) + if st.st_mtime >= self.currTime: self.progressBarUi.writeSimulationStatusToConsole(isSuccess=True) else: self.progressBarUi.writeSimulationStatusToConsole(isSuccess=False) @@ -101,10 +100,4 @@ class NgspiceWidget(QtWidgets.QWidget): stderror = self.process.readAllStandardError() if stderror.toUpper().contains(b"ERROR"): self.errorFlag = True - self.progressBarUi.writeIntoConsole(str(stderror.data(), encoding='utf-8')) - - # def launchProgressBar(self): - # self.progressBar = QtWidgets.QWidget() - # self.progressBarUi = progressBar.Ui_Dialog() - # self.progressBarUi.setupUi(self.progressBar) - # self.progressBar.show() + self.progressBarUi.writeIntoConsole(str(stderror.data(), encoding='utf-8'))
\ No newline at end of file diff --git a/src/progressBar/progressBar.py b/src/progressBar/progressBar.py index e1b9be34..4631e16b 100644 --- a/src/progressBar/progressBar.py +++ b/src/progressBar/progressBar.py @@ -13,11 +13,8 @@ import os class Ui_Form(object): - def __init__(self, qProcess, simulationEssentials): + def __init__(self, qProcess): self.qProcess = qProcess - self.enableButtons = simulationEssentials['enableButtons'] - self.isSimulationSuccess = simulationEssentials['isSimulationSuccess'] - self.resetSimulationVariables = simulationEssentials['resetSimulationVariables'] self.iconDir = "../progressBar/icons" # super().__init__() def setupUi(self, Form): @@ -148,7 +145,6 @@ class Ui_Form(object): return self.showProgressRunning() self.simulationConsole.setText("") - self.resetSimulationVariables() self.qProcess.start('ngspice', self.args) def changeColor(self): |