Skip to content

Commit

Permalink
Mark project as dirty on export
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed Dec 30, 2019
1 parent 005791d commit 46a50e0
Showing 1 changed file with 40 additions and 38 deletions.
78 changes: 40 additions & 38 deletions src/windows/export.py
Expand Up @@ -92,10 +92,10 @@ def __init__(self):
self.delayed_fps_timer.stop()

# Pause playback (to prevent crash since we are fixing to change the timeline's max size)
get_app().window.actionPlay_trigger(None, force="pause")
app.window.actionPlay_trigger(None, force="pause")

# Clear timeline preview cache (to get more available memory)
get_app().window.timeline_sync.timeline.ClearAllCache()
app.window.timeline_sync.timeline.ClearAllCache()

# Hide audio channels
self.lblChannels.setVisible(False)
Expand All @@ -106,12 +106,12 @@ def __init__(self):
openshot.Settings.Instance().HIGH_QUALITY_SCALING = True

# Get the original timeline settings
width = get_app().window.timeline_sync.timeline.info.width
height = get_app().window.timeline_sync.timeline.info.height
fps = get_app().window.timeline_sync.timeline.info.fps
sample_rate = get_app().window.timeline_sync.timeline.info.sample_rate
channels = get_app().window.timeline_sync.timeline.info.channels
channel_layout = get_app().window.timeline_sync.timeline.info.channel_layout
width = app.window.timeline_sync.timeline.info.width
height = app.window.timeline_sync.timeline.info.height
fps = app.window.timeline_sync.timeline.info.fps
sample_rate = app.window.timeline_sync.timeline.info.sample_rate
channels = app.window.timeline_sync.timeline.info.channels
channel_layout = app.window.timeline_sync.timeline.info.channel_layout

# No keyframe rescaling has happened yet (due to differences in FPS)
self.keyframes_rescaled = False
Expand All @@ -120,16 +120,16 @@ def __init__(self):
self.timeline = openshot.Timeline(width, height, openshot.Fraction(fps.num, fps.den),
sample_rate, channels, channel_layout)
# Init various properties
self.timeline.info.channel_layout = get_app().window.timeline_sync.timeline.info.channel_layout
self.timeline.info.has_audio = get_app().window.timeline_sync.timeline.info.has_audio
self.timeline.info.has_video = get_app().window.timeline_sync.timeline.info.has_video
self.timeline.info.video_length = get_app().window.timeline_sync.timeline.info.video_length
self.timeline.info.duration = get_app().window.timeline_sync.timeline.info.duration
self.timeline.info.sample_rate = get_app().window.timeline_sync.timeline.info.sample_rate
self.timeline.info.channels = get_app().window.timeline_sync.timeline.info.channels
self.timeline.info.channel_layout = app.window.timeline_sync.timeline.info.channel_layout
self.timeline.info.has_audio = app.window.timeline_sync.timeline.info.has_audio
self.timeline.info.has_video = app.window.timeline_sync.timeline.info.has_video
self.timeline.info.video_length = app.window.timeline_sync.timeline.info.video_length
self.timeline.info.duration = app.window.timeline_sync.timeline.info.duration
self.timeline.info.sample_rate = app.window.timeline_sync.timeline.info.sample_rate
self.timeline.info.channels = app.window.timeline_sync.timeline.info.channels

# Load the "export" Timeline reader with the JSON from the real timeline
json_timeline = json.dumps(get_app().project._data)
json_timeline = json.dumps(app.project._data)
self.timeline.SetJson(json_timeline)

# Open the "export" Timeline reader
Expand All @@ -140,7 +140,7 @@ def __init__(self):
if app.project.current_filepath:
recommended_path = os.path.dirname(app.project.current_filepath)

export_path = get_app().project.get("export_path")
export_path = app.project.get("export_path")
if export_path and os.path.exists(export_path):
# Use last selected export path
self.txtExportFolder.setText(export_path)
Expand All @@ -149,13 +149,13 @@ def __init__(self):
self.txtExportFolder.setText(recommended_path)

# Is this a saved project?
if not get_app().project.current_filepath:
if not app.project.current_filepath:
# Not saved yet
self.txtFileName.setText(_("Untitled Project"))
else:
# Yes, project is saved
# Get just the filename
filename = os.path.basename(get_app().project.current_filepath)
filename = os.path.basename(app.project.current_filepath)
filename = os.path.splitext(filename)[0]
self.txtFileName.setText(filename)

Expand Down Expand Up @@ -191,7 +191,7 @@ def __init__(self):
self.cboSimpleQuality.currentIndexChanged.connect(
functools.partial(self.cboSimpleQuality_index_changed, self.cboSimpleQuality))
self.cboChannelLayout.currentIndexChanged.connect(self.updateChannels)
get_app().window.ExportFrame.connect(self.updateProgressBar)
app.window.ExportFrame.connect(self.updateProgressBar)

# ********* Advanced Profile List **********
# Loop through profiles
Expand Down Expand Up @@ -614,8 +614,6 @@ def btnBrowse_clicked(self):

if os.path.exists(file_path):
self.txtExportFolder.setText(file_path)
# update export folder path in project file
app.updates.update_untracked(["export_path"], file_path)

