Skip to content

Commit

Permalink
implemented run
Browse files Browse the repository at this point in the history
  • Loading branch information
KylieGong committed Aug 22, 2023
1 parent 4ba295b commit 3e434d0
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions pyqt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from PyQt5 import QtCore, QtWidgets
import argparse
import re
import subprocess

class MainWindow(QtWidgets.QMainWindow):

Expand Down Expand Up @@ -58,9 +59,12 @@ def initUI(self):

def run(self):
contents = self.gatherData()
param = ""
for line in contents:
for key, value in line.items():
print(f"{key}={','.join(value)}")
param += f"{key}={value} "
print(param.split())
subprocess.run([self.param_file_type, self.param_file] + param.split())

def save(self):
contents = self.gatherData()
Expand All @@ -70,19 +74,7 @@ def save(self):
with open(file_path, "w") as file:
for line in contents:
for key, value in line.items():
if self.param_file_type == 'csh':
file.write("set ")

file.write(f"{key}=")

if self.param_file_type == 'py':
file.write('"')

file.write(f"{','.join(value)}")

if self.param_file_type == 'py':
file.write('"')

file.write(f"{key}={value}")
file.write("\n")
print("saved to " + file_path)

Expand All @@ -100,7 +92,7 @@ def load(self):
if self.param_file_type == 'csh':
line = re.sub("set","",line,count=1)
label, value = line.strip().split("=")
if value.startswith('"') and value.endswith('"'):
if value.startswith('"') and value.endswith('"') or value.startswith("'") and value.endswith("'"):
value = value[1:-1]
value = value.split(",") if "," in value else [value]
default_values[label] = value
Expand Down Expand Up @@ -269,27 +261,38 @@ def gatherData(self):

if widget_index == 0 and isinstance(widget, QtWidgets.QLabel):
key = widget.text().split(':')[0]
if self.param_file_type == "csh":
key = "set " + key
defaults[key] = []

elif isinstance(widget, QtWidgets.QLineEdit):
defaults[key].append(widget.text())
value = widget.text()
defaults[key].append(value)

elif isinstance(widget, QtWidgets.QRadioButton) or isinstance(widget, QtWidgets.QCheckBox):
if widget.isChecked():
defaults[key].append(widget.text())
value = widget.text()
defaults[key].append(value)

elif isinstance(widget, QtWidgets.QSlider):
multiplier = self.sliderMultiplier.pop(0)
defaults[key].append(str(widget.value()/multiplier))
value = str(widget.value()/multiplier)
defaults[key].append(value)
self.sliderMultiplier.append(multiplier)

values = defaults[key]
values = ','.join(values)

if self.param_file_type == "python":
defaults[key] = "'" + values + "'"
else:
defaults[key] = values
layout_data.append(defaults)
return layout_data

def parsefile(file):
filetype = "sh"
with open(file, "r") as f:
# content = file.read()
lines = f.readlines()

groups = []
Expand All @@ -306,13 +309,13 @@ def parsefile(file):
if match:
if match.group(1):
filetype = "csh"
group_type = match.group(5)
group_name = match.group(2)
group_type = match.group(5).strip()
group_name = match.group(2).strip()
default_option = match.group(3).strip()
#check for quotations
if default_option[0] == '"' and default_option[-1] == '"':
if (default_option[0] == '"' and default_option[-1] == '"') or (default_option[0] == "'" and default_option[-1] == "'"):
default_option = default_option[1:-1]
filetype = "py"
filetype = "python"
options = match.group(7).split(',') if match.group(7) else ""
help = match.group(4).split('#')[1].strip() if match.group(4) else ""
groups.append((group_type, group_name, options, default_option, help))
Expand Down

0 comments on commit 3e434d0

Please sign in to comment.