summaryrefslogtreecommitdiff
path: root/src/subcircuit
diff options
context:
space:
mode:
Diffstat (limited to 'src/subcircuit')
-rw-r--r--src/subcircuit/Subcircuit.py62
-rw-r--r--src/subcircuit/__init__.py0
-rw-r--r--src/subcircuit/convertSub.py45
-rw-r--r--src/subcircuit/newSub.py65
-rw-r--r--src/subcircuit/openSub.py24
5 files changed, 196 insertions, 0 deletions
diff --git a/src/subcircuit/Subcircuit.py b/src/subcircuit/Subcircuit.py
new file mode 100644
index 00000000..94ca37e4
--- /dev/null
+++ b/src/subcircuit/Subcircuit.py
@@ -0,0 +1,62 @@
+from PyQt4 import QtCore, QtGui
+from configuration.Appconfig import Appconfig
+from projManagement.Validation import Validation
+from subcircuit.newSub import NewSub
+from subcircuit.openSub import openSub
+from subcircuit.convertSub import convertSub
+
+class Subcircuit(QtGui.QWidget):
+ """
+ This class creates Subcircuit GUI.
+ """
+ def __init__(self,parent=None):
+ super(Subcircuit, self).__init__()
+ QtGui.QWidget.__init__(self)
+ self.obj_appconfig=Appconfig()
+ self.obj_validation=Validation()
+
+ self.layout = QtGui.QVBoxLayout()
+ self.splitter= QtGui.QSplitter()
+ self.splitter.setOrientation(QtCore.Qt.Vertical)
+
+ self.newbtn = QtGui.QPushButton('New Subcircuit Schematic')
+ self.newbtn.setFixedSize(200,40)
+ self.newbtn.clicked.connect(self.newsch)
+ self.editbtn = QtGui.QPushButton('Edit Subcircuit Schematic')
+ self.editbtn.setFixedSize(200,40)
+ self.editbtn.clicked.connect(self.editsch)
+ self.convertbtn = QtGui.QPushButton('Convert Kicad to Ngspice')
+ self.convertbtn.setFixedSize(200,40)
+ self.convertbtn.clicked.connect(self.convertsch)
+
+ self.hbox = QtGui.QHBoxLayout()
+ self.hbox.addWidget(self.newbtn)
+ self.hbox.addWidget(self.editbtn)
+ self.hbox.addWidget(self.convertbtn)
+ self.hbox.addStretch(1)
+
+ self.vbox = QtGui.QVBoxLayout()
+ self.vbox.addLayout(self.hbox)
+ self.vbox.addStretch(1)
+
+ self.setLayout(self.vbox)
+ self.show()
+
+ def newsch(self):
+ text,ok = QtGui.QInputDialog.getText(self, 'New Schematic','Enter Schematic Name:')
+ if ok:
+ self.schematic_name = (str(text))
+ self.subcircuit = NewSub()
+ self.subcircuit.createSubcircuit(self.schematic_name)
+
+ else:
+ print "No subcircuit created"
+
+
+ def editsch(self):
+ self.obj_opensubcircuit = openSub()
+ self.obj_opensubcircuit.body()
+
+ def convertsch(self):
+ self.obj_convertsubcircuit = convertSub()
+ self.obj_convertsubcircuit.createSub() \ No newline at end of file
diff --git a/src/subcircuit/__init__.py b/src/subcircuit/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/src/subcircuit/__init__.py
diff --git a/src/subcircuit/convertSub.py b/src/subcircuit/convertSub.py
new file mode 100644
index 00000000..bb045e3b
--- /dev/null
+++ b/src/subcircuit/convertSub.py
@@ -0,0 +1,45 @@
+from PyQt4 import QtGui,QtCore
+from projManagement.Validation import Validation
+from projManagement import Worker
+from configuration.Appconfig import Appconfig
+import os
+
+class convertSub(QtGui.QWidget):
+ """
+ This class is called when User create new Project.
+ """
+
+ def __init__(self):
+ super(convertSub, self).__init__()
+ self.obj_validation = Validation()
+ self.obj_appconfig=Appconfig()
+
+ def createSub(self):
+ """
+ This function create command to call kicad to Ngspice converter.
+ """
+ print "Open Kicad to Ngspice Conversion"
+ self.projDir = self.obj_appconfig.current_subcircuit["SubcircuitName"]
+ #Validating if current project is available or not
+ if self.obj_validation.validateKicad(self.projDir):
+ #print "Project is present"
+ #Checking if project has .cir file or not
+ if self.obj_validation.validateCir(self.projDir):
+ #print "CIR file present"
+ self.projName = os.path.basename(self.projDir)
+ self.project = os.path.join(self.projDir,self.projName)
+
+ #Creating a command to run
+ self.cmd = "python ../kicadtoNgspice/KicadtoNgspice.py "+self.project+".cir "+"sub"
+ os.system(self.cmd)
+# self.obj_workThread = Worker.WorkerThread(self.cmd)
+# self.obj_workThread.start()
+ else:
+ self.msg = QtGui.QErrorMessage(None)
+ self.msg.showMessage('The subcircuit does not contain any Kicad netlist file for conversion.')
+ self.msg.setWindowTitle("Error Message")
+
+ else:
+ self.msg = QtGui.QErrorMessage(None)
+ self.msg.showMessage('Please select the subcircuit first. You can either create new subcircuit or open existing subcircuit')
+ self.msg.setWindowTitle("Error Message") \ No newline at end of file
diff --git a/src/subcircuit/newSub.py b/src/subcircuit/newSub.py
new file mode 100644
index 00000000..7ea247ab
--- /dev/null
+++ b/src/subcircuit/newSub.py
@@ -0,0 +1,65 @@
+from PyQt4 import QtGui,QtCore
+from projManagement.Validation import Validation
+from configuration.Appconfig import Appconfig
+from projManagement import Worker
+import os
+
+class NewSub(QtGui.QWidget):
+ """
+ This class is called when User create new Project.
+ """
+
+ def __init__(self):
+ super(NewSub, self).__init__()
+ self.obj_validation = Validation()
+ self.obj_appconfig = Appconfig()
+
+
+ def createSubcircuit(self,subName):
+ """
+ This function create Subcircuit related directories and files
+ """
+ self.create_schematic = subName
+ #Checking if Workspace already exist or not
+ self.schematic_path = (os.path.join(os.path.abspath('..'),'SubcircuitLibrary',self.create_schematic))
+
+ #Validation for new subcircuit
+ if self.schematic_path == "":
+ self.reply = "NONE"
+ else:
+ self.reply = self.obj_validation.validateNewproj(str(self.schematic_path))
+
+ #Checking Validations Response
+ if self.reply == "VALID":
+ print "Validated : Creating subcircuit directory"
+ try:
+ os.mkdir(self.schematic_path)
+ self.schematic = os.path.join(self.schematic_path,self.create_schematic)
+ self.cmd = "eeschema "+self.schematic+".sch"
+ self.obj_workThread = Worker.WorkerThread(self.cmd)
+ self.obj_workThread.start()
+ self.close()
+ except:
+ #print "Some Thing Went Wrong"
+ self.msg = QtGui.QErrorMessage(self)
+ self.msg.showMessage('Unable to create subcircuit. Please make sure you have write permission on '+self.schematic_path)
+ self.msg.setWindowTitle("Error Message")
+
+ self.obj_appconfig.current_subcircuit['SubcircuitName'] = self.schematic_path
+
+ elif self.reply == "CHECKEXIST":
+ #print "Project already exist"
+ self.msg = QtGui.QErrorMessage(self)
+ self.msg.showMessage('The subcircuit "'+self.create_schematic+'" already exist.Please select the different name or delete existing subcircuit')
+ self.msg.setWindowTitle("Error Message")
+
+ elif self.reply == "CHECKNAME":
+ #print "Name is not proper"
+ self.msg = QtGui.QErrorMessage(self)
+ self.msg.showMessage('The subcircuit name should not contain space between them')
+ self.msg.setWindowTitle("Error Message")
+
+ elif self.reply == "NONE":
+ self.msg = QtGui.QErrorMessage(self)
+ self.msg.showMessage('The subcircuit name cannot be empty')
+ self.msg.setWindowTitle("Error Message") \ No newline at end of file
diff --git a/src/subcircuit/openSub.py b/src/subcircuit/openSub.py
new file mode 100644
index 00000000..fb349f0a
--- /dev/null
+++ b/src/subcircuit/openSub.py
@@ -0,0 +1,24 @@
+from PyQt4 import QtGui
+from configuration.Appconfig import Appconfig
+from projManagement.Worker import WorkerThread
+import os
+
+
+class openSub(QtGui.QWidget):
+ """
+ This class is called when User click on Open Project Button
+ """
+ def __init__(self):
+ super(openSub, self).__init__()
+ self.obj_appconfig = Appconfig()
+
+ def body(self):
+ self.editfile = str(QtGui.QFileDialog.getExistingDirectory(None,"Open File","../SubcircuitLibrary"))
+ if self.editfile:
+ self.obj_Appconfig = Appconfig()
+ self.obj_Appconfig.current_subcircuit['SubcircuitName'] = self.editfile
+ self.schname = os.path.basename(self.editfile)
+ self.editfile = os.path.join(self.editfile,self.schname)
+ self.cmd = "eeschema "+self.editfile+".sch "
+ self.obj_workThread = WorkerThread(self.cmd)
+ self.obj_workThread.start() \ No newline at end of file