summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frontEnd/Application.py142
-rw-r--r--src/ngspiceSimulation/NgspiceWidget.py40
-rw-r--r--src/progressBar/progressBar.py51
3 files changed, 159 insertions, 74 deletions
diff --git a/src/frontEnd/Application.py b/src/frontEnd/Application.py
index 7588b1a1..44237d56 100644
--- a/src/frontEnd/Application.py
+++ b/src/frontEnd/Application.py
@@ -549,12 +549,69 @@ class Application(QtWidgets.QMainWindow):
psutil.AccessDenied, psutil.ZombieProcess):
pass
return False
+
+ def check_change_in_plotfile(self, currTime):
+ print("The function has executed")
+ try:
+ # if os.name == 'nt':
+ # proc = 'mintty'
+ # else:
+ # proc = 'xterm'
+
+ # Edited by Sumanto Kar 25/08/2021
+ if False and os.name != 'nt' and \
+ self.checkIfProcessRunning('xterm') is False:
+ self.msg = QtWidgets.QErrorMessage()
+ self.msg.setModal(True)
+ self.msg.setWindowTitle("Warning Message")
+ self.msg.showMessage(
+ 'Simulation was interrupted/failed. '
+ 'Please close all the Ngspice windows '
+ 'and then rerun the simulation.'
+ )
+ self.msg.exec_()
+ return
+
+ st = os.stat(os.path.join(self.projDir, "plot_data_i.txt"))
+ print(st.st_mtime, currTime - 1)
+ if st.st_mtime >= currTime - 1:
+ self.is_file_changed = True
+ self.timer.stop()
+ self.plot_simulation()
+ return
+ except Exception:
+ pass
+
+ if self.is_file_changed is False:
+ self.timer.start()
+
+ # Fail Safe ===>
+ self.count += 1
+ if self.count >= 10:
+ print(
+ "Ngspice taking too long for simulation. "
+ "Check netlist file (*.cir.out) "
+ "to change simulation parameters."
+ )
+
+ self.msg = QtWidgets.QErrorMessage()
+ self.msg.setModal(True)
+ self.msg.setWindowTitle("Warning Message")
+ self.msg.showMessage(
+ 'Ngspice taking too long for simulation. '
+ 'Check netlist file (*.cir.out) '
+ 'to change simulation parameters.'
+ )
+ self.msg.exec_()
+
+ return
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:
+ currTime = time.time()
# Edited by Sumanto Kar 25/08/2021
if self.obj_Mainview.obj_dockarea.ngspiceEditor(
@@ -572,71 +629,11 @@ class Application(QtWidgets.QMainWindow):
self.msg.exec_()
return
- currTime = time.time()
- count = 0
- while True:
- try:
- # if os.name == 'nt':
- # proc = 'mintty'
- # else:
- # proc = 'xterm'
-
- # Edited by Sumanto Kar 25/08/2021
- if os.name != 'nt' and \
- self.checkIfProcessRunning('xterm') is False:
- self.msg = QtWidgets.QErrorMessage()
- self.msg.setModal(True)
- self.msg.setWindowTitle("Warning Message")
- self.msg.showMessage(
- 'Simulation was interrupted/failed. '
- 'Please close all the Ngspice windows '
- 'and then rerun the simulation.'
- )
- self.msg.exec_()
- return
-
- st = os.stat(os.path.join(self.projDir, "plot_data_i.txt"))
- if st.st_mtime >= currTime:
- break
- except Exception:
- pass
- time.sleep(1)
-
- # Fail Safe ===>
- count += 1
- if count >= 10:
- print(
- "Ngspice taking too long for simulation. "
- "Check netlist file (*.cir.out) "
- "to change simulation parameters."
- )
-
- self.msg = QtWidgets.QErrorMessage()
- self.msg.setModal(True)
- self.msg.setWindowTitle("Warning Message")
- self.msg.showMessage(
- 'Ngspice taking too long for simulation. '
- 'Check netlist file (*.cir.out) '
- 'to change simulation parameters.'
- )
- self.msg.exec_()
-
- return
-
- # Calling Python Plotting
- 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))
+ self.count = 0
+ self.timer = QtCore.QTimer(self)
+ self.timer.setInterval(1000)
+ self.timer.timeout.connect(lambda: self.check_change_in_plotfile(currTime))
+ self.timer.start()
else:
self.msg = QtWidgets.QErrorMessage()
@@ -648,6 +645,21 @@ 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/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py
index 8c63a22a..651b421d 100644
--- a/src/ngspiceSimulation/NgspiceWidget.py
+++ b/src/ngspiceSimulation/NgspiceWidget.py
@@ -1,6 +1,7 @@
from PyQt5 import QtWidgets, QtCore
from configuration.Appconfig import Appconfig
from configparser import ConfigParser
+from progressBar import progressBar
import os
@@ -19,6 +20,7 @@ class NgspiceWidget(QtWidgets.QWidget):
self.terminal = QtWidgets.QWidget(self)
self.layout = QtWidgets.QVBoxLayout(self)
self.layout.addWidget(self.terminal)
+ self.errorFlag = False
print("Argument to ngspice command : ", command)
@@ -39,12 +41,16 @@ 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.launchProgressBar()
+ self.process.start('ngspice', self.args)
+ self.process.readyReadStandardOutput.connect(lambda: self.readyReadAll())
+ self.process.finished.connect(self.progressBarUi.showProgressCompleted)
self.obj_appconfig.process_obj.append(self.process)
print(self.obj_appconfig.proc_dict)
(
@@ -52,7 +58,23 @@ 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)
+
+ @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()
diff --git a/src/progressBar/progressBar.py b/src/progressBar/progressBar.py
new file mode 100644
index 00000000..938b0774
--- /dev/null
+++ b/src/progressBar/progressBar.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+
+# Form implementation generated from reading ui file 'pop_up_design.ui'
+#
+# Created by: PyQt5 UI code generator 5.15.6
+#
+# WARNING: Any manual changes made to this file will be lost when pyuic5 is
+# run again. Do not edit this file unless you know what you are doing.
+
+
+from PyQt5 import QtCore, QtGui, QtWidgets
+
+
+class Ui_Dialog(object):
+ def setupUi(self, Dialog):
+ Dialog.setObjectName("Dialog")
+ Dialog.resize(843, 396)
+ self.progressBar = QtWidgets.QProgressBar(Dialog)
+ self.progressBar.setGeometry(QtCore.QRect(30, 30, 781, 31))
+ self.progressBar.setStyleSheet("QProgressBar::chunk {\n"
+" background-color: rgb(38, 162, 105);\n"
+"}")
+ self.progressBar.setMaximum(0)
+ #self.progressBar.setProperty("value", 100)
+ self.progressBar.setTextDirection(QtWidgets.QProgressBar.TopToBottom)
+ self.progressBar.setFormat("")
+ self.progressBar.setObjectName("progressBar")
+ self.ngspiceConsole = QtWidgets.QPlainTextEdit(Dialog)
+ self.ngspiceConsole.setGeometry(QtCore.QRect(30, 80, 781, 281))
+ self.ngspiceConsole.setAutoFillBackground(False)
+ self.ngspiceConsole.setTextInteractionFlags(QtCore.Qt.TextSelectableByKeyboard | QtCore.Qt.TextSelectableByMouse)
+ self.ngspiceConsole.setStyleSheet("QPlainTextEdit {\n"
+" background-color: rgb(36, 31, 49);\n"
+" color: white;\n"
+"}")
+ self.ngspiceConsole.setObjectName("ngspiceConsole")
+
+ self.retranslateUi(Dialog)
+ QtCore.QMetaObject.connectSlotsByName(Dialog)
+
+ def retranslateUi(self, Dialog):
+ _translate = QtCore.QCoreApplication.translate
+ Dialog.setWindowTitle(_translate("Dialog", "Dialog"))
+ #self.ngspiceConsole.setPlainText(_translate("Dialog", "The Ngspice simulation log will appear here."))
+
+ def writeIntoConsole(self, text):
+ self.ngspiceConsole.insertPlainText(text)
+
+ def showProgressCompleted(self):
+ self.progressBar.setMaximum(100)
+ self.progressBar.setProperty("value", 100)