def convert_to_bytes(self, BitRateString):
bit_rate_bytes = 0
Expand Down Expand Up @@ -690,7 +688,6 @@ def accept(self):
# Prompt error message
if self.txtStartFrame.value() == self.txtEndFrame.value():
msg = QMessageBox()
_ = get_app()._tr
msg.setWindowTitle(_("Export Error"))
msg.setText(_("Sorry, please select a valid range of frames to export"))
msg.exec_()
Expand Down Expand Up @@ -732,22 +729,23 @@ def accept(self):
export_file_path = os.path.join(self.txtExportFolder.text().strip() or default_folder, file_name_with_ext)
log.info("Invalid export path detected, changing to: %s" % export_file_path)

# Translate object
_ = get_app()._tr

file = File.get(path=export_file_path)
if file:
ret = QMessageBox.question(self, _("Export Video"), _("%s is an input file.\nPlease choose a different name.") % file_name_with_ext,
QMessageBox.Ok)
ret = QMessageBox.question(self,
_("Export Video"),
_("%s is an input file.\nPlease choose a different name.") % file_name_with_ext,
QMessageBox.Ok)
self.enableControls()
self.exporting = False
return

# Handle exception
if os.path.exists(export_file_path) and export_type in [_("Video & Audio"), _("Video Only"), _("Audio Only")]:
# File already exists! Prompt user
ret = QMessageBox.question(self, _("Export Video"), _("%s already exists.\nDo you want to replace it?") % file_name_with_ext,
QMessageBox.No | QMessageBox.Yes)
ret = QMessageBox.question(self,
_("Export Video"),
_("%s already exists.\nDo you want to replace it?") % file_name_with_ext,
QMessageBox.No | QMessageBox.Yes)
if ret == QMessageBox.No:
# Stop and don't do anything
# Re-enable controls
Expand Down Expand Up @@ -783,6 +781,11 @@ def accept(self):
else:
video_settings["vcodec"] = image_ext

# Store updated export folder path in project file
app.updates.update_untracked(["export_path"], os.path.dirname(export_file_path))
# Mark project file as unsaved
app.project.has_unsaved_changes = True

# Set MaxSize (so we don't have any downsampling)
self.timeline.SetMaxSize(video_settings.get("width"), video_settings.get("height"))

Expand All @@ -793,10 +796,10 @@ def accept(self):
# Rescale all keyframes and reload project
if self.export_fps_factor != 1.0:
self.keyframes_rescaled = True
get_app().project.rescale_keyframes(self.export_fps_factor)
app.project.rescale_keyframes(self.export_fps_factor)

# Load the "export" Timeline reader with the JSON from the real timeline
json_timeline = json.dumps(get_app().project._data)
json_timeline = json.dumps(app.project._data)
self.timeline.SetJson(json_timeline)

# Re-update the timeline FPS again (since the timeline just got clobbered)
Expand Down Expand Up @@ -847,7 +850,7 @@ def accept(self):

# Notify window of export started
title_message = ""
get_app().window.ExportStarted.emit(export_file_path, video_settings.get("start_frame"), video_settings.get("end_frame"))
app.window.ExportStarted.emit(export_file_path, video_settings.get("start_frame"), video_settings.get("end_frame"))

progressstep = max(1 , round(( video_settings.get("end_frame") - video_settings.get("start_frame") ) / 1000))
start_time_export = time.time()
Expand All @@ -868,7 +871,7 @@ def accept(self):
'fps': fps_encode}

# Emit frame exported
get_app().window.ExportFrame.emit(title_message, video_settings.get("start_frame"), video_settings.get("end_frame"), frame)
app.window.ExportFrame.emit(title_message, video_settings.get("start_frame"), video_settings.get("end_frame"), frame)

# Process events (to show the progress bar moving)
QCoreApplication.processEvents()
Expand All @@ -891,7 +894,7 @@ def accept(self):
'seconds': seconds_run % 60,
'fps': fps_encode}

get_app().window.ExportFrame.emit(title_message, video_settings.get("start_frame"),
app.window.ExportFrame.emit(title_message, video_settings.get("start_frame"),
video_settings.get("end_frame"), frame)

except Exception as e:
Expand Down Expand Up @@ -925,13 +928,12 @@ def accept(self):

# Prompt error message
msg = QMessageBox()
_ = get_app()._tr
msg.setWindowTitle(_("Export Error"))
msg.setText(_("Sorry, there was an error exporting your video: \n%s") % friendly_error)
msg.exec_()

# Notify window of export started
get_app().window.ExportEnded.emit(export_file_path)
app.window.ExportEnded.emit(export_file_path)

# Close timeline object
self.timeline.Close()
Expand All @@ -950,7 +952,7 @@ def accept(self):

# Return keyframes to preview scaling
if self.keyframes_rescaled:
get_app().project.rescale_keyframes(self.original_fps_factor)
app.project.rescale_keyframes(self.original_fps_factor)

# Handle end of export (for non-canceled exports)
if self.s.get("show_finished_window") and self.exporting:
Expand Down

0 comments on commit 46a50e0

Please sign in to comment.