summaryrefslogtreecommitdiff
path: root/src/ngspiceSimulation/NgspiceWidget.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/ngspiceSimulation/NgspiceWidget.py')
-rw-r--r--src/ngspiceSimulation/NgspiceWidget.py65
1 files changed, 55 insertions, 10 deletions
diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py
index 8c63a22a..f7c88ba9 100644
--- a/src/ngspiceSimulation/NgspiceWidget.py
+++ b/src/ngspiceSimulation/NgspiceWidget.py
@@ -1,13 +1,15 @@
from PyQt5 import QtWidgets, QtCore
from configuration.Appconfig import Appconfig
from configparser import ConfigParser
+from progressBar import progressBar
import os
+import time
# This Class creates NgSpice Window
class NgspiceWidget(QtWidgets.QWidget):
- def __init__(self, command, projPath):
+ def __init__(self, command, projPath, simulationEssentials):
"""
- Creates constructor for NgspiceWidget class.
- Checks whether OS is Linux or Windows and
@@ -17,8 +19,13 @@ class NgspiceWidget(QtWidgets.QWidget):
self.obj_appconfig = Appconfig()
self.process = QtCore.QProcess(self)
self.terminal = QtWidgets.QWidget(self)
+ self.simulationEssentials = simulationEssentials
+ self.qTimer = simulationEssentials['timer']
+ self.progressBarUi = progressBar.Ui_Form(self.process, self.simulationEssentials)
+ self.progressBarUi.setupUi(self.terminal)
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.addWidget(self.terminal)
+ self.errorFlag = False
print("Argument to ngspice command : ", command)
@@ -39,12 +46,15 @@ class NgspiceWidget(QtWidgets.QWidget):
os.chdir(tempdir)
else: # For Linux OS
- self.command = "cd " + projPath + \
- ";ngspice -r " + command.replace(".cir.out", ".raw") + \
- " " + command
+ # self.command = "cd " + projPath + \
+ # ";ngspice -r " + command.replace(".cir.out", ".raw") + \
+ # " " + command
# Creating argument for process
- self.args = ['-hold', '-e', self.command]
- self.process.start('xterm', self.args)
+ self.args = ['-b', '-r', command.replace(".cir.out", ".raw"), command]
+ self.process.setWorkingDirectory(projPath)
+ 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)
(
@@ -52,7 +62,42 @@ class NgspiceWidget(QtWidgets.QWidget):
[self.obj_appconfig.current_project['ProjectName']].append(
self.process.pid())
)
- self.process = QtCore.QProcess(self)
- self.command = "gaw " + command.replace(".cir.out", ".raw")
- self.process.start('sh', ['-c', self.command])
- print(self.command)
+ 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):
+ self.enableButtons = self.simulationEssentials['enableButtons']
+
+ self.enableButtons(True)
+ self.progressBarUi.showProgressCompleted()
+
+ self.qTimer.timeout.connect(self.writeSimulationStatus)
+
+ def writeSimulationStatus(self):
+ self.isSimulationSuccess = self.simulationEssentials['isSimulationSuccess']
+
+ if self.isSimulationSuccess():
+ self.progressBarUi.writeSimulationStatusToConsole(isSuccess=True)
+ else:
+ self.progressBarUi.writeSimulationStatusToConsole(isSuccess=False)
+
+ scrollLength = self.progressBarUi.simulationConsole.verticalScrollBar().maximum()
+ self.progressBarUi.simulationConsole.verticalScrollBar().setValue(scrollLength)
+
+ @QtCore.pyqtSlot()
+ def readyReadAll(self):
+ self.progressBarUi.writeIntoConsole(
+ str(self.process.readAllStandardOutput().data(), encoding='utf-8')
+ )
+ 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()