Added binary file format
This commit is contained in:
@@ -14,7 +14,7 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from bedit.core.model import Component, Parameter
|
||||
from bedit.core.application_log import get_logger
|
||||
from bedit.core.serializer import JsonDocumentSerializer
|
||||
from bedit.core.serializer import DocumentSerializer
|
||||
from bedit.core.simulation import Simulation
|
||||
from bedit.gui.controllers.document import DocumentController
|
||||
from bedit.gui.dialogs.component_options import ComponentOptionsDialog
|
||||
@@ -407,7 +407,11 @@ class MainWindow(QMainWindow):
|
||||
if not self._resolve_source_edits() or not self._maybe_save():
|
||||
return
|
||||
filename, _ = QFileDialog.getOpenFileName(
|
||||
self, "Open graph", "", "BEdit graphs (*.bedit.json *.json);;All files (*)"
|
||||
self,
|
||||
"Open graph",
|
||||
"",
|
||||
"BEdit documents (*.bedit.json *.json *.beb);;"
|
||||
"BEdit JSON (*.bedit.json *.json);;BEdit Binary (*.beb);;All files (*)",
|
||||
)
|
||||
if not filename:
|
||||
return
|
||||
@@ -437,16 +441,21 @@ class MainWindow(QMainWindow):
|
||||
def save_document_as(self) -> bool:
|
||||
if self.document_controller.document is None:
|
||||
return False
|
||||
filename, _ = QFileDialog.getSaveFileName(
|
||||
filename, selected_filter = QFileDialog.getSaveFileName(
|
||||
self,
|
||||
"Save graph",
|
||||
"untitled.bedit.json",
|
||||
"BEdit graphs (*.bedit.json);;JSON files (*.json);;All files (*)",
|
||||
"untitled.beb",
|
||||
"BEdit Binary (*.beb);;BEdit JSON (*.bedit.json *.json);;All files (*)",
|
||||
)
|
||||
if not filename:
|
||||
return False
|
||||
path = Path(filename)
|
||||
if path.suffix.lower() not in {".json", ".beb"}:
|
||||
path = path.with_suffix(
|
||||
".beb" if "Binary" in selected_filter else ".bedit.json"
|
||||
)
|
||||
try:
|
||||
path = self.document_controller.save(Path(filename))
|
||||
path = self.document_controller.save(path)
|
||||
self.log.info("Saved document %s", path)
|
||||
except OSError as error:
|
||||
self.log.error("Could not save document %s: %s", filename, error)
|
||||
@@ -557,7 +566,7 @@ class MainWindow(QMainWindow):
|
||||
try:
|
||||
if library is not None:
|
||||
library.document.validate()
|
||||
JsonDocumentSerializer.save(library.document, Path(library.source_path))
|
||||
DocumentSerializer.save(library.document, Path(library.source_path))
|
||||
except (OSError, ValueError) as error:
|
||||
component.inputs, component.outputs = old_inputs, old_outputs
|
||||
self.log.error("Could not change library ports: %s", error)
|
||||
|
||||
Reference in New Issue
Block a user