Skip to content

Commit

Permalink
feat: prompt save before submit (#53) (#69)
Browse files Browse the repository at this point in the history
* feat: prompt save before submit (#53)

Signed-off-by: dan <[email protected]>

* feat: prompt save before submit (#53)

Add _prompt_save_current_document() to warn user before submitting
unsaved changes.

Signed-off-by: dan <[email protected]>

* fix: document name bug in save prompt

Signed-off-by: dan <[email protected]>

* fix: short circuit if user cancels untitled document save

Signed-off-by: dan <[email protected]>

* fix: prompt scene save before _show_submitter()

Signed-off-by: dan <[email protected]>

* fix: handle corner case submitting untitled file

Signed-off-by: dan <[email protected]>

---------

Signed-off-by: dan <[email protected]>
Co-authored-by: Karthik Bekal Pattathana <[email protected]>
  • Loading branch information
gp-dan and karthikbekalp authored Oct 29, 2024
1 parent 817eb68 commit c1d463c
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions src/deadline/cinema4d_submitter/cinema4d_render_submitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class TakeData:


def show_submitter():

if _prompt_save_current_document() is False:
return

try:
app = QtWidgets.QApplication.instance()
if not app:
Expand Down Expand Up @@ -237,6 +241,50 @@ def _get_job_template(
return job_template


def _prompt_save_current_document():
doc = c4d.documents.GetActiveDocument()
if not doc.GetChanged():
# Document has no unsaved changes
return True
file_path = doc.GetDocumentPath()
file_name = doc.GetDocumentName()
save_path = None
if file_path:
# Document save path exists
save_path = os.path.join(file_path, file_name)
if not c4d.gui.QuestionDialog("Save scene changes before submission?"):
# User selected No
if not save_path:
c4d.gui.MessageDialog(
"Submission canceled. File must be saved to disk before submission."
)
return False
else:
return True
else:
if not save_path:
# Prompt with Save As to set path for Untitled document
save_path = c4d.storage.SaveDialog(c4d.FILESELECTTYPE_ANYTHING, "Save As", "c4d")
# Handle user cancels document save
if not save_path:
c4d.gui.MessageDialog(
"Submission canceled. File must be saved to disk before submission."
)
return False
# Set document path and name
doc_path = os.path.dirname(save_path)
base_name = os.path.basename(save_path)
doc.SetDocumentPath(doc_path)
doc.SetDocumentName(base_name)
# Save document to disk
c4d.documents.SaveDocument(doc, save_path, c4d.SAVEDOCUMENTFLAGS_0, c4d.FORMAT_C4DEXPORT)
# Ensure document is active
c4d.documents.InsertBaseDocument(doc)
# Update UI
c4d.EventAdd()
return True


def _show_submitter(parent=None, f=Qt.WindowFlags()):

render_settings = RenderSubmitterUISettings()
Expand Down

0 comments on commit c1d463c

Please sign in to comment.