Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/controller/file/showfile_dialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PySide6.QtWidgets import QFileDialog, QWidget

from controller.file.read import read_document
from controller.file.write import write_document
from controller.file.write import export_document, write_document
from model import BoardConfiguration


Expand Down Expand Up @@ -78,3 +78,13 @@ def show_load_showfile_dialog(parent: QWidget, show_data: BoardConfiguration) ->

"""
_select_file(parent, _load_show_file, False, show_data)

def open_show_export_dialog(parent: QWidget, show_data: BoardConfiguration) -> None:
"""Opens a dialog to export the provided show by fish in standalone mode."""
file_dialog = QFileDialog(parent, "Export Show")
file_dialog.setNameFilter("Fish Standalone Show (*.fs)")
file_dialog.setAcceptMode(QFileDialog.AcceptMode.AcceptSave)
file_dialog.setDefaultSuffix(".fs")
file_dialog.setDirectory(os.path.expanduser("~"))
file_dialog.fileSelected.connect(lambda file_name: export_document(file_name, show_data))
file_dialog.show()
32 changes: 30 additions & 2 deletions src/controller/file/write.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@

def write_document(file_name: str, show_data: BoardConfiguration) -> bool:
"""Writes the xml element to the specified file.

See https://github.com/Mission-DMX/Docs/blob/main/FormatSchemes/ProjectFile/ShowFile_v0.xsd for more information.

Args:
file_name: The (path and) file to which the xml element should be written.
show_data: The show to save
show_data: The show to save.

Returns:
True, if successfully, otherwise false with error message.

Returns: True, if successfully, otherwise false with error message.
"""
pn = get_process_notifier("Saving Showfile", 2)
xml = create_xml(show_data, pn)
Expand All @@ -42,3 +45,28 @@ def write_document(file_name: str, show_data: BoardConfiguration) -> bool:
# except IOError:
# print(f"Could not save {file_name}")
# return False


def export_document(file_name: str, show_data: BoardConfiguration) -> bool:
"""Exports the show data into a fish stand-alone show file.

Warning: This method will override existing files without warning.

Args:
file_name: The (path and) file to which the xml element should be written.
show_data: The show to save

Returns:
True, if successfully, otherwise false with error message.

"""
pn = get_process_notifier("Exporting Showfile", 2)
xml = create_xml(show_data, pn, assemble_for_fish_loading=True)
pn.current_step_description = "Writing to disk."
pn.current_step_number += 1
with open(file_name, "w+", encoding="UTF-8") as file:
ET.indent(xml)
file.write(ET.tostring(xml, encoding="unicode", method="xml"))
pn.current_step_number += 1
pn.close()
return True
9 changes: 8 additions & 1 deletion src/view/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@

import proto.RealTimeControl_pb2
import style
from controller.file.showfile_dialogs import _save_show_file, show_load_showfile_dialog, show_save_showfile_dialog
from controller.file.showfile_dialogs import (
_save_show_file,
open_show_export_dialog,
show_load_showfile_dialog,
show_save_showfile_dialog,
)
from controller.network import NetworkManager
from controller.utils.process_notifications import get_global_process_state, get_progress_changed_signal
from model.board_configuration import BoardConfiguration
Expand Down Expand Up @@ -194,6 +199,8 @@ def _setup_menubar(self) -> None:
("Save Showfile", self._save_show, "S"),
("&Save Showfile As", lambda: show_save_showfile_dialog(self, self._board_configuration), "Shift+S"),
("---", None, None),
("Export to Standalone", lambda: open_show_export_dialog(self, self._board_configuration), None),
("---", None, None),
("Settings", self.open_show_settings, ","),
],
"Edit": [
Expand Down
Loading