applying yaml code to widget function works now

master
Jaka Perovšek 2024-10-05 11:41:07 +02:00
parent a3e6c32ae9
commit 3036478f1d
1 changed files with 23 additions and 10 deletions

View File

@ -228,8 +228,8 @@ class CodeEditorWidget(QWidget):
self.status_label.setText(self.status_editor_code_changed) self.status_label.setText(self.status_editor_code_changed)
def apply_code(self): def apply_code(self):
print("applying code") tapes = yaml.safe_load(self.editor.toPlainText())
pass self.parent.validation_widget.load_tapes(tapes)
class TapeEditWidget(QWidget): class TapeEditWidget(QWidget):
@ -289,6 +289,12 @@ class TapeListWidget(QWidget):
def append(self, widget): def append(self, widget):
self.layout.addWidget(widget) self.layout.addWidget(widget)
def clear(self):
for i, widget in enumerate(self.children()):
if i > 0:
self.layout.removeWidget(widget)
widget.deleteLater()
class ValidationWidget(QWidget): class ValidationWidget(QWidget):
def __init__(self, parent: QWidget): def __init__(self, parent: QWidget):
@ -296,7 +302,6 @@ class ValidationWidget(QWidget):
self.parent = parent self.parent = parent
self.tapes = self.load_tapes()
self.transfer_to_code_pushbutton = QPushButton() self.transfer_to_code_pushbutton = QPushButton()
self.transfer_to_code_pushbutton.setIcon(QIcon("./gui/icons/ic_keyboard_double_arrow_left_24px.svg")) self.transfer_to_code_pushbutton.setIcon(QIcon("./gui/icons/ic_keyboard_double_arrow_left_24px.svg"))
self.transfer_to_code_pushbutton.setToolTip("Update the code") self.transfer_to_code_pushbutton.setToolTip("Update the code")
@ -327,10 +332,6 @@ class ValidationWidget(QWidget):
self.validation_gbox = QGroupBox("Data validation") self.validation_gbox = QGroupBox("Data validation")
self.validation_gbox.setLayout(self.validation_vbox) self.validation_gbox.setLayout(self.validation_vbox)
for i, tape in enumerate(self.tapes):
self.tape_list_widget.append(TapeEditWidget(tape, i))
self.jump_spinbox.setMaximum(i)
self.jump_spinbox.valueChanged.connect(self.jump_to_tape) self.jump_spinbox.valueChanged.connect(self.jump_to_tape)
layout = QVBoxLayout(self) layout = QVBoxLayout(self)
@ -338,13 +339,25 @@ class ValidationWidget(QWidget):
self.setMinimumWidth(470) self.setMinimumWidth(470)
self.setMaximumWidth(470) self.setMaximumWidth(470)
import tempfile self.tapes = None
self.load_tapes_from_file()
def load_tapes(self): def load_tapes_from_file(self):
with open("./source/tapes.yaml", encoding="utf-8") as fp: with open("./source/tapes.yaml", encoding="utf-8") as fp:
tapes = yaml.safe_load(fp) tapes = yaml.safe_load(fp)
return tapes self.load_tapes(tapes)
def load_tapes(self, tapes):
self.tapes = tapes
self.tape_list_widget.clear()
for i, tape in enumerate(self.tapes):
self.tape_list_widget.append(TapeEditWidget(tape, i))
self.jump_spinbox.setValue(0)
self.jump_spinbox.setMaximum(i)
def save_tapes(self): def save_tapes(self):
yaml_text = yaml.safe_dump(self.tapes, sort_keys=False, allow_unicode=True).replace("\n-", "\n\n-") yaml_text = yaml.safe_dump(self.tapes, sort_keys=False, allow_unicode=True).replace("\n-", "\n\n-")