diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py | 17 | ||||
-rw-r--r-- | src/converter/LtspiceLibConverter.py | 19 | ||||
-rw-r--r-- | src/converter/libConverter.py | 15 | ||||
-rw-r--r-- | src/converter/ltspiceToKicad.py | 5 | ||||
-rw-r--r-- | src/converter/schematic_converters/lib/PythonLib/libParser.py | 108 | ||||
-rwxr-xr-x | src/frontEnd/ProjectExplorer.py | 44 | ||||
-rw-r--r-- | src/ngspiceSimulation/NgspiceWidget.py | 22 | ||||
-rw-r--r-- | src/projManagement/Validation.py | 8 | ||||
-rw-r--r-- | src/projManagement/newProject.py | 8 |
9 files changed, 137 insertions, 109 deletions
diff --git a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py index 2160dac5..bf1a1eac 100644 --- a/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py +++ b/src/converter/LTSpiceToKiCadConverter/src/Windows/lib_LTspice2Kicad.py @@ -33,16 +33,23 @@ def find_all(a_str, sub): yield start
start += len(sub) # use start += 1 to find overlapping matches
-directory = sys.argv[1]
-# out_file = sys.argv[2]
+# Always go 1 level up from the given path
+directory = os.path.abspath(os.path.join(sys.argv[1], ".."))
if directory=="." : directory = os.getcwd()
+if not os.path.isdir(directory):
+ print(f"ERROR: '{directory}' is not a valid directory.")
+ sys.exit(1)
+
+# out_file = sys.argv[2]
+
dir = os.listdir(directory)
comp = []
for component in dir:
if (component[-4:]==".asy") : comp.append(component)
-indir = directory.split("\\")
-out_file = "LTspice_" + indir[len(indir)-1] + ".lib"
+base_name = os.path.basename(os.path.normpath(directory)) # Get last folder name
+out_file = os.path.join(directory, "LTspice_" + base_name + ".lib")
+print("Output Lib File: ", out_file)
outfl = codecs.open(out_file,"w");
outfl.write("EESchema-LIBRARY Version 2.3\n#encoding utf-8\n#\n")
@@ -207,4 +214,4 @@ for component in comp : outfl.write("ENDDRAW\nENDDEF\n#\n")
-outfl.close()
\ No newline at end of file +outfl.close()
diff --git a/src/converter/LtspiceLibConverter.py b/src/converter/LtspiceLibConverter.py index 1914f8ba..2f652659 100644 --- a/src/converter/LtspiceLibConverter.py +++ b/src/converter/LtspiceLibConverter.py @@ -18,15 +18,24 @@ class LTspiceLibConverter: script_dir = os.path.dirname(os.path.abspath(__file__)) # Define the relative path to parser.py from the current script's directory - relative_parser_path = "LTSpiceToKiCadConverter/src/Ubuntu" + # Check the current operating system + if os.name == 'nt': # Windows + relative_parser_path = "LTSpiceToKiCadConverter/src/Windows" + else: + relative_parser_path = "LTSpiceToKiCadConverter/src/Ubuntu" + + # Construct the full path to libParser.py parser_path = os.path.join(script_dir, relative_parser_path) print(parser_path) - command = f"cd {parser_path} ; python3 lib_LTspice2Kicad.py {file_path}" - print(f"cd {parser_path} ; python3 lib_LTspice2Kicad.py {file_path}") + # Strip the .asy extension + file_path_no_ext = os.path.splitext(file_path)[0] + command = ["python3", "lib_LTspice2Kicad.py", file_path_no_ext] + print("Running command:", " ".join(command), "in", parser_path) try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=parser_path) + # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) @@ -81,4 +90,4 @@ class LTspiceLibConverter: msg_box.setWindowTitle("No File Selected") msg_box.setText("Please select a file before uploading.") msg_box.setStandardButtons(QMessageBox.Ok) - msg_box.exec_()
\ No newline at end of file + msg_box.exec_() diff --git a/src/converter/libConverter.py b/src/converter/libConverter.py index 617c72c2..3c30f7d3 100644 --- a/src/converter/libConverter.py +++ b/src/converter/libConverter.py @@ -22,11 +22,16 @@ class PspiceLibConverter: # Construct the full path to libParser.py parser_path = os.path.join(script_dir, relative_parser_path) - print(parser_path) - command = f"cd {parser_path} ; python3 libParser.py {file_path}" - print(f"cd {parser_path} ; python3 libParser.py {file_path}") + print("Parser Path:",parser_path) + + # Prepare the command as a list + output_dir = os.path.dirname(file_path) + + command = ["python3", "libparser.py", file_path, output_dir] + print(f"Running command: {' '.join(command)} in directory: {parser_path}") + try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=parser_path) # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) @@ -81,4 +86,4 @@ class PspiceLibConverter: msg_box.setWindowTitle("No File Selected") msg_box.setText("Please select a file before uploading.") msg_box.setStandardButtons(QMessageBox.Ok) - msg_box.exec_()
\ No newline at end of file + msg_box.exec_() diff --git a/src/converter/ltspiceToKicad.py b/src/converter/ltspiceToKicad.py index e9715f7e..7ec696a5 100644 --- a/src/converter/ltspiceToKicad.py +++ b/src/converter/ltspiceToKicad.py @@ -44,9 +44,10 @@ class LTspiceConverter: # Construct the full path to parser.py parser_path = os.path.join(script_dir, relative_parser_path) - command = f"cd {conPath} && python3 {parser_path}/sch_LTspice2Kicad.py {file_name}" + command = command = ["python3", f"{parser_path}/sch_LTspice2Kicad.py", f"{filename}.asc"] + try: - subprocess.run(command, shell=True, check=True) + subprocess.run(command, check=True, cwd=conPath) # Message box with the conversion success message msg_box = QMessageBox() msg_box.setIcon(QMessageBox.Information) diff --git a/src/converter/schematic_converters/lib/PythonLib/libParser.py b/src/converter/schematic_converters/lib/PythonLib/libParser.py index c94bd7d5..364ecedc 100644 --- a/src/converter/schematic_converters/lib/PythonLib/libParser.py +++ b/src/converter/schematic_converters/lib/PythonLib/libParser.py @@ -21,60 +21,66 @@ libDescr = 'EESchema-LIBRARY Version 4.7 Date: \n#encoding utf-8\n' nameAppend = '_PSPICE' REMOVEDCOMPONENTS = ['TITLEBLK', 'PARAM', 'readme', 'VIEWPOINT', 'LIB', 'copyright', 'WATCH1', 'VECTOR', 'NODESET1'] -for fcounter in range(1, len(sys.argv[1:])+1): - input_file = open(sys.argv[fcounter], 'r+') - fbasename = os.path.basename(sys.argv[fcounter]) - flname = fbasename[:fbasename.find('.')] + '.lib' - flib = open(flname, 'w+') #Write .lib header: - print('Library file name: ',flname) +input_file_path = sys.argv[1] +output_dir = sys.argv[2] - flib.write(libDescr) +# Prepare input/output +input_file = open(input_file_path, 'r') +fbasename = os.path.basename(input_file_path) +flname = fbasename[:fbasename.find('.')] + '.lib' +flpath = os.path.join(output_dir, flname) +os.makedirs(output_dir, exist_ok=True) - line = skipTo(input_file,'*symbol') - print('Parser',line) - ''' +flib = open(flpath, 'w+') # Output .lib file + +print('Library file name: ', flname) + + +line = skipTo(input_file,'*symbol') +print('Parser',line) +''' +while(line != '' and '*symbol' not in line): + line = input_file.readline().strip() + print(line) +''' + +while(line != '__ERROR__'): + #print(input_file.tell()) + #print('Compo line',line) + d = line.find(' ') + cnametmp = line[d+1:] + #print('cnametmp',cnametmp) + d = cnametmp.find(' ') + if d == -1: + cname = cnametmp + else: + cname = cnametmp[0:d] + + #print('cname->',cname) + + fileTMP = open(input_file_path) + c = Component(fileTMP, cname) + #print(c.ref) + fixComp(c) + #print('After fixComp',cname, 'ref=', c.ref) + + write = True + + for i in range(len(REMOVEDCOMPONENTS)): #Don't let these components be saved. + if cname == REMOVEDCOMPONENTS[i]: + write = False + break + #print('write->', write) + #print('line->', line) + if write: + c.type_ = c.type_ + nameAppend + c.print(flib) + + '''line = input_file.readline().strip() while(line != '' and '*symbol' not in line): line = input_file.readline().strip() print(line) ''' - - while(line != '__ERROR__'): - #print(input_file.tell()) - #print('Compo line',line) - d = line.find(' ') - cnametmp = line[d+1:] - #print('cnametmp',cnametmp) - d = cnametmp.find(' ') - if d == -1: - cname = cnametmp - else: - cname = cnametmp[0:d] - - #print('cname->',cname) - - fileTMP = open(sys.argv[fcounter]) - c = Component(fileTMP, cname) - #print(c.ref) - fixComp(c) - #print('After fixComp',cname, 'ref=', c.ref) - - write = True - - for i in range(len(REMOVEDCOMPONENTS)): #Don't let these components be saved. - if cname == REMOVEDCOMPONENTS[i]: - write = False - break - #print('write->', write) - #print('line->', line) - if write: - c.type_ = c.type_ + nameAppend - c.print(flib) - - '''line = input_file.readline().strip() - while(line != '' and '*symbol' not in line): - line = input_file.readline().strip() - print(line) - ''' - line = skipTo(input_file, '*symbol') - flib.write('#\n#End Library\n') - flib.close() + line = skipTo(input_file, '*symbol') +flib.write('#\n#End Library\n') +flib.close() diff --git a/src/frontEnd/ProjectExplorer.py b/src/frontEnd/ProjectExplorer.py index b91f162c..99772378 100755 --- a/src/frontEnd/ProjectExplorer.py +++ b/src/frontEnd/ProjectExplorer.py @@ -32,27 +32,29 @@ class ProjectExplorer(QtWidgets.QWidget): self.treewidget.setHeaderItem(header) self.treewidget.setColumnHidden(1, True) - # Apply dark theme to header and background to match 'Welcome' dock - self.treewidget.setStyleSheet(''' - QHeaderView::section { - background: qlineargradient(x1:0, y1:0, x2:1, y2:0, - stop:0 rgba(33, 37, 51, 0.95), stop:1 rgba(20, 25, 35, 0.9)); - color: #90caf9; /* Soft blue */ - font-weight: 700; - font-size: 17px; - border-radius: 0; - padding: 12px 0px 12px 18px; - letter-spacing: 0.5px; - - } - QTreeWidget { - background: qlineargradient(x1:0, y1:0, x2:0, y2:1, - stop:0 rgba(26, 29, 41, 0.98), stop:1 rgba(15, 20, 25, 0.95)); - color: #e8eaed; - border: 1px solid rgba(255, 255, 255, 0.12); - border-radius: 0 0 12px 12px; - } - ''') + # CSS + init_path = '../../' + if os.name == 'nt': + init_path = '' + + self.treewidget.setStyleSheet(" \ + QTreeView { border-radius: 15px; border: 1px \ + solid gray; padding: 5px; width: 200px; height: 150px; }\ + QTreeView::branch:has-siblings:!adjoins-item { \ + border-image: url(" + init_path + "images/vline.png) 0;} \ + QTreeView::branch:has-siblings:adjoins-item { \ + border-image: url(" + init_path + "images/branch-more.png) 0; } \ + QTreeView::branch:!has-children:!has-siblings:adjoins-item { \ + border-image: url(" + init_path + "images/branch-end.png) 0; } \ + QTreeView::branch:has-children:!has-siblings:closed, \ + QTreeView::branch:closed:has-children:has-siblings { \ + border-image: none; \ + image: url(" + init_path + "images/branch-closed.png); } \ + QTreeView::branch:open:has-children:!has-siblings, \ + QTreeView::branch:open:has-children:has-siblings { \ + border-image: none; \ + image: url(" + init_path + "images/branch-open.png); } \ + ") for parents, children in list( self.obj_appconfig.project_explorer.items()): diff --git a/src/ngspiceSimulation/NgspiceWidget.py b/src/ngspiceSimulation/NgspiceWidget.py index 518a1b91..6d8a9d74 100644 --- a/src/ngspiceSimulation/NgspiceWidget.py +++ b/src/ngspiceSimulation/NgspiceWidget.py @@ -188,30 +188,30 @@ class NgspiceWidget(QtWidgets.QWidget): def plotFlagFunc(self,projPath,command): if self.plotFlag == True: - print("reached here too") if os.name == 'nt': parser_nghdl = ConfigParser() - parser_nghdl.read( - os.path.join('library', 'config', '.nghdl', 'config.ini') - ) - + config_path = os.path.join('library', 'config', '.nghdl', 'config.ini') + parser_nghdl.read(config_path) msys_home = parser_nghdl.get('COMPILER', 'MSYS_HOME') - tempdir = os.getcwd() projPath = self.obj_appconfig.current_project["ProjectName"] os.chdir(projPath) - self.command = 'cmd /c ' + '"start /min ' + \ - msys_home + "/usr/bin/mintty.exe ngspice -p " + command + '"' + + self.command = ( + 'cmd /c "start /min ' + + msys_home + '/usr/bin/mintty.exe ngspice -p ' + command + '"' + ) + + # Create a new QProcess for mintty + self.minttyProcess = QtCore.QProcess(self) + self.minttyProcess.start(self.command) - self.process.start(self.command) os.chdir(tempdir) else: - print("reached .. 4") self.commandi = "cd " + projPath + \ ";ngspice -r " + command.replace(".cir.out", ".raw") + \ " " + command self.xtermArgs = ['-hold', '-e', self.commandi] - print("xTerm") self.xtermProcess = QtCore.QProcess(self) self.xtermProcess.start('xterm', self.xtermArgs) diff --git a/src/projManagement/Validation.py b/src/projManagement/Validation.py index 18b8a0aa..5f239163 100644 --- a/src/projManagement/Validation.py +++ b/src/projManagement/Validation.py @@ -61,8 +61,8 @@ class Validation: :projDir => Contains path of the new projDir created @return - :"CHECKEXIST" => If same project name folder exists - :"CHECKNAME" => If space is there in project name + :"CHECKEXIST" => If smae project name folder exists + :"CHECKNAME" => If space is there in name :"VALID" => If valid project name given """ print("Function: Validating New Project Information") @@ -72,9 +72,7 @@ class Validation: return "CHECKEXIST" # Project with name already exist else: # Check Proper name for project. It should not have space - # Extract only the project name (basename) from the full path - projName = os.path.basename(projDir) - if re.search(r"\s", projName): + if re.search(r"\s", projDir): return "CHECKNAME" else: return "VALID" diff --git a/src/projManagement/newProject.py b/src/projManagement/newProject.py index 2a443678..10fb0cb5 100644 --- a/src/projManagement/newProject.py +++ b/src/projManagement/newProject.py @@ -63,8 +63,8 @@ class NewProjectInfo(QtWidgets.QWidget): self.projName = projName self.workspace = self.obj_appconfig.default_workspace['workspace'] # self.projName = self.projEdit.text() - # Remove leading and trailing spaces AND replace internal spaces with underscores - self.projName = str(self.projName).strip().replace(" ", "_") + # Remove leading and trailing space + self.projName = str(self.projName).rstrip().lstrip() self.projDir = os.path.join(self.workspace, str(self.projName)) @@ -144,5 +144,5 @@ class NewProjectInfo(QtWidgets.QWidget): self.msg.exec_() return None, None -def cancelProject(self): - self.close() + def cancelProject(self): + self.close() |