Generating code from a validator + saving file
parent
ca878de953
commit
1fce5f2d69
|
@ -21,9 +21,11 @@ def change_font_size(label: QLabel | QLineEdit, factor: float) -> QLabel:
|
|||
|
||||
|
||||
class OptionsWidget(QWidget):
|
||||
def __init__(self):
|
||||
def __init__(self, parent: QWidget):
|
||||
super().__init__()
|
||||
|
||||
self.parent = parent
|
||||
|
||||
options = [("Buffs", "Some songs affect the characters with strengthen\nand haste afflictions."),
|
||||
("De-buffs", "Some songs affect the characters with psychosis \naffliction."),
|
||||
("Walkmans", "Include personal music players (walkmans)"),
|
||||
|
@ -112,9 +114,11 @@ class OptionsWidget(QWidget):
|
|||
|
||||
|
||||
class EditorWidget(QWidget):
|
||||
def __init__(self):
|
||||
def __init__(self, parent: QWidget):
|
||||
super().__init__()
|
||||
|
||||
self.parent = parent
|
||||
|
||||
self.tapes_yaml = Path("../source/tapes.yaml")
|
||||
self.filename_string = f"<tt style=\"font-family: consolas;\"><b>{self.tapes_yaml.name}</b></tt>"
|
||||
|
||||
|
@ -133,6 +137,7 @@ class EditorWidget(QWidget):
|
|||
self.save_code_pushbutton = QPushButton()
|
||||
self.save_code_pushbutton.setIcon(QIcon("./icons/ic_save_24px.svg"))
|
||||
self.save_code_pushbutton.setToolTip("Save setup")
|
||||
self.save_code_pushbutton.clicked.connect(self.save_file)
|
||||
self.transfer_to_validator_pushbutton = QPushButton()
|
||||
self.transfer_to_validator_pushbutton.setIcon(QIcon("./icons/ic_keyboard_double_arrow_right_24px.svg"))
|
||||
self.transfer_to_validator_pushbutton.setToolTip("Apply the code.")
|
||||
|
@ -175,6 +180,10 @@ class EditorWidget(QWidget):
|
|||
text = fp.read()
|
||||
self.editor.setPlainText(text)
|
||||
|
||||
def save_file(self):
|
||||
with open(self.tapes_yaml, "w+", encoding="utf-8") as fp:
|
||||
fp.write(self.editor.toPlainText())
|
||||
|
||||
def open_file(self):
|
||||
os.startfile(self.tapes_yaml)
|
||||
|
||||
|
@ -202,7 +211,6 @@ class EditorWidget(QWidget):
|
|||
|
||||
|
||||
class ProcessEditWidget(QWidget):
|
||||
# TODO: move process to another part in yaml
|
||||
def __init__(self, tape: dict):
|
||||
super().__init__()
|
||||
|
||||
|
@ -527,13 +535,16 @@ class TapeListWidget(QWidget):
|
|||
|
||||
|
||||
class ValidationWidget(QWidget):
|
||||
def __init__(self):
|
||||
def __init__(self, parent: QWidget):
|
||||
super().__init__()
|
||||
|
||||
self.parent = parent
|
||||
|
||||
self.tapes = self.load_tapes()
|
||||
self.transfer_to_code_pushbutton = QPushButton()
|
||||
self.transfer_to_code_pushbutton.setIcon(QIcon("./icons/ic_keyboard_double_arrow_left_24px.svg"))
|
||||
self.transfer_to_code_pushbutton.setToolTip("Update the code")
|
||||
self.transfer_to_code_pushbutton.clicked.connect(self.save_tapes)
|
||||
self.jump_spinbox = QSpinBox()
|
||||
#self.search_lineedit = QLineEdit()
|
||||
#self.search_lineedit.setPlaceholderText("Search ...")
|
||||
|
@ -571,12 +582,18 @@ class ValidationWidget(QWidget):
|
|||
self.setMinimumWidth(470)
|
||||
self.setMaximumWidth(470)
|
||||
|
||||
import tempfile
|
||||
|
||||
def load_tapes(self):
|
||||
with open("../source/tapes.yaml", encoding="utf-8") as fp:
|
||||
tapes = yaml.safe_load(fp)
|
||||
|
||||
return tapes
|
||||
|
||||
def save_tapes(self):
|
||||
yaml_text = yaml.safe_dump(self.tapes, sort_keys=False, allow_unicode=True).replace("\n-", "\n\n-")
|
||||
self.parent.editor_widget.editor.setPlainText(yaml_text)
|
||||
|
||||
def jump_to_tape(self, tape_number):
|
||||
scrollbar = self.scroll.verticalScrollBar()
|
||||
|
||||
|
@ -676,13 +693,13 @@ class MainWidget(QWidget):
|
|||
|
||||
layout = QHBoxLayout()
|
||||
|
||||
options = OptionsWidget()
|
||||
editor = EditorWidget()
|
||||
validation = ValidationWidget()
|
||||
self.options_widget = OptionsWidget(self)
|
||||
self.editor_widget = EditorWidget(self)
|
||||
self.validation_widget = ValidationWidget(self)
|
||||
# install = InstallWidget()
|
||||
layout.addWidget(options)
|
||||
layout.addWidget(editor)
|
||||
layout.addWidget(validation)
|
||||
layout.addWidget(self.options_widget)
|
||||
layout.addWidget(self.editor_widget)
|
||||
layout.addWidget(self.validation_widget)
|
||||
# layout.addWidget(install)
|
||||
|
||||
self.setLayout(layout)
|
||||
|
|
1984
source/tapes.yaml
1984
source/tapes.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